Chromium Code Reviews| Index: components/search_engines/template_url_prepopulate_data.cc |
| diff --git a/components/search_engines/template_url_prepopulate_data.cc b/components/search_engines/template_url_prepopulate_data.cc |
| index e66a22f4cc76dd3791e07b34c0ac3660ee48989f..1f93c947e7a405919782f147ace2632de94c0730 100644 |
| --- a/components/search_engines/template_url_prepopulate_data.cc |
| +++ b/components/search_engines/template_url_prepopulate_data.cc |
| @@ -536,128 +536,6 @@ int CountryCharsToCountryIDWithUpdate(char c1, char c2) { |
| return CountryCharsToCountryID(c1, c2); |
| } |
| -#if defined(OS_WIN) |
| - |
| -// For reference, a list of GeoIDs can be found at |
| -// http://msdn.microsoft.com/en-us/library/dd374073.aspx . |
| -int GeoIDToCountryID(GEOID geo_id) { |
| - const int kISOBufferSize = 3; // Two plus one for the terminator. |
| - wchar_t isobuf[kISOBufferSize] = { 0 }; |
| - int retval = GetGeoInfo(geo_id, GEO_ISO2, isobuf, kISOBufferSize, 0); |
| - |
| - if (retval == kISOBufferSize && |
| - !(isobuf[0] == L'X' && isobuf[1] == L'X')) |
| - return CountryCharsToCountryIDWithUpdate(static_cast<char>(isobuf[0]), |
| - static_cast<char>(isobuf[1])); |
| - |
| - // Various locations have ISO codes that Windows does not return. |
| - switch (geo_id) { |
| - case 0x144: // Guernsey |
| - return CountryCharsToCountryID('G', 'G'); |
| - case 0x148: // Jersey |
| - return CountryCharsToCountryID('J', 'E'); |
| - case 0x3B16: // Isle of Man |
| - return CountryCharsToCountryID('I', 'M'); |
| - |
| - // 'UM' (U.S. Minor Outlying Islands) |
| - case 0x7F: // Johnston Atoll |
| - case 0x102: // Wake Island |
| - case 0x131: // Baker Island |
| - case 0x146: // Howland Island |
| - case 0x147: // Jarvis Island |
| - case 0x149: // Kingman Reef |
| - case 0x152: // Palmyra Atoll |
| - case 0x52FA: // Midway Islands |
| - return CountryCharsToCountryID('U', 'M'); |
| - |
| - // 'SH' (Saint Helena) |
| - case 0x12F: // Ascension Island |
| - case 0x15C: // Tristan da Cunha |
| - return CountryCharsToCountryID('S', 'H'); |
| - |
| - // 'IO' (British Indian Ocean Territory) |
| - case 0x13A: // Diego Garcia |
| - return CountryCharsToCountryID('I', 'O'); |
| - |
| - // Other cases where there is no ISO country code; we assign countries that |
| - // can serve as reasonable defaults. |
| - case 0x154: // Rota Island |
| - case 0x155: // Saipan |
| - case 0x15A: // Tinian Island |
| - return CountryCharsToCountryID('U', 'S'); |
| - case 0x134: // Channel Islands |
| - return CountryCharsToCountryID('G', 'B'); |
| - case 0x143: // Guantanamo Bay |
| - default: |
| - return kCountryIDUnknown; |
| - } |
| -} |
| - |
| -int GetCurrentCountryID() { |
| - GEOID geo_id = GetUserGeoID(GEOCLASS_NATION); |
| - |
| - return GeoIDToCountryID(geo_id); |
| -} |
| - |
| -#elif defined(OS_MACOSX) |
| - |
| -int GetCurrentCountryID() { |
| - base::ScopedCFTypeRef<CFLocaleRef> locale(CFLocaleCopyCurrent()); |
| - CFStringRef country = (CFStringRef)CFLocaleGetValue(locale.get(), |
| - kCFLocaleCountryCode); |
| - if (!country) |
| - return kCountryIDUnknown; |
| - |
| - UniChar isobuf[2]; |
| - CFRange char_range = CFRangeMake(0, 2); |
| - CFStringGetCharacters(country, char_range, isobuf); |
| - |
| - return CountryCharsToCountryIDWithUpdate(static_cast<char>(isobuf[0]), |
| - static_cast<char>(isobuf[1])); |
| -} |
| - |
| -#elif defined(OS_ANDROID) |
| - |
| -int GetCurrentCountryID() { |
| - const std::string& country_code = base::android::GetDefaultCountryCode(); |
| - return (country_code.size() == 2) ? |
| - CountryCharsToCountryIDWithUpdate(country_code[0], country_code[1]) : |
| - kCountryIDUnknown; |
| -} |
| - |
| -#elif defined(OS_POSIX) |
| - |
| -int GetCurrentCountryID() { |
| - const char* locale = setlocale(LC_MESSAGES, NULL); |
| - |
| - if (!locale) |
| - return kCountryIDUnknown; |
| - |
| - // The format of a locale name is: |
| - // language[_territory][.codeset][@modifier], where territory is an ISO 3166 |
| - // country code, which is what we want. |
| - std::string locale_str(locale); |
| - size_t begin = locale_str.find('_'); |
| - if (begin == std::string::npos || locale_str.size() - begin < 3) |
| - return kCountryIDUnknown; |
| - |
| - ++begin; |
| - size_t end = locale_str.find_first_of(".@", begin); |
| - if (end == std::string::npos) |
| - end = locale_str.size(); |
| - |
| - // The territory part must contain exactly two characters. |
| - if (end - begin == 2) { |
| - return CountryCharsToCountryIDWithUpdate( |
| - base::ToUpperASCII(locale_str[begin]), |
| - base::ToUpperASCII(locale_str[begin + 1])); |
| - } |
| - |
| - return kCountryIDUnknown; |
| -} |
| - |
| -#endif // OS_* |
| - |
| int GetCountryIDFromPrefs(PrefService* prefs) { |
| if (!prefs) |
| return GetCurrentCountryID(); |
| @@ -1180,6 +1058,131 @@ bool SameDomain(const GURL& given_url, const GURL& prepopulated_url) { |
| } // namespace |
| +#if defined(OS_WIN) |
| + |
| +namespace { |
| + |
| +// For reference, a list of GeoIDs can be found at |
| +// http://msdn.microsoft.com/en-us/library/dd374073.aspx . |
| +int GeoIDToCountryID(GEOID geo_id) { |
|
Peter Kasting
2015/05/18 18:31:34
Nit: Leave this function (still #if'd) where it us
sdefresne
2015/05/19 09:04:22
Done.
|
| + const int kISOBufferSize = 3; // Two plus one for the terminator. |
| + wchar_t isobuf[kISOBufferSize] = { 0 }; |
| + int retval = GetGeoInfo(geo_id, GEO_ISO2, isobuf, kISOBufferSize, 0); |
| + |
| + if (retval == kISOBufferSize && |
| + !(isobuf[0] == L'X' && isobuf[1] == L'X')) |
| + return CountryCharsToCountryIDWithUpdate(static_cast<char>(isobuf[0]), |
| + static_cast<char>(isobuf[1])); |
| + |
| + // Various locations have ISO codes that Windows does not return. |
| + switch (geo_id) { |
| + case 0x144: // Guernsey |
| + return CountryCharsToCountryID('G', 'G'); |
| + case 0x148: // Jersey |
| + return CountryCharsToCountryID('J', 'E'); |
| + case 0x3B16: // Isle of Man |
| + return CountryCharsToCountryID('I', 'M'); |
| + |
| + // 'UM' (U.S. Minor Outlying Islands) |
| + case 0x7F: // Johnston Atoll |
| + case 0x102: // Wake Island |
| + case 0x131: // Baker Island |
| + case 0x146: // Howland Island |
| + case 0x147: // Jarvis Island |
| + case 0x149: // Kingman Reef |
| + case 0x152: // Palmyra Atoll |
| + case 0x52FA: // Midway Islands |
| + return CountryCharsToCountryID('U', 'M'); |
| + |
| + // 'SH' (Saint Helena) |
| + case 0x12F: // Ascension Island |
| + case 0x15C: // Tristan da Cunha |
| + return CountryCharsToCountryID('S', 'H'); |
| + |
| + // 'IO' (British Indian Ocean Territory) |
| + case 0x13A: // Diego Garcia |
| + return CountryCharsToCountryID('I', 'O'); |
| + |
| + // Other cases where there is no ISO country code; we assign countries that |
| + // can serve as reasonable defaults. |
| + case 0x154: // Rota Island |
| + case 0x155: // Saipan |
| + case 0x15A: // Tinian Island |
| + return CountryCharsToCountryID('U', 'S'); |
| + case 0x134: // Channel Islands |
| + return CountryCharsToCountryID('G', 'B'); |
| + case 0x143: // Guantanamo Bay |
| + default: |
| + return kCountryIDUnknown; |
| + } |
| +} |
| + |
| +} // namespace |
| + |
| +int GetCurrentCountryID() { |
| + GEOID geo_id = GetUserGeoID(GEOCLASS_NATION); |
| + |
| + return GeoIDToCountryID(geo_id); |
| +} |
| + |
| +#elif defined(OS_MACOSX) |
| + |
| +int GetCurrentCountryID() { |
| + base::ScopedCFTypeRef<CFLocaleRef> locale(CFLocaleCopyCurrent()); |
| + CFStringRef country = (CFStringRef)CFLocaleGetValue(locale.get(), |
| + kCFLocaleCountryCode); |
| + if (!country) |
| + return kCountryIDUnknown; |
| + |
| + UniChar isobuf[2]; |
| + CFRange char_range = CFRangeMake(0, 2); |
| + CFStringGetCharacters(country, char_range, isobuf); |
| + |
| + return CountryCharsToCountryIDWithUpdate(static_cast<char>(isobuf[0]), |
| + static_cast<char>(isobuf[1])); |
| +} |
| + |
| +#elif defined(OS_ANDROID) |
| + |
| +int GetCurrentCountryID() { |
| + const std::string& country_code = base::android::GetDefaultCountryCode(); |
| + return (country_code.size() == 2) ? |
| + CountryCharsToCountryIDWithUpdate(country_code[0], country_code[1]) : |
| + kCountryIDUnknown; |
| +} |
| + |
| +#elif defined(OS_POSIX) |
| + |
| +int GetCurrentCountryID() { |
| + const char* locale = setlocale(LC_MESSAGES, NULL); |
| + |
| + if (!locale) |
| + return kCountryIDUnknown; |
| + |
| + // The format of a locale name is: |
| + // language[_territory][.codeset][@modifier], where territory is an ISO 3166 |
| + // country code, which is what we want. |
| + std::string locale_str(locale); |
| + size_t begin = locale_str.find('_'); |
| + if (begin == std::string::npos || locale_str.size() - begin < 3) |
| + return kCountryIDUnknown; |
| + |
| + ++begin; |
| + size_t end = locale_str.find_first_of(".@", begin); |
| + if (end == std::string::npos) |
| + end = locale_str.size(); |
| + |
| + // The territory part must contain exactly two characters. |
| + if (end - begin == 2) { |
| + return CountryCharsToCountryIDWithUpdate( |
| + base::ToUpperASCII(locale_str[begin]), |
| + base::ToUpperASCII(locale_str[begin + 1])); |
| + } |
| + |
| + return kCountryIDUnknown; |
| +} |
| + |
| +#endif // OS_* |
| // Global functions ----------------------------------------------------------- |