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 #ifndef COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_MANAGER_H_ | 5 #ifndef COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_MANAGER_H_ |
6 #define COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_MANAGER_H_ | 6 #define COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_MANAGER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 static const char kLastModified[]; | 56 static const char kLastModified[]; |
57 static const char kLastVisited[]; | 57 static const char kLastVisited[]; |
58 | 58 |
59 static const char kUsageCount[]; | 59 static const char kUsageCount[]; |
60 static const char kAlternateURLs[]; | 60 static const char kAlternateURLs[]; |
61 static const char kSearchTermsReplacementKey[]; | 61 static const char kSearchTermsReplacementKey[]; |
62 static const char kCreatedByPolicy[]; | 62 static const char kCreatedByPolicy[]; |
63 static const char kDisabledByPolicy[]; | 63 static const char kDisabledByPolicy[]; |
64 | 64 |
65 enum Source { | 65 enum Source { |
| 66 // Default search engine chosen either from prepopulated engines set for |
| 67 // current country or overriden from kSearchProviderOverrides preference. |
66 FROM_FALLBACK = 0, | 68 FROM_FALLBACK = 0, |
| 69 // User selected engine. |
67 FROM_USER, | 70 FROM_USER, |
| 71 // Search engine set by extension overriding default search. |
68 FROM_EXTENSION, | 72 FROM_EXTENSION, |
| 73 // Search engine controlled externally through enterprise configuration |
| 74 // management (e.g. windows group policy). |
69 FROM_POLICY, | 75 FROM_POLICY, |
70 }; | 76 }; |
71 | 77 |
72 typedef base::Callback<void(const TemplateURLData*, Source)> ObserverCallback; | 78 typedef base::Callback<void(const TemplateURLData*, Source)> ObserverCallback; |
73 | 79 |
74 DefaultSearchManager(PrefService* pref_service, | 80 DefaultSearchManager(PrefService* pref_service, |
75 const ObserverCallback& change_observer); | 81 const ObserverCallback& change_observer); |
76 | 82 |
77 ~DefaultSearchManager(); | 83 ~DefaultSearchManager(); |
78 | 84 |
79 // Register prefs needed for tracking the default search provider. | 85 // Register prefs needed for tracking the default search provider. |
80 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 86 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
81 | 87 |
82 // Save default search provider pref values into the map provided. | 88 // Save default search provider pref values into the map provided. |
83 static void AddPrefValueToMap(std::unique_ptr<base::DictionaryValue> value, | 89 static void AddPrefValueToMap(std::unique_ptr<base::DictionaryValue> value, |
84 PrefValueMap* pref_value_map); | 90 PrefValueMap* pref_value_map); |
85 | 91 |
86 // Testing code can call this with |disabled| set to true to cause | 92 // Testing code can call this with |disabled| set to true to cause |
87 // GetDefaultSearchEngine() to return NULL instead of | 93 // GetDefaultSearchEngine() to return nullptr instead of |
88 // |fallback_default_search_| in cases where the DSE source is FROM_FALLBACK. | 94 // |fallback_default_search_| in cases where the DSE source is FROM_FALLBACK. |
89 static void SetFallbackSearchEnginesDisabledForTesting(bool disabled); | 95 static void SetFallbackSearchEnginesDisabledForTesting(bool disabled); |
90 | 96 |
91 // Gets a pointer to the current Default Search Engine. If NULL, indicates | 97 // Gets a pointer to the current Default Search Engine. If NULL, indicates |
92 // that Default Search is explicitly disabled. |source|, if not NULL, will be | 98 // that Default Search is explicitly disabled. |source|, if not NULL, will be |
93 // filled in with the source of the result. | 99 // filled in with the source of the result. |
94 TemplateURLData* GetDefaultSearchEngine(Source* source) const; | 100 const TemplateURLData* GetDefaultSearchEngine(Source* source) const; |
95 | 101 |
96 // Gets the source of the current Default Search Engine value. | 102 // Gets the source of the current Default Search Engine value. |
97 Source GetDefaultSearchEngineSource() const; | 103 Source GetDefaultSearchEngineSource() const; |
98 | 104 |
| 105 // Returns a pointer to the fallback engine. |
| 106 const TemplateURLData* GetFallbackSearchEngine() const; |
| 107 |
99 // Write default search provider data to |pref_service_|. | 108 // Write default search provider data to |pref_service_|. |
100 void SetUserSelectedDefaultSearchEngine(const TemplateURLData& data); | 109 void SetUserSelectedDefaultSearchEngine(const TemplateURLData& data); |
101 | 110 |
102 // Override the default search provider with an extension. | 111 // Override the default search provider with an extension. |
103 void SetExtensionControlledDefaultSearchEngine(const TemplateURLData& data); | 112 void SetExtensionControlledDefaultSearchEngine(const TemplateURLData& data); |
104 | 113 |
105 // Clear the extension-provided default search engine. Does not explicitly | 114 // Clear the extension-provided default search engine. Does not explicitly |
106 // disable Default Search. The new current default search engine will be | 115 // disable Default Search. The new current default search engine will be |
107 // defined by policy, extensions, or pre-populated data. | 116 // defined by policy, extensions, or pre-populated data. |
108 void ClearExtensionControlledDefaultSearchEngine(); | 117 void ClearExtensionControlledDefaultSearchEngine(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 // prefs). This will be null if no value was set in the pref store. | 167 // prefs). This will be null if no value was set in the pref store. |
159 std::unique_ptr<TemplateURLData> prefs_default_search_; | 168 std::unique_ptr<TemplateURLData> prefs_default_search_; |
160 | 169 |
161 // True if the default search is currently enforced by policy. | 170 // True if the default search is currently enforced by policy. |
162 bool default_search_controlled_by_policy_; | 171 bool default_search_controlled_by_policy_; |
163 | 172 |
164 DISALLOW_COPY_AND_ASSIGN(DefaultSearchManager); | 173 DISALLOW_COPY_AND_ASSIGN(DefaultSearchManager); |
165 }; | 174 }; |
166 | 175 |
167 #endif // COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_MANAGER_H_ | 176 #endif // COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_MANAGER_H_ |
OLD | NEW |