template_url_prepopulate_data.cc 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444
  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
  3. // found in the LICENSE file.
  4. #include "components/search_engines/template_url_prepopulate_data.h"
  5. #include "base/logging.h"
  6. #include "build/build_config.h"
  7. #include "components/country_codes/country_codes.h"
  8. #include "components/pref_registry/pref_registry_syncable.h"
  9. #include "components/prefs/pref_service.h"
  10. #include "components/search_engines/prepopulated_engines.h"
  11. #include "components/search_engines/search_engines_pref_names.h"
  12. #include "components/search_engines/template_url_data.h"
  13. #include "components/search_engines/template_url_data_util.h"
  14. namespace TemplateURLPrepopulateData {
  15. // Helpers --------------------------------------------------------------------
  16. namespace {
  17. // NOTE: You should probably not change the data in this file without changing
  18. // |kCurrentDataVersion| in prepopulated_engines.json. See comments in
  19. // GetDataVersion() below!
  20. // Put the engines within each country in order with most interesting/important
  21. // first. The default will be the first engine.
  22. // Default (for countries with no better engine set)
  23. const PrepopulatedEngine* const engines_default[] = {
  24. &google,
  25. &bing,
  26. &yahoo,
  27. };
  28. // Note, the below entries are sorted by country code, not the name in comment.
  29. // Engine selection by country ------------------------------------------------
  30. // clang-format off
  31. // United Arab Emirates
  32. const PrepopulatedEngine* const engines_AE[] = {
  33. &google,
  34. &bing,
  35. &yahoo,
  36. &duckduckgo,
  37. &ecosia,
  38. };
  39. // Albania
  40. const PrepopulatedEngine* const engines_AL[] = {
  41. &google,
  42. &bing,
  43. &yahoo,
  44. &duckduckgo,
  45. &yandex_com,
  46. };
  47. // Argentina
  48. const PrepopulatedEngine* const engines_AR[] = {
  49. &google,
  50. &bing,
  51. &yahoo_ar,
  52. &duckduckgo,
  53. &ecosia,
  54. };
  55. // Austria
  56. const PrepopulatedEngine* const engines_AT[] = {
  57. &google,
  58. &bing,
  59. &duckduckgo,
  60. &yahoo_at,
  61. &ecosia,
  62. };
  63. // Australia
  64. const PrepopulatedEngine* const engines_AU[] = {
  65. &google,
  66. &bing,
  67. &yahoo_au,
  68. &duckduckgo,
  69. &ecosia,
  70. };
  71. // Bosnia and Herzegovina
  72. const PrepopulatedEngine* const engines_BA[] = {
  73. &google,
  74. &bing,
  75. &yahoo,
  76. &duckduckgo,
  77. &yandex_com,
  78. };
  79. // Belgium
  80. const PrepopulatedEngine* const engines_BE[] = {
  81. &google,
  82. &bing,
  83. &yahoo,
  84. &ecosia,
  85. &duckduckgo,
  86. };
  87. // Bulgaria
  88. const PrepopulatedEngine* const engines_BG[] = {
  89. &google,
  90. &bing,
  91. &yahoo,
  92. &duckduckgo,
  93. &yandex_ru,
  94. };
  95. // Bahrain
  96. const PrepopulatedEngine* const engines_BH[] = {
  97. &google,
  98. &bing,
  99. &yahoo,
  100. &duckduckgo,
  101. &yandex_com,
  102. };
  103. // Burundi
  104. const PrepopulatedEngine* const engines_BI[] = {
  105. &google,
  106. &bing,
  107. &yahoo,
  108. &duckduckgo,
  109. &yandex_ru,
  110. };
  111. // Brunei
  112. const PrepopulatedEngine* const engines_BN[] = {
  113. &google,
  114. &bing,
  115. &yahoo,
  116. &duckduckgo,
  117. &ecosia,
  118. };
  119. // Bolivia
  120. const PrepopulatedEngine* const engines_BO[] = {
  121. &google,
  122. &bing,
  123. &yahoo,
  124. &duckduckgo,
  125. &ecosia,
  126. };
  127. // Brazil
  128. const PrepopulatedEngine* const engines_BR[] = {
  129. &google,
  130. &bing,
  131. &yahoo_br,
  132. &duckduckgo,
  133. &ecosia,
  134. };
  135. // Belarus
  136. const PrepopulatedEngine* const engines_BY[] = {
  137. &google,
  138. &yandex_by,
  139. &mail_ru,
  140. &bing,
  141. &duckduckgo,
  142. };
  143. // Belize
  144. const PrepopulatedEngine* const engines_BZ[] = {
  145. &google,
  146. &bing,
  147. &yahoo,
  148. &duckduckgo,
  149. &ecosia,
  150. };
  151. // Canada
  152. const PrepopulatedEngine* const engines_CA[] = {
  153. &google,
  154. &bing,
  155. &yahoo_ca,
  156. &duckduckgo,
  157. &ecosia,
  158. };
  159. // Switzerland
  160. const PrepopulatedEngine* const engines_CH[] = {
  161. &google,
  162. &bing,
  163. &duckduckgo,
  164. &ecosia,
  165. &yahoo_ch,
  166. };
  167. // Chile
  168. const PrepopulatedEngine* const engines_CL[] = {
  169. &google,
  170. &bing,
  171. &yahoo_cl,
  172. &duckduckgo,
  173. &ecosia,
  174. };
  175. // China
  176. const PrepopulatedEngine* const engines_CN[] = {
  177. &sogou,
  178. &baidu,
  179. &bing,
  180. &google,
  181. &so_360,
  182. };
  183. // Colombia
  184. const PrepopulatedEngine* const engines_CO[] = {
  185. &google,
  186. &bing,
  187. &yahoo_co,
  188. &ecosia,
  189. &duckduckgo,
  190. };
  191. // Costa Rica
  192. const PrepopulatedEngine* const engines_CR[] = {
  193. &google,
  194. &bing,
  195. &yahoo,
  196. &duckduckgo,
  197. &ecosia,
  198. };
  199. // Czech Republic
  200. const PrepopulatedEngine* const engines_CZ[] = {
  201. &google,
  202. &seznam_cz,
  203. &bing,
  204. &yahoo,
  205. &duckduckgo,
  206. };
  207. // Germany
  208. const PrepopulatedEngine* const engines_DE[] = {
  209. &google,
  210. &bing,
  211. &ecosia,
  212. &duckduckgo,
  213. &yahoo_de,
  214. };
  215. // Denmark
  216. const PrepopulatedEngine* const engines_DK[] = {
  217. &google,
  218. &bing,
  219. &yahoo_dk,
  220. &duckduckgo,
  221. &ecosia,
  222. };
  223. // Dominican Republic
  224. const PrepopulatedEngine* const engines_DO[] = {
  225. &google,
  226. &bing,
  227. &yahoo,
  228. &duckduckgo,
  229. &ecosia,
  230. };
  231. // Algeria
  232. const PrepopulatedEngine* const engines_DZ[] = {
  233. &google,
  234. &bing,
  235. &yahoo_fr,
  236. &yandex_com,
  237. &duckduckgo,
  238. };
  239. // Ecuador
  240. const PrepopulatedEngine* const engines_EC[] = {
  241. &google,
  242. &bing,
  243. &yahoo,
  244. &ecosia,
  245. &duckduckgo,
  246. };
  247. // Estonia
  248. const PrepopulatedEngine* const engines_EE[] = {
  249. &google,
  250. &bing,
  251. &yandex_ru,
  252. &duckduckgo,
  253. &yahoo,
  254. };
  255. // Egypt
  256. const PrepopulatedEngine* const engines_EG[] = {
  257. &google,
  258. &bing,
  259. &yahoo,
  260. &yandex_com,
  261. &duckduckgo,
  262. };
  263. // Spain
  264. const PrepopulatedEngine* const engines_ES[] = {
  265. &google,
  266. &bing,
  267. &yahoo_es,
  268. &duckduckgo,
  269. &ecosia,
  270. };
  271. // Finland
  272. const PrepopulatedEngine* const engines_FI[] = {
  273. &google,
  274. &bing,
  275. &yahoo_fi,
  276. &duckduckgo,
  277. &yandex_ru,
  278. };
  279. // Faroe Islands
  280. const PrepopulatedEngine* const engines_FO[] = {
  281. &google,
  282. &bing,
  283. &yahoo_dk,
  284. &duckduckgo,
  285. &ecosia,
  286. };
  287. // France
  288. const PrepopulatedEngine* const engines_FR[] = {
  289. &google,
  290. &bing,
  291. &yahoo_fr,
  292. &qwant,
  293. &ecosia,
  294. };
  295. // United Kingdom
  296. const PrepopulatedEngine* const engines_GB[] = {
  297. &google,
  298. &bing,
  299. &yahoo_uk,
  300. &duckduckgo,
  301. &ecosia,
  302. };
  303. // Greece
  304. const PrepopulatedEngine* const engines_GR[] = {
  305. &google,
  306. &bing,
  307. &yahoo,
  308. &duckduckgo,
  309. &yandex_ru,
  310. };
  311. // Guatemala
  312. const PrepopulatedEngine* const engines_GT[] = {
  313. &google,
  314. &bing,
  315. &yahoo,
  316. &duckduckgo,
  317. &ecosia,
  318. };
  319. // Hong Kong
  320. const PrepopulatedEngine* const engines_HK[] = {
  321. &google,
  322. &yahoo_hk,
  323. &bing,
  324. &baidu,
  325. &duckduckgo,
  326. };
  327. // Honduras
  328. const PrepopulatedEngine* const engines_HN[] = {
  329. &google,
  330. &bing,
  331. &yahoo,
  332. &duckduckgo,
  333. &ecosia,
  334. };
  335. // Croatia
  336. const PrepopulatedEngine* const engines_HR[] = {
  337. &google,
  338. &bing,
  339. &yahoo,
  340. &duckduckgo,
  341. &ecosia,
  342. };
  343. // Hungary
  344. const PrepopulatedEngine* const engines_HU[] = {
  345. &google,
  346. &bing,
  347. &yahoo,
  348. &duckduckgo,
  349. &yandex_com,
  350. };
  351. // Indonesia
  352. const PrepopulatedEngine* const engines_ID[] = {
  353. &google,
  354. &yahoo_id,
  355. &bing,
  356. &yandex_com,
  357. &duckduckgo,
  358. };
  359. // Ireland
  360. const PrepopulatedEngine* const engines_IE[] = {
  361. &google,
  362. &bing,
  363. &yahoo_uk,
  364. &duckduckgo,
  365. &ecosia,
  366. };
  367. // Israel
  368. const PrepopulatedEngine* const engines_IL[] = {
  369. &google,
  370. &bing,
  371. &yandex_ru,
  372. &yahoo,
  373. &duckduckgo,
  374. };
  375. // India
  376. const PrepopulatedEngine* const engines_IN[] = {
  377. &google,
  378. &bing,
  379. &yahoo_in,
  380. &duckduckgo,
  381. &info_com,
  382. };
  383. // Iraq
  384. const PrepopulatedEngine* const engines_IQ[] = {
  385. &google,
  386. &bing,
  387. &yahoo,
  388. &yandex_tr,
  389. &duckduckgo,
  390. };
  391. // Iran
  392. const PrepopulatedEngine* const engines_IR[] = {
  393. &google,
  394. &bing,
  395. &yahoo,
  396. &ask,
  397. &duckduckgo,
  398. };
  399. // Iceland
  400. const PrepopulatedEngine* const engines_IS[] = {
  401. &google,
  402. &bing,
  403. &duckduckgo,
  404. &yahoo,
  405. &ecosia,
  406. };
  407. // Italy
  408. const PrepopulatedEngine* const engines_IT[] = {
  409. &google,
  410. &bing,
  411. &yahoo,
  412. &duckduckgo,
  413. &ecosia,
  414. };
  415. // Jamaica
  416. const PrepopulatedEngine* const engines_JM[] = {
  417. &google,
  418. &bing,
  419. &yahoo,
  420. &duckduckgo,
  421. &ecosia,
  422. };
  423. // Jordan
  424. const PrepopulatedEngine* const engines_JO[] = {
  425. &google,
  426. &bing,
  427. &yahoo,
  428. &duckduckgo,
  429. &yandex_com,
  430. };
  431. // Japan
  432. const PrepopulatedEngine* const engines_JP[] = {
  433. &google,
  434. &yahoo_jp,
  435. &bing,
  436. &duckduckgo,
  437. &baidu,
  438. };
  439. // Kenya
  440. const PrepopulatedEngine* const engines_KE[] = {
  441. &google,
  442. &bing,
  443. &yahoo,
  444. &duckduckgo,
  445. &ecosia,
  446. };
  447. // South Korea
  448. const PrepopulatedEngine* const engines_KR[] = {
  449. &google,
  450. &naver,
  451. &daum,
  452. &bing,
  453. &yahoo,
  454. };
  455. // Kuwait
  456. const PrepopulatedEngine* const engines_KW[] = {
  457. &google,
  458. &bing,
  459. &yahoo,
  460. &duckduckgo,
  461. &yandex_com,
  462. };
  463. // Kazakhstan
  464. const PrepopulatedEngine* const engines_KZ[] = {
  465. &google,
  466. &yandex_kz,
  467. &mail_ru,
  468. &bing,
  469. &duckduckgo,
  470. };
  471. // Lebanon
  472. const PrepopulatedEngine* const engines_LB[] = {
  473. &google,
  474. &bing,
  475. &yahoo,
  476. &duckduckgo,
  477. &ecosia,
  478. };
  479. // Liechtenstein
  480. const PrepopulatedEngine* const engines_LI[] = {
  481. &google,
  482. &bing,
  483. &duckduckgo,
  484. &yahoo,
  485. &ecosia,
  486. };
  487. // Lithuania
  488. const PrepopulatedEngine* const engines_LT[] = {
  489. &google,
  490. &bing,
  491. &yahoo,
  492. &duckduckgo,
  493. &yandex_ru,
  494. };
  495. // Luxembourg
  496. const PrepopulatedEngine* const engines_LU[] = {
  497. &google,
  498. &bing,
  499. &duckduckgo,
  500. &yahoo,
  501. &ecosia,
  502. };
  503. // Latvia
  504. const PrepopulatedEngine* const engines_LV[] = {
  505. &google,
  506. &bing,
  507. &yandex_ru,
  508. &yahoo,
  509. &duckduckgo,
  510. };
  511. // Libya
  512. const PrepopulatedEngine* const engines_LY[] = {
  513. &google,
  514. &bing,
  515. &yahoo,
  516. &yandex_com,
  517. &duckduckgo,
  518. };
  519. // Morocco
  520. const PrepopulatedEngine* const engines_MA[] = {
  521. &google,
  522. &bing,
  523. &yahoo_fr,
  524. &yandex_com,
  525. &duckduckgo,
  526. };
  527. // Monaco
  528. const PrepopulatedEngine* const engines_MC[] = {
  529. &google,
  530. &bing,
  531. &duckduckgo,
  532. &yahoo_fr,
  533. &ecosia,
  534. };
  535. // Moldova
  536. const PrepopulatedEngine* const engines_MD[] = {
  537. &google,
  538. &yandex_ru,
  539. &bing,
  540. &mail_ru,
  541. &yahoo,
  542. };
  543. // Montenegro
  544. const PrepopulatedEngine* const engines_ME[] = {
  545. &google,
  546. &bing,
  547. &yahoo,
  548. &yandex_ru,
  549. &duckduckgo,
  550. };
  551. // Macedonia
  552. const PrepopulatedEngine* const engines_MK[] = {
  553. &google,
  554. &bing,
  555. &yahoo,
  556. &duckduckgo,
  557. &yandex_ru,
  558. };
  559. // Mexico
  560. const PrepopulatedEngine* const engines_MX[] = {
  561. &google,
  562. &bing,
  563. &yahoo_mx,
  564. &duckduckgo,
  565. &ecosia,
  566. };
  567. // Malaysia
  568. const PrepopulatedEngine* const engines_MY[] = {
  569. &google,
  570. &bing,
  571. &yahoo_my,
  572. &duckduckgo,
  573. &ecosia,
  574. };
  575. // Nicaragua
  576. const PrepopulatedEngine* const engines_NI[] = {
  577. &google,
  578. &bing,
  579. &yahoo,
  580. &duckduckgo,
  581. &ecosia,
  582. };
  583. // Netherlands
  584. const PrepopulatedEngine* const engines_NL[] = {
  585. &google,
  586. &bing,
  587. &yahoo_nl,
  588. &duckduckgo,
  589. &ecosia,
  590. };
  591. // Norway
  592. const PrepopulatedEngine* const engines_NO[] = {
  593. &google,
  594. &bing,
  595. &yahoo,
  596. &duckduckgo,
  597. &ecosia,
  598. };
  599. // New Zealand
  600. const PrepopulatedEngine* const engines_NZ[] = {
  601. &google,
  602. &bing,
  603. &yahoo_nz,
  604. &duckduckgo,
  605. &ecosia,
  606. };
  607. // Oman
  608. const PrepopulatedEngine* const engines_OM[] = {
  609. &google,
  610. &bing,
  611. &yahoo,
  612. &duckduckgo,
  613. &petal_search,
  614. };
  615. // Panama
  616. const PrepopulatedEngine* const engines_PA[] = {
  617. &google,
  618. &bing,
  619. &yahoo_es,
  620. &duckduckgo,
  621. &ecosia,
  622. };
  623. // Peru
  624. const PrepopulatedEngine* const engines_PE[] = {
  625. &google,
  626. &bing,
  627. &yahoo_pe,
  628. &ecosia,
  629. &duckduckgo,
  630. };
  631. // Philippines
  632. const PrepopulatedEngine* const engines_PH[] = {
  633. &google,
  634. &bing,
  635. &yahoo,
  636. &ecosia,
  637. &duckduckgo,
  638. };
  639. // Pakistan
  640. const PrepopulatedEngine* const engines_PK[] = {
  641. &google,
  642. &bing,
  643. &yahoo,
  644. &duckduckgo,
  645. &yandex_com,
  646. };
  647. // Poland
  648. const PrepopulatedEngine* const engines_PL[] = {
  649. &google,
  650. &bing,
  651. &yahoo,
  652. &duckduckgo,
  653. &yandex_ru,
  654. };
  655. // Puerto Rico
  656. const PrepopulatedEngine* const engines_PR[] = {
  657. &google,
  658. &bing,
  659. &yahoo,
  660. &duckduckgo,
  661. &ecosia,
  662. };
  663. // Portugal
  664. const PrepopulatedEngine* const engines_PT[] = {
  665. &google,
  666. &bing,
  667. &yahoo,
  668. &duckduckgo,
  669. &ecosia,
  670. };
  671. // Paraguay
  672. const PrepopulatedEngine* const engines_PY[] = {
  673. &google,
  674. &bing,
  675. &yahoo_es,
  676. &duckduckgo,
  677. &ecosia,
  678. };
  679. // Qatar
  680. const PrepopulatedEngine* const engines_QA[] = {
  681. &google,
  682. &bing,
  683. &yahoo,
  684. &duckduckgo,
  685. &yandex_tr,
  686. };
  687. // Romania
  688. const PrepopulatedEngine* const engines_RO[] = {
  689. &google,
  690. &bing,
  691. &yahoo,
  692. &duckduckgo,
  693. &yandex_tr,
  694. };
  695. // Serbia
  696. const PrepopulatedEngine* const engines_RS[] = {
  697. &google,
  698. &bing,
  699. &yahoo,
  700. &duckduckgo,
  701. &yandex_ru,
  702. };
  703. // Russia
  704. const PrepopulatedEngine* const engines_RU[] = {
  705. &google,
  706. &yandex_ru,
  707. &mail_ru,
  708. &bing,
  709. &duckduckgo,
  710. };
  711. // Rwanda
  712. const PrepopulatedEngine* const engines_RW[] = {
  713. &google,
  714. &bing,
  715. &yahoo,
  716. &duckduckgo,
  717. &ecosia,
  718. };
  719. // Saudi Arabia
  720. const PrepopulatedEngine* const engines_SA[] = {
  721. &google,
  722. &bing,
  723. &yahoo,
  724. &yandex_com,
  725. &duckduckgo,
  726. };
  727. // Sweden
  728. const PrepopulatedEngine* const engines_SE[] = {
  729. &google,
  730. &bing,
  731. &yahoo_se,
  732. &duckduckgo,
  733. &ecosia,
  734. };
  735. // Singapore
  736. const PrepopulatedEngine* const engines_SG[] = {
  737. &google,
  738. &bing,
  739. &yahoo_sg,
  740. &duckduckgo,
  741. &baidu,
  742. };
  743. // Slovenia
  744. const PrepopulatedEngine* const engines_SI[] = {
  745. &google,
  746. &bing,
  747. &duckduckgo,
  748. &yahoo,
  749. &yandex_com,
  750. };
  751. // Slovakia
  752. const PrepopulatedEngine* const engines_SK[] = {
  753. &google,
  754. &bing,
  755. &duckduckgo,
  756. &yahoo,
  757. &yandex_com,
  758. };
  759. // El Salvador
  760. const PrepopulatedEngine* const engines_SV[] = {
  761. &google,
  762. &bing,
  763. &yahoo_es,
  764. &duckduckgo,
  765. &ecosia,
  766. };
  767. // Syria
  768. const PrepopulatedEngine* const engines_SY[] = {
  769. &google,
  770. &bing,
  771. &yahoo,
  772. &yandex_com,
  773. &duckduckgo,
  774. };
  775. // Thailand
  776. const PrepopulatedEngine* const engines_TH[] = {
  777. &google,
  778. &bing,
  779. &yahoo_th,
  780. &yandex_ru,
  781. &mail_ru,
  782. };
  783. // Tunisia
  784. const PrepopulatedEngine* const engines_TN[] = {
  785. &google,
  786. &bing,
  787. &yahoo_fr,
  788. &duckduckgo,
  789. &yandex_com,
  790. };
  791. // Turkey
  792. const PrepopulatedEngine* const engines_TR[] = {
  793. &google,
  794. &yandex_tr,
  795. &yahoo_tr,
  796. &bing,
  797. &duckduckgo,
  798. };
  799. // Trinidad and Tobago
  800. const PrepopulatedEngine* const engines_TT[] = {
  801. &google,
  802. &bing,
  803. &yahoo,
  804. &duckduckgo,
  805. &ecosia,
  806. };
  807. // Taiwan
  808. const PrepopulatedEngine* const engines_TW[] = {
  809. &google,
  810. &yahoo_tw,
  811. &bing,
  812. &baidu,
  813. &duckduckgo,
  814. };
  815. // Tanzania
  816. const PrepopulatedEngine* const engines_TZ[] = {
  817. &google,
  818. &bing,
  819. &yahoo,
  820. &duckduckgo,
  821. &baidu,
  822. };
  823. // Ukraine
  824. const PrepopulatedEngine* const engines_UA[] = {
  825. &google,
  826. &yandex_ua,
  827. &bing,
  828. &duckduckgo,
  829. &yahoo,
  830. };
  831. // United States
  832. const PrepopulatedEngine* const engines_US[] = {
  833. &google,
  834. &bing,
  835. &yahoo,
  836. &duckduckgo,
  837. &ecosia,
  838. };
  839. // Uruguay
  840. const PrepopulatedEngine* const engines_UY[] = {
  841. &google,
  842. &bing,
  843. &yahoo_es,
  844. &duckduckgo,
  845. &ecosia,
  846. };
  847. // Venezuela
  848. const PrepopulatedEngine* const engines_VE[] = {
  849. &google,
  850. &bing,
  851. &yahoo_es,
  852. &duckduckgo,
  853. &ecosia,
  854. };
  855. // Vietnam
  856. const PrepopulatedEngine* const engines_VN[] = {
  857. &google,
  858. &coccoc,
  859. &yahoo,
  860. &bing,
  861. &yandex_ru,
  862. };
  863. // Yemen
  864. const PrepopulatedEngine* const engines_YE[] = {
  865. &google,
  866. &bing,
  867. &yahoo,
  868. &yandex_com,
  869. &duckduckgo,
  870. };
  871. // South Africa
  872. const PrepopulatedEngine* const engines_ZA[] = {
  873. &google,
  874. &bing,
  875. &yahoo,
  876. &duckduckgo,
  877. &ecosia,
  878. };
  879. // Zimbabwe
  880. const PrepopulatedEngine* const engines_ZW[] = {
  881. &google,
  882. &bing,
  883. &yahoo,
  884. &duckduckgo,
  885. &ecosia,
  886. };
  887. // clang-format on
  888. // ----------------------------------------------------------------------------
  889. std::vector<std::unique_ptr<TemplateURLData>> GetPrepopulationSetFromCountryID(
  890. int country_id) {
  891. const PrepopulatedEngine* const* engines;
  892. size_t num_engines;
  893. // If you add a new country make sure to update the unit test for coverage.
  894. switch (country_id) {
  895. #define UNHANDLED_COUNTRY(code1, code2) \
  896. case country_codes::CountryCharsToCountryID((#code1)[0], (#code2)[0]):
  897. #define END_UNHANDLED_COUNTRIES(code1, code2) \
  898. engines = engines_##code1##code2; \
  899. num_engines = std::size(engines_##code1##code2); \
  900. break;
  901. #define DECLARE_COUNTRY(code1, code2)\
  902. UNHANDLED_COUNTRY(code1, code2)\
  903. END_UNHANDLED_COUNTRIES(code1, code2)
  904. // Countries with their own, dedicated engine set.
  905. DECLARE_COUNTRY(A, E) // United Arab Emirates
  906. DECLARE_COUNTRY(A, L) // Albania
  907. DECLARE_COUNTRY(A, R) // Argentina
  908. DECLARE_COUNTRY(A, T) // Austria
  909. DECLARE_COUNTRY(A, U) // Australia
  910. DECLARE_COUNTRY(B, A) // Bosnia and Herzegovina
  911. DECLARE_COUNTRY(B, E) // Belgium
  912. DECLARE_COUNTRY(B, G) // Bulgaria
  913. DECLARE_COUNTRY(B, H) // Bahrain
  914. DECLARE_COUNTRY(B, I) // Burundi
  915. DECLARE_COUNTRY(B, N) // Brunei
  916. DECLARE_COUNTRY(B, O) // Bolivia
  917. DECLARE_COUNTRY(B, R) // Brazil
  918. DECLARE_COUNTRY(B, Y) // Belarus
  919. DECLARE_COUNTRY(B, Z) // Belize
  920. DECLARE_COUNTRY(C, A) // Canada
  921. DECLARE_COUNTRY(C, H) // Switzerland
  922. DECLARE_COUNTRY(C, L) // Chile
  923. DECLARE_COUNTRY(C, N) // China
  924. DECLARE_COUNTRY(C, O) // Colombia
  925. DECLARE_COUNTRY(C, R) // Costa Rica
  926. DECLARE_COUNTRY(C, Z) // Czech Republic
  927. DECLARE_COUNTRY(D, E) // Germany
  928. DECLARE_COUNTRY(D, K) // Denmark
  929. DECLARE_COUNTRY(D, O) // Dominican Republic
  930. DECLARE_COUNTRY(D, Z) // Algeria
  931. DECLARE_COUNTRY(E, C) // Ecuador
  932. DECLARE_COUNTRY(E, E) // Estonia
  933. DECLARE_COUNTRY(E, G) // Egypt
  934. DECLARE_COUNTRY(E, S) // Spain
  935. DECLARE_COUNTRY(F, I) // Finland
  936. DECLARE_COUNTRY(F, O) // Faroe Islands
  937. DECLARE_COUNTRY(F, R) // France
  938. DECLARE_COUNTRY(G, B) // United Kingdom
  939. DECLARE_COUNTRY(G, R) // Greece
  940. DECLARE_COUNTRY(G, T) // Guatemala
  941. DECLARE_COUNTRY(H, K) // Hong Kong
  942. DECLARE_COUNTRY(H, N) // Honduras
  943. DECLARE_COUNTRY(H, R) // Croatia
  944. DECLARE_COUNTRY(H, U) // Hungary
  945. DECLARE_COUNTRY(I, D) // Indonesia
  946. DECLARE_COUNTRY(I, E) // Ireland
  947. DECLARE_COUNTRY(I, L) // Israel
  948. DECLARE_COUNTRY(I, N) // India
  949. DECLARE_COUNTRY(I, Q) // Iraq
  950. DECLARE_COUNTRY(I, R) // Iran
  951. DECLARE_COUNTRY(I, S) // Iceland
  952. DECLARE_COUNTRY(I, T) // Italy
  953. DECLARE_COUNTRY(J, M) // Jamaica
  954. DECLARE_COUNTRY(J, O) // Jordan
  955. DECLARE_COUNTRY(J, P) // Japan
  956. DECLARE_COUNTRY(K, E) // Kenya
  957. DECLARE_COUNTRY(K, R) // South Korea
  958. DECLARE_COUNTRY(K, W) // Kuwait
  959. DECLARE_COUNTRY(K, Z) // Kazakhstan
  960. DECLARE_COUNTRY(L, B) // Lebanon
  961. DECLARE_COUNTRY(L, I) // Liechtenstein
  962. DECLARE_COUNTRY(L, T) // Lithuania
  963. DECLARE_COUNTRY(L, U) // Luxembourg
  964. DECLARE_COUNTRY(L, V) // Latvia
  965. DECLARE_COUNTRY(L, Y) // Libya
  966. DECLARE_COUNTRY(M, A) // Morocco
  967. DECLARE_COUNTRY(M, C) // Monaco
  968. DECLARE_COUNTRY(M, D) // Moldova
  969. DECLARE_COUNTRY(M, E) // Montenegro
  970. DECLARE_COUNTRY(M, K) // Macedonia
  971. DECLARE_COUNTRY(M, X) // Mexico
  972. DECLARE_COUNTRY(M, Y) // Malaysia
  973. DECLARE_COUNTRY(N, I) // Nicaragua
  974. DECLARE_COUNTRY(N, L) // Netherlands
  975. DECLARE_COUNTRY(N, O) // Norway
  976. DECLARE_COUNTRY(N, Z) // New Zealand
  977. DECLARE_COUNTRY(O, M) // Oman
  978. DECLARE_COUNTRY(P, A) // Panama
  979. DECLARE_COUNTRY(P, E) // Peru
  980. DECLARE_COUNTRY(P, H) // Philippines
  981. DECLARE_COUNTRY(P, K) // Pakistan
  982. DECLARE_COUNTRY(P, L) // Poland
  983. DECLARE_COUNTRY(P, R) // Puerto Rico
  984. DECLARE_COUNTRY(P, T) // Portugal
  985. DECLARE_COUNTRY(P, Y) // Paraguay
  986. DECLARE_COUNTRY(Q, A) // Qatar
  987. DECLARE_COUNTRY(R, O) // Romania
  988. DECLARE_COUNTRY(R, S) // Serbia
  989. DECLARE_COUNTRY(R, U) // Russia
  990. DECLARE_COUNTRY(R, W) // Rwanda
  991. DECLARE_COUNTRY(S, A) // Saudi Arabia
  992. DECLARE_COUNTRY(S, E) // Sweden
  993. DECLARE_COUNTRY(S, G) // Singapore
  994. DECLARE_COUNTRY(S, I) // Slovenia
  995. DECLARE_COUNTRY(S, K) // Slovakia
  996. DECLARE_COUNTRY(S, V) // El Salvador
  997. DECLARE_COUNTRY(S, Y) // Syria
  998. DECLARE_COUNTRY(T, H) // Thailand
  999. DECLARE_COUNTRY(T, N) // Tunisia
  1000. DECLARE_COUNTRY(T, R) // Turkey
  1001. DECLARE_COUNTRY(T, T) // Trinidad and Tobago
  1002. DECLARE_COUNTRY(T, W) // Taiwan
  1003. DECLARE_COUNTRY(T, Z) // Tanzania
  1004. DECLARE_COUNTRY(U, A) // Ukraine
  1005. DECLARE_COUNTRY(U, S) // United States
  1006. DECLARE_COUNTRY(U, Y) // Uruguay
  1007. DECLARE_COUNTRY(V, E) // Venezuela
  1008. DECLARE_COUNTRY(V, N) // Vietnam
  1009. DECLARE_COUNTRY(Y, E) // Yemen
  1010. DECLARE_COUNTRY(Z, A) // South Africa
  1011. DECLARE_COUNTRY(Z, W) // Zimbabwe
  1012. // Countries using the "Australia" engine set.
  1013. UNHANDLED_COUNTRY(C, C) // Cocos Islands
  1014. UNHANDLED_COUNTRY(C, X) // Christmas Island
  1015. UNHANDLED_COUNTRY(H, M) // Heard Island and McDonald Islands
  1016. UNHANDLED_COUNTRY(N, F) // Norfolk Island
  1017. END_UNHANDLED_COUNTRIES(A, U)
  1018. // Countries using the "China" engine set.
  1019. UNHANDLED_COUNTRY(M, O) // Macao
  1020. END_UNHANDLED_COUNTRIES(C, N)
  1021. // Countries using the "Denmark" engine set.
  1022. UNHANDLED_COUNTRY(G, L) // Greenland
  1023. END_UNHANDLED_COUNTRIES(D, K)
  1024. // Countries using the "Spain" engine set.
  1025. UNHANDLED_COUNTRY(A, D) // Andorra
  1026. END_UNHANDLED_COUNTRIES(E, S)
  1027. // Countries using the "Finland" engine set.
  1028. UNHANDLED_COUNTRY(A, X) // Aland Islands
  1029. END_UNHANDLED_COUNTRIES(F, I)
  1030. // Countries using the "France" engine set.
  1031. UNHANDLED_COUNTRY(B, F) // Burkina Faso
  1032. UNHANDLED_COUNTRY(B, J) // Benin
  1033. UNHANDLED_COUNTRY(C, D) // Congo - Kinshasa
  1034. UNHANDLED_COUNTRY(C, F) // Central African Republic
  1035. UNHANDLED_COUNTRY(C, G) // Congo - Brazzaville
  1036. UNHANDLED_COUNTRY(C, I) // Ivory Coast
  1037. UNHANDLED_COUNTRY(C, M) // Cameroon
  1038. UNHANDLED_COUNTRY(D, J) // Djibouti
  1039. UNHANDLED_COUNTRY(G, A) // Gabon
  1040. UNHANDLED_COUNTRY(G, F) // French Guiana
  1041. UNHANDLED_COUNTRY(G, N) // Guinea
  1042. UNHANDLED_COUNTRY(G, P) // Guadeloupe
  1043. UNHANDLED_COUNTRY(H, T) // Haiti
  1044. #if BUILDFLAG(IS_WIN)
  1045. UNHANDLED_COUNTRY(I, P) // Clipperton Island ('IP' is an WinXP-ism; ISO
  1046. // includes it with France)
  1047. #endif
  1048. UNHANDLED_COUNTRY(M, L) // Mali
  1049. UNHANDLED_COUNTRY(M, Q) // Martinique
  1050. UNHANDLED_COUNTRY(N, C) // New Caledonia
  1051. UNHANDLED_COUNTRY(N, E) // Niger
  1052. UNHANDLED_COUNTRY(P, F) // French Polynesia
  1053. UNHANDLED_COUNTRY(P, M) // Saint Pierre and Miquelon
  1054. UNHANDLED_COUNTRY(R, E) // Reunion
  1055. UNHANDLED_COUNTRY(S, N) // Senegal
  1056. UNHANDLED_COUNTRY(T, D) // Chad
  1057. UNHANDLED_COUNTRY(T, F) // French Southern Territories
  1058. UNHANDLED_COUNTRY(T, G) // Togo
  1059. UNHANDLED_COUNTRY(W, F) // Wallis and Futuna
  1060. UNHANDLED_COUNTRY(Y, T) // Mayotte
  1061. END_UNHANDLED_COUNTRIES(F, R)
  1062. // Countries using the "Greece" engine set.
  1063. UNHANDLED_COUNTRY(C, Y) // Cyprus
  1064. END_UNHANDLED_COUNTRIES(G, R)
  1065. // Countries using the "Italy" engine set.
  1066. UNHANDLED_COUNTRY(S, M) // San Marino
  1067. UNHANDLED_COUNTRY(V, A) // Vatican
  1068. END_UNHANDLED_COUNTRIES(I, T)
  1069. // Countries using the "Morocco" engine set.
  1070. UNHANDLED_COUNTRY(E, H) // Western Sahara
  1071. END_UNHANDLED_COUNTRIES(M, A)
  1072. // Countries using the "Netherlands" engine set.
  1073. UNHANDLED_COUNTRY(A, N) // Netherlands Antilles
  1074. UNHANDLED_COUNTRY(A, W) // Aruba
  1075. END_UNHANDLED_COUNTRIES(N, L)
  1076. // Countries using the "Norway" engine set.
  1077. UNHANDLED_COUNTRY(B, V) // Bouvet Island
  1078. UNHANDLED_COUNTRY(S, J) // Svalbard and Jan Mayen
  1079. END_UNHANDLED_COUNTRIES(N, O)
  1080. // Countries using the "New Zealand" engine set.
  1081. UNHANDLED_COUNTRY(C, K) // Cook Islands
  1082. UNHANDLED_COUNTRY(N, U) // Niue
  1083. UNHANDLED_COUNTRY(T, K) // Tokelau
  1084. END_UNHANDLED_COUNTRIES(N, Z)
  1085. // Countries using the "Portugal" engine set.
  1086. UNHANDLED_COUNTRY(C, V) // Cape Verde
  1087. UNHANDLED_COUNTRY(G, W) // Guinea-Bissau
  1088. UNHANDLED_COUNTRY(M, Z) // Mozambique
  1089. UNHANDLED_COUNTRY(S, T) // Sao Tome and Principe
  1090. UNHANDLED_COUNTRY(T, L) // Timor-Leste
  1091. END_UNHANDLED_COUNTRIES(P, T)
  1092. // Countries using the "Russia" engine set.
  1093. UNHANDLED_COUNTRY(A, M) // Armenia
  1094. UNHANDLED_COUNTRY(A, Z) // Azerbaijan
  1095. UNHANDLED_COUNTRY(K, G) // Kyrgyzstan
  1096. UNHANDLED_COUNTRY(T, J) // Tajikistan
  1097. UNHANDLED_COUNTRY(T, M) // Turkmenistan
  1098. UNHANDLED_COUNTRY(U, Z) // Uzbekistan
  1099. END_UNHANDLED_COUNTRIES(R, U)
  1100. // Countries using the "Saudi Arabia" engine set.
  1101. UNHANDLED_COUNTRY(M, R) // Mauritania
  1102. UNHANDLED_COUNTRY(P, S) // Palestinian Territory
  1103. UNHANDLED_COUNTRY(S, D) // Sudan
  1104. END_UNHANDLED_COUNTRIES(S, A)
  1105. // Countries using the "United Kingdom" engine set.
  1106. UNHANDLED_COUNTRY(B, M) // Bermuda
  1107. UNHANDLED_COUNTRY(F, K) // Falkland Islands
  1108. UNHANDLED_COUNTRY(G, G) // Guernsey
  1109. UNHANDLED_COUNTRY(G, I) // Gibraltar
  1110. UNHANDLED_COUNTRY(G, S) // South Georgia and the South Sandwich
  1111. // Islands
  1112. UNHANDLED_COUNTRY(I, M) // Isle of Man
  1113. UNHANDLED_COUNTRY(I, O) // British Indian Ocean Territory
  1114. UNHANDLED_COUNTRY(J, E) // Jersey
  1115. UNHANDLED_COUNTRY(K, Y) // Cayman Islands
  1116. UNHANDLED_COUNTRY(M, S) // Montserrat
  1117. UNHANDLED_COUNTRY(M, T) // Malta
  1118. UNHANDLED_COUNTRY(P, N) // Pitcairn Islands
  1119. UNHANDLED_COUNTRY(S, H) // Saint Helena, Ascension Island, and Tristan da
  1120. // Cunha
  1121. UNHANDLED_COUNTRY(T, C) // Turks and Caicos Islands
  1122. UNHANDLED_COUNTRY(V, G) // British Virgin Islands
  1123. END_UNHANDLED_COUNTRIES(G, B)
  1124. // Countries using the "United States" engine set.
  1125. UNHANDLED_COUNTRY(A, S) // American Samoa
  1126. UNHANDLED_COUNTRY(G, U) // Guam
  1127. UNHANDLED_COUNTRY(M, P) // Northern Mariana Islands
  1128. UNHANDLED_COUNTRY(U, M) // U.S. Minor Outlying Islands
  1129. UNHANDLED_COUNTRY(V, I) // U.S. Virgin Islands
  1130. END_UNHANDLED_COUNTRIES(U, S)
  1131. // Countries using the "default" engine set.
  1132. UNHANDLED_COUNTRY(A, F) // Afghanistan
  1133. UNHANDLED_COUNTRY(A, G) // Antigua and Barbuda
  1134. UNHANDLED_COUNTRY(A, I) // Anguilla
  1135. UNHANDLED_COUNTRY(A, O) // Angola
  1136. UNHANDLED_COUNTRY(A, Q) // Antarctica
  1137. UNHANDLED_COUNTRY(B, B) // Barbados
  1138. UNHANDLED_COUNTRY(B, D) // Bangladesh
  1139. UNHANDLED_COUNTRY(B, S) // Bahamas
  1140. UNHANDLED_COUNTRY(B, T) // Bhutan
  1141. UNHANDLED_COUNTRY(B, W) // Botswana
  1142. UNHANDLED_COUNTRY(C, U) // Cuba
  1143. UNHANDLED_COUNTRY(D, M) // Dominica
  1144. UNHANDLED_COUNTRY(E, R) // Eritrea
  1145. UNHANDLED_COUNTRY(E, T) // Ethiopia
  1146. UNHANDLED_COUNTRY(F, J) // Fiji
  1147. UNHANDLED_COUNTRY(F, M) // Micronesia
  1148. UNHANDLED_COUNTRY(G, D) // Grenada
  1149. UNHANDLED_COUNTRY(G, E) // Georgia
  1150. UNHANDLED_COUNTRY(G, H) // Ghana
  1151. UNHANDLED_COUNTRY(G, M) // Gambia
  1152. UNHANDLED_COUNTRY(G, Q) // Equatorial Guinea
  1153. UNHANDLED_COUNTRY(G, Y) // Guyana
  1154. UNHANDLED_COUNTRY(K, H) // Cambodia
  1155. UNHANDLED_COUNTRY(K, I) // Kiribati
  1156. UNHANDLED_COUNTRY(K, M) // Comoros
  1157. UNHANDLED_COUNTRY(K, N) // Saint Kitts and Nevis
  1158. UNHANDLED_COUNTRY(K, P) // North Korea
  1159. UNHANDLED_COUNTRY(L, A) // Laos
  1160. UNHANDLED_COUNTRY(L, C) // Saint Lucia
  1161. UNHANDLED_COUNTRY(L, K) // Sri Lanka
  1162. UNHANDLED_COUNTRY(L, R) // Liberia
  1163. UNHANDLED_COUNTRY(L, S) // Lesotho
  1164. UNHANDLED_COUNTRY(M, G) // Madagascar
  1165. UNHANDLED_COUNTRY(M, H) // Marshall Islands
  1166. UNHANDLED_COUNTRY(M, M) // Myanmar
  1167. UNHANDLED_COUNTRY(M, N) // Mongolia
  1168. UNHANDLED_COUNTRY(M, U) // Mauritius
  1169. UNHANDLED_COUNTRY(M, V) // Maldives
  1170. UNHANDLED_COUNTRY(M, W) // Malawi
  1171. UNHANDLED_COUNTRY(N, A) // Namibia
  1172. UNHANDLED_COUNTRY(N, G) // Nigeria
  1173. UNHANDLED_COUNTRY(N, P) // Nepal
  1174. UNHANDLED_COUNTRY(N, R) // Nauru
  1175. UNHANDLED_COUNTRY(P, G) // Papua New Guinea
  1176. UNHANDLED_COUNTRY(P, W) // Palau
  1177. UNHANDLED_COUNTRY(S, B) // Solomon Islands
  1178. UNHANDLED_COUNTRY(S, C) // Seychelles
  1179. UNHANDLED_COUNTRY(S, L) // Sierra Leone
  1180. UNHANDLED_COUNTRY(S, O) // Somalia
  1181. UNHANDLED_COUNTRY(S, R) // Suriname
  1182. UNHANDLED_COUNTRY(S, Z) // Swaziland
  1183. UNHANDLED_COUNTRY(T, O) // Tonga
  1184. UNHANDLED_COUNTRY(T, V) // Tuvalu
  1185. UNHANDLED_COUNTRY(U, G) // Uganda
  1186. UNHANDLED_COUNTRY(V, C) // Saint Vincent and the Grenadines
  1187. UNHANDLED_COUNTRY(V, U) // Vanuatu
  1188. UNHANDLED_COUNTRY(W, S) // Samoa
  1189. UNHANDLED_COUNTRY(Z, M) // Zambia
  1190. case country_codes::kCountryIDUnknown:
  1191. default: // Unhandled location
  1192. END_UNHANDLED_COUNTRIES(def, ault)
  1193. }
  1194. std::vector<std::unique_ptr<TemplateURLData>> t_urls;
  1195. for (size_t i = 0; i < num_engines; ++i)
  1196. t_urls.push_back(TemplateURLDataFromPrepopulatedEngine(*engines[i]));
  1197. return t_urls;
  1198. }
  1199. std::vector<std::unique_ptr<TemplateURLData>> GetPrepopulatedTemplateURLData(
  1200. PrefService* prefs) {
  1201. std::vector<std::unique_ptr<TemplateURLData>> t_urls;
  1202. if (!prefs)
  1203. return t_urls;
  1204. const base::Value::List& list =
  1205. prefs->GetValueList(prefs::kSearchProviderOverrides);
  1206. for (const base::Value& engine : list) {
  1207. if (engine.is_dict()) {
  1208. auto t_url = TemplateURLDataFromOverrideDictionary(engine);
  1209. if (t_url)
  1210. t_urls.push_back(std::move(t_url));
  1211. }
  1212. }
  1213. return t_urls;
  1214. }
  1215. } // namespace
  1216. // Global functions -----------------------------------------------------------
  1217. void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
  1218. country_codes::RegisterProfilePrefs(registry);
  1219. registry->RegisterListPref(prefs::kSearchProviderOverrides);
  1220. registry->RegisterIntegerPref(prefs::kSearchProviderOverridesVersion, -1);
  1221. }
  1222. int GetDataVersion(PrefService* prefs) {
  1223. // Allow tests to override the local version.
  1224. return (prefs && prefs->HasPrefPath(prefs::kSearchProviderOverridesVersion)) ?
  1225. prefs->GetInteger(prefs::kSearchProviderOverridesVersion) :
  1226. kCurrentDataVersion;
  1227. }
  1228. std::vector<std::unique_ptr<TemplateURLData>> GetPrepopulatedEngines(
  1229. PrefService* prefs,
  1230. size_t* default_search_provider_index) {
  1231. // If there is a set of search engines in the preferences file, it overrides
  1232. // the built-in set.
  1233. std::vector<std::unique_ptr<TemplateURLData>> t_urls =
  1234. GetPrepopulatedTemplateURLData(prefs);
  1235. if (t_urls.empty()) {
  1236. t_urls = GetPrepopulationSetFromCountryID(
  1237. country_codes::GetCountryIDFromPrefs(prefs));
  1238. }
  1239. if (default_search_provider_index) {
  1240. const auto itr = std::find_if(
  1241. t_urls.begin(), t_urls.end(),
  1242. [](const auto& t_url) { return t_url->prepopulate_id == google.id; });
  1243. *default_search_provider_index =
  1244. itr == t_urls.end() ? 0 : std::distance(t_urls.begin(), itr);
  1245. }
  1246. return t_urls;
  1247. }
  1248. std::unique_ptr<TemplateURLData> GetPrepopulatedEngine(PrefService* prefs,
  1249. int prepopulated_id) {
  1250. auto engines =
  1251. TemplateURLPrepopulateData::GetPrepopulatedEngines(prefs, nullptr);
  1252. for (auto& engine : engines) {
  1253. if (engine->prepopulate_id == prepopulated_id)
  1254. return std::move(engine);
  1255. }
  1256. return nullptr;
  1257. }
  1258. #if BUILDFLAG(IS_ANDROID)
  1259. std::vector<std::unique_ptr<TemplateURLData>> GetLocalPrepopulatedEngines(
  1260. const std::string& locale) {
  1261. int country_id = country_codes::CountryStringToCountryID(locale);
  1262. if (country_id == country_codes::kCountryIDUnknown) {
  1263. LOG(ERROR) << "Unknown country code specified: " << locale;
  1264. return std::vector<std::unique_ptr<TemplateURLData>>();
  1265. }
  1266. return GetPrepopulationSetFromCountryID(country_id);
  1267. }
  1268. #endif
  1269. std::vector<const PrepopulatedEngine*> GetAllPrepopulatedEngines() {
  1270. return std::vector<const PrepopulatedEngine*>(
  1271. &kAllEngines[0], &kAllEngines[0] + kAllEnginesLength);
  1272. }
  1273. void ClearPrepopulatedEnginesInPrefs(PrefService* prefs) {
  1274. if (!prefs)
  1275. return;
  1276. prefs->ClearPref(prefs::kSearchProviderOverrides);
  1277. prefs->ClearPref(prefs::kSearchProviderOverridesVersion);
  1278. }
  1279. std::unique_ptr<TemplateURLData> GetPrepopulatedDefaultSearch(
  1280. PrefService* prefs) {
  1281. size_t default_search_index;
  1282. // This could be more efficient. We load all URLs but keep only the default.
  1283. std::vector<std::unique_ptr<TemplateURLData>> loaded_urls =
  1284. GetPrepopulatedEngines(prefs, &default_search_index);
  1285. return (default_search_index < loaded_urls.size())
  1286. ? std::move(loaded_urls[default_search_index])
  1287. : nullptr;
  1288. }
  1289. } // namespace TemplateURLPrepopulateData