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

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

Issue 268643002: Use the DefaultSearchManager as the exclusive authority on DSE, ignoring Web Data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nearly all non-sync tests pass. Created 6 years, 7 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 #ifndef CHROME_BROWSER_SEARCH_ENGINES_DEFAULT_SEARCH_MANAGER_H_ 5 #ifndef CHROME_BROWSER_SEARCH_ENGINES_DEFAULT_SEARCH_MANAGER_H_
6 #define CHROME_BROWSER_SEARCH_ENGINES_DEFAULT_SEARCH_MANAGER_H_ 6 #define CHROME_BROWSER_SEARCH_ENGINES_DEFAULT_SEARCH_MANAGER_H_
7 7
8 #include "base/callback.h"
8 #include "base/macros.h" 9 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
10 #include "base/prefs/pref_change_registrar.h" 11 #include "base/prefs/pref_change_registrar.h"
11 12
12 namespace base { 13 namespace base {
13 class DictionaryValue; 14 class DictionaryValue;
14 } 15 }
15 16
16 namespace base { 17 namespace base {
17 class DictionaryValue; 18 class DictionaryValue;
18 } 19 }
19 20
20 namespace user_prefs { 21 namespace user_prefs {
21 class PrefRegistrySyncable; 22 class PrefRegistrySyncable;
22 } 23 }
23 24
24 class PrefService; 25 class PrefService;
25 class PrefValueMap; 26 class PrefValueMap;
26 struct TemplateURLData; 27 struct TemplateURLData;
27 28
28 // DefaultSearchManager handles the loading and writing of the user's default 29 // DefaultSearchManager handles the loading and writing of the user's default
29 // search engine selection to and from prefs. 30 // search engine selection to and from prefs.
30 31
31 class DefaultSearchManager { 32 class DefaultSearchManager {
32 public: 33 public:
34 static const char kDefaultSearchProviderDataPrefName[];
35
33 static const char kID[]; 36 static const char kID[];
34 static const char kShortName[]; 37 static const char kShortName[];
35 static const char kKeyword[]; 38 static const char kKeyword[];
36 static const char kPrepopulateID[]; 39 static const char kPrepopulateID[];
37 static const char kSyncGUID[]; 40 static const char kSyncGUID[];
38 41
39 static const char kURL[]; 42 static const char kURL[];
40 static const char kSuggestionsURL[]; 43 static const char kSuggestionsURL[];
41 static const char kInstantURL[]; 44 static const char kInstantURL[];
42 static const char kImageURL[]; 45 static const char kImageURL[];
(...skipping 18 matching lines...) Expand all
61 static const char kCreatedByPolicy[]; 64 static const char kCreatedByPolicy[];
62 static const char kDisabledByPolicy[]; 65 static const char kDisabledByPolicy[];
63 66
64 enum Source { 67 enum Source {
65 FROM_FALLBACK = 0, 68 FROM_FALLBACK = 0,
66 FROM_USER, 69 FROM_USER,
67 FROM_EXTENSION, 70 FROM_EXTENSION,
68 FROM_POLICY, 71 FROM_POLICY,
69 }; 72 };
70 73
71 explicit DefaultSearchManager(PrefService* pref_service); 74
75 typedef base::Callback<void(const TemplateURLData*, Source)> ObserverCallback;
76
77 DefaultSearchManager(PrefService* pref_service,
erikwright (departed) 2014/05/02 16:35:56 TODO: comments.
78 const ObserverCallback& change_observer);
79
72 ~DefaultSearchManager(); 80 ~DefaultSearchManager();
73 81
74 // Register prefs needed for tracking the default search provider. 82 // Register prefs needed for tracking the default search provider.
75 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 83 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
76 84
77 // Save default search provider pref values into the map provided. 85 // Save default search provider pref values into the map provided.
78 static void AddPrefValueToMap(base::DictionaryValue* value, 86 static void AddPrefValueToMap(base::DictionaryValue* value,
79 PrefValueMap* pref_value_map); 87 PrefValueMap* pref_value_map);
80 88
81 // Gets a pointer to the current DefaultSearchEngine. If NULL, indicates that 89 // Gets a pointer to the current Default Search Engine. If NULL, indicates
82 // Default Search is explicitly disabled. 90 // that Default Search is explicitly disabled. |source|, if not NULL, will be
83 TemplateURLData* GetDefaultSearchEngine() const; 91 // filled in with the source of the result.
92 TemplateURLData* GetDefaultSearchEngine(Source* source) const;
84 93
85 // Write default search provider data to |pref_service_|. 94 // Write default search provider data to |pref_service_|.
86 void SetUserSelectedDefaultSearchEngine(const TemplateURLData& data); 95 void SetUserSelectedDefaultSearchEngine(const TemplateURLData& data);
87 96
88 // Override the default search provider with an extension. Takes ownership of 97 // Override the default search provider with an extension. Takes ownership of
89 // |data|. 98 // |data|.
90 void SetExtensionControlledDefaultSearchEngine(TemplateURLData* data); 99 void SetExtensionControlledDefaultSearchEngine(TemplateURLData* data);
91 100
92 // Clear the extension-provided default search engine. Does not explicitly 101 // Clear the extension-provided default search engine. Does not explicitly
93 // disable Default Search.The new current default search engine will be 102 // disable Default Search.The new current default search engine will be
94 // defined by policy, extensions, or pre-populated data. 103 // defined by policy, extensions, or pre-populated data.
95 void ClearExtensionControlledDefaultSearchEngine(); 104 void ClearExtensionControlledDefaultSearchEngine();
96 105
97 // Clear the user's default search provider choice from |pref_service_|. Does 106 // Clear the user's default search provider choice from |pref_service_|. Does
98 // not explicitly disable Default Search. The new current default search 107 // not explicitly disable Default Search. The new current default search
99 // engine will be defined by policy, extensions, or pre-populated data. 108 // engine will be defined by policy, extensions, or pre-populated data.
100 void ClearUserSelectedDefaultSearchEngine(); 109 void ClearUserSelectedDefaultSearchEngine();
101 110
102 // Determines the source of the current default search provider value.
103 Source GetDefaultSearchEngineSource() const;
104
105 private: 111 private:
106 // Handle changes to kDefaultSearchProviderData pref. This includes sync and 112 // Handle changes to kDefaultSearchProviderData pref. This includes sync and
107 // policy changes. 113 // policy changes. Calls |LoadDefaultSearchEngineFromPrefs| and
114 // |NotifyObserver| if the effective DSE might have changed.
108 void OnDefaultSearchPrefChanged(); 115 void OnDefaultSearchPrefChanged();
109 116
110 // Handle changes to kSearchProviderOverrides pref, and update necessary 117 // Handle changes to kSearchProviderOverrides pref. Calls
111 // members. 118 // |LoadPrepopulatedDefaultSearch| and |NotifyObserver| if the effective DSE
119 // might have changed.
112 void OnOverridesPrefChanged(); 120 void OnOverridesPrefChanged();
113 121
114 // Update |default_search_controlled_by_policy_|. 122 // Updates |prefs_default_search_| with values from its corresponding
115 void UpdatePolicyStatus(); 123 // pre-populated search provider record, if any.
116
117 // Merge data from prefs with prepopulated data.
118 void MergePrefsDataWithPrepopulated(); 124 void MergePrefsDataWithPrepopulated();
119 125
120 // Read default search provider data from |pref_service_|. 126 // Read default search provider data from |pref_service_|, updating
121 bool ReadDefaultSearchEngineFromPrefs(TemplateURLData** data); 127 // |prefs_default_search_| and |default_search_controlled_by_policy_|.
128 // Will invoke |MergePrefsDataWithPrepopulated|.
129 void LoadDefaultSearchEngineFromPrefs();
130
131 // Read pre-populated search providers, which may be built-in or overridden by
132 // kSearchProviderOverrides. Updates |fallback_default_search_|. Will invoke
133 // |MergePrefsDataWithPrepopulated|.
134 void LoadPrepopulatedDefaultSearch();
135
136 // Invokes |change_observer_| if it is not NULL.
137 void NotifyObserver();
122 138
123 PrefService* pref_service_; 139 PrefService* pref_service_;
140 const ObserverCallback change_observer_;
124 PrefChangeRegistrar pref_change_registrar_; 141 PrefChangeRegistrar pref_change_registrar_;
125 142
126 scoped_ptr<TemplateURLData> fallback_default_search_; 143 scoped_ptr<TemplateURLData> fallback_default_search_;
127 scoped_ptr<TemplateURLData> extension_default_search_; 144 scoped_ptr<TemplateURLData> extension_default_search_;
128 scoped_ptr<TemplateURLData> prefs_default_search_; 145 scoped_ptr<TemplateURLData> prefs_default_search_;
129 146
130 bool default_search_controlled_by_policy_; 147 bool default_search_controlled_by_policy_;
131 148
132 DISALLOW_COPY_AND_ASSIGN(DefaultSearchManager); 149 DISALLOW_COPY_AND_ASSIGN(DefaultSearchManager);
133 }; 150 };
134 151
135 #endif // CHROME_BROWSER_SEARCH_ENGINES_DEFAULT_SEARCH_MANAGER_H_ 152 #endif // CHROME_BROWSER_SEARCH_ENGINES_DEFAULT_SEARCH_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698