Chromium Code Reviews| 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 "chrome/browser/search_engines/default_search_manager.h" | 5 #include "chrome/browser/search_engines/default_search_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/i18n/case_conversion.h" | 13 #include "base/i18n/case_conversion.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
| 16 #include "base/prefs/pref_value_map.h" | 16 #include "base/prefs/pref_value_map.h" |
| 17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
| 18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/strings/string_split.h" | 19 #include "base/strings/string_split.h" |
| 20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 22 #include "base/time/time.h" | 22 #include "base/time/time.h" |
| 23 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" | 23 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
| 24 #include "chrome/browser/search_engines/template_url_service.h" | |
| 25 #include "chrome/browser/search_engines/util.h" | |
| 26 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 27 #include "components/pref_registry/pref_registry_syncable.h" | 25 #include "components/pref_registry/pref_registry_syncable.h" |
| 28 #include "components/search_engines/template_url_data.h" | 26 #include "components/search_engines/template_url_data.h" |
| 29 | 27 |
| 28 namespace { | |
| 29 | |
| 30 bool g_fallback_search_engines_disabled = false; | |
|
Peter Kasting
2014/06/18 00:01:04
Nit: Extra space
hashimoto
2014/06/18 00:08:37
Done.
| |
| 31 | |
| 32 } // namespace | |
| 33 | |
| 30 // A dictionary to hold all data related to the Default Search Engine. | 34 // A dictionary to hold all data related to the Default Search Engine. |
| 31 // Eventually, this should replace all the data stored in the | 35 // Eventually, this should replace all the data stored in the |
| 32 // default_search_provider.* prefs. | 36 // default_search_provider.* prefs. |
| 33 const char DefaultSearchManager::kDefaultSearchProviderDataPrefName[] = | 37 const char DefaultSearchManager::kDefaultSearchProviderDataPrefName[] = |
| 34 "default_search_provider_data.template_url_data"; | 38 "default_search_provider_data.template_url_data"; |
| 35 | 39 |
| 36 const char DefaultSearchManager::kID[] = "id"; | 40 const char DefaultSearchManager::kID[] = "id"; |
| 37 const char DefaultSearchManager::kShortName[] = "short_name"; | 41 const char DefaultSearchManager::kShortName[] = "short_name"; |
| 38 const char DefaultSearchManager::kKeyword[] = "keyword"; | 42 const char DefaultSearchManager::kKeyword[] = "keyword"; |
| 39 const char DefaultSearchManager::kPrepopulateID[] = "prepopulate_id"; | 43 const char DefaultSearchManager::kPrepopulateID[] = "prepopulate_id"; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 return extension_default_search_.get(); | 124 return extension_default_search_.get(); |
| 121 } | 125 } |
| 122 if (prefs_default_search_) { | 126 if (prefs_default_search_) { |
| 123 if (source) | 127 if (source) |
| 124 *source = FROM_USER; | 128 *source = FROM_USER; |
| 125 return prefs_default_search_.get(); | 129 return prefs_default_search_.get(); |
| 126 } | 130 } |
| 127 | 131 |
| 128 if (source) | 132 if (source) |
| 129 *source = FROM_FALLBACK; | 133 *source = FROM_FALLBACK; |
| 130 return TemplateURLService::fallback_search_engines_disabled() ? | 134 return g_fallback_search_engines_disabled ? |
| 131 NULL : fallback_default_search_.get(); | 135 NULL : fallback_default_search_.get(); |
| 132 } | 136 } |
| 133 | 137 |
| 134 DefaultSearchManager::Source | 138 DefaultSearchManager::Source |
| 135 DefaultSearchManager::GetDefaultSearchEngineSource() const { | 139 DefaultSearchManager::GetDefaultSearchEngineSource() const { |
| 136 Source source; | 140 Source source; |
| 137 GetDefaultSearchEngine(&source); | 141 GetDefaultSearchEngine(&source); |
| 138 return source; | 142 return source; |
| 139 } | 143 } |
| 140 | 144 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 | 220 |
| 217 void DefaultSearchManager::ClearUserSelectedDefaultSearchEngine() { | 221 void DefaultSearchManager::ClearUserSelectedDefaultSearchEngine() { |
| 218 if (pref_service_) { | 222 if (pref_service_) { |
| 219 pref_service_->ClearPref(kDefaultSearchProviderDataPrefName); | 223 pref_service_->ClearPref(kDefaultSearchProviderDataPrefName); |
| 220 } else { | 224 } else { |
| 221 prefs_default_search_.reset(); | 225 prefs_default_search_.reset(); |
| 222 NotifyObserver(); | 226 NotifyObserver(); |
| 223 } | 227 } |
| 224 } | 228 } |
| 225 | 229 |
| 230 // static | |
| 231 void DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting( | |
| 232 bool disabled) { | |
| 233 g_fallback_search_engines_disabled = disabled; | |
| 234 } | |
| 235 | |
| 226 void DefaultSearchManager::OnDefaultSearchPrefChanged() { | 236 void DefaultSearchManager::OnDefaultSearchPrefChanged() { |
| 227 Source source = GetDefaultSearchEngineSource(); | 237 Source source = GetDefaultSearchEngineSource(); |
| 228 LoadDefaultSearchEngineFromPrefs(); | 238 LoadDefaultSearchEngineFromPrefs(); |
| 229 | 239 |
| 230 // If we were/are FROM_USER or FROM_POLICY the effective DSE may have changed. | 240 // If we were/are FROM_USER or FROM_POLICY the effective DSE may have changed. |
| 231 if (source != FROM_USER && source != FROM_POLICY) | 241 if (source != FROM_USER && source != FROM_POLICY) |
| 232 source = GetDefaultSearchEngineSource(); | 242 source = GetDefaultSearchEngineSource(); |
| 233 if (source == FROM_USER || source == FROM_POLICY) | 243 if (source == FROM_USER || source == FROM_POLICY) |
| 234 NotifyObserver(); | 244 NotifyObserver(); |
| 235 } | 245 } |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 396 MergePrefsDataWithPrepopulated(); | 406 MergePrefsDataWithPrepopulated(); |
| 397 } | 407 } |
| 398 | 408 |
| 399 void DefaultSearchManager::NotifyObserver() { | 409 void DefaultSearchManager::NotifyObserver() { |
| 400 if (!change_observer_.is_null()) { | 410 if (!change_observer_.is_null()) { |
| 401 Source source = FROM_FALLBACK; | 411 Source source = FROM_FALLBACK; |
| 402 TemplateURLData* data = GetDefaultSearchEngine(&source); | 412 TemplateURLData* data = GetDefaultSearchEngine(&source); |
| 403 change_observer_.Run(data, source); | 413 change_observer_.Run(data, source); |
| 404 } | 414 } |
| 405 } | 415 } |
| OLD | NEW |