OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_EXTENSIONS_API_PREFERENCE_PREFERENCE_API_H__ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_PREFERENCE_API_H__ |
6 #define CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_PREFERENCE_API_H__ | 6 #define CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_PREFERENCE_API_H__ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 virtual ExtensionPrefValueMap* extension_pref_value_map() = 0; | 89 virtual ExtensionPrefValueMap* extension_pref_value_map() = 0; |
90 virtual scoped_refptr<ContentSettingsStore> content_settings_store() = 0; | 90 virtual scoped_refptr<ContentSettingsStore> content_settings_store() = 0; |
91 }; | 91 }; |
92 | 92 |
93 class PreferenceAPI : public PreferenceAPIBase, | 93 class PreferenceAPI : public PreferenceAPIBase, |
94 public BrowserContextKeyedAPI, | 94 public BrowserContextKeyedAPI, |
95 public EventRouter::Observer, | 95 public EventRouter::Observer, |
96 public ContentSettingsStore::Observer { | 96 public ContentSettingsStore::Observer { |
97 public: | 97 public: |
98 explicit PreferenceAPI(content::BrowserContext* context); | 98 explicit PreferenceAPI(content::BrowserContext* context); |
99 virtual ~PreferenceAPI(); | 99 ~PreferenceAPI() override; |
100 | 100 |
101 // KeyedService implementation. | 101 // KeyedService implementation. |
102 virtual void Shutdown() override; | 102 void Shutdown() override; |
103 | 103 |
104 // BrowserContextKeyedAPI implementation. | 104 // BrowserContextKeyedAPI implementation. |
105 static BrowserContextKeyedAPIFactory<PreferenceAPI>* GetFactoryInstance(); | 105 static BrowserContextKeyedAPIFactory<PreferenceAPI>* GetFactoryInstance(); |
106 | 106 |
107 // Convenience method to get the PreferenceAPI for a profile. | 107 // Convenience method to get the PreferenceAPI for a profile. |
108 static PreferenceAPI* Get(content::BrowserContext* context); | 108 static PreferenceAPI* Get(content::BrowserContext* context); |
109 | 109 |
110 // EventRouter::Observer implementation. | 110 // EventRouter::Observer implementation. |
111 virtual void OnListenerAdded(const EventListenerInfo& details) override; | 111 void OnListenerAdded(const EventListenerInfo& details) override; |
112 | 112 |
113 private: | 113 private: |
114 friend class BrowserContextKeyedAPIFactory<PreferenceAPI>; | 114 friend class BrowserContextKeyedAPIFactory<PreferenceAPI>; |
115 | 115 |
116 // ContentSettingsStore::Observer implementation. | 116 // ContentSettingsStore::Observer implementation. |
117 virtual void OnContentSettingChanged(const std::string& extension_id, | 117 void OnContentSettingChanged(const std::string& extension_id, |
118 bool incognito) override; | 118 bool incognito) override; |
119 | 119 |
120 // Clears incognito session-only content settings for all extensions. | 120 // Clears incognito session-only content settings for all extensions. |
121 void ClearIncognitoSessionOnlyContentSettings(); | 121 void ClearIncognitoSessionOnlyContentSettings(); |
122 | 122 |
123 // PreferenceAPIBase implementation. | 123 // PreferenceAPIBase implementation. |
124 virtual ExtensionPrefs* extension_prefs() override; | 124 ExtensionPrefs* extension_prefs() override; |
125 virtual ExtensionPrefValueMap* extension_pref_value_map() override; | 125 ExtensionPrefValueMap* extension_pref_value_map() override; |
126 virtual scoped_refptr<ContentSettingsStore> content_settings_store() override; | 126 scoped_refptr<ContentSettingsStore> content_settings_store() override; |
127 | 127 |
128 Profile* profile_; | 128 Profile* profile_; |
129 | 129 |
130 // BrowserContextKeyedAPI implementation. | 130 // BrowserContextKeyedAPI implementation. |
131 static const char* service_name() { | 131 static const char* service_name() { |
132 return "PreferenceAPI"; | 132 return "PreferenceAPI"; |
133 } | 133 } |
134 static const bool kServiceIsNULLWhileTesting = true; | 134 static const bool kServiceIsNULLWhileTesting = true; |
135 static const bool kServiceRedirectedInIncognito = true; | 135 static const bool kServiceRedirectedInIncognito = true; |
136 | 136 |
(...skipping 25 matching lines...) Expand all Loading... |
162 virtual base::Value* BrowserToExtensionPref( | 162 virtual base::Value* BrowserToExtensionPref( |
163 const base::Value* browser_pref) = 0; | 163 const base::Value* browser_pref) = 0; |
164 }; | 164 }; |
165 | 165 |
166 // A base class to provide functionality common to the other *PreferenceFunction | 166 // A base class to provide functionality common to the other *PreferenceFunction |
167 // classes. | 167 // classes. |
168 class PreferenceFunction : public ChromeSyncExtensionFunction { | 168 class PreferenceFunction : public ChromeSyncExtensionFunction { |
169 protected: | 169 protected: |
170 enum PermissionType { PERMISSION_TYPE_READ, PERMISSION_TYPE_WRITE }; | 170 enum PermissionType { PERMISSION_TYPE_READ, PERMISSION_TYPE_WRITE }; |
171 | 171 |
172 virtual ~PreferenceFunction(); | 172 ~PreferenceFunction() override; |
173 | 173 |
174 // Given an |extension_pref_key|, provides its |browser_pref_key| from the | 174 // Given an |extension_pref_key|, provides its |browser_pref_key| from the |
175 // static map in preference_api.cc. Returns true if the corresponding | 175 // static map in preference_api.cc. Returns true if the corresponding |
176 // browser pref exists and the extension has the API permission needed to | 176 // browser pref exists and the extension has the API permission needed to |
177 // modify that pref. Sets |error_| if the extension doesn't have the needed | 177 // modify that pref. Sets |error_| if the extension doesn't have the needed |
178 // permission. | 178 // permission. |
179 bool ValidateBrowserPref(const std::string& extension_pref_key, | 179 bool ValidateBrowserPref(const std::string& extension_pref_key, |
180 PermissionType permission_type, | 180 PermissionType permission_type, |
181 std::string* browser_pref_key); | 181 std::string* browser_pref_key); |
182 }; | 182 }; |
183 | 183 |
184 class GetPreferenceFunction : public PreferenceFunction { | 184 class GetPreferenceFunction : public PreferenceFunction { |
185 public: | 185 public: |
186 DECLARE_EXTENSION_FUNCTION("types.ChromeSetting.get", TYPES_CHROMESETTING_GET) | 186 DECLARE_EXTENSION_FUNCTION("types.ChromeSetting.get", TYPES_CHROMESETTING_GET) |
187 | 187 |
188 protected: | 188 protected: |
189 virtual ~GetPreferenceFunction(); | 189 ~GetPreferenceFunction() override; |
190 | 190 |
191 // ExtensionFunction: | 191 // ExtensionFunction: |
192 virtual bool RunSync() override; | 192 bool RunSync() override; |
193 }; | 193 }; |
194 | 194 |
195 class SetPreferenceFunction : public PreferenceFunction { | 195 class SetPreferenceFunction : public PreferenceFunction { |
196 public: | 196 public: |
197 DECLARE_EXTENSION_FUNCTION("types.ChromeSetting.set", TYPES_CHROMESETTING_SET) | 197 DECLARE_EXTENSION_FUNCTION("types.ChromeSetting.set", TYPES_CHROMESETTING_SET) |
198 | 198 |
199 protected: | 199 protected: |
200 virtual ~SetPreferenceFunction(); | 200 ~SetPreferenceFunction() override; |
201 | 201 |
202 // ExtensionFunction: | 202 // ExtensionFunction: |
203 virtual bool RunSync() override; | 203 bool RunSync() override; |
204 }; | 204 }; |
205 | 205 |
206 class ClearPreferenceFunction : public PreferenceFunction { | 206 class ClearPreferenceFunction : public PreferenceFunction { |
207 public: | 207 public: |
208 DECLARE_EXTENSION_FUNCTION("types.ChromeSetting.clear", | 208 DECLARE_EXTENSION_FUNCTION("types.ChromeSetting.clear", |
209 TYPES_CHROMESETTING_CLEAR) | 209 TYPES_CHROMESETTING_CLEAR) |
210 | 210 |
211 protected: | 211 protected: |
212 virtual ~ClearPreferenceFunction(); | 212 ~ClearPreferenceFunction() override; |
213 | 213 |
214 // ExtensionFunction: | 214 // ExtensionFunction: |
215 virtual bool RunSync() override; | 215 bool RunSync() override; |
216 }; | 216 }; |
217 | 217 |
218 } // namespace extensions | 218 } // namespace extensions |
219 | 219 |
220 #endif // CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_PREFERENCE_API_H__ | 220 #endif // CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_PREFERENCE_API_H__ |
OLD | NEW |