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

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: Last test fix? 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"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/prefs/pref_change_registrar.h"
9 12
10 namespace base { 13 namespace base {
11 class DictionaryValue; 14 class DictionaryValue;
15 }
16
17 namespace base {
18 class DictionaryValue;
12 } 19 }
13 20
14 namespace user_prefs { 21 namespace user_prefs {
15 class PrefRegistrySyncable; 22 class PrefRegistrySyncable;
16 } 23 }
17 24
18 class PrefService; 25 class PrefService;
19 class PrefValueMap; 26 class PrefValueMap;
20 struct TemplateURLData; 27 struct TemplateURLData;
21 28
22 // DefaultSearchManager handles the loading and writing of the user's default 29 // DefaultSearchManager handles the loading and writing of the user's default
23 // search engine selection to and from prefs. 30 // search engine selection to and from prefs.
24
25 class DefaultSearchManager { 31 class DefaultSearchManager {
26 public: 32 public:
33 static const char kDefaultSearchProviderDataPrefName[];
34
27 static const char kID[]; 35 static const char kID[];
28 static const char kShortName[]; 36 static const char kShortName[];
29 static const char kKeyword[]; 37 static const char kKeyword[];
30 static const char kPrepopulateID[]; 38 static const char kPrepopulateID[];
31 static const char kSyncGUID[]; 39 static const char kSyncGUID[];
32 40
33 static const char kURL[]; 41 static const char kURL[];
34 static const char kSuggestionsURL[]; 42 static const char kSuggestionsURL[];
35 static const char kInstantURL[]; 43 static const char kInstantURL[];
36 static const char kImageURL[]; 44 static const char kImageURL[];
(...skipping 11 matching lines...) Expand all
48 56
49 static const char kDateCreated[]; 57 static const char kDateCreated[];
50 static const char kLastModified[]; 58 static const char kLastModified[];
51 59
52 static const char kUsageCount[]; 60 static const char kUsageCount[];
53 static const char kAlternateURLs[]; 61 static const char kAlternateURLs[];
54 static const char kSearchTermsReplacementKey[]; 62 static const char kSearchTermsReplacementKey[];
55 static const char kCreatedByPolicy[]; 63 static const char kCreatedByPolicy[];
56 static const char kDisabledByPolicy[]; 64 static const char kDisabledByPolicy[];
57 65
58 explicit DefaultSearchManager(PrefService* pref_service); 66 enum Source {
67 FROM_FALLBACK = 0,
68 FROM_USER,
69 FROM_EXTENSION,
70 FROM_POLICY,
71 };
72
73 typedef base::Callback<void(const TemplateURLData*, Source)> ObserverCallback;
74
75 DefaultSearchManager(PrefService* pref_service,
76 const ObserverCallback& change_observer);
77
59 ~DefaultSearchManager(); 78 ~DefaultSearchManager();
60 79
61 // Register prefs needed for tracking the default search provider. 80 // Register prefs needed for tracking the default search provider.
62 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 81 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
63 82
64 // Save default search provider pref values into the map provided. 83 // Save default search provider pref values into the map provided.
65 static void AddPrefValueToMap(base::DictionaryValue* value, 84 static void AddPrefValueToMap(base::DictionaryValue* value,
66 PrefValueMap* pref_value_map); 85 PrefValueMap* pref_value_map);
67 86
68 // Read default search provider data from |pref_service_|. 87 // Gets a pointer to the current Default Search Engine. If NULL, indicates
69 bool GetDefaultSearchEngine(TemplateURLData* url); 88 // that Default Search is explicitly disabled. |source|, if not NULL, will be
89 // filled in with the source of the result.
90 TemplateURLData* GetDefaultSearchEngine(Source* source) const;
91
92 // Gets the source of the current Default Search Engine value.
93 Source GetDefaultSearchEngineSource() const;
70 94
71 // Write default search provider data to |pref_service_|. 95 // Write default search provider data to |pref_service_|.
72 void SetUserSelectedDefaultSearchEngine(const TemplateURLData& data); 96 void SetUserSelectedDefaultSearchEngine(const TemplateURLData& data);
73 97
74 // Clear the user's default search provider choice from |pref_service_|. 98 // Override the default search provider with an extension.
99 void SetExtensionControlledDefaultSearchEngine(const TemplateURLData& data);
100
101 // Clear the extension-provided default search engine. Does not explicitly
102 // disable Default Search.The new current default search engine will be
103 // defined by policy, extensions, or pre-populated data.
104 void ClearExtensionControlledDefaultSearchEngine();
105
106 // Clear the user's default search provider choice from |pref_service_|. Does
107 // not explicitly disable Default Search. The new current default search
108 // engine will be defined by policy, extensions, or pre-populated data.
75 void ClearUserSelectedDefaultSearchEngine(); 109 void ClearUserSelectedDefaultSearchEngine();
76 110
77 private: 111 private:
112 // Handles changes to kDefaultSearchProviderData pref. This includes sync and
113 // policy changes. Calls LoadDefaultSearchEngineFromPrefs() and
114 // NotifyObserver() if the effective DSE might have changed.
115 void OnDefaultSearchPrefChanged();
116
117 // Handles changes to kSearchProviderOverrides pref. Calls
118 // LoadPrepopulatedDefaultSearch() and NotifyObserver() if the effective DSE
119 // might have changed.
120 void OnOverridesPrefChanged();
121
122 // Updates |prefs_default_search_| with values from its corresponding
123 // pre-populated search provider record, if any.
124 void MergePrefsDataWithPrepopulated();
125
126 // Reads default search provider data from |pref_service_|, updating
127 // |prefs_default_search_| and |default_search_controlled_by_policy_|.
128 // Invokes MergePrefsDataWithPrepopulated().
129 void LoadDefaultSearchEngineFromPrefs();
130
131 // Reads pre-populated search providers, which may be built-in or overridden
132 // by kSearchProviderOverrides. Updates |fallback_default_search_|. Invoke
133 // MergePrefsDataWithPrepopulated().
134 void LoadPrepopulatedDefaultSearch();
135
136 // Invokes |change_observer_| if it is not NULL.
137 void NotifyObserver();
138
78 PrefService* pref_service_; 139 PrefService* pref_service_;
140 const ObserverCallback change_observer_;
141 PrefChangeRegistrar pref_change_registrar_;
142
143 scoped_ptr<TemplateURLData> fallback_default_search_;
144 scoped_ptr<TemplateURLData> extension_default_search_;
145 scoped_ptr<TemplateURLData> prefs_default_search_;
146
147 bool default_search_controlled_by_policy_;
79 148
80 DISALLOW_COPY_AND_ASSIGN(DefaultSearchManager); 149 DISALLOW_COPY_AND_ASSIGN(DefaultSearchManager);
81 }; 150 };
82 151
83 #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