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

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

Issue 10952021: Moving preference API into api/preferences (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFERENCE_API_H__
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFERENCE_API_H__
7
8 #include <string>
9
10 #include "chrome/browser/api/prefs/pref_change_registrar.h"
11 #include "chrome/browser/extensions/extension_function.h"
12 #include "content/public/browser/notification_observer.h"
13
14 class PrefService;
15
16 namespace base {
17 class Value;
18 }
19
20 class ExtensionPreferenceEventRouter : public content::NotificationObserver {
21 public:
22 explicit ExtensionPreferenceEventRouter(Profile* profile);
23 virtual ~ExtensionPreferenceEventRouter();
24
25 private:
26 // content::NotificationObserver implementation.
27 virtual void Observe(int type,
28 const content::NotificationSource& source,
29 const content::NotificationDetails& details) OVERRIDE;
30
31 void OnPrefChanged(PrefService* pref_service, const std::string& pref_key);
32
33 // This method dispatches events to the extension message service.
34 void DispatchEvent(const std::string& extension_id,
35 const std::string& event_name,
36 const std::string& json_args);
37
38 PrefChangeRegistrar registrar_;
39 PrefChangeRegistrar incognito_registrar_;
40
41 // Weak, owns us (transitively via ExtensionService).
42 Profile* profile_;
43
44 DISALLOW_COPY_AND_ASSIGN(ExtensionPreferenceEventRouter);
45 };
46
47 class PrefTransformerInterface {
48 public:
49 virtual ~PrefTransformerInterface() {}
50
51 // Converts the representation of a preference as seen by the extension
52 // into a representation that is used in the pref stores of the browser.
53 // Returns the pref store representation in case of success or sets
54 // |error| and returns NULL otherwise. |bad_message| is passed to simulate
55 // the behavior of EXTENSION_FUNCTION_VALIDATE. It is never NULL.
56 // The ownership of the returned value is passed to the caller.
57 virtual base::Value* ExtensionToBrowserPref(
58 const base::Value* extension_pref,
59 std::string* error,
60 bool* bad_message) = 0;
61
62 // Converts the representation of the preference as stored in the browser
63 // into a representation that is used by the extension.
64 // Returns the extension representation in case of success or NULL otherwise.
65 // The ownership of the returned value is passed to the caller.
66 virtual base::Value* BrowserToExtensionPref(
67 const base::Value* browser_pref) = 0;
68 };
69
70 // A base class to provide functionality common to the other *PreferenceFunction
71 // classes.
72 class PreferenceFunction : public SyncExtensionFunction {
73 protected:
74 virtual ~PreferenceFunction();
75
76 // Given an |extension_pref_key|, provides its |browser_pref_key| from the
77 // static map in extension_preference.cc. Returns true if the corresponding
78 // browser pref exists and the extension has the API permission needed to
79 // modify that pref. Sets |error_| if the extension doesn't have the needed
80 // permission.
81 bool ValidateBrowserPref(const std::string& extension_pref_key,
82 std::string* browser_pref_key);
83 };
84
85 class GetPreferenceFunction : public PreferenceFunction {
86 public:
87 DECLARE_EXTENSION_FUNCTION_NAME("types.ChromeSetting.get")
88
89 protected:
90 virtual ~GetPreferenceFunction();
91
92 // ExtensionFunction:
93 virtual bool RunImpl() OVERRIDE;
94 };
95
96 class SetPreferenceFunction : public PreferenceFunction {
97 public:
98 DECLARE_EXTENSION_FUNCTION_NAME("types.ChromeSetting.set")
99
100 protected:
101 virtual ~SetPreferenceFunction();
102
103 // ExtensionFunction:
104 virtual bool RunImpl() OVERRIDE;
105 };
106
107 class ClearPreferenceFunction : public PreferenceFunction {
108 public:
109 DECLARE_EXTENSION_FUNCTION_NAME("types.ChromeSetting.clear")
110
111 protected:
112 virtual ~ClearPreferenceFunction();
113
114 // ExtensionFunction:
115 virtual bool RunImpl() OVERRIDE;
116 };
117
118 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFERENCE_API_H__
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_function_registry.cc ('k') | chrome/browser/extensions/extension_preference_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698