1 // Copyright 2014 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/search_engines/template_url_prepopulate_data.h"
7 #include "base/logging.h"
8 #include "base/ranges/algorithm.h"
9 #include "build/build_config.h"
10 #include "components/country_codes/country_codes.h"
11 #include "components/pref_registry/pref_registry_syncable.h"
12 #include "components/prefs/pref_service.h"
13 #include "components/search_engines/prepopulated_engines.h"
14 #include "components/search_engines/search_engines_pref_names.h"
15 #include "components/search_engines/template_url_data.h"
16 #include "components/search_engines/template_url_data_util.h"
18 namespace TemplateURLPrepopulateData {
20 // Helpers --------------------------------------------------------------------
23 // NOTE: You should probably not change the data in this file without changing
24 // |kCurrentDataVersion| in prepopulated_engines.json. See comments in
25 // GetDataVersion() below!
27 // Put the engines within each country in order with most interesting/important
28 // first. The default will be the first engine.
30 // Default (for countries with no better engine set)
31 const PrepopulatedEngine* const engines_default[] = {
37 // Note, the below entries are sorted by country code, not the name in comment.
38 // Engine selection by country ------------------------------------------------
40 // United Arab Emirates
41 const PrepopulatedEngine* const engines_AE[] = {
50 const PrepopulatedEngine* const engines_AL[] = {
59 const PrepopulatedEngine* const engines_AR[] = {
68 const PrepopulatedEngine* const engines_AT[] = {
77 const PrepopulatedEngine* const engines_AU[] = {
85 // Bosnia and Herzegovina
86 const PrepopulatedEngine* const engines_BA[] = {
95 const PrepopulatedEngine* const engines_BE[] = {
104 const PrepopulatedEngine* const engines_BG[] = {
113 const PrepopulatedEngine* const engines_BH[] = {
122 const PrepopulatedEngine* const engines_BI[] = {
131 const PrepopulatedEngine* const engines_BN[] = {
140 const PrepopulatedEngine* const engines_BO[] = {
149 const PrepopulatedEngine* const engines_BR[] = {
158 const PrepopulatedEngine* const engines_BY[] = {
167 const PrepopulatedEngine* const engines_BZ[] = {
176 const PrepopulatedEngine* const engines_CA[] = {
185 const PrepopulatedEngine* const engines_CH[] = {
194 const PrepopulatedEngine* const engines_CL[] = {
203 const PrepopulatedEngine* const engines_CN[] = {
212 const PrepopulatedEngine* const engines_CO[] = {
221 const PrepopulatedEngine* const engines_CR[] = {
230 const PrepopulatedEngine* const engines_CZ[] = {
239 const PrepopulatedEngine* const engines_DE[] = {
248 const PrepopulatedEngine* const engines_DK[] = {
256 // Dominican Republic
257 const PrepopulatedEngine* const engines_DO[] = {
266 const PrepopulatedEngine* const engines_DZ[] = {
275 const PrepopulatedEngine* const engines_EC[] = {
284 const PrepopulatedEngine* const engines_EE[] = {
293 const PrepopulatedEngine* const engines_EG[] = {
302 const PrepopulatedEngine* const engines_ES[] = {
311 const PrepopulatedEngine* const engines_FI[] = {
320 const PrepopulatedEngine* const engines_FO[] = {
329 const PrepopulatedEngine* const engines_FR[] = {
338 const PrepopulatedEngine* const engines_GB[] = {
347 const PrepopulatedEngine* const engines_GR[] = {
356 const PrepopulatedEngine* const engines_GT[] = {
365 const PrepopulatedEngine* const engines_HK[] = {
374 const PrepopulatedEngine* const engines_HN[] = {
383 const PrepopulatedEngine* const engines_HR[] = {
392 const PrepopulatedEngine* const engines_HU[] = {
401 const PrepopulatedEngine* const engines_ID[] = {
410 const PrepopulatedEngine* const engines_IE[] = {
419 const PrepopulatedEngine* const engines_IL[] = {
428 const PrepopulatedEngine* const engines_IN[] = {
437 const PrepopulatedEngine* const engines_IQ[] = {
446 const PrepopulatedEngine* const engines_IR[] = {
455 const PrepopulatedEngine* const engines_IS[] = {
464 const PrepopulatedEngine* const engines_IT[] = {
473 const PrepopulatedEngine* const engines_JM[] = {
482 const PrepopulatedEngine* const engines_JO[] = {
491 const PrepopulatedEngine* const engines_JP[] = {
500 const PrepopulatedEngine* const engines_KE[] = {
509 const PrepopulatedEngine* const engines_KR[] = {
518 const PrepopulatedEngine* const engines_KW[] = {
527 const PrepopulatedEngine* const engines_KZ[] = {
536 const PrepopulatedEngine* const engines_LB[] = {
545 const PrepopulatedEngine* const engines_LI[] = {
554 const PrepopulatedEngine* const engines_LT[] = {
563 const PrepopulatedEngine* const engines_LU[] = {
572 const PrepopulatedEngine* const engines_LV[] = {
581 const PrepopulatedEngine* const engines_LY[] = {
590 const PrepopulatedEngine* const engines_MA[] = {
599 const PrepopulatedEngine* const engines_MC[] = {
608 const PrepopulatedEngine* const engines_MD[] = {
617 const PrepopulatedEngine* const engines_ME[] = {
626 const PrepopulatedEngine* const engines_MK[] = {
635 const PrepopulatedEngine* const engines_MX[] = {
644 const PrepopulatedEngine* const engines_MY[] = {
653 const PrepopulatedEngine* const engines_NI[] = {
662 const PrepopulatedEngine* const engines_NL[] = {
671 const PrepopulatedEngine* const engines_NO[] = {
680 const PrepopulatedEngine* const engines_NZ[] = {
689 const PrepopulatedEngine* const engines_OM[] = {
698 const PrepopulatedEngine* const engines_PA[] = {
707 const PrepopulatedEngine* const engines_PE[] = {
716 const PrepopulatedEngine* const engines_PH[] = {
725 const PrepopulatedEngine* const engines_PK[] = {
734 const PrepopulatedEngine* const engines_PL[] = {
743 const PrepopulatedEngine* const engines_PR[] = {
752 const PrepopulatedEngine* const engines_PT[] = {
761 const PrepopulatedEngine* const engines_PY[] = {
770 const PrepopulatedEngine* const engines_QA[] = {
779 const PrepopulatedEngine* const engines_RO[] = {
788 const PrepopulatedEngine* const engines_RS[] = {
797 const PrepopulatedEngine* const engines_RU[] = {
806 const PrepopulatedEngine* const engines_RW[] = {
815 const PrepopulatedEngine* const engines_SA[] = {
824 const PrepopulatedEngine* const engines_SE[] = {
833 const PrepopulatedEngine* const engines_SG[] = {
842 const PrepopulatedEngine* const engines_SI[] = {
851 const PrepopulatedEngine* const engines_SK[] = {
860 const PrepopulatedEngine* const engines_SV[] = {
869 const PrepopulatedEngine* const engines_SY[] = {
878 const PrepopulatedEngine* const engines_TH[] = {
887 const PrepopulatedEngine* const engines_TN[] = {
896 const PrepopulatedEngine* const engines_TR[] = {
904 // Trinidad and Tobago
905 const PrepopulatedEngine* const engines_TT[] = {
914 const PrepopulatedEngine* const engines_TW[] = {
923 const PrepopulatedEngine* const engines_TZ[] = {
932 const PrepopulatedEngine* const engines_UA[] = {
941 const PrepopulatedEngine* const engines_US[] = {
950 const PrepopulatedEngine* const engines_UY[] = {
959 const PrepopulatedEngine* const engines_VE[] = {
968 const PrepopulatedEngine* const engines_VN[] = {
977 const PrepopulatedEngine* const engines_YE[] = {
986 const PrepopulatedEngine* const engines_ZA[] = {
995 const PrepopulatedEngine* const engines_ZW[] = {
1004 // ----------------------------------------------------------------------------
1006 std::vector<std::unique_ptr<TemplateURLData>> GetPrepopulationSetFromCountryID(
1008 const PrepopulatedEngine* const* engines;
1010 // If you add a new country make sure to update the unit test for coverage.
1011 switch (country_id) {
1012 #define UNHANDLED_COUNTRY(code1, code2) \
1013 case country_codes::CountryCharsToCountryID((#code1)[0], (#code2)[0]):
1014 #define END_UNHANDLED_COUNTRIES(code1, code2) \
1015 engines = engines_##code1##code2; \
1016 num_engines = std::size(engines_##code1##code2); \
1018 #define DECLARE_COUNTRY(code1, code2)\
1019 UNHANDLED_COUNTRY(code1, code2)\
1020 END_UNHANDLED_COUNTRIES(code1, code2)
1022 // Countries with their own, dedicated engine set.
1023 DECLARE_COUNTRY(A, E) // United Arab Emirates
1024 DECLARE_COUNTRY(A, L) // Albania
1025 DECLARE_COUNTRY(A, R) // Argentina
1026 DECLARE_COUNTRY(A, T) // Austria
1027 DECLARE_COUNTRY(A, U) // Australia
1028 DECLARE_COUNTRY(B, A) // Bosnia and Herzegovina
1029 DECLARE_COUNTRY(B, E) // Belgium
1030 DECLARE_COUNTRY(B, G) // Bulgaria
1031 DECLARE_COUNTRY(B, H) // Bahrain
1032 DECLARE_COUNTRY(B, I) // Burundi
1033 DECLARE_COUNTRY(B, N) // Brunei
1034 DECLARE_COUNTRY(B, O) // Bolivia
1035 DECLARE_COUNTRY(B, R) // Brazil
1036 DECLARE_COUNTRY(B, Y) // Belarus
1037 DECLARE_COUNTRY(B, Z) // Belize
1038 DECLARE_COUNTRY(C, A) // Canada
1039 DECLARE_COUNTRY(C, H) // Switzerland
1040 DECLARE_COUNTRY(C, L) // Chile
1041 DECLARE_COUNTRY(C, N) // China
1042 DECLARE_COUNTRY(C, O) // Colombia
1043 DECLARE_COUNTRY(C, R) // Costa Rica
1044 DECLARE_COUNTRY(C, Z) // Czech Republic
1045 DECLARE_COUNTRY(D, E) // Germany
1046 DECLARE_COUNTRY(D, K) // Denmark
1047 DECLARE_COUNTRY(D, O) // Dominican Republic
1048 DECLARE_COUNTRY(D, Z) // Algeria
1049 DECLARE_COUNTRY(E, C) // Ecuador
1050 DECLARE_COUNTRY(E, E) // Estonia
1051 DECLARE_COUNTRY(E, G) // Egypt
1052 DECLARE_COUNTRY(E, S) // Spain
1053 DECLARE_COUNTRY(F, I) // Finland
1054 DECLARE_COUNTRY(F, O) // Faroe Islands
1055 DECLARE_COUNTRY(F, R) // France
1056 DECLARE_COUNTRY(G, B) // United Kingdom
1057 DECLARE_COUNTRY(G, R) // Greece
1058 DECLARE_COUNTRY(G, T) // Guatemala
1059 DECLARE_COUNTRY(H, K) // Hong Kong
1060 DECLARE_COUNTRY(H, N) // Honduras
1061 DECLARE_COUNTRY(H, R) // Croatia
1062 DECLARE_COUNTRY(H, U) // Hungary
1063 DECLARE_COUNTRY(I, D) // Indonesia
1064 DECLARE_COUNTRY(I, E) // Ireland
1065 DECLARE_COUNTRY(I, L) // Israel
1066 DECLARE_COUNTRY(I, N) // India
1067 DECLARE_COUNTRY(I, Q) // Iraq
1068 DECLARE_COUNTRY(I, R) // Iran
1069 DECLARE_COUNTRY(I, S) // Iceland
1070 DECLARE_COUNTRY(I, T) // Italy
1071 DECLARE_COUNTRY(J, M) // Jamaica
1072 DECLARE_COUNTRY(J, O) // Jordan
1073 DECLARE_COUNTRY(J, P) // Japan
1074 DECLARE_COUNTRY(K, E) // Kenya
1075 DECLARE_COUNTRY(K, R) // South Korea
1076 DECLARE_COUNTRY(K, W) // Kuwait
1077 DECLARE_COUNTRY(K, Z) // Kazakhstan
1078 DECLARE_COUNTRY(L, B) // Lebanon
1079 DECLARE_COUNTRY(L, I) // Liechtenstein
1080 DECLARE_COUNTRY(L, T) // Lithuania
1081 DECLARE_COUNTRY(L, U) // Luxembourg
1082 DECLARE_COUNTRY(L, V) // Latvia
1083 DECLARE_COUNTRY(L, Y) // Libya
1084 DECLARE_COUNTRY(M, A) // Morocco
1085 DECLARE_COUNTRY(M, C) // Monaco
1086 DECLARE_COUNTRY(M, D) // Moldova
1087 DECLARE_COUNTRY(M, E) // Montenegro
1088 DECLARE_COUNTRY(M, K) // Macedonia
1089 DECLARE_COUNTRY(M, X) // Mexico
1090 DECLARE_COUNTRY(M, Y) // Malaysia
1091 DECLARE_COUNTRY(N, I) // Nicaragua
1092 DECLARE_COUNTRY(N, L) // Netherlands
1093 DECLARE_COUNTRY(N, O) // Norway
1094 DECLARE_COUNTRY(N, Z) // New Zealand
1095 DECLARE_COUNTRY(O, M) // Oman
1096 DECLARE_COUNTRY(P, A) // Panama
1097 DECLARE_COUNTRY(P, E) // Peru
1098 DECLARE_COUNTRY(P, H) // Philippines
1099 DECLARE_COUNTRY(P, K) // Pakistan
1100 DECLARE_COUNTRY(P, L) // Poland
1101 DECLARE_COUNTRY(P, R) // Puerto Rico
1102 DECLARE_COUNTRY(P, T) // Portugal
1103 DECLARE_COUNTRY(P, Y) // Paraguay
1104 DECLARE_COUNTRY(Q, A) // Qatar
1105 DECLARE_COUNTRY(R, O) // Romania
1106 DECLARE_COUNTRY(R, S) // Serbia
1107 DECLARE_COUNTRY(R, U) // Russia
1108 DECLARE_COUNTRY(R, W) // Rwanda
1109 DECLARE_COUNTRY(S, A) // Saudi Arabia
1110 DECLARE_COUNTRY(S, E) // Sweden
1111 DECLARE_COUNTRY(S, G) // Singapore
1112 DECLARE_COUNTRY(S, I) // Slovenia
1113 DECLARE_COUNTRY(S, K) // Slovakia
1114 DECLARE_COUNTRY(S, V) // El Salvador
1115 DECLARE_COUNTRY(S, Y) // Syria
1116 DECLARE_COUNTRY(T, H) // Thailand
1117 DECLARE_COUNTRY(T, N) // Tunisia
1118 DECLARE_COUNTRY(T, R) // Turkey
1119 DECLARE_COUNTRY(T, T) // Trinidad and Tobago
1120 DECLARE_COUNTRY(T, W) // Taiwan
1121 DECLARE_COUNTRY(T, Z) // Tanzania
1122 DECLARE_COUNTRY(U, A) // Ukraine
1123 DECLARE_COUNTRY(U, S) // United States
1124 DECLARE_COUNTRY(U, Y) // Uruguay
1125 DECLARE_COUNTRY(V, E) // Venezuela
1126 DECLARE_COUNTRY(V, N) // Vietnam
1127 DECLARE_COUNTRY(Y, E) // Yemen
1128 DECLARE_COUNTRY(Z, A) // South Africa
1129 DECLARE_COUNTRY(Z, W) // Zimbabwe
1131 // Countries using the "Australia" engine set.
1132 UNHANDLED_COUNTRY(C, C) // Cocos Islands
1133 UNHANDLED_COUNTRY(C, X) // Christmas Island
1134 UNHANDLED_COUNTRY(H, M) // Heard Island and McDonald Islands
1135 UNHANDLED_COUNTRY(N, F) // Norfolk Island
1136 END_UNHANDLED_COUNTRIES(A, U)
1138 // Countries using the "China" engine set.
1139 UNHANDLED_COUNTRY(M, O) // Macao
1140 END_UNHANDLED_COUNTRIES(C, N)
1142 // Countries using the "Denmark" engine set.
1143 UNHANDLED_COUNTRY(G, L) // Greenland
1144 END_UNHANDLED_COUNTRIES(D, K)
1146 // Countries using the "Spain" engine set.
1147 UNHANDLED_COUNTRY(A, D) // Andorra
1148 END_UNHANDLED_COUNTRIES(E, S)
1150 // Countries using the "Finland" engine set.
1151 UNHANDLED_COUNTRY(A, X) // Aland Islands
1152 END_UNHANDLED_COUNTRIES(F, I)
1154 // Countries using the "France" engine set.
1155 UNHANDLED_COUNTRY(B, F) // Burkina Faso
1156 UNHANDLED_COUNTRY(B, J) // Benin
1157 UNHANDLED_COUNTRY(C, D) // Congo - Kinshasa
1158 UNHANDLED_COUNTRY(C, F) // Central African Republic
1159 UNHANDLED_COUNTRY(C, G) // Congo - Brazzaville
1160 UNHANDLED_COUNTRY(C, I) // Ivory Coast
1161 UNHANDLED_COUNTRY(C, M) // Cameroon
1162 UNHANDLED_COUNTRY(D, J) // Djibouti
1163 UNHANDLED_COUNTRY(G, A) // Gabon
1164 UNHANDLED_COUNTRY(G, F) // French Guiana
1165 UNHANDLED_COUNTRY(G, N) // Guinea
1166 UNHANDLED_COUNTRY(G, P) // Guadeloupe
1167 UNHANDLED_COUNTRY(H, T) // Haiti
1168 #if BUILDFLAG(IS_WIN)
1169 UNHANDLED_COUNTRY(I, P) // Clipperton Island ('IP' is an WinXP-ism; ISO
1170 // includes it with France)
1172 UNHANDLED_COUNTRY(M, L) // Mali
1173 UNHANDLED_COUNTRY(M, Q) // Martinique
1174 UNHANDLED_COUNTRY(N, C) // New Caledonia
1175 UNHANDLED_COUNTRY(N, E) // Niger
1176 UNHANDLED_COUNTRY(P, F) // French Polynesia
1177 UNHANDLED_COUNTRY(P, M) // Saint Pierre and Miquelon
1178 UNHANDLED_COUNTRY(R, E) // Reunion
1179 UNHANDLED_COUNTRY(S, N) // Senegal
1180 UNHANDLED_COUNTRY(T, D) // Chad
1181 UNHANDLED_COUNTRY(T, F) // French Southern Territories
1182 UNHANDLED_COUNTRY(T, G) // Togo
1183 UNHANDLED_COUNTRY(W, F) // Wallis and Futuna
1184 UNHANDLED_COUNTRY(Y, T) // Mayotte
1185 END_UNHANDLED_COUNTRIES(F, R)
1187 // Countries using the "Greece" engine set.
1188 UNHANDLED_COUNTRY(C, Y) // Cyprus
1189 END_UNHANDLED_COUNTRIES(G, R)
1191 // Countries using the "Italy" engine set.
1192 UNHANDLED_COUNTRY(S, M) // San Marino
1193 UNHANDLED_COUNTRY(V, A) // Vatican
1194 END_UNHANDLED_COUNTRIES(I, T)
1196 // Countries using the "Morocco" engine set.
1197 UNHANDLED_COUNTRY(E, H) // Western Sahara
1198 END_UNHANDLED_COUNTRIES(M, A)
1200 // Countries using the "Netherlands" engine set.
1201 UNHANDLED_COUNTRY(A, N) // Netherlands Antilles
1202 UNHANDLED_COUNTRY(A, W) // Aruba
1203 END_UNHANDLED_COUNTRIES(N, L)
1205 // Countries using the "Norway" engine set.
1206 UNHANDLED_COUNTRY(B, V) // Bouvet Island
1207 UNHANDLED_COUNTRY(S, J) // Svalbard and Jan Mayen
1208 END_UNHANDLED_COUNTRIES(N, O)
1210 // Countries using the "New Zealand" engine set.
1211 UNHANDLED_COUNTRY(C, K) // Cook Islands
1212 UNHANDLED_COUNTRY(N, U) // Niue
1213 UNHANDLED_COUNTRY(T, K) // Tokelau
1214 END_UNHANDLED_COUNTRIES(N, Z)
1216 // Countries using the "Portugal" engine set.
1217 UNHANDLED_COUNTRY(C, V) // Cape Verde
1218 UNHANDLED_COUNTRY(G, W) // Guinea-Bissau
1219 UNHANDLED_COUNTRY(M, Z) // Mozambique
1220 UNHANDLED_COUNTRY(S, T) // Sao Tome and Principe
1221 UNHANDLED_COUNTRY(T, L) // Timor-Leste
1222 END_UNHANDLED_COUNTRIES(P, T)
1224 // Countries using the "Russia" engine set.
1225 UNHANDLED_COUNTRY(A, M) // Armenia
1226 UNHANDLED_COUNTRY(A, Z) // Azerbaijan
1227 UNHANDLED_COUNTRY(K, G) // Kyrgyzstan
1228 UNHANDLED_COUNTRY(T, J) // Tajikistan
1229 UNHANDLED_COUNTRY(T, M) // Turkmenistan
1230 UNHANDLED_COUNTRY(U, Z) // Uzbekistan
1231 END_UNHANDLED_COUNTRIES(R, U)
1233 // Countries using the "Saudi Arabia" engine set.
1234 UNHANDLED_COUNTRY(M, R) // Mauritania
1235 UNHANDLED_COUNTRY(P, S) // Palestinian Territory
1236 UNHANDLED_COUNTRY(S, D) // Sudan
1237 END_UNHANDLED_COUNTRIES(S, A)
1239 // Countries using the "United Kingdom" engine set.
1240 UNHANDLED_COUNTRY(B, M) // Bermuda
1241 UNHANDLED_COUNTRY(F, K) // Falkland Islands
1242 UNHANDLED_COUNTRY(G, G) // Guernsey
1243 UNHANDLED_COUNTRY(G, I) // Gibraltar
1244 UNHANDLED_COUNTRY(G, S) // South Georgia and the South Sandwich
1246 UNHANDLED_COUNTRY(I, M) // Isle of Man
1247 UNHANDLED_COUNTRY(I, O) // British Indian Ocean Territory
1248 UNHANDLED_COUNTRY(J, E) // Jersey
1249 UNHANDLED_COUNTRY(K, Y) // Cayman Islands
1250 UNHANDLED_COUNTRY(M, S) // Montserrat
1251 UNHANDLED_COUNTRY(M, T) // Malta
1252 UNHANDLED_COUNTRY(P, N) // Pitcairn Islands
1253 UNHANDLED_COUNTRY(S, H) // Saint Helena, Ascension Island, and Tristan da
1255 UNHANDLED_COUNTRY(T, C) // Turks and Caicos Islands
1256 UNHANDLED_COUNTRY(V, G) // British Virgin Islands
1257 END_UNHANDLED_COUNTRIES(G, B)
1259 // Countries using the "United States" engine set.
1260 UNHANDLED_COUNTRY(A, S) // American Samoa
1261 UNHANDLED_COUNTRY(G, U) // Guam
1262 UNHANDLED_COUNTRY(M, P) // Northern Mariana Islands
1263 UNHANDLED_COUNTRY(U, M) // U.S. Minor Outlying Islands
1264 UNHANDLED_COUNTRY(V, I) // U.S. Virgin Islands
1265 END_UNHANDLED_COUNTRIES(U, S)
1267 // Countries using the "default" engine set.
1268 UNHANDLED_COUNTRY(A, F) // Afghanistan
1269 UNHANDLED_COUNTRY(A, G) // Antigua and Barbuda
1270 UNHANDLED_COUNTRY(A, I) // Anguilla
1271 UNHANDLED_COUNTRY(A, O) // Angola
1272 UNHANDLED_COUNTRY(A, Q) // Antarctica
1273 UNHANDLED_COUNTRY(B, B) // Barbados
1274 UNHANDLED_COUNTRY(B, D) // Bangladesh
1275 UNHANDLED_COUNTRY(B, S) // Bahamas
1276 UNHANDLED_COUNTRY(B, T) // Bhutan
1277 UNHANDLED_COUNTRY(B, W) // Botswana
1278 UNHANDLED_COUNTRY(C, U) // Cuba
1279 UNHANDLED_COUNTRY(D, M) // Dominica
1280 UNHANDLED_COUNTRY(E, R) // Eritrea
1281 UNHANDLED_COUNTRY(E, T) // Ethiopia
1282 UNHANDLED_COUNTRY(F, J) // Fiji
1283 UNHANDLED_COUNTRY(F, M) // Micronesia
1284 UNHANDLED_COUNTRY(G, D) // Grenada
1285 UNHANDLED_COUNTRY(G, E) // Georgia
1286 UNHANDLED_COUNTRY(G, H) // Ghana
1287 UNHANDLED_COUNTRY(G, M) // Gambia
1288 UNHANDLED_COUNTRY(G, Q) // Equatorial Guinea
1289 UNHANDLED_COUNTRY(G, Y) // Guyana
1290 UNHANDLED_COUNTRY(K, H) // Cambodia
1291 UNHANDLED_COUNTRY(K, I) // Kiribati
1292 UNHANDLED_COUNTRY(K, M) // Comoros
1293 UNHANDLED_COUNTRY(K, N) // Saint Kitts and Nevis
1294 UNHANDLED_COUNTRY(K, P) // North Korea
1295 UNHANDLED_COUNTRY(L, A) // Laos
1296 UNHANDLED_COUNTRY(L, C) // Saint Lucia
1297 UNHANDLED_COUNTRY(L, K) // Sri Lanka
1298 UNHANDLED_COUNTRY(L, R) // Liberia
1299 UNHANDLED_COUNTRY(L, S) // Lesotho
1300 UNHANDLED_COUNTRY(M, G) // Madagascar
1301 UNHANDLED_COUNTRY(M, H) // Marshall Islands
1302 UNHANDLED_COUNTRY(M, M) // Myanmar
1303 UNHANDLED_COUNTRY(M, N) // Mongolia
1304 UNHANDLED_COUNTRY(M, U) // Mauritius
1305 UNHANDLED_COUNTRY(M, V) // Maldives
1306 UNHANDLED_COUNTRY(M, W) // Malawi
1307 UNHANDLED_COUNTRY(N, A) // Namibia
1308 UNHANDLED_COUNTRY(N, G) // Nigeria
1309 UNHANDLED_COUNTRY(N, P) // Nepal
1310 UNHANDLED_COUNTRY(N, R) // Nauru
1311 UNHANDLED_COUNTRY(P, G) // Papua New Guinea
1312 UNHANDLED_COUNTRY(P, W) // Palau
1313 UNHANDLED_COUNTRY(S, B) // Solomon Islands
1314 UNHANDLED_COUNTRY(S, C) // Seychelles
1315 UNHANDLED_COUNTRY(S, L) // Sierra Leone
1316 UNHANDLED_COUNTRY(S, O) // Somalia
1317 UNHANDLED_COUNTRY(S, R) // Suriname
1318 UNHANDLED_COUNTRY(S, Z) // Swaziland
1319 UNHANDLED_COUNTRY(T, O) // Tonga
1320 UNHANDLED_COUNTRY(T, V) // Tuvalu
1321 UNHANDLED_COUNTRY(U, G) // Uganda
1322 UNHANDLED_COUNTRY(V, C) // Saint Vincent and the Grenadines
1323 UNHANDLED_COUNTRY(V, U) // Vanuatu
1324 UNHANDLED_COUNTRY(W, S) // Samoa
1325 UNHANDLED_COUNTRY(Z, M) // Zambia
1326 case country_codes::kCountryIDUnknown:
1327 default: // Unhandled location
1328 END_UNHANDLED_COUNTRIES(def, ault)
1331 std::vector<std::unique_ptr<TemplateURLData>> t_urls;
1332 for (size_t i = 0; i < num_engines; ++i)
1333 t_urls.push_back(TemplateURLDataFromPrepopulatedEngine(*engines[i]));
1337 std::vector<std::unique_ptr<TemplateURLData>> GetPrepopulatedTemplateURLData(
1338 PrefService* prefs) {
1339 std::vector<std::unique_ptr<TemplateURLData>> t_urls;
1343 const base::Value::List& list =
1344 prefs->GetList(prefs::kSearchProviderOverrides);
1346 for (const base::Value& engine : list) {
1347 if (engine.is_dict()) {
1348 auto t_url = TemplateURLDataFromOverrideDictionary(engine.GetDict());
1350 t_urls.push_back(std::move(t_url));
1359 // Global functions -----------------------------------------------------------
1361 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
1362 country_codes::RegisterProfilePrefs(registry);
1363 registry->RegisterListPref(prefs::kSearchProviderOverrides);
1364 registry->RegisterIntegerPref(prefs::kSearchProviderOverridesVersion, -1);
1367 int GetDataVersion(PrefService* prefs) {
1368 // Allow tests to override the local version.
1369 return (prefs && prefs->HasPrefPath(prefs::kSearchProviderOverridesVersion)) ?
1370 prefs->GetInteger(prefs::kSearchProviderOverridesVersion) :
1371 kCurrentDataVersion;
1374 std::vector<std::unique_ptr<TemplateURLData>> GetPrepopulatedEngines(
1376 size_t* default_search_provider_index) {
1377 // If there is a set of search engines in the preferences file, it overrides
1378 // the built-in set.
1379 std::vector<std::unique_ptr<TemplateURLData>> t_urls =
1380 GetPrepopulatedTemplateURLData(prefs);
1381 if (t_urls.empty()) {
1382 t_urls = GetPrepopulationSetFromCountryID(
1383 country_codes::GetCountryIDFromPrefs(prefs));
1385 if (default_search_provider_index) {
1387 base::ranges::find(t_urls, google.id, &TemplateURLData::prepopulate_id);
1388 *default_search_provider_index =
1389 itr == t_urls.end() ? 0 : std::distance(t_urls.begin(), itr);
1394 std::unique_ptr<TemplateURLData> GetPrepopulatedEngine(PrefService* prefs,
1395 int prepopulated_id) {
1397 TemplateURLPrepopulateData::GetPrepopulatedEngines(prefs, nullptr);
1398 for (auto& engine : engines) {
1399 if (engine->prepopulate_id == prepopulated_id)
1400 return std::move(engine);
1405 #if BUILDFLAG(IS_ANDROID)
1407 std::vector<std::unique_ptr<TemplateURLData>> GetLocalPrepopulatedEngines(
1408 const std::string& locale) {
1409 int country_id = country_codes::CountryStringToCountryID(locale);
1410 if (country_id == country_codes::kCountryIDUnknown) {
1411 LOG(ERROR) << "Unknown country code specified: " << locale;
1412 return std::vector<std::unique_ptr<TemplateURLData>>();
1415 return GetPrepopulationSetFromCountryID(country_id);
1420 std::vector<const PrepopulatedEngine*> GetAllPrepopulatedEngines() {
1421 return std::vector<const PrepopulatedEngine*>(
1422 &kAllEngines[0], &kAllEngines[0] + kAllEnginesLength);
1425 void ClearPrepopulatedEnginesInPrefs(PrefService* prefs) {
1429 prefs->ClearPref(prefs::kSearchProviderOverrides);
1430 prefs->ClearPref(prefs::kSearchProviderOverridesVersion);
1433 std::unique_ptr<TemplateURLData> GetPrepopulatedDefaultSearch(
1434 PrefService* prefs) {
1435 size_t default_search_index;
1436 // This could be more efficient. We load all URLs but keep only the default.
1437 std::vector<std::unique_ptr<TemplateURLData>> loaded_urls =
1438 GetPrepopulatedEngines(prefs, &default_search_index);
1440 return (default_search_index < loaded_urls.size())
1441 ? std::move(loaded_urls[default_search_index])
1445 } // namespace TemplateURLPrepopulateData