Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1159)

Side by Side Diff: components/search_engines/template_url_prepopulate_data.cc

Issue 628263004: [Android] Simplify logic for grabbing initial country-code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 "base/android/locale_utils.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
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 = base::android::GetDefaultCountryCode();
630 return (country_code.size() == 2) ?
631 CountryCharsToCountryIDWithUpdate(country_code[0], country_code[1]) :
632 kCountryIDUnknown;
629 } 633 }
630 634
631 #elif defined(OS_POSIX) 635 #elif defined(OS_POSIX)
632 636
633 int GetCurrentCountryID() { 637 int GetCurrentCountryID() {
634 const char* locale = setlocale(LC_MESSAGES, NULL); 638 const char* locale = setlocale(LC_MESSAGES, NULL);
635 639
636 if (!locale) 640 if (!locale)
637 return kCountryIDUnknown; 641 return kCountryIDUnknown;
638 642
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 net::registry_controlled_domains::SameDomainOrHost( 1183 net::registry_controlled_domains::SameDomainOrHost(
1180 given_url, prepopulated_url, 1184 given_url, prepopulated_url,
1181 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); 1185 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
1182 } 1186 }
1183 1187
1184 } // namespace 1188 } // namespace
1185 1189
1186 1190
1187 // Global functions ----------------------------------------------------------- 1191 // Global functions -----------------------------------------------------------
1188 1192
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) { 1193 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
1202 registry->RegisterIntegerPref( 1194 registry->RegisterIntegerPref(
1203 prefs::kCountryIDAtInstall, 1195 prefs::kCountryIDAtInstall,
1204 kCountryIDUnknown, 1196 kCountryIDUnknown,
1205 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 1197 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
1206 registry->RegisterListPref(prefs::kSearchProviderOverrides, 1198 registry->RegisterListPref(prefs::kSearchProviderOverrides,
1207 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 1199 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
1208 registry->RegisterIntegerPref( 1200 registry->RegisterIntegerPref(
1209 prefs::kSearchProviderOverridesVersion, 1201 prefs::kSearchProviderOverridesVersion,
1210 -1, 1202 -1,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1293 for (size_t j = 0; j < kAllEngines[i]->alternate_urls_size; ++j) { 1285 for (size_t j = 0; j < kAllEngines[i]->alternate_urls_size; ++j) {
1294 if (SameDomain(url, GURL(kAllEngines[i]->alternate_urls[j]))) 1286 if (SameDomain(url, GURL(kAllEngines[i]->alternate_urls[j])))
1295 return kAllEngines[i]->type; 1287 return kAllEngines[i]->type;
1296 } 1288 }
1297 } 1289 }
1298 1290
1299 return SEARCH_ENGINE_OTHER; 1291 return SEARCH_ENGINE_OTHER;
1300 } 1292 }
1301 1293
1302 } // namespace TemplateURLPrepopulateData 1294 } // namespace TemplateURLPrepopulateData
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698