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 1019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1030 // the built-in set. | 1030 // the built-in set. |
1031 *default_search_provider_index = 0; | 1031 *default_search_provider_index = 0; |
1032 std::vector<std::unique_ptr<TemplateURLData>> t_urls = | 1032 std::vector<std::unique_ptr<TemplateURLData>> t_urls = |
1033 GetPrepopulatedTemplateURLData(prefs); | 1033 GetPrepopulatedTemplateURLData(prefs); |
1034 if (!t_urls.empty()) | 1034 if (!t_urls.empty()) |
1035 return t_urls; | 1035 return t_urls; |
1036 | 1036 |
1037 return GetPrepopulationSetFromCountryID(GetCountryIDFromPrefs(prefs)); | 1037 return GetPrepopulationSetFromCountryID(GetCountryIDFromPrefs(prefs)); |
1038 } | 1038 } |
1039 | 1039 |
| 1040 // Find the prepopulated search engine with the given id. |
| 1041 std::unique_ptr<TemplateURLData> GetPrepopulatedEngine(PrefService* prefs, |
| 1042 int prepopulated_id) { |
| 1043 size_t default_index; |
| 1044 std::vector<std::unique_ptr<TemplateURLData>> engines = |
| 1045 TemplateURLPrepopulateData::GetPrepopulatedEngines(prefs, &default_index); |
| 1046 for (auto& engine : engines) { |
| 1047 if (engine->prepopulate_id == prepopulated_id) |
| 1048 return std::move(engine); |
| 1049 } |
| 1050 return nullptr; |
| 1051 } |
| 1052 |
1040 #if defined(OS_ANDROID) | 1053 #if defined(OS_ANDROID) |
1041 std::vector<std::unique_ptr<TemplateURLData>> GetLocalPrepopulatedEngines( | 1054 std::vector<std::unique_ptr<TemplateURLData>> GetLocalPrepopulatedEngines( |
1042 const std::string& locale, | 1055 const std::string& locale, |
1043 PrefService* prefs) { | 1056 PrefService* prefs) { |
1044 int country_id = CountryStringToCountryID(locale); | 1057 int country_id = CountryStringToCountryID(locale); |
1045 if (country_id == kCountryIDUnknown || | 1058 if (country_id == kCountryIDUnknown || |
1046 country_id == GetCountryIDFromPrefs(prefs)) { | 1059 country_id == GetCountryIDFromPrefs(prefs)) { |
1047 return std::vector<std::unique_ptr<TemplateURLData>>(); | 1060 return std::vector<std::unique_ptr<TemplateURLData>>(); |
1048 } | 1061 } |
1049 | 1062 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1154 locale_str.erase(0, territory_delim + 1); | 1167 locale_str.erase(0, territory_delim + 1); |
1155 | 1168 |
1156 // Next remove any codeset/modifier portion and uppercase. | 1169 // Next remove any codeset/modifier portion and uppercase. |
1157 return CountryStringToCountryID( | 1170 return CountryStringToCountryID( |
1158 base::ToUpperASCII(locale_str.substr(0, locale_str.find_first_of(".@")))); | 1171 base::ToUpperASCII(locale_str.substr(0, locale_str.find_first_of(".@")))); |
1159 } | 1172 } |
1160 | 1173 |
1161 #endif // OS_* | 1174 #endif // OS_* |
1162 | 1175 |
1163 } // namespace TemplateURLPrepopulateData | 1176 } // namespace TemplateURLPrepopulateData |
OLD | NEW |