Chromium Code Reviews| Index: components/search_engines/template_url_prepopulate_data.cc |
| diff --git a/components/search_engines/template_url_prepopulate_data.cc b/components/search_engines/template_url_prepopulate_data.cc |
| index 1aac969e1e227a416214df3b4ac958480019970e..7a0b3f2396c6b2192709c01006f8f982e9dab9b9 100644 |
| --- a/components/search_engines/template_url_prepopulate_data.cc |
| +++ b/components/search_engines/template_url_prepopulate_data.cc |
| @@ -615,14 +615,13 @@ int GetCountryIDFromPrefs(PrefService* prefs) { |
| return prefs->GetInteger(prefs::kCountryIDAtInstall); |
| } |
| -void GetPrepopulationSetFromCountryID(PrefService* prefs, |
| - const PrepopulatedEngine*** engines, |
| - size_t* num_engines) { |
| - // NOTE: This function should ALWAYS set its outparams. |
| - |
| +void GetPrepopulationSetFromCountryID( |
| + int country_id, |
| + std::vector<std::unique_ptr<TemplateURLData>>& t_urls) { |
|
Peter Kasting
2016/09/21 21:45:08
Nit: Don't take an outparam by non-const ref. If
Ian Wen
2016/09/21 23:12:38
Done.
|
| + const PrepopulatedEngine** engines; |
| + size_t num_engines; |
| // If you add a new country make sure to update the unit test for coverage. |
| - switch (GetCountryIDFromPrefs(prefs)) { |
| - |
| + switch (country_id) { |
| #define CHAR_A 'A' |
| #define CHAR_B 'B' |
| #define CHAR_C 'C' |
| @@ -656,9 +655,9 @@ void GetPrepopulationSetFromCountryID(PrefService* prefs, |
| #define UNHANDLED_COUNTRY(code1, code2)\ |
| case CODE_TO_ID(code1, code2): |
| #define END_UNHANDLED_COUNTRIES(code1, code2)\ |
| - *engines = engines_##code1##code2;\ |
| - *num_engines = arraysize(engines_##code1##code2);\ |
| - return; |
| + engines = engines_##code1##code2;\ |
| + num_engines = arraysize(engines_##code1##code2);\ |
| + break; |
| #define DECLARE_COUNTRY(code1, code2)\ |
| UNHANDLED_COUNTRY(code1, code2)\ |
| END_UNHANDLED_COUNTRIES(code1, code2) |
| @@ -971,6 +970,9 @@ void GetPrepopulationSetFromCountryID(PrefService* prefs, |
| default: // Unhandled location |
| END_UNHANDLED_COUNTRIES(def, ault) |
| } |
| + for (size_t i = 0; i < num_engines; ++i) { |
|
Peter Kasting
2016/09/21 21:45:08
Nit: Blank line above this.
No {}.
Ian Wen
2016/09/21 23:12:38
Done.
|
| + t_urls.push_back(MakeTemplateURLDataFromPrepopulatedEngine(*engines[i])); |
| + } |
| } |
| std::unique_ptr<TemplateURLData> MakePrepopulatedTemplateURLData( |
| @@ -1121,14 +1123,26 @@ std::vector<std::unique_ptr<TemplateURLData>> GetPrepopulatedEngines( |
| if (!t_urls.empty()) |
| return t_urls; |
| - const PrepopulatedEngine** engines; |
| - size_t num_engines; |
| - GetPrepopulationSetFromCountryID(prefs, &engines, &num_engines); |
| - for (size_t i = 0; i != num_engines; ++i) { |
| - t_urls.push_back(MakeTemplateURLDataFromPrepopulatedEngine(*engines[i])); |
| + GetPrepopulationSetFromCountryID(GetCountryIDFromPrefs(prefs), t_urls); |
| + return t_urls; |
| +} |
| + |
| +#if defined(OS_ANDROID) |
| +std::vector<std::unique_ptr<TemplateURLData>> GetLocalPrepopulatedEngines( |
| + const std::string& locale, |
| + PrefService* prefs) { |
| + std::vector<std::unique_ptr<TemplateURLData>> t_urls; |
| + |
| + int country_id = CountryStringToCountryID(locale); |
| + if (country_id == kCountryIDUnknown || |
| + country_id == GetCountryIDFromPrefs(prefs)) { |
| + return t_urls; |
| } |
| + |
| + GetPrepopulationSetFromCountryID(country_id, t_urls); |
| return t_urls; |
| } |
| +#endif |
| std::vector<const PrepopulatedEngine*> GetAllPrepopulatedEngines() { |
| return std::vector<const PrepopulatedEngine*>(std::begin(kAllEngines), |