OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/search_engines/template_url_prepopulate_data.h" | 5 #include "chrome/browser/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 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
15 #include "base/strings/string_piece.h" | 15 #include "base/strings/string_piece.h" |
16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "chrome/common/pref_names.h" | |
19 #include "components/google/core/browser/google_util.h" | 18 #include "components/google/core/browser/google_util.h" |
20 #include "components/pref_registry/pref_registry_syncable.h" | 19 #include "components/pref_registry/pref_registry_syncable.h" |
21 #include "components/search_engines/prepopulated_engines.h" | 20 #include "components/search_engines/prepopulated_engines.h" |
| 21 #include "components/search_engines/search_engines_pref_names.h" |
22 #include "components/search_engines/template_url.h" | 22 #include "components/search_engines/template_url.h" |
23 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
24 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
25 #include "grit/theme_resources.h" | 25 #include "grit/theme_resources.h" |
26 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 26 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
27 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
28 #include "url/gurl.h" | 28 #include "url/gurl.h" |
29 | 29 |
30 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
31 #undef IN // On Windows, windef.h defines this, which screws up "India" cases. | 31 #undef IN // On Windows, windef.h defines this, which screws up "India" cases. |
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 | 667 |
668 int GetCountryIDFromPrefs(PrefService* prefs) { | 668 int GetCountryIDFromPrefs(PrefService* prefs) { |
669 if (!prefs) | 669 if (!prefs) |
670 return GetCurrentCountryID(); | 670 return GetCurrentCountryID(); |
671 | 671 |
672 // Cache first run Country ID value in prefs, and use it afterwards. This | 672 // Cache first run Country ID value in prefs, and use it afterwards. This |
673 // ensures that just because the user moves around, we won't automatically | 673 // ensures that just because the user moves around, we won't automatically |
674 // make major changes to their available search providers, which would feel | 674 // make major changes to their available search providers, which would feel |
675 // surprising. | 675 // surprising. |
676 if (!prefs->HasPrefPath(prefs::kCountryIDAtInstall)) { | 676 if (!prefs->HasPrefPath(prefs::kCountryIDAtInstall)) { |
677 int new_country_id = GetCurrentCountryID(); | 677 prefs->SetInteger(prefs::kCountryIDAtInstall, GetCurrentCountryID()); |
678 #if defined(OS_WIN) | |
679 // Migrate the old platform-specific value if it's present. | |
680 if (prefs->HasPrefPath(prefs::kGeoIDAtInstall)) { | |
681 int geo_id = prefs->GetInteger(prefs::kGeoIDAtInstall); | |
682 prefs->ClearPref(prefs::kGeoIDAtInstall); | |
683 new_country_id = GeoIDToCountryID(geo_id); | |
684 } | |
685 #endif | |
686 prefs->SetInteger(prefs::kCountryIDAtInstall, new_country_id); | |
687 } | 678 } |
688 return prefs->GetInteger(prefs::kCountryIDAtInstall); | 679 return prefs->GetInteger(prefs::kCountryIDAtInstall); |
689 } | 680 } |
690 | 681 |
691 void GetPrepopulationSetFromCountryID(PrefService* prefs, | 682 void GetPrepopulationSetFromCountryID(PrefService* prefs, |
692 const PrepopulatedEngine*** engines, | 683 const PrepopulatedEngine*** engines, |
693 size_t* num_engines) { | 684 size_t* num_engines) { |
694 // NOTE: This function should ALWAYS set its outparams. | 685 // NOTE: This function should ALWAYS set its outparams. |
695 | 686 |
696 // If you add a new country make sure to update the unit test for coverage. | 687 // If you add a new country make sure to update the unit test for coverage. |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1215 registry->RegisterIntegerPref( | 1206 registry->RegisterIntegerPref( |
1216 prefs::kCountryIDAtInstall, | 1207 prefs::kCountryIDAtInstall, |
1217 kCountryIDUnknown, | 1208 kCountryIDUnknown, |
1218 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 1209 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
1219 registry->RegisterListPref(prefs::kSearchProviderOverrides, | 1210 registry->RegisterListPref(prefs::kSearchProviderOverrides, |
1220 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 1211 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
1221 registry->RegisterIntegerPref( | 1212 registry->RegisterIntegerPref( |
1222 prefs::kSearchProviderOverridesVersion, | 1213 prefs::kSearchProviderOverridesVersion, |
1223 -1, | 1214 -1, |
1224 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 1215 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
1225 // Obsolete pref, for migration. | |
1226 registry->RegisterIntegerPref( | |
1227 prefs::kGeoIDAtInstall, | |
1228 -1, | |
1229 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
1230 } | 1216 } |
1231 | 1217 |
1232 int GetDataVersion(PrefService* prefs) { | 1218 int GetDataVersion(PrefService* prefs) { |
1233 // Allow tests to override the local version. | 1219 // Allow tests to override the local version. |
1234 return (prefs && prefs->HasPrefPath(prefs::kSearchProviderOverridesVersion)) ? | 1220 return (prefs && prefs->HasPrefPath(prefs::kSearchProviderOverridesVersion)) ? |
1235 prefs->GetInteger(prefs::kSearchProviderOverridesVersion) : | 1221 prefs->GetInteger(prefs::kSearchProviderOverridesVersion) : |
1236 kCurrentDataVersion; | 1222 kCurrentDataVersion; |
1237 } | 1223 } |
1238 | 1224 |
1239 ScopedVector<TemplateURLData> GetPrepopulatedEngines( | 1225 ScopedVector<TemplateURLData> GetPrepopulatedEngines( |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1316 for (size_t j = 0; j < kAllEngines[i]->alternate_urls_size; ++j) { | 1302 for (size_t j = 0; j < kAllEngines[i]->alternate_urls_size; ++j) { |
1317 if (SameDomain(url, GURL(kAllEngines[i]->alternate_urls[j]))) | 1303 if (SameDomain(url, GURL(kAllEngines[i]->alternate_urls[j]))) |
1318 return kAllEngines[i]->type; | 1304 return kAllEngines[i]->type; |
1319 } | 1305 } |
1320 } | 1306 } |
1321 | 1307 |
1322 return SEARCH_ENGINE_OTHER; | 1308 return SEARCH_ENGINE_OTHER; |
1323 } | 1309 } |
1324 | 1310 |
1325 } // namespace TemplateURLPrepopulateData | 1311 } // namespace TemplateURLPrepopulateData |
OLD | NEW |