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

Side by Side Diff: chrome/browser/search_engines/default_search_manager.cc

Issue 340553005: Stop depending on TemplateURLService from DefaultSearchManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 6 years, 6 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 | Annotate | Revision Log
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 "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;
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 kDefaultSearchProviderDataPrefName, 104 kDefaultSearchProviderDataPrefName,
101 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 105 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
102 } 106 }
103 107
104 // static 108 // static
105 void DefaultSearchManager::AddPrefValueToMap(base::DictionaryValue* value, 109 void DefaultSearchManager::AddPrefValueToMap(base::DictionaryValue* value,
106 PrefValueMap* pref_value_map) { 110 PrefValueMap* pref_value_map) {
107 pref_value_map->SetValue(kDefaultSearchProviderDataPrefName, value); 111 pref_value_map->SetValue(kDefaultSearchProviderDataPrefName, value);
108 } 112 }
109 113
114 // static
115 void DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(
116 bool disabled) {
117 g_fallback_search_engines_disabled = disabled;
118 }
119
110 TemplateURLData* DefaultSearchManager::GetDefaultSearchEngine( 120 TemplateURLData* DefaultSearchManager::GetDefaultSearchEngine(
111 Source* source) const { 121 Source* source) const {
112 if (default_search_controlled_by_policy_) { 122 if (default_search_controlled_by_policy_) {
113 if (source) 123 if (source)
114 *source = FROM_POLICY; 124 *source = FROM_POLICY;
115 return prefs_default_search_.get(); 125 return prefs_default_search_.get();
116 } 126 }
117 if (extension_default_search_) { 127 if (extension_default_search_) {
118 if (source) 128 if (source)
119 *source = FROM_EXTENSION; 129 *source = FROM_EXTENSION;
120 return extension_default_search_.get(); 130 return extension_default_search_.get();
121 } 131 }
122 if (prefs_default_search_) { 132 if (prefs_default_search_) {
123 if (source) 133 if (source)
124 *source = FROM_USER; 134 *source = FROM_USER;
125 return prefs_default_search_.get(); 135 return prefs_default_search_.get();
126 } 136 }
127 137
128 if (source) 138 if (source)
129 *source = FROM_FALLBACK; 139 *source = FROM_FALLBACK;
130 return TemplateURLService::fallback_search_engines_disabled() ? 140 return g_fallback_search_engines_disabled ?
131 NULL : fallback_default_search_.get(); 141 NULL : fallback_default_search_.get();
132 } 142 }
133 143
134 DefaultSearchManager::Source 144 DefaultSearchManager::Source
135 DefaultSearchManager::GetDefaultSearchEngineSource() const { 145 DefaultSearchManager::GetDefaultSearchEngineSource() const {
136 Source source; 146 Source source;
137 GetDefaultSearchEngine(&source); 147 GetDefaultSearchEngine(&source);
138 return source; 148 return source;
139 } 149 }
140 150
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
OLDNEW
« no previous file with comments | « chrome/browser/search_engines/default_search_manager.h ('k') | chrome/browser/search_engines/template_url_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698