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 <memory> |
8 #include <string> | 9 #include <string> |
9 | 10 |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
11 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
12 #include "chrome/browser/extensions/api/content_settings/content_settings_store.
h" | 13 #include "chrome/browser/extensions/api/content_settings/content_settings_store.
h" |
13 #include "chrome/browser/extensions/chrome_extension_function.h" | 14 #include "chrome/browser/extensions/chrome_extension_function.h" |
14 #include "components/prefs/pref_change_registrar.h" | 15 #include "components/prefs/pref_change_registrar.h" |
15 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
16 #include "extensions/browser/browser_context_keyed_api_factory.h" | 17 #include "extensions/browser/browser_context_keyed_api_factory.h" |
17 #include "extensions/browser/event_router.h" | 18 #include "extensions/browser/event_router.h" |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 class PrefTransformerInterface { | 145 class PrefTransformerInterface { |
145 public: | 146 public: |
146 virtual ~PrefTransformerInterface() {} | 147 virtual ~PrefTransformerInterface() {} |
147 | 148 |
148 // Converts the representation of a preference as seen by the extension | 149 // Converts the representation of a preference as seen by the extension |
149 // into a representation that is used in the pref stores of the browser. | 150 // into a representation that is used in the pref stores of the browser. |
150 // Returns the pref store representation in case of success or sets | 151 // Returns the pref store representation in case of success or sets |
151 // |error| and returns NULL otherwise. |bad_message| is passed to simulate | 152 // |error| and returns NULL otherwise. |bad_message| is passed to simulate |
152 // the behavior of EXTENSION_FUNCTION_VALIDATE. It is never NULL. | 153 // the behavior of EXTENSION_FUNCTION_VALIDATE. It is never NULL. |
153 // The ownership of the returned value is passed to the caller. | 154 // The ownership of the returned value is passed to the caller. |
154 virtual base::Value* ExtensionToBrowserPref( | 155 virtual std::unique_ptr<base::Value> ExtensionToBrowserPref( |
155 const base::Value* extension_pref, | 156 const base::Value* extension_pref, |
156 std::string* error, | 157 std::string* error, |
157 bool* bad_message) = 0; | 158 bool* bad_message) = 0; |
158 | 159 |
159 // Converts the representation of the preference as stored in the browser | 160 // Converts the representation of the preference as stored in the browser |
160 // into a representation that is used by the extension. | 161 // into a representation that is used by the extension. |
161 // Returns the extension representation in case of success or NULL otherwise. | 162 // Returns the extension representation in case of success or NULL otherwise. |
162 // The ownership of the returned value is passed to the caller. | 163 // The ownership of the returned value is passed to the caller. |
163 virtual base::Value* BrowserToExtensionPref( | 164 virtual std::unique_ptr<base::Value> BrowserToExtensionPref( |
164 const base::Value* browser_pref) = 0; | 165 const base::Value* browser_pref) = 0; |
165 }; | 166 }; |
166 | 167 |
167 // A base class to provide functionality common to the other *PreferenceFunction | 168 // A base class to provide functionality common to the other *PreferenceFunction |
168 // classes. | 169 // classes. |
169 class PreferenceFunction : public UIThreadExtensionFunction { | 170 class PreferenceFunction : public UIThreadExtensionFunction { |
170 protected: | 171 protected: |
171 enum PermissionType { PERMISSION_TYPE_READ, PERMISSION_TYPE_WRITE }; | 172 enum PermissionType { PERMISSION_TYPE_READ, PERMISSION_TYPE_WRITE }; |
172 | 173 |
173 ~PreferenceFunction() override; | 174 ~PreferenceFunction() override; |
(...skipping 29 matching lines...) Expand all Loading... |
203 protected: | 204 protected: |
204 ~ClearPreferenceFunction() override; | 205 ~ClearPreferenceFunction() override; |
205 | 206 |
206 // ExtensionFunction: | 207 // ExtensionFunction: |
207 ResponseAction Run() override; | 208 ResponseAction Run() override; |
208 }; | 209 }; |
209 | 210 |
210 } // namespace extensions | 211 } // namespace extensions |
211 | 212 |
212 #endif // CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_PREFERENCE_API_H__ | 213 #endif // CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_PREFERENCE_API_H__ |
OLD | NEW |