OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/search_engines/template_url_prepopulate_data.h" | 5 #include "components/search_engines/template_url_prepopulate_data.h" |
6 | 6 |
7 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 7 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
8 #include <locale.h> | 8 #include <locale.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1034 // the built-in set. | 1034 // the built-in set. |
1035 *default_search_provider_index = 0; | 1035 *default_search_provider_index = 0; |
1036 std::vector<std::unique_ptr<TemplateURLData>> t_urls = | 1036 std::vector<std::unique_ptr<TemplateURLData>> t_urls = |
1037 GetPrepopulatedTemplateURLData(prefs); | 1037 GetPrepopulatedTemplateURLData(prefs); |
1038 if (!t_urls.empty()) | 1038 if (!t_urls.empty()) |
1039 return t_urls; | 1039 return t_urls; |
1040 | 1040 |
1041 return GetPrepopulationSetFromCountryID(GetCountryIDFromPrefs(prefs)); | 1041 return GetPrepopulationSetFromCountryID(GetCountryIDFromPrefs(prefs)); |
1042 } | 1042 } |
1043 | 1043 |
1044 // Find the prepopulated search engine with the given id. | |
1045 std::unique_ptr<TemplateURLData> GetPrepopulatedEngine(PrefService* prefs, | |
1046 int prepopulated_id) { | |
1047 size_t default_index; | |
Peter Kasting
2016/12/22 20:49:04
Nit: Probably should be done in a separate CL, but
Alexander Yashkin
2016/12/23 19:44:09
Agree, it should be done, but in separate CL.
| |
1048 std::vector<std::unique_ptr<TemplateURLData>> engines = | |
Peter Kasting
2016/12/22 20:49:04
Nit: Use auto
Alexander Yashkin
2016/12/23 19:44:09
Done
| |
1049 TemplateURLPrepopulateData::GetPrepopulatedEngines(prefs, &default_index); | |
1050 for (auto& engine : engines) { | |
1051 if (engine->prepopulate_id == prepopulated_id) | |
1052 return std::move(engine); | |
1053 } | |
Peter Kasting
2016/12/22 20:49:04
I tried writing this out with find_if(), but I don
Alexander Yashkin
2016/12/23 19:44:09
Old style is more clear here, IMHO.
| |
1054 return nullptr; | |
1055 } | |
1056 | |
1044 #if defined(OS_ANDROID) | 1057 #if defined(OS_ANDROID) |
1045 | 1058 |
1046 std::vector<std::unique_ptr<TemplateURLData>> GetLocalPrepopulatedEngines( | 1059 std::vector<std::unique_ptr<TemplateURLData>> GetLocalPrepopulatedEngines( |
1047 const std::string& locale, | 1060 const std::string& locale, |
1048 PrefService* prefs) { | 1061 PrefService* prefs) { |
1049 int country_id = CountryStringToCountryID(locale); | 1062 int country_id = CountryStringToCountryID(locale); |
1050 if (country_id == kCountryIDUnknown || | 1063 if (country_id == kCountryIDUnknown || |
1051 country_id == GetCountryIDFromPrefs(prefs)) { | 1064 country_id == GetCountryIDFromPrefs(prefs)) { |
1052 return std::vector<std::unique_ptr<TemplateURLData>>(); | 1065 return std::vector<std::unique_ptr<TemplateURLData>>(); |
1053 } | 1066 } |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1160 locale_str.erase(0, territory_delim + 1); | 1173 locale_str.erase(0, territory_delim + 1); |
1161 | 1174 |
1162 // Next remove any codeset/modifier portion and uppercase. | 1175 // Next remove any codeset/modifier portion and uppercase. |
1163 return CountryStringToCountryID( | 1176 return CountryStringToCountryID( |
1164 base::ToUpperASCII(locale_str.substr(0, locale_str.find_first_of(".@")))); | 1177 base::ToUpperASCII(locale_str.substr(0, locale_str.find_first_of(".@")))); |
1165 } | 1178 } |
1166 | 1179 |
1167 #endif // OS_* | 1180 #endif // OS_* |
1168 | 1181 |
1169 } // namespace TemplateURLPrepopulateData | 1182 } // namespace TemplateURLPrepopulateData |
OLD | NEW |