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(); |
newt (away)
2014/10/06 18:36:48
Is it worth caching this value?
Peter Kasting
2014/10/06 20:28:27
No. This is called at most once per run, I believ
Yaron
2014/10/08 00:08:54
Agreed. Nobody else is caching these calls either
| |
630 if (country_code.size() != 2) { | |
631 DLOG(ERROR) << "Invalid country code: " << country_code; | |
Peter Kasting
2014/10/06 20:28:27
Unless you have a concrete plan to retrieve and ac
Yaron
2014/10/08 00:08:54
it's not new (moved from below) but removed
Peter Kasting
2014/10/08 00:23:08
So is it actually possible for this to return anyt
Yaron
2014/10/17 18:24:00
I think it's possible, especially in the context o
| |
632 return kCountryIDUnknown; | |
633 } else { | |
634 return CountryCharsToCountryIDWithUpdate(country_code[0], country_code[1]); | |
635 } | |
629 } | 636 } |
630 | 637 |
631 #elif defined(OS_POSIX) | 638 #elif defined(OS_POSIX) |
632 | 639 |
633 int GetCurrentCountryID() { | 640 int GetCurrentCountryID() { |
634 const char* locale = setlocale(LC_MESSAGES, NULL); | 641 const char* locale = setlocale(LC_MESSAGES, NULL); |
635 | 642 |
636 if (!locale) | 643 if (!locale) |
637 return kCountryIDUnknown; | 644 return kCountryIDUnknown; |
638 | 645 |
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1179 net::registry_controlled_domains::SameDomainOrHost( | 1186 net::registry_controlled_domains::SameDomainOrHost( |
1180 given_url, prepopulated_url, | 1187 given_url, prepopulated_url, |
1181 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); | 1188 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); |
1182 } | 1189 } |
1183 | 1190 |
1184 } // namespace | 1191 } // namespace |
1185 | 1192 |
1186 | 1193 |
1187 // Global functions ----------------------------------------------------------- | 1194 // Global functions ----------------------------------------------------------- |
1188 | 1195 |
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) { | 1196 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { |
1202 registry->RegisterIntegerPref( | 1197 registry->RegisterIntegerPref( |
1203 prefs::kCountryIDAtInstall, | 1198 prefs::kCountryIDAtInstall, |
1204 kCountryIDUnknown, | 1199 kCountryIDUnknown, |
1205 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 1200 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
1206 registry->RegisterListPref(prefs::kSearchProviderOverrides, | 1201 registry->RegisterListPref(prefs::kSearchProviderOverrides, |
1207 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 1202 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
1208 registry->RegisterIntegerPref( | 1203 registry->RegisterIntegerPref( |
1209 prefs::kSearchProviderOverridesVersion, | 1204 prefs::kSearchProviderOverridesVersion, |
1210 -1, | 1205 -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) { | 1288 for (size_t j = 0; j < kAllEngines[i]->alternate_urls_size; ++j) { |
1294 if (SameDomain(url, GURL(kAllEngines[i]->alternate_urls[j]))) | 1289 if (SameDomain(url, GURL(kAllEngines[i]->alternate_urls[j]))) |
1295 return kAllEngines[i]->type; | 1290 return kAllEngines[i]->type; |
1296 } | 1291 } |
1297 } | 1292 } |
1298 | 1293 |
1299 return SEARCH_ENGINE_OTHER; | 1294 return SEARCH_ENGINE_OTHER; |
1300 } | 1295 } |
1301 | 1296 |
1302 } // namespace TemplateURLPrepopulateData | 1297 } // namespace TemplateURLPrepopulateData |
OLD | NEW |