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 std::unique_ptr<TemplateURLData> GetPrepopulatedEngine(PrefService* prefs, | |
1045 int prepopulated_id) { | |
1046 size_t default_index; | |
1047 auto engines = | |
1048 TemplateURLPrepopulateData::GetPrepopulatedEngines(prefs, &default_index); | |
1049 for (auto& engine : engines) { | |
1050 if (engine->prepopulate_id == prepopulated_id) | |
1051 return std::move(engine); | |
1052 } | |
1053 return nullptr; | |
1054 } | |
1055 | |
1056 #if defined(OS_ANDROID) | 1044 #if defined(OS_ANDROID) |
1057 | 1045 |
1058 std::vector<std::unique_ptr<TemplateURLData>> GetLocalPrepopulatedEngines( | 1046 std::vector<std::unique_ptr<TemplateURLData>> GetLocalPrepopulatedEngines( |
1059 const std::string& locale, | 1047 const std::string& locale, |
1060 PrefService* prefs) { | 1048 PrefService* prefs) { |
1061 int country_id = CountryStringToCountryID(locale); | 1049 int country_id = CountryStringToCountryID(locale); |
1062 if (country_id == kCountryIDUnknown || | 1050 if (country_id == kCountryIDUnknown || |
1063 country_id == GetCountryIDFromPrefs(prefs)) { | 1051 country_id == GetCountryIDFromPrefs(prefs)) { |
1064 return std::vector<std::unique_ptr<TemplateURLData>>(); | 1052 return std::vector<std::unique_ptr<TemplateURLData>>(); |
1065 } | 1053 } |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1172 locale_str.erase(0, territory_delim + 1); | 1160 locale_str.erase(0, territory_delim + 1); |
1173 | 1161 |
1174 // Next remove any codeset/modifier portion and uppercase. | 1162 // Next remove any codeset/modifier portion and uppercase. |
1175 return CountryStringToCountryID( | 1163 return CountryStringToCountryID( |
1176 base::ToUpperASCII(locale_str.substr(0, locale_str.find_first_of(".@")))); | 1164 base::ToUpperASCII(locale_str.substr(0, locale_str.find_first_of(".@")))); |
1177 } | 1165 } |
1178 | 1166 |
1179 #endif // OS_* | 1167 #endif // OS_* |
1180 | 1168 |
1181 } // namespace TemplateURLPrepopulateData | 1169 } // namespace TemplateURLPrepopulateData |
OLD | NEW |