Commit 78b72848 authored by David Narsiya's avatar David Narsiya Committed by Commit Bot

Added behaviour to generate array of search engines

All search engines are described in prepopulated_engines.json. In
template_url_prepopulate_data.cc there was an array kAllEngines
consisted of them, created by enumeration. There is a danger of
modifying prepopulated_engines.json without modifying this array. This
changes contain automatical generation of kAllEngines.

Change-Id: Idc78552372f73b07fc7070fff66c000a30c6a6ca
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1807312Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: default avatarBruce Dawson <brucedawson@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Commit-Queue: Alexander Yashkin <a-v-y@yandex-team.ru>
Cr-Commit-Position: refs/heads/master@{#701133}
parent 49215b9c
......@@ -635,6 +635,7 @@
"alternate_urls": [
"http://hladaj.atlas.sk/fulltext/?phrase={searchTerms}"
],
"type": "SEARCH_ENGINE_ATLAS",
"id": 27
},
......@@ -1009,5 +1010,9 @@
"type": "SEARCH_ENGINE_ZOZNAM",
"id": 85
}
},
"generate_array": {
"array_name": "kAllEngines"
}
}
......@@ -9,6 +9,7 @@
{
"type_name": "PrepopulatedEngine",
"headers": [
"base/stl_util.h",
"components/search_engines/search_engine_type.h"
],
"schema": [
......
......@@ -889,96 +889,6 @@ const PrepopulatedEngine* const engines_ZW[] = {
};
// ----------------------------------------------------------------------------
// A list of all the engines that we know about.
const PrepopulatedEngine* const kAllEngines[] = {
// Prepopulated engines:
&ask,
&baidu,
&bing,
&coccoc,
&daum,
&duckduckgo,
&google,
&mail_ru,
&naver,
&qwant,
&seznam,
&sogou,
&yahoo,
&yahoo_ar,
&yahoo_at,
&yahoo_au,
&yahoo_br,
&yahoo_ca,
&yahoo_ch,
&yahoo_cl,
&yahoo_co,
&yahoo_de,
&yahoo_dk,
&yahoo_es,
&yahoo_fi,
&yahoo_fr,
&yahoo_hk,
&yahoo_id,
&yahoo_in,
&yahoo_jp,
&yahoo_mx,
&yahoo_my,
&yahoo_nl,
&yahoo_nz,
&yahoo_pe,
&yahoo_ph,
&yahoo_qc,
&yahoo_se,
&yahoo_sg,
&yahoo_th,
&yahoo_tr,
&yahoo_tw,
&yahoo_uk,
&yahoo_ve,
&yahoo_vn,
&yandex_by,
&yandex_com,
&yandex_kz,
&yandex_ru,
&yandex_tr,
&yandex_ua,
// UMA-only engines:
&atlas_cz,
&atlas_sk,
&avg,
&babylon,
&conduit,
&delfi_lt,
&delfi_lv,
&delta,
&funmoods,
&goo,
&imesh,
&iminent,
&in,
&incredibar,
&libero,
&neti,
&nigma,
&ok,
&rambler,
&sapo,
&search_results,
&searchnu,
&snapdo,
&softonic,
&sweetim,
&sweetpacks,
&terra_ar,
&terra_es,
&tut,
&walla,
&wp,
&zoznam,
};
std::vector<std::unique_ptr<TemplateURLData>> GetPrepopulationSetFromCountryID(
int country_id) {
const PrepopulatedEngine* const* engines;
......@@ -1404,8 +1314,8 @@ std::vector<std::unique_ptr<TemplateURLData>> GetLocalPrepopulatedEngines(
#endif
std::vector<const PrepopulatedEngine*> GetAllPrepopulatedEngines() {
return std::vector<const PrepopulatedEngine*>(std::begin(kAllEngines),
std::end(kAllEngines));
return std::vector<const PrepopulatedEngine*>(
&kAllEngines[0], &kAllEngines[0] + kAllEnginesLength);
}
void ClearPrepopulatedEnginesInPrefs(PrefService* prefs) {
......@@ -1442,7 +1352,7 @@ SearchEngineType GetEngineType(const GURL& url) {
return google.type;
// Now check the rest of the prepopulate data.
for (size_t i = 0; i < base::size(kAllEngines); ++i) {
for (size_t i = 0; i < kAllEnginesLength; ++i) {
// First check the main search URL.
if (SameDomain(url, GURL(kAllEngines[i]->search_url)))
return kAllEngines[i]->type;
......
......@@ -136,6 +136,13 @@ def _GenerateH(basepath, fileroot, head, namespace, schema, description):
for element_name, element in description['elements'].items():
f.write('extern const %s %s;\n' % (schema['type_name'], element_name))
if 'generate_array' in description:
f.write('\n')
f.write('extern const %s* const %s[];\n' % (schema['type_name'],
description['generate_array']['array_name']))
f.write('extern const size_t %s;\n' %
(description['generate_array']['array_name'] + 'Length'))
if namespace:
f.write('\n')
f.write('} // namespace %s\n' % namespace)
......@@ -171,6 +178,17 @@ def _GenerateCC(basepath, fileroot, head, namespace, schema, description):
f.write(element_generator.GenerateElements(schema['type_name'],
schema['schema'], description))
if 'generate_array' in description:
f.write('\n')
f.write('const %s* const %s[] = {\n' % (schema['type_name'],
description['generate_array']['array_name']))
for element_name, _ in description['elements'].items():
f.write('\t&%s,\n' % element_name)
f.write('};\n')
f.write('const size_t %s = base::size(%s);\n' %
(description['generate_array']['array_name'] + 'Length',
description['generate_array']['array_name']))
if namespace:
f.write('\n')
f.write('} // namespace %s\n' % namespace)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment