OLD | NEW |
---|---|
(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 // This is the base interface for a preference services that provides | |
6 // a way to access the application's current preferences. | |
7 // | |
8 // This base interface assumes all preferences are local. See | |
9 // SyncablePrefServiceBase for the interface to a preference service | |
10 // that stores preferences that can be synced. | |
11 // | |
12 // Chromium settings and storage represent user-selected preferences and | |
13 // information and MUST not be extracted, overwritten or modified except | |
14 // through Chromium defined APIs. | |
15 | |
16 #ifndef CHROME_BROWSER_API_PREFS_PREF_SERVICE_BASE_H_ | |
17 #define CHROME_BROWSER_API_PREFS_PREF_SERVICE_BASE_H_ | |
18 | |
19 #include "base/values.h" | |
20 | |
21 namespace content { | |
22 class NotificationObserver; | |
23 } | |
24 | |
25 namespace subtle { | |
26 class PrefMemberBase; | |
27 } | |
28 | |
29 class FilePath; | |
30 class Profile; | |
31 class TabContents; | |
32 | |
33 class PrefServiceBase { | |
34 public: | |
35 // Retrieves a PrefServiceBase for the given profile. | |
erikwright (departed)
2012/08/16 15:12:40
I'm not a big fan of this. Is there a reason why P
Jói
2012/08/16 15:35:56
First off I should note that we want to stop depen
| |
36 static PrefServiceBase* ForProfile(Profile* profile); | |
37 | |
38 virtual ~PrefServiceBase() {} | |
39 | |
40 // Enum used when registering preferences to determine if it should be synced | |
41 // or not. This is only used for profile prefs, not local state prefs. | |
42 // See the Register*Pref methods for profile prefs below. | |
43 enum PrefSyncStatus { | |
44 UNSYNCABLE_PREF, | |
45 SYNCABLE_PREF | |
46 }; | |
47 | |
48 // Returns true if the preference for the given preference name is available | |
49 // and is managed. | |
50 virtual bool IsManagedPreference(const char* pref_name) const = 0; | |
51 | |
52 // Returns |true| if a preference with the given name is available and its | |
53 // value can be changed by the user. | |
54 virtual bool IsUserModifiablePreference(const char* pref_name) const = 0; | |
55 | |
56 // Make the PrefService aware of a pref. | |
57 // TODO(zea): split local state and profile prefs into their own subclasses. | |
58 // ---------- Local state prefs ---------- | |
59 virtual void RegisterBooleanPref(const char* path, | |
60 bool default_value) = 0; | |
61 virtual void RegisterIntegerPref(const char* path, | |
62 int default_value) = 0; | |
63 virtual void RegisterDoublePref(const char* path, | |
64 double default_value) = 0; | |
65 virtual void RegisterStringPref(const char* path, | |
66 const std::string& default_value) = 0; | |
67 virtual void RegisterFilePathPref(const char* path, | |
68 const FilePath& default_value) = 0; | |
69 virtual void RegisterListPref(const char* path) = 0; | |
70 virtual void RegisterDictionaryPref(const char* path) = 0; | |
71 // These take ownership of the default_value: | |
72 virtual void RegisterListPref(const char* path, | |
73 base::ListValue* default_value) = 0; | |
74 virtual void RegisterDictionaryPref( | |
75 const char* path, base::DictionaryValue* default_value) = 0; | |
76 // These variants use a default value from the locale dll instead. | |
77 virtual void RegisterLocalizedBooleanPref( | |
78 const char* path, int locale_default_message_id) = 0; | |
79 virtual void RegisterLocalizedIntegerPref( | |
80 const char* path, int locale_default_message_id) = 0; | |
81 virtual void RegisterLocalizedDoublePref( | |
82 const char* path, int locale_default_message_id) = 0; | |
83 virtual void RegisterLocalizedStringPref( | |
84 const char* path, int locale_default_message_id) = 0; | |
85 virtual void RegisterInt64Pref(const char* path, | |
86 int64 default_value) = 0; | |
87 | |
88 // ---------- Profile prefs ---------- | |
89 // Profile prefs must specify whether the pref should be synchronized across | |
90 // machines or not (see PrefSyncStatus enum above). | |
91 virtual void RegisterBooleanPref(const char* path, | |
92 bool default_value, | |
93 PrefSyncStatus sync_status) = 0; | |
94 virtual void RegisterIntegerPref(const char* path, | |
95 int default_value, | |
96 PrefSyncStatus sync_status) = 0; | |
97 virtual void RegisterDoublePref(const char* path, | |
98 double default_value, | |
99 PrefSyncStatus sync_status) = 0; | |
100 virtual void RegisterStringPref(const char* path, | |
101 const std::string& default_value, | |
102 PrefSyncStatus sync_status) = 0; | |
103 virtual void RegisterFilePathPref(const char* path, | |
104 const FilePath& default_value, | |
105 PrefSyncStatus sync_status) = 0; | |
106 virtual void RegisterListPref(const char* path, | |
107 PrefSyncStatus sync_status) = 0; | |
108 virtual void RegisterDictionaryPref(const char* path, | |
109 PrefSyncStatus sync_status) = 0; | |
110 // These take ownership of the default_value: | |
111 virtual void RegisterListPref(const char* path, | |
112 base::ListValue* default_value, | |
113 PrefSyncStatus sync_status) = 0; | |
114 virtual void RegisterDictionaryPref(const char* path, | |
115 base::DictionaryValue* default_value, | |
116 PrefSyncStatus sync_status) = 0; | |
117 // These variants use a default value from the locale dll instead. | |
118 virtual void RegisterLocalizedBooleanPref( | |
119 const char* path, | |
120 int locale_default_message_id, | |
121 PrefSyncStatus sync_status) = 0; | |
122 virtual void RegisterLocalizedIntegerPref( | |
123 const char* path, | |
124 int locale_default_message_id, | |
125 PrefSyncStatus sync_status) = 0; | |
126 virtual void RegisterLocalizedDoublePref( | |
127 const char* path, | |
128 int locale_default_message_id, | |
129 PrefSyncStatus sync_status) = 0; | |
130 virtual void RegisterLocalizedStringPref( | |
131 const char* path, | |
132 int locale_default_message_id, | |
133 PrefSyncStatus sync_status) = 0; | |
134 virtual void RegisterInt64Pref(const char* path, | |
135 int64 default_value, | |
136 PrefSyncStatus sync_status) = 0; | |
137 virtual void RegisterUint64Pref(const char* path, | |
138 uint64 default_value, | |
139 PrefSyncStatus sync_status) = 0; | |
140 // Unregisters a preference. | |
141 virtual void UnregisterPreference(const char* path) = 0; | |
142 | |
143 // If the path is valid and the value at the end of the path matches the type | |
144 // specified, it will return the specified value. Otherwise, the default | |
145 // value (set when the pref was registered) will be returned. | |
146 virtual bool GetBoolean(const char* path) const = 0; | |
147 virtual int GetInteger(const char* path) const = 0; | |
148 virtual double GetDouble(const char* path) const = 0; | |
149 virtual std::string GetString(const char* path) const = 0; | |
150 virtual FilePath GetFilePath(const char* path) const = 0; | |
151 | |
152 // Returns the branch if it exists, or the registered default value otherwise. | |
153 // Note that |path| must point to a registered preference. In that case, these | |
154 // functions will never return NULL. | |
155 virtual const base::DictionaryValue* GetDictionary( | |
156 const char* path) const = 0; | |
157 virtual const base::ListValue* GetList(const char* path) const = 0; | |
158 | |
159 // Returns the value of the given preference, from the user pref store. If | |
160 // the preference is not set in the user pref store, returns NULL. | |
161 virtual const base::Value* GetUserPrefValue(const char* path) const = 0; | |
162 | |
163 // Returns the default value of the given preference. |path| must point to a | |
164 // registered preference. In that case, will never return NULL. | |
165 virtual const base::Value* GetDefaultPrefValue( | |
166 const char* path) const = 0; | |
167 | |
168 // Removes a user pref and restores the pref to its default value. | |
169 virtual void ClearPref(const char* path) = 0; | |
170 | |
171 // If the path is valid (i.e., registered), update the pref value in the user | |
172 // prefs. | |
173 // To set the value of dictionary or list values in the pref tree use | |
174 // Set(), but to modify the value of a dictionary or list use either | |
175 // ListPrefUpdate or DictionaryPrefUpdate from scoped_user_pref_update.h. | |
176 virtual void Set(const char* path, const base::Value& value) = 0; | |
177 virtual void SetBoolean(const char* path, bool value) = 0; | |
178 virtual void SetInteger(const char* path, int value) = 0; | |
179 virtual void SetDouble(const char* path, double value) = 0; | |
180 virtual void SetString(const char* path, const std::string& value) = 0; | |
181 virtual void SetFilePath(const char* path, const FilePath& value) = 0; | |
182 | |
183 // Int64 helper methods that actually store the given value as a string. | |
184 // Note that if obtaining the named value via GetDictionary or GetList, the | |
185 // Value type will be TYPE_STRING. | |
186 virtual void SetInt64(const char* path, int64 value) = 0; | |
187 virtual int64 GetInt64(const char* path) const = 0; | |
188 | |
189 // As above, but for unsigned values. | |
190 virtual void SetUint64(const char* path, uint64 value) = 0; | |
191 virtual uint64 GetUint64(const char* path) const = 0; | |
192 | |
193 protected: | |
194 // Registration of pref change observers must be done using the | |
195 // PrefChangeRegistrar, which is declared as a friend here to grant it | |
196 // access to the otherwise protected members Add/RemovePrefObserver. | |
197 // PrefMember registers for preferences changes notification directly to | |
198 // avoid the storage overhead of the registrar, so its base class must be | |
199 // declared as a friend, too. | |
200 friend class PrefChangeRegistrar; | |
201 friend class subtle::PrefMemberBase; | |
202 | |
203 // These are protected so they can only be accessed by the friend | |
204 // classes listed above. | |
205 // | |
206 // If the pref at the given path changes, we call the observer's Observe | |
207 // method with PREF_CHANGED. Note that observers should not call these methods | |
208 // directly but rather use a PrefChangeRegistrar to make sure the observer | |
209 // gets cleaned up properly. | |
210 virtual void AddPrefObserver(const char* path, | |
211 content::NotificationObserver* obs) = 0; | |
212 virtual void RemovePrefObserver(const char* path, | |
213 content::NotificationObserver* obs) = 0; | |
214 }; | |
215 | |
216 #endif // CHROME_BROWSER_API_PREFS_PREF_SERVICE_BASE_H_ | |
OLD | NEW |