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

Side by Side Diff: chrome/browser/extensions/extension_preference_api.h

Issue 6596044: Add onChange event to preference extension APIs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 9 years, 9 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_EXTENSION_PREFERENCE_API_H__ 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFERENCE_API_H__
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFERENCE_API_H__ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFERENCE_API_H__
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "chrome/browser/extensions/extension_function.h" 11 #include "chrome/browser/extensions/extension_function.h"
12 #include "chrome/browser/prefs/pref_change_registrar.h"
13 #include "content/common/notification_observer.h"
14
15 class ExtensionPreferenceEventRouter : public NotificationObserver {
16 public:
17 explicit ExtensionPreferenceEventRouter(Profile* profile);
18 virtual ~ExtensionPreferenceEventRouter();
19
20 private:
21 // NotificationObserver implementation.
22 virtual void Observe(NotificationType type,
23 const NotificationSource& source,
24 const NotificationDetails& details);
25
26 void OnPrefChanged(PrefService* pref_service, const std::string& pref_key);
27
28 // This method dispatches events to the extension message service.
29 void DispatchEvent(const std::string& extension_id,
30 const std::string& event_name,
31 const std::string& json_args);
32
33 PrefChangeRegistrar registrar_;
34 PrefChangeRegistrar incognito_registrar_;
35
36 // Weak, owns us (transitively via ExtensionService).
37 Profile* profile_;
38
39 DISALLOW_COPY_AND_ASSIGN(ExtensionPreferenceEventRouter);
40 };
12 41
13 class Value; 42 class Value;
14 43
15 class PrefTransformerInterface { 44 class PrefTransformerInterface {
16 public: 45 public:
17 virtual ~PrefTransformerInterface() {} 46 virtual ~PrefTransformerInterface() {}
18 47
19 // Converts the representation of a preference as seen by the extension 48 // Converts the representation of a preference as seen by the extension
20 // into a representation that is used in the pref stores of the browser. 49 // into a representation that is used in the pref stores of the browser.
21 // Returns the pref store representation in case of success or sets 50 // Returns the pref store representation in case of success or sets
22 // |error| and returns NULL otherwise. 51 // |error| and returns NULL otherwise.
23 // The ownership of the returned value is passed to the caller. 52 // The ownership of the returned value is passed to the caller.
24 virtual Value* ExtensionToBrowserPref(const Value* extension_pref, 53 virtual Value* ExtensionToBrowserPref(const Value* extension_pref,
25 std::string* error) = 0; 54 std::string* error) = 0;
26 55
27 // Converts the representation of the preference as stored in the browser 56 // Converts the representation of the preference as stored in the browser
28 // into a representation that is used by the extension. 57 // into a representation that is used by the extension.
29 // Returns the extension representation in case of success or NULL otherwise. 58 // Returns the extension representation in case of success or NULL otherwise.
30 // The ownership of the returned value is passed to the caller. 59 // The ownership of the returned value is passed to the caller.
31 virtual Value* BrowserToExtensionPref(const Value* browser_pref) = 0; 60 virtual Value* BrowserToExtensionPref(const Value* browser_pref) = 0;
32 }; 61 };
33 62
34 class GetPreferenceFunction : public SyncExtensionFunction { 63 class GetPreferenceFunction : public SyncExtensionFunction {
35 public: 64 public:
36 virtual ~GetPreferenceFunction(); 65 virtual ~GetPreferenceFunction();
37 virtual bool RunImpl(); 66 virtual bool RunImpl();
38 DECLARE_EXTENSION_FUNCTION_NAME("experimental.preferences.get") 67 DECLARE_EXTENSION_FUNCTION_NAME("experimental.preferences.get")
39
40 private:
41 // Returns a string constant (defined in API) indicating the level of
42 // control this extension has on the specified preference.
43 const char* GetLevelOfControl(const std::string& browser_pref,
44 bool incognito) const;
45 }; 68 };
46 69
47 class SetPreferenceFunction : public SyncExtensionFunction { 70 class SetPreferenceFunction : public SyncExtensionFunction {
48 public: 71 public:
49 virtual ~SetPreferenceFunction(); 72 virtual ~SetPreferenceFunction();
50 virtual bool RunImpl(); 73 virtual bool RunImpl();
51 DECLARE_EXTENSION_FUNCTION_NAME("experimental.preferences.set") 74 DECLARE_EXTENSION_FUNCTION_NAME("experimental.preferences.set")
52 }; 75 };
53 76
54 class ClearPreferenceFunction : public SyncExtensionFunction { 77 class ClearPreferenceFunction : public SyncExtensionFunction {
55 public: 78 public:
56 virtual ~ClearPreferenceFunction(); 79 virtual ~ClearPreferenceFunction();
57 virtual bool RunImpl(); 80 virtual bool RunImpl();
58 DECLARE_EXTENSION_FUNCTION_NAME("experimental.preferences.clear") 81 DECLARE_EXTENSION_FUNCTION_NAME("experimental.preferences.clear")
59 }; 82 };
60 83
61 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFERENCE_API_H__ 84 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFERENCE_API_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698