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 11 matching lines...) Expand all Loading... |
22 #include "components/search_engines/template_url.h" | 22 #include "components/search_engines/template_url.h" |
23 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 23 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
24 #include "url/gurl.h" | 24 #include "url/gurl.h" |
25 | 25 |
26 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
27 #undef IN // On Windows, windef.h defines this, which screws up "India" cases. | 27 #undef IN // On Windows, windef.h defines this, which screws up "India" cases. |
28 #elif defined(OS_MACOSX) | 28 #elif defined(OS_MACOSX) |
29 #include "base/mac/scoped_cftyperef.h" | 29 #include "base/mac/scoped_cftyperef.h" |
30 #endif | 30 #endif |
31 | 31 |
| 32 #if defined(OS_ANDROID) |
| 33 #include "ui/base/l10n/l10n_util_android.h" |
| 34 #endif |
| 35 |
32 namespace TemplateURLPrepopulateData { | 36 namespace TemplateURLPrepopulateData { |
33 | 37 |
34 | 38 |
35 // Helpers -------------------------------------------------------------------- | 39 // Helpers -------------------------------------------------------------------- |
36 | 40 |
37 namespace { | 41 namespace { |
38 | 42 |
39 // NOTE: You should probably not change the data in this file without changing | 43 // NOTE: You should probably not change the data in this file without changing |
40 // |kCurrentDataVersion| in prepopulated_engines.json. See comments in | 44 // |kCurrentDataVersion| in prepopulated_engines.json. See comments in |
41 // GetDataVersion() below! | 45 // GetDataVersion() below! |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 UniChar isobuf[2]; | 618 UniChar isobuf[2]; |
615 CFRange char_range = CFRangeMake(0, 2); | 619 CFRange char_range = CFRangeMake(0, 2); |
616 CFStringGetCharacters(country, char_range, isobuf); | 620 CFStringGetCharacters(country, char_range, isobuf); |
617 | 621 |
618 return CountryCharsToCountryIDWithUpdate(static_cast<char>(isobuf[0]), | 622 return CountryCharsToCountryIDWithUpdate(static_cast<char>(isobuf[0]), |
619 static_cast<char>(isobuf[1])); | 623 static_cast<char>(isobuf[1])); |
620 } | 624 } |
621 | 625 |
622 #elif defined(OS_ANDROID) | 626 #elif defined(OS_ANDROID) |
623 | 627 |
624 // Initialized by InitCountryCode(). | |
625 int g_country_code_at_install = kCountryIDUnknown; | |
626 | |
627 int GetCurrentCountryID() { | 628 int GetCurrentCountryID() { |
628 return g_country_code_at_install; | 629 const std::string& country_code = l10n_util::GetDefaultCountryCode(); |
| 630 if (country_code.size() != 2) { |
| 631 return kCountryIDUnknown; |
| 632 } else { |
| 633 return CountryCharsToCountryIDWithUpdate(country_code[0], country_code[1]); |
| 634 } |
629 } | 635 } |
630 | 636 |
631 #elif defined(OS_POSIX) | 637 #elif defined(OS_POSIX) |
632 | 638 |
633 int GetCurrentCountryID() { | 639 int GetCurrentCountryID() { |
634 const char* locale = setlocale(LC_MESSAGES, NULL); | 640 const char* locale = setlocale(LC_MESSAGES, NULL); |
635 | 641 |
636 if (!locale) | 642 if (!locale) |
637 return kCountryIDUnknown; | 643 return kCountryIDUnknown; |
638 | 644 |
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1179 net::registry_controlled_domains::SameDomainOrHost( | 1185 net::registry_controlled_domains::SameDomainOrHost( |
1180 given_url, prepopulated_url, | 1186 given_url, prepopulated_url, |
1181 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); | 1187 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); |
1182 } | 1188 } |
1183 | 1189 |
1184 } // namespace | 1190 } // namespace |
1185 | 1191 |
1186 | 1192 |
1187 // Global functions ----------------------------------------------------------- | 1193 // Global functions ----------------------------------------------------------- |
1188 | 1194 |
1189 #if defined(OS_ANDROID) | |
1190 void InitCountryCode(const std::string& country_code) { | |
1191 if (country_code.size() != 2) { | |
1192 DLOG(ERROR) << "Invalid country code: " << country_code; | |
1193 g_country_code_at_install = kCountryIDUnknown; | |
1194 } else { | |
1195 g_country_code_at_install = | |
1196 CountryCharsToCountryIDWithUpdate(country_code[0], country_code[1]); | |
1197 } | |
1198 } | |
1199 #endif | |
1200 | |
1201 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { | 1195 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { |
1202 registry->RegisterIntegerPref( | 1196 registry->RegisterIntegerPref( |
1203 prefs::kCountryIDAtInstall, | 1197 prefs::kCountryIDAtInstall, |
1204 kCountryIDUnknown, | 1198 kCountryIDUnknown, |
1205 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 1199 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
1206 registry->RegisterListPref(prefs::kSearchProviderOverrides, | 1200 registry->RegisterListPref(prefs::kSearchProviderOverrides, |
1207 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 1201 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
1208 registry->RegisterIntegerPref( | 1202 registry->RegisterIntegerPref( |
1209 prefs::kSearchProviderOverridesVersion, | 1203 prefs::kSearchProviderOverridesVersion, |
1210 -1, | 1204 -1, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1293 for (size_t j = 0; j < kAllEngines[i]->alternate_urls_size; ++j) { | 1287 for (size_t j = 0; j < kAllEngines[i]->alternate_urls_size; ++j) { |
1294 if (SameDomain(url, GURL(kAllEngines[i]->alternate_urls[j]))) | 1288 if (SameDomain(url, GURL(kAllEngines[i]->alternate_urls[j]))) |
1295 return kAllEngines[i]->type; | 1289 return kAllEngines[i]->type; |
1296 } | 1290 } |
1297 } | 1291 } |
1298 | 1292 |
1299 return SEARCH_ENGINE_OTHER; | 1293 return SEARCH_ENGINE_OTHER; |
1300 } | 1294 } |
1301 | 1295 |
1302 } // namespace TemplateURLPrepopulateData | 1296 } // namespace TemplateURLPrepopulateData |
OLD | NEW |