Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: components/search_engines/template_url_prepopulate_data.cc

Issue 2347973002: Enable Chrome to tweak search engines for some locales (Closed)
Patch Set: final nits Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 // Cache first run Country ID value in prefs, and use it afterwards. This 608 // Cache first run Country ID value in prefs, and use it afterwards. This
609 // ensures that just because the user moves around, we won't automatically 609 // ensures that just because the user moves around, we won't automatically
610 // make major changes to their available search providers, which would feel 610 // make major changes to their available search providers, which would feel
611 // surprising. 611 // surprising.
612 if (!prefs->HasPrefPath(prefs::kCountryIDAtInstall)) { 612 if (!prefs->HasPrefPath(prefs::kCountryIDAtInstall)) {
613 prefs->SetInteger(prefs::kCountryIDAtInstall, GetCurrentCountryID()); 613 prefs->SetInteger(prefs::kCountryIDAtInstall, GetCurrentCountryID());
614 } 614 }
615 return prefs->GetInteger(prefs::kCountryIDAtInstall); 615 return prefs->GetInteger(prefs::kCountryIDAtInstall);
616 } 616 }
617 617
618 void GetPrepopulationSetFromCountryID(PrefService* prefs, 618 std::vector<std::unique_ptr<TemplateURLData>> GetPrepopulationSetFromCountryID(
619 const PrepopulatedEngine*** engines, 619 int country_id) {
620 size_t* num_engines) { 620 const PrepopulatedEngine** engines;
621 // NOTE: This function should ALWAYS set its outparams. 621 size_t num_engines;
622
623 // If you add a new country make sure to update the unit test for coverage. 622 // If you add a new country make sure to update the unit test for coverage.
624 switch (GetCountryIDFromPrefs(prefs)) { 623 switch (country_id) {
625
626 #define CHAR_A 'A' 624 #define CHAR_A 'A'
627 #define CHAR_B 'B' 625 #define CHAR_B 'B'
628 #define CHAR_C 'C' 626 #define CHAR_C 'C'
629 #define CHAR_D 'D' 627 #define CHAR_D 'D'
630 #define CHAR_E 'E' 628 #define CHAR_E 'E'
631 #define CHAR_F 'F' 629 #define CHAR_F 'F'
632 #define CHAR_G 'G' 630 #define CHAR_G 'G'
633 #define CHAR_H 'H' 631 #define CHAR_H 'H'
634 #define CHAR_I 'I' 632 #define CHAR_I 'I'
635 #define CHAR_J 'J' 633 #define CHAR_J 'J'
(...skipping 13 matching lines...) Expand all
649 #define CHAR_X 'X' 647 #define CHAR_X 'X'
650 #define CHAR_Y 'Y' 648 #define CHAR_Y 'Y'
651 #define CHAR_Z 'Z' 649 #define CHAR_Z 'Z'
652 #define CHAR(ch) CHAR_##ch 650 #define CHAR(ch) CHAR_##ch
653 #define CODE_TO_ID(code1, code2)\ 651 #define CODE_TO_ID(code1, code2)\
654 (CHAR(code1) << 8 | CHAR(code2)) 652 (CHAR(code1) << 8 | CHAR(code2))
655 653
656 #define UNHANDLED_COUNTRY(code1, code2)\ 654 #define UNHANDLED_COUNTRY(code1, code2)\
657 case CODE_TO_ID(code1, code2): 655 case CODE_TO_ID(code1, code2):
658 #define END_UNHANDLED_COUNTRIES(code1, code2)\ 656 #define END_UNHANDLED_COUNTRIES(code1, code2)\
659 *engines = engines_##code1##code2;\ 657 engines = engines_##code1##code2;\
660 *num_engines = arraysize(engines_##code1##code2);\ 658 num_engines = arraysize(engines_##code1##code2);\
661 return; 659 break;
662 #define DECLARE_COUNTRY(code1, code2)\ 660 #define DECLARE_COUNTRY(code1, code2)\
663 UNHANDLED_COUNTRY(code1, code2)\ 661 UNHANDLED_COUNTRY(code1, code2)\
664 END_UNHANDLED_COUNTRIES(code1, code2) 662 END_UNHANDLED_COUNTRIES(code1, code2)
665 663
666 // Countries with their own, dedicated engine set. 664 // Countries with their own, dedicated engine set.
667 DECLARE_COUNTRY(A, E) // United Arab Emirates 665 DECLARE_COUNTRY(A, E) // United Arab Emirates
668 DECLARE_COUNTRY(A, L) // Albania 666 DECLARE_COUNTRY(A, L) // Albania
669 DECLARE_COUNTRY(A, R) // Argentina 667 DECLARE_COUNTRY(A, R) // Argentina
670 DECLARE_COUNTRY(A, T) // Austria 668 DECLARE_COUNTRY(A, T) // Austria
671 DECLARE_COUNTRY(A, U) // Australia 669 DECLARE_COUNTRY(A, U) // Australia
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 UNHANDLED_COUNTRY(T, V) // Tuvalu 962 UNHANDLED_COUNTRY(T, V) // Tuvalu
965 UNHANDLED_COUNTRY(U, G) // Uganda 963 UNHANDLED_COUNTRY(U, G) // Uganda
966 UNHANDLED_COUNTRY(V, C) // Saint Vincent and the Grenadines 964 UNHANDLED_COUNTRY(V, C) // Saint Vincent and the Grenadines
967 UNHANDLED_COUNTRY(V, U) // Vanuatu 965 UNHANDLED_COUNTRY(V, U) // Vanuatu
968 UNHANDLED_COUNTRY(W, S) // Samoa 966 UNHANDLED_COUNTRY(W, S) // Samoa
969 UNHANDLED_COUNTRY(Z, M) // Zambia 967 UNHANDLED_COUNTRY(Z, M) // Zambia
970 case kCountryIDUnknown: 968 case kCountryIDUnknown:
971 default: // Unhandled location 969 default: // Unhandled location
972 END_UNHANDLED_COUNTRIES(def, ault) 970 END_UNHANDLED_COUNTRIES(def, ault)
973 } 971 }
972
973 std::vector<std::unique_ptr<TemplateURLData>> t_urls;
974 for (size_t i = 0; i < num_engines; ++i)
975 t_urls.push_back(MakeTemplateURLDataFromPrepopulatedEngine(*engines[i]));
976 return t_urls;
974 } 977 }
975 978
976 std::unique_ptr<TemplateURLData> MakePrepopulatedTemplateURLData( 979 std::unique_ptr<TemplateURLData> MakePrepopulatedTemplateURLData(
977 const base::string16& name, 980 const base::string16& name,
978 const base::string16& keyword, 981 const base::string16& keyword,
979 const base::StringPiece& search_url, 982 const base::StringPiece& search_url,
980 const base::StringPiece& suggest_url, 983 const base::StringPiece& suggest_url,
981 const base::StringPiece& instant_url, 984 const base::StringPiece& instant_url,
982 const base::StringPiece& image_url, 985 const base::StringPiece& image_url,
983 const base::StringPiece& new_tab_url, 986 const base::StringPiece& new_tab_url,
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1114 PrefService* prefs, 1117 PrefService* prefs,
1115 size_t* default_search_provider_index) { 1118 size_t* default_search_provider_index) {
1116 // If there is a set of search engines in the preferences file, it overrides 1119 // If there is a set of search engines in the preferences file, it overrides
1117 // the built-in set. 1120 // the built-in set.
1118 *default_search_provider_index = 0; 1121 *default_search_provider_index = 0;
1119 std::vector<std::unique_ptr<TemplateURLData>> t_urls = 1122 std::vector<std::unique_ptr<TemplateURLData>> t_urls =
1120 GetPrepopulatedTemplateURLData(prefs); 1123 GetPrepopulatedTemplateURLData(prefs);
1121 if (!t_urls.empty()) 1124 if (!t_urls.empty())
1122 return t_urls; 1125 return t_urls;
1123 1126
1124 const PrepopulatedEngine** engines; 1127 return GetPrepopulationSetFromCountryID(GetCountryIDFromPrefs(prefs));
1125 size_t num_engines; 1128 }
1126 GetPrepopulationSetFromCountryID(prefs, &engines, &num_engines); 1129
1127 for (size_t i = 0; i != num_engines; ++i) { 1130 #if defined(OS_ANDROID)
1128 t_urls.push_back(MakeTemplateURLDataFromPrepopulatedEngine(*engines[i])); 1131 std::vector<std::unique_ptr<TemplateURLData>> GetLocalPrepopulatedEngines(
1132 const std::string& locale,
1133 PrefService* prefs) {
1134 int country_id = CountryStringToCountryID(locale);
1135 if (country_id == kCountryIDUnknown ||
1136 country_id == GetCountryIDFromPrefs(prefs)) {
1137 return std::vector<std::unique_ptr<TemplateURLData>>();
1129 } 1138 }
1130 return t_urls; 1139
1140 return GetPrepopulationSetFromCountryID(country_id);
Alexander Yashkin 2016/10/21 06:34:41 Is it ok, that GetLocalPrepopulatedEngines returns
Peter Kasting 2016/10/21 06:44:42 What do you mean "is it OK"? This is a utility fu
1131 } 1141 }
1142 #endif
1132 1143
1133 std::vector<const PrepopulatedEngine*> GetAllPrepopulatedEngines() { 1144 std::vector<const PrepopulatedEngine*> GetAllPrepopulatedEngines() {
1134 return std::vector<const PrepopulatedEngine*>(std::begin(kAllEngines), 1145 return std::vector<const PrepopulatedEngine*>(std::begin(kAllEngines),
1135 std::end(kAllEngines)); 1146 std::end(kAllEngines));
1136 } 1147 }
1137 1148
1138 std::unique_ptr<TemplateURLData> MakeTemplateURLDataFromPrepopulatedEngine( 1149 std::unique_ptr<TemplateURLData> MakeTemplateURLDataFromPrepopulatedEngine(
1139 const PrepopulatedEngine& engine) { 1150 const PrepopulatedEngine& engine) {
1140 base::ListValue alternate_urls; 1151 base::ListValue alternate_urls;
1141 if (engine.alternate_urls) { 1152 if (engine.alternate_urls) {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1251 locale_str.erase(0, territory_delim + 1); 1262 locale_str.erase(0, territory_delim + 1);
1252 1263
1253 // Next remove any codeset/modifier portion and uppercase. 1264 // Next remove any codeset/modifier portion and uppercase.
1254 return CountryStringToCountryID( 1265 return CountryStringToCountryID(
1255 base::ToUpperASCII(locale_str.substr(0, locale_str.find_first_of(".@")))); 1266 base::ToUpperASCII(locale_str.substr(0, locale_str.find_first_of(".@"))));
1256 } 1267 }
1257 1268
1258 #endif // OS_* 1269 #endif // OS_*
1259 1270
1260 } // namespace TemplateURLPrepopulateData 1271 } // namespace TemplateURLPrepopulateData
OLDNEW
« no previous file with comments | « components/search_engines/template_url_prepopulate_data.h ('k') | components/search_engines/template_url_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698