OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/search_engines/template_url_prepopulate_data.h" | 5 #include "components/search_engines/template_url_prepopulate_data.h" |
6 | 6 |
7 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 7 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
8 #include <locale.h> | 8 #include <locale.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 } | 530 } |
531 | 531 |
532 // SPECIAL CASE: Timor-Leste changed from 'TP' to 'TL' in 2002. Windows XP | 532 // SPECIAL CASE: Timor-Leste changed from 'TP' to 'TL' in 2002. Windows XP |
533 // predates this; we therefore map this value. | 533 // predates this; we therefore map this value. |
534 if (c1 == 'T' && c2 == 'P') | 534 if (c1 == 'T' && c2 == 'P') |
535 c2 = 'L'; | 535 c2 = 'L'; |
536 | 536 |
537 return CountryCharsToCountryID(c1, c2); | 537 return CountryCharsToCountryID(c1, c2); |
538 } | 538 } |
539 | 539 |
| 540 #if !defined(OS_WIN) && !defined(OS_MACOSX) |
| 541 |
540 int CountryStringToCountryID(const std::string& country) { | 542 int CountryStringToCountryID(const std::string& country) { |
541 return (country.length() == 2) | 543 return (country.length() == 2) |
542 ? CountryCharsToCountryIDWithUpdate(country[0], country[1]) | 544 ? CountryCharsToCountryIDWithUpdate(country[0], country[1]) |
543 : kCountryIDUnknown; | 545 : kCountryIDUnknown; |
544 } | 546 } |
545 | 547 |
| 548 #endif |
| 549 |
546 #if defined(OS_WIN) | 550 #if defined(OS_WIN) |
547 | 551 |
548 // For reference, a list of GeoIDs can be found at | 552 // For reference, a list of GeoIDs can be found at |
549 // http://msdn.microsoft.com/en-us/library/dd374073.aspx . | 553 // http://msdn.microsoft.com/en-us/library/dd374073.aspx . |
550 int GeoIDToCountryID(GEOID geo_id) { | 554 int GeoIDToCountryID(GEOID geo_id) { |
551 const int kISOBufferSize = 3; // Two plus one for the terminator. | 555 const int kISOBufferSize = 3; // Two plus one for the terminator. |
552 wchar_t isobuf[kISOBufferSize] = { 0 }; | 556 wchar_t isobuf[kISOBufferSize] = { 0 }; |
553 int retval = GetGeoInfo(geo_id, GEO_ISO2, isobuf, kISOBufferSize, 0); | 557 int retval = GetGeoInfo(geo_id, GEO_ISO2, isobuf, kISOBufferSize, 0); |
554 | 558 |
555 if (retval == kISOBufferSize && | 559 if (retval == kISOBufferSize && |
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1031 *default_search_provider_index = 0; | 1035 *default_search_provider_index = 0; |
1032 std::vector<std::unique_ptr<TemplateURLData>> t_urls = | 1036 std::vector<std::unique_ptr<TemplateURLData>> t_urls = |
1033 GetPrepopulatedTemplateURLData(prefs); | 1037 GetPrepopulatedTemplateURLData(prefs); |
1034 if (!t_urls.empty()) | 1038 if (!t_urls.empty()) |
1035 return t_urls; | 1039 return t_urls; |
1036 | 1040 |
1037 return GetPrepopulationSetFromCountryID(GetCountryIDFromPrefs(prefs)); | 1041 return GetPrepopulationSetFromCountryID(GetCountryIDFromPrefs(prefs)); |
1038 } | 1042 } |
1039 | 1043 |
1040 #if defined(OS_ANDROID) | 1044 #if defined(OS_ANDROID) |
| 1045 |
1041 std::vector<std::unique_ptr<TemplateURLData>> GetLocalPrepopulatedEngines( | 1046 std::vector<std::unique_ptr<TemplateURLData>> GetLocalPrepopulatedEngines( |
1042 const std::string& locale, | 1047 const std::string& locale, |
1043 PrefService* prefs) { | 1048 PrefService* prefs) { |
1044 int country_id = CountryStringToCountryID(locale); | 1049 int country_id = CountryStringToCountryID(locale); |
1045 if (country_id == kCountryIDUnknown || | 1050 if (country_id == kCountryIDUnknown || |
1046 country_id == GetCountryIDFromPrefs(prefs)) { | 1051 country_id == GetCountryIDFromPrefs(prefs)) { |
1047 return std::vector<std::unique_ptr<TemplateURLData>>(); | 1052 return std::vector<std::unique_ptr<TemplateURLData>>(); |
1048 } | 1053 } |
1049 | 1054 |
1050 return GetPrepopulationSetFromCountryID(country_id); | 1055 return GetPrepopulationSetFromCountryID(country_id); |
1051 } | 1056 } |
| 1057 |
1052 #endif | 1058 #endif |
1053 | 1059 |
1054 std::vector<const PrepopulatedEngine*> GetAllPrepopulatedEngines() { | 1060 std::vector<const PrepopulatedEngine*> GetAllPrepopulatedEngines() { |
1055 return std::vector<const PrepopulatedEngine*>(std::begin(kAllEngines), | 1061 return std::vector<const PrepopulatedEngine*>(std::begin(kAllEngines), |
1056 std::end(kAllEngines)); | 1062 std::end(kAllEngines)); |
1057 } | 1063 } |
1058 | 1064 |
1059 void ClearPrepopulatedEnginesInPrefs(PrefService* prefs) { | 1065 void ClearPrepopulatedEnginesInPrefs(PrefService* prefs) { |
1060 if (!prefs) | 1066 if (!prefs) |
1061 return; | 1067 return; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1154 locale_str.erase(0, territory_delim + 1); | 1160 locale_str.erase(0, territory_delim + 1); |
1155 | 1161 |
1156 // Next remove any codeset/modifier portion and uppercase. | 1162 // Next remove any codeset/modifier portion and uppercase. |
1157 return CountryStringToCountryID( | 1163 return CountryStringToCountryID( |
1158 base::ToUpperASCII(locale_str.substr(0, locale_str.find_first_of(".@")))); | 1164 base::ToUpperASCII(locale_str.substr(0, locale_str.find_first_of(".@")))); |
1159 } | 1165 } |
1160 | 1166 |
1161 #endif // OS_* | 1167 #endif // OS_* |
1162 | 1168 |
1163 } // namespace TemplateURLPrepopulateData | 1169 } // namespace TemplateURLPrepopulateData |
OLD | NEW |