country_codes.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. // Please refer to ISO 3166-1 for information about the two-character country
  5. // codes; http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 is useful. In the
  6. // following (C++) code, we pack the two letters of the country code into an int
  7. // value we call the CountryID.
  8. #ifndef COMPONENTS_COUNTRY_CODES_COUNTRY_CODES_H_
  9. #define COMPONENTS_COUNTRY_CODES_COUNTRY_CODES_H_
  10. #include <string>
  11. class PrefRegistrySimple;
  12. class PrefService;
  13. namespace country_codes {
  14. // Integer containing the system Country ID the first time we checked the
  15. // template URL prepopulate data. This is used to avoid adding a whole bunch of
  16. // new search engine choices if prepopulation runs when the user's Country ID
  17. // differs from their previous Country ID. This pref does not exist until
  18. // prepopulation has been run at least once.
  19. extern const char kCountryIDAtInstall[];
  20. const int kCountryIDUnknown = -1;
  21. // Takes in each of the two characters of a ISO 3166-1 country code, and
  22. // converts it into an int value to be used as a reference to that country.
  23. constexpr int CountryCharsToCountryID(char c1, char c2) {
  24. return c1 << 8 | c2;
  25. }
  26. void RegisterProfilePrefs(PrefRegistrySimple* registry);
  27. // Returns the identifier for the user current country.
  28. int GetCurrentCountryID();
  29. // Converts a two-letter country code to an integer-based country identifier.
  30. int CountryStringToCountryID(const std::string& country);
  31. // Returns the country identifier that was stored at install. If no such pref
  32. // is available, it will return identifier of the current country instead.
  33. int GetCountryIDFromPrefs(PrefService* prefs);
  34. } // namespace country_codes
  35. #endif // COMPONENTS_COUNTRY_CODES_COUNTRY_CODES_H_