Upload upstream chromium 114.0.5735.31
[platform/framework/web/chromium-efl.git] / components / search_engines / template_url_prepopulate_data.cc
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.
4
5 #include "components/search_engines/template_url_prepopulate_data.h"
6
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"
17
18 namespace TemplateURLPrepopulateData {
19
20 // Helpers --------------------------------------------------------------------
21
22 namespace {
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!
26
27 // Put the engines within each country in order with most interesting/important
28 // first.  The default will be the first engine.
29
30 // Default (for countries with no better engine set)
31 const PrepopulatedEngine* const engines_default[] = {
32     &google,
33     &bing,
34     &yahoo,
35 };
36
37 // Note, the below entries are sorted by country code, not the name in comment.
38 // Engine selection by country ------------------------------------------------
39 // clang-format off
40 // United Arab Emirates
41 const PrepopulatedEngine* const engines_AE[] = {
42     &google,
43     &bing,
44     &yahoo,
45     &duckduckgo,
46     &yandex_ru,
47 };
48
49 // Albania
50 const PrepopulatedEngine* const engines_AL[] = {
51     &google,
52     &bing,
53     &yahoo,
54     &duckduckgo,
55     &yandex_tr,
56 };
57
58 // Argentina
59 const PrepopulatedEngine* const engines_AR[] = {
60     &google,
61     &bing,
62     &yahoo_ar,
63     &duckduckgo,
64     &ecosia,
65 };
66
67 // Austria
68 const PrepopulatedEngine* const engines_AT[] = {
69     &google,
70     &bing,
71     &yahoo_at,
72     &duckduckgo,
73     &ecosia,
74 };
75
76 // Australia
77 const PrepopulatedEngine* const engines_AU[] = {
78     &google,
79     &bing,
80     &yahoo_au,
81     &duckduckgo,
82     &ecosia,
83 };
84
85 // Bosnia and Herzegovina
86 const PrepopulatedEngine* const engines_BA[] = {
87     &google,
88     &bing,
89     &yahoo,
90     &duckduckgo,
91     &yandex_com,
92 };
93
94 // Belgium
95 const PrepopulatedEngine* const engines_BE[] = {
96     &google,
97     &bing,
98     &yahoo,
99     &ecosia,
100     &duckduckgo,
101 };
102
103 // Bulgaria
104 const PrepopulatedEngine* const engines_BG[] = {
105     &google,
106     &bing,
107     &yahoo,
108     &duckduckgo,
109     &yandex_ru,
110 };
111
112 // Bahrain
113 const PrepopulatedEngine* const engines_BH[] = {
114     &google,
115     &bing,
116     &yahoo,
117     &duckduckgo,
118     &ecosia,
119 };
120
121 // Burundi
122 const PrepopulatedEngine* const engines_BI[] = {
123     &google,
124     &bing,
125     &yahoo,
126     &duckduckgo,
127     &yandex_ru,
128 };
129
130 // Brunei
131 const PrepopulatedEngine* const engines_BN[] = {
132     &google,
133     &bing,
134     &yahoo,
135     &duckduckgo,
136     &ecosia,
137 };
138
139 // Bolivia
140 const PrepopulatedEngine* const engines_BO[] = {
141     &google,
142     &bing,
143     &yahoo,
144     &duckduckgo,
145     &ecosia,
146 };
147
148 // Brazil
149 const PrepopulatedEngine* const engines_BR[] = {
150     &google,
151     &bing,
152     &yahoo_br,
153     &duckduckgo,
154     &yandex_com,
155 };
156
157 // Belarus
158 const PrepopulatedEngine* const engines_BY[] = {
159     &google,
160     &yandex_by,
161     &mail_ru,
162     &bing,
163     &duckduckgo,
164 };
165
166 // Belize
167 const PrepopulatedEngine* const engines_BZ[] = {
168     &google,
169     &bing,
170     &yahoo,
171     &duckduckgo,
172     &naver,
173 };
174
175 // Canada
176 const PrepopulatedEngine* const engines_CA[] = {
177     &google,
178     &bing,
179     &yahoo_ca,
180     &duckduckgo,
181     &ecosia,
182 };
183
184 // Switzerland
185 const PrepopulatedEngine* const engines_CH[] = {
186     &google,
187     &bing,
188     &duckduckgo,
189     &yahoo_ch,
190     &ecosia,
191 };
192
193 // Chile
194 const PrepopulatedEngine* const engines_CL[] = {
195     &google,
196     &bing,
197     &yahoo_cl,
198     &duckduckgo,
199     &ecosia,
200 };
201
202 // China
203 const PrepopulatedEngine* const engines_CN[] = {
204     &baidu,
205     &bing,
206     &sogou,
207     &so_360,
208     &google,
209 };
210
211 // Colombia
212 const PrepopulatedEngine* const engines_CO[] = {
213     &google,
214     &bing,
215     &yahoo_co,
216     &duckduckgo,
217     &ecosia,
218 };
219
220 // Costa Rica
221 const PrepopulatedEngine* const engines_CR[] = {
222     &google,
223     &bing,
224     &yahoo,
225     &duckduckgo,
226     &ecosia,
227 };
228
229 // Czech Republic
230 const PrepopulatedEngine* const engines_CZ[] = {
231     &google,
232     &seznam_cz,
233     &bing,
234     &yahoo,
235     &duckduckgo,
236 };
237
238 // Germany
239 const PrepopulatedEngine* const engines_DE[] = {
240     &google,
241     &bing,
242     &yahoo_de,
243     &duckduckgo,
244     &ecosia,
245 };
246
247 // Denmark
248 const PrepopulatedEngine* const engines_DK[] = {
249     &google,
250     &bing,
251     &yahoo_dk,
252     &duckduckgo,
253     &ecosia,
254 };
255
256 // Dominican Republic
257 const PrepopulatedEngine* const engines_DO[] = {
258     &google,
259     &bing,
260     &yahoo,
261     &duckduckgo,
262     &ecosia,
263 };
264
265 // Algeria
266 const PrepopulatedEngine* const engines_DZ[] = {
267     &google,
268     &bing,
269     &yahoo_fr,
270     &yandex_com,
271     &duckduckgo,
272 };
273
274 // Ecuador
275 const PrepopulatedEngine* const engines_EC[] = {
276     &google,
277     &bing,
278     &yahoo_es,
279     &ecosia,
280     &duckduckgo,
281 };
282
283 // Estonia
284 const PrepopulatedEngine* const engines_EE[] = {
285     &google,
286     &bing,
287     &yandex_ru,
288     &duckduckgo,
289     &mail_ru,
290 };
291
292 // Egypt
293 const PrepopulatedEngine* const engines_EG[] = {
294     &google,
295     &bing,
296     &yahoo,
297     &yandex_com,
298     &duckduckgo,
299 };
300
301 // Spain
302 const PrepopulatedEngine* const engines_ES[] = {
303     &google,
304     &bing,
305     &yahoo_es,
306     &duckduckgo,
307     &ecosia,
308 };
309
310 // Finland
311 const PrepopulatedEngine* const engines_FI[] = {
312     &google,
313     &bing,
314     &yahoo_fi,
315     &duckduckgo,
316     &yandex_ru,
317 };
318
319 // Faroe Islands
320 const PrepopulatedEngine* const engines_FO[] = {
321     &google,
322     &bing,
323     &yahoo_uk,
324     &duckduckgo,
325     &ecosia,
326 };
327
328 // France
329 const PrepopulatedEngine* const engines_FR[] = {
330     &google,
331     &bing,
332     &yahoo_fr,
333     &qwant,
334     &ecosia,
335 };
336
337 // United Kingdom
338 const PrepopulatedEngine* const engines_GB[] = {
339     &google,
340     &bing,
341     &yahoo_uk,
342     &duckduckgo,
343     &ecosia,
344 };
345
346 // Greece
347 const PrepopulatedEngine* const engines_GR[] = {
348     &google,
349     &bing,
350     &yahoo,
351     &duckduckgo,
352     &yandex_ru,
353 };
354
355 // Guatemala
356 const PrepopulatedEngine* const engines_GT[] = {
357     &google,
358     &bing,
359     &yahoo,
360     &duckduckgo,
361     &ecosia,
362 };
363
364 // Hong Kong
365 const PrepopulatedEngine* const engines_HK[] = {
366     &google,
367     &bing,
368     &yahoo_hk,
369     &baidu,
370     &so_360,
371 };
372
373 // Honduras
374 const PrepopulatedEngine* const engines_HN[] = {
375     &google,
376     &bing,
377     &yahoo,
378     &duckduckgo,
379     &ecosia,
380 };
381
382 // Croatia
383 const PrepopulatedEngine* const engines_HR[] = {
384     &google,
385     &bing,
386     &duckduckgo,
387     &yahoo,
388     &ecosia,
389 };
390
391 // Hungary
392 const PrepopulatedEngine* const engines_HU[] = {
393     &google,
394     &bing,
395     &yahoo,
396     &duckduckgo,
397     &yandex_com,
398 };
399
400 // Indonesia
401 const PrepopulatedEngine* const engines_ID[] = {
402     &google,
403     &bing,
404     &yahoo_id,
405     &duckduckgo,
406     &yandex_com,
407 };
408
409 // Ireland
410 const PrepopulatedEngine* const engines_IE[] = {
411     &google,
412     &bing,
413     &yahoo_uk,
414     &duckduckgo,
415     &ecosia,
416 };
417
418 // Israel
419 const PrepopulatedEngine* const engines_IL[] = {
420     &google,
421     &bing,
422     &yandex_ru,
423     &yahoo,
424     &duckduckgo,
425 };
426
427 // India
428 const PrepopulatedEngine* const engines_IN[] = {
429     &google,
430     &bing,
431     &yahoo_in,
432     &duckduckgo,
433     &info_com,
434 };
435
436 // Iraq
437 const PrepopulatedEngine* const engines_IQ[] = {
438     &google,
439     &bing,
440     &yahoo,
441     &yandex_tr,
442     &petal_search,
443 };
444
445 // Iran
446 const PrepopulatedEngine* const engines_IR[] = {
447     &google,
448     &bing,
449     &yahoo,
450     &duckduckgo,
451     &ask,
452 };
453
454 // Iceland
455 const PrepopulatedEngine* const engines_IS[] = {
456     &google,
457     &bing,
458     &duckduckgo,
459     &yahoo,
460     &ecosia,
461 };
462
463 // Italy
464 const PrepopulatedEngine* const engines_IT[] = {
465     &google,
466     &bing,
467     &yahoo,
468     &duckduckgo,
469     &ecosia,
470 };
471
472 // Jamaica
473 const PrepopulatedEngine* const engines_JM[] = {
474     &google,
475     &bing,
476     &yahoo,
477     &duckduckgo,
478     &ecosia,
479 };
480
481 // Jordan
482 const PrepopulatedEngine* const engines_JO[] = {
483     &google,
484     &bing,
485     &yahoo,
486     &petal_search,
487     &duckduckgo,
488 };
489
490 // Japan
491 const PrepopulatedEngine* const engines_JP[] = {
492     &google,
493     &bing,
494     &yahoo_jp,
495     &duckduckgo,
496     &baidu,
497 };
498
499 // Kenya
500 const PrepopulatedEngine* const engines_KE[] = {
501     &google,
502     &bing,
503     &yahoo,
504     &duckduckgo,
505     &yandex_com,
506 };
507
508 // South Korea
509 const PrepopulatedEngine* const engines_KR[] = {
510     &google,
511     &naver,
512     &bing,
513     &daum,
514     &yahoo,
515 };
516
517 // Kuwait
518 const PrepopulatedEngine* const engines_KW[] = {
519     &google,
520     &bing,
521     &yahoo,
522     &duckduckgo,
523     &yandex_tr,
524 };
525
526 // Kazakhstan
527 const PrepopulatedEngine* const engines_KZ[] = {
528     &google,
529     &yandex_kz,
530     &mail_ru,
531     &bing,
532     &duckduckgo,
533 };
534
535 // Lebanon
536 const PrepopulatedEngine* const engines_LB[] = {
537     &google,
538     &bing,
539     &yahoo,
540     &duckduckgo,
541     &ecosia,
542 };
543
544 // Liechtenstein
545 const PrepopulatedEngine* const engines_LI[] = {
546     &google,
547     &bing,
548     &duckduckgo,
549     &yahoo,
550     &ecosia,
551 };
552
553 // Lithuania
554 const PrepopulatedEngine* const engines_LT[] = {
555     &google,
556     &bing,
557     &yandex_ru,
558     &duckduckgo,
559     &yahoo,
560 };
561
562 // Luxembourg
563 const PrepopulatedEngine* const engines_LU[] = {
564     &google,
565     &bing,
566     &duckduckgo,
567     &yahoo,
568     &ecosia,
569 };
570
571 // Latvia
572 const PrepopulatedEngine* const engines_LV[] = {
573     &google,
574     &bing,
575     &yandex_ru,
576     &yahoo,
577     &duckduckgo,
578 };
579
580 // Libya
581 const PrepopulatedEngine* const engines_LY[] = {
582     &google,
583     &bing,
584     &yahoo,
585     &yandex_tr,
586     &duckduckgo,
587 };
588
589 // Morocco
590 const PrepopulatedEngine* const engines_MA[] = {
591     &google,
592     &bing,
593     &yahoo_fr,
594     &yandex_com,
595     &duckduckgo,
596 };
597
598 // Monaco
599 const PrepopulatedEngine* const engines_MC[] = {
600     &google,
601     &bing,
602     &yahoo_fr,
603     &duckduckgo,
604     &qwant,
605 };
606
607 // Moldova
608 const PrepopulatedEngine* const engines_MD[] = {
609     &google,
610     &yandex_ru,
611     &bing,
612     &mail_ru,
613     &duckduckgo,
614 };
615
616 // Montenegro
617 const PrepopulatedEngine* const engines_ME[] = {
618     &google,
619     &bing,
620     &yandex_ru,
621     &yahoo,
622     &duckduckgo,
623 };
624
625 // Macedonia
626 const PrepopulatedEngine* const engines_MK[] = {
627     &google,
628     &bing,
629     &yahoo,
630     &duckduckgo,
631     &yandex_com,
632 };
633
634 // Mexico
635 const PrepopulatedEngine* const engines_MX[] = {
636     &google,
637     &bing,
638     &yahoo_mx,
639     &duckduckgo,
640     &ecosia,
641 };
642
643 // Malaysia
644 const PrepopulatedEngine* const engines_MY[] = {
645     &google,
646     &bing,
647     &yahoo_my,
648     &duckduckgo,
649     &ecosia,
650 };
651
652 // Nicaragua
653 const PrepopulatedEngine* const engines_NI[] = {
654     &google,
655     &bing,
656     &yahoo,
657     &duckduckgo,
658     &ecosia,
659 };
660
661 // Netherlands
662 const PrepopulatedEngine* const engines_NL[] = {
663     &google,
664     &bing,
665     &yahoo_nl,
666     &duckduckgo,
667     &yandex_ru,
668 };
669
670 // Norway
671 const PrepopulatedEngine* const engines_NO[] = {
672     &google,
673     &bing,
674     &yahoo,
675     &duckduckgo,
676     &ecosia,
677 };
678
679 // New Zealand
680 const PrepopulatedEngine* const engines_NZ[] = {
681     &google,
682     &bing,
683     &yahoo_nz,
684     &duckduckgo,
685     &ecosia,
686 };
687
688 // Oman
689 const PrepopulatedEngine* const engines_OM[] = {
690     &google,
691     &bing,
692     &yahoo,
693     &petal_search,
694     &duckduckgo,
695 };
696
697 // Panama
698 const PrepopulatedEngine* const engines_PA[] = {
699     &google,
700     &bing,
701     &yahoo_es,
702     &duckduckgo,
703     &ecosia,
704 };
705
706 // Peru
707 const PrepopulatedEngine* const engines_PE[] = {
708     &google,
709     &bing,
710     &yahoo_pe,
711     &ecosia,
712     &duckduckgo,
713 };
714
715 // Philippines
716 const PrepopulatedEngine* const engines_PH[] = {
717     &google,
718     &bing,
719     &yahoo_ph,
720     &ecosia,
721     &duckduckgo,
722 };
723
724 // Pakistan
725 const PrepopulatedEngine* const engines_PK[] = {
726     &google,
727     &bing,
728     &yahoo,
729     &duckduckgo,
730     &yandex_com,
731 };
732
733 // Poland
734 const PrepopulatedEngine* const engines_PL[] = {
735     &google,
736     &bing,
737     &yahoo,
738     &duckduckgo,
739     &yandex_ru,
740 };
741
742 // Puerto Rico
743 const PrepopulatedEngine* const engines_PR[] = {
744     &google,
745     &bing,
746     &yahoo,
747     &duckduckgo,
748     &ecosia,
749 };
750
751 // Portugal
752 const PrepopulatedEngine* const engines_PT[] = {
753     &google,
754     &bing,
755     &yahoo,
756     &duckduckgo,
757     &ecosia,
758 };
759
760 // Paraguay
761 const PrepopulatedEngine* const engines_PY[] = {
762     &google,
763     &bing,
764     &yahoo_es,
765     &duckduckgo,
766     &ecosia,
767 };
768
769 // Qatar
770 const PrepopulatedEngine* const engines_QA[] = {
771     &google,
772     &bing,
773     &yahoo,
774     &duckduckgo,
775     &yandex_tr,
776 };
777
778 // Romania
779 const PrepopulatedEngine* const engines_RO[] = {
780     &google,
781     &bing,
782     &yahoo,
783     &duckduckgo,
784     &yandex_tr,
785 };
786
787 // Serbia
788 const PrepopulatedEngine* const engines_RS[] = {
789     &google,
790     &bing,
791     &yahoo,
792     &duckduckgo,
793     &yandex_ru,
794 };
795
796 // Russia
797 const PrepopulatedEngine* const engines_RU[] = {
798     &yandex_ru,
799     &google,
800     &duckduckgo,
801     &bing,
802     &mail_ru,
803 };
804
805 // Rwanda
806 const PrepopulatedEngine* const engines_RW[] = {
807     &google,
808     &bing,
809     &yahoo,
810     &duckduckgo,
811     &ecosia,
812 };
813
814 // Saudi Arabia
815 const PrepopulatedEngine* const engines_SA[] = {
816     &google,
817     &bing,
818     &yahoo,
819     &yandex_com,
820     &duckduckgo,
821 };
822
823 // Sweden
824 const PrepopulatedEngine* const engines_SE[] = {
825     &google,
826     &bing,
827     &yahoo_se,
828     &duckduckgo,
829     &yandex_ru,
830 };
831
832 // Singapore
833 const PrepopulatedEngine* const engines_SG[] = {
834     &google,
835     &bing,
836     &yahoo_sg,
837     &baidu,
838     &duckduckgo,
839 };
840
841 // Slovenia
842 const PrepopulatedEngine* const engines_SI[] = {
843     &google,
844     &bing,
845     &duckduckgo,
846     &yahoo,
847     &yandex_com,
848 };
849
850 // Slovakia
851 const PrepopulatedEngine* const engines_SK[] = {
852     &google,
853     &bing,
854     &duckduckgo,
855     &yahoo,
856     &yandex_ru,
857 };
858
859 // El Salvador
860 const PrepopulatedEngine* const engines_SV[] = {
861     &google,
862     &bing,
863     &yahoo_es,
864     &duckduckgo,
865     &ecosia,
866 };
867
868 // Syria
869 const PrepopulatedEngine* const engines_SY[] = {
870     &google,
871     &bing,
872     &yandex_ru,
873     &yahoo,
874     &duckduckgo,
875 };
876
877 // Thailand
878 const PrepopulatedEngine* const engines_TH[] = {
879     &google,
880     &bing,
881     &yahoo_th,
882     &naver,
883     &duckduckgo,
884 };
885
886 // Tunisia
887 const PrepopulatedEngine* const engines_TN[] = {
888     &google,
889     &bing,
890     &yahoo_fr,
891     &duckduckgo,
892     &yandex_com,
893 };
894
895 // Turkey
896 const PrepopulatedEngine* const engines_TR[] = {
897     &google,
898     &yandex_tr,
899     &yahoo_tr,
900     &bing,
901     &duckduckgo,
902 };
903
904 // Trinidad and Tobago
905 const PrepopulatedEngine* const engines_TT[] = {
906     &google,
907     &bing,
908     &yahoo,
909     &duckduckgo,
910     &yandex_com,
911 };
912
913 // Taiwan
914 const PrepopulatedEngine* const engines_TW[] = {
915     &google,
916     &yahoo_tw,
917     &bing,
918     &baidu,
919     &duckduckgo,
920 };
921
922 // Tanzania
923 const PrepopulatedEngine* const engines_TZ[] = {
924     &google,
925     &bing,
926     &yahoo,
927     &duckduckgo,
928     &ecosia,
929 };
930
931 // Ukraine
932 const PrepopulatedEngine* const engines_UA[] = {
933     &google,
934     &yandex_ru,
935     &bing,
936     &duckduckgo,
937     &mail_ru,
938 };
939
940 // United States
941 const PrepopulatedEngine* const engines_US[] = {
942     &google,
943     &bing,
944     &yahoo,
945     &duckduckgo,
946     &ecosia,
947 };
948
949 // Uruguay
950 const PrepopulatedEngine* const engines_UY[] = {
951     &google,
952     &bing,
953     &yahoo_es,
954     &duckduckgo,
955     &ecosia,
956 };
957
958 // Venezuela
959 const PrepopulatedEngine* const engines_VE[] = {
960     &google,
961     &bing,
962     &yahoo_es,
963     &duckduckgo,
964     &yandex_com,
965 };
966
967 // Vietnam
968 const PrepopulatedEngine* const engines_VN[] = {
969     &google,
970     &coccoc,
971     &bing,
972     &yahoo,
973     &baidu,
974 };
975
976 // Yemen
977 const PrepopulatedEngine* const engines_YE[] = {
978     &google,
979     &bing,
980     &yahoo,
981     &duckduckgo,
982     &yandex_com,
983 };
984
985 // South Africa
986 const PrepopulatedEngine* const engines_ZA[] = {
987     &google,
988     &bing,
989     &yahoo,
990     &duckduckgo,
991     &ecosia,
992 };
993
994 // Zimbabwe
995 const PrepopulatedEngine* const engines_ZW[] = {
996     &google,
997     &bing,
998     &yahoo,
999     &duckduckgo,
1000     &ecosia,
1001 };
1002
1003 // clang-format on
1004 // ----------------------------------------------------------------------------
1005
1006 std::vector<std::unique_ptr<TemplateURLData>> GetPrepopulationSetFromCountryID(
1007     int country_id) {
1008   const PrepopulatedEngine* const* engines;
1009   size_t num_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); \
1017   break;
1018 #define DECLARE_COUNTRY(code1, code2)\
1019     UNHANDLED_COUNTRY(code1, code2)\
1020     END_UNHANDLED_COUNTRIES(code1, code2)
1021
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
1130
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)
1137
1138     // Countries using the "China" engine set.
1139     UNHANDLED_COUNTRY(M, O)  // Macao
1140     END_UNHANDLED_COUNTRIES(C, N)
1141
1142     // Countries using the "Denmark" engine set.
1143     UNHANDLED_COUNTRY(G, L)  // Greenland
1144     END_UNHANDLED_COUNTRIES(D, K)
1145
1146     // Countries using the "Spain" engine set.
1147     UNHANDLED_COUNTRY(A, D)  // Andorra
1148     END_UNHANDLED_COUNTRIES(E, S)
1149
1150     // Countries using the "Finland" engine set.
1151     UNHANDLED_COUNTRY(A, X)  // Aland Islands
1152     END_UNHANDLED_COUNTRIES(F, I)
1153
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)
1171 #endif
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)
1186
1187     // Countries using the "Greece" engine set.
1188     UNHANDLED_COUNTRY(C, Y)  // Cyprus
1189     END_UNHANDLED_COUNTRIES(G, R)
1190
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)
1195
1196     // Countries using the "Morocco" engine set.
1197     UNHANDLED_COUNTRY(E, H)  // Western Sahara
1198     END_UNHANDLED_COUNTRIES(M, A)
1199
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)
1204
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)
1209
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)
1215
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)
1223
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)
1232
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)
1238
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
1245                              //   Islands
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
1254                              //   Cunha
1255     UNHANDLED_COUNTRY(T, C)  // Turks and Caicos Islands
1256     UNHANDLED_COUNTRY(V, G)  // British Virgin Islands
1257     END_UNHANDLED_COUNTRIES(G, B)
1258
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)
1266
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)
1329   }
1330
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]));
1334   return t_urls;
1335 }
1336
1337 std::vector<std::unique_ptr<TemplateURLData>> GetPrepopulatedTemplateURLData(
1338     PrefService* prefs) {
1339   std::vector<std::unique_ptr<TemplateURLData>> t_urls;
1340   if (!prefs)
1341     return t_urls;
1342
1343   const base::Value::List& list =
1344       prefs->GetList(prefs::kSearchProviderOverrides);
1345
1346   for (const base::Value& engine : list) {
1347     if (engine.is_dict()) {
1348     auto t_url = TemplateURLDataFromOverrideDictionary(engine.GetDict());
1349     if (t_url) {
1350       t_urls.push_back(std::move(t_url));
1351     }
1352     }
1353   }
1354   return t_urls;
1355 }
1356
1357 }  // namespace
1358
1359 // Global functions -----------------------------------------------------------
1360
1361 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
1362   country_codes::RegisterProfilePrefs(registry);
1363   registry->RegisterListPref(prefs::kSearchProviderOverrides);
1364   registry->RegisterIntegerPref(prefs::kSearchProviderOverridesVersion, -1);
1365 }
1366
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;
1372 }
1373
1374 std::vector<std::unique_ptr<TemplateURLData>> GetPrepopulatedEngines(
1375     PrefService* prefs,
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));
1384   }
1385   if (default_search_provider_index) {
1386     const auto itr =
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);
1390   }
1391   return t_urls;
1392 }
1393
1394 std::unique_ptr<TemplateURLData> GetPrepopulatedEngine(PrefService* prefs,
1395                                                        int prepopulated_id) {
1396   auto engines =
1397       TemplateURLPrepopulateData::GetPrepopulatedEngines(prefs, nullptr);
1398   for (auto& engine : engines) {
1399     if (engine->prepopulate_id == prepopulated_id)
1400       return std::move(engine);
1401   }
1402   return nullptr;
1403 }
1404
1405 #if BUILDFLAG(IS_ANDROID)
1406
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>>();
1413   }
1414
1415   return GetPrepopulationSetFromCountryID(country_id);
1416 }
1417
1418 #endif
1419
1420 std::vector<const PrepopulatedEngine*> GetAllPrepopulatedEngines() {
1421   return std::vector<const PrepopulatedEngine*>(
1422       &kAllEngines[0], &kAllEngines[0] + kAllEnginesLength);
1423 }
1424
1425 void ClearPrepopulatedEnginesInPrefs(PrefService* prefs) {
1426   if (!prefs)
1427     return;
1428
1429   prefs->ClearPref(prefs::kSearchProviderOverrides);
1430   prefs->ClearPref(prefs::kSearchProviderOverridesVersion);
1431 }
1432
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);
1439
1440   return (default_search_index < loaded_urls.size())
1441              ? std::move(loaded_urls[default_search_index])
1442              : nullptr;
1443 }
1444
1445 }  // namespace TemplateURLPrepopulateData