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 // This provides a way to access the application's current preferences. | 5 // This provides a way to access the application's current preferences. |
6 | 6 |
7 // Chromium settings and storage represent user-selected preferences and | 7 // Chromium settings and storage represent user-selected preferences and |
8 // information and MUST not be extracted, overwritten or modified except | 8 // information and MUST not be extracted, overwritten or modified except |
9 // through Chromium defined APIs. | 9 // through Chromium defined APIs. |
10 | 10 |
11 #ifndef CHROME_BROWSER_PREFS_PREF_SERVICE_H_ | 11 #ifndef CHROME_BROWSER_PREFS_PREF_SERVICE_H_ |
12 #define CHROME_BROWSER_PREFS_PREF_SERVICE_H_ | 12 #define CHROME_BROWSER_PREFS_PREF_SERVICE_H_ |
13 | 13 |
14 #include <set> | 14 #include <set> |
15 #include <string> | 15 #include <string> |
16 | 16 |
17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
19 #include "base/threading/non_thread_safe.h" | 19 #include "base/threading/non_thread_safe.h" |
20 #include "base/values.h" | 20 #include "chrome/browser/api/prefs/pref_service_base.h" |
21 | 21 |
22 class CommandLine; | 22 class CommandLine; |
23 class DefaultPrefStore; | 23 class DefaultPrefStore; |
24 class FilePath; | |
25 class PersistentPrefStore; | 24 class PersistentPrefStore; |
26 class PrefModelAssociator; | 25 class PrefModelAssociator; |
27 class PrefNotifier; | 26 class PrefNotifier; |
28 class PrefNotifierImpl; | 27 class PrefNotifierImpl; |
29 class PrefStore; | 28 class PrefStore; |
30 class PrefValueStore; | 29 class PrefValueStore; |
31 | 30 |
32 namespace content { | |
33 class NotificationObserver; | |
34 } | |
35 | |
36 namespace syncer { | 31 namespace syncer { |
37 class SyncableService; | 32 class SyncableService; |
38 } | 33 } |
39 | 34 |
40 namespace policy { | 35 namespace policy { |
41 class PolicyService; | 36 class PolicyService; |
42 } | 37 } |
43 | 38 |
44 namespace subtle { | 39 namespace subtle { |
45 class PrefMemberBase; | |
46 class ScopedUserPrefUpdateBase; | 40 class ScopedUserPrefUpdateBase; |
47 }; | 41 }; |
48 | 42 |
49 class PrefService : public base::NonThreadSafe { | 43 class PrefService : public PrefServiceBase, public base::NonThreadSafe { |
50 public: | 44 public: |
51 // Enum used when registering preferences to determine if it should be synced | |
52 // or not. This is only used for profile prefs, not local state prefs. | |
53 // See the Register*Pref methods for profile prefs below. | |
54 enum PrefSyncStatus { | |
55 UNSYNCABLE_PREF, | |
56 SYNCABLE_PREF | |
57 }; | |
58 | |
59 enum PrefInitializationStatus { | 45 enum PrefInitializationStatus { |
60 INITIALIZATION_STATUS_WAITING, | 46 INITIALIZATION_STATUS_WAITING, |
61 INITIALIZATION_STATUS_SUCCESS, | 47 INITIALIZATION_STATUS_SUCCESS, |
62 INITIALIZATION_STATUS_CREATED_NEW_PROFILE, | 48 INITIALIZATION_STATUS_CREATED_NEW_PROFILE, |
63 INITIALIZATION_STATUS_ERROR | 49 INITIALIZATION_STATUS_ERROR |
64 }; | 50 }; |
65 | 51 |
66 // A helper class to store all the information associated with a preference. | 52 // A helper class to store all the information associated with a preference. |
67 class Preference { | 53 class Preference : public PrefServiceBase::Preference { |
68 public: | 54 public: |
69 // The type of the preference is determined by the type with which it is | 55 // The type of the preference is determined by the type with which it is |
70 // registered. This type needs to be a boolean, integer, double, string, | 56 // registered. This type needs to be a boolean, integer, double, string, |
71 // dictionary (a branch), or list. You shouldn't need to construct this on | 57 // dictionary (a branch), or list. You shouldn't need to construct this on |
72 // your own; use the PrefService::Register*Pref methods instead. | 58 // your own; use the PrefService::Register*Pref methods instead. |
73 Preference(const PrefService* service, | 59 Preference(const PrefService* service, |
74 const char* name, | 60 const char* name, |
75 base::Value::Type type); | 61 base::Value::Type type); |
76 ~Preference() {} | 62 virtual ~Preference() {} |
77 | 63 |
78 // Returns the name of the Preference (i.e., the key, e.g., | 64 // PrefServiceBase::Preference implementation. |
79 // browser.window_placement). | 65 virtual const std::string name() const OVERRIDE; |
80 const std::string name() const { return name_; } | 66 virtual base::Value::Type GetType() const OVERRIDE; |
81 | 67 virtual const base::Value* GetValue() const OVERRIDE; |
82 // Returns the registered type of the preference. | 68 virtual const base::Value* GetRecommendedValue() const OVERRIDE; |
83 base::Value::Type GetType() const; | 69 virtual bool IsManaged() const OVERRIDE; |
84 | 70 virtual bool IsRecommended() const OVERRIDE; |
85 // Returns the value of the Preference, falling back to the registered | 71 virtual bool HasExtensionSetting() const OVERRIDE; |
86 // default value if no other has been set. | 72 virtual bool HasUserSetting() const OVERRIDE; |
87 const base::Value* GetValue() const; | 73 virtual bool IsExtensionControlled() const OVERRIDE; |
88 | 74 virtual bool IsUserControlled() const OVERRIDE; |
89 // Returns the value recommended by the admin, if any. | 75 virtual bool IsDefaultValue() const OVERRIDE; |
90 const base::Value* GetRecommendedValue() const; | 76 virtual bool IsUserModifiable() const OVERRIDE; |
91 | 77 virtual bool IsExtensionModifiable() const OVERRIDE; |
92 // Returns true if the Preference is managed, i.e. set by an admin policy. | |
93 // Since managed prefs have the highest priority, this also indicates | |
94 // whether the pref is actually being controlled by the policy setting. | |
95 bool IsManaged() const; | |
96 | |
97 // Returns true if the Preference is recommended, i.e. set by an admin | |
98 // policy but the user is allowed to change it. | |
99 bool IsRecommended() const; | |
100 | |
101 // Returns true if the Preference has a value set by an extension, even if | |
102 // that value is being overridden by a higher-priority source. | |
103 bool HasExtensionSetting() const; | |
104 | |
105 // Returns true if the Preference has a user setting, even if that value is | |
106 // being overridden by a higher-priority source. | |
107 bool HasUserSetting() const; | |
108 | |
109 // Returns true if the Preference value is currently being controlled by an | |
110 // extension, and not by any higher-priority source. | |
111 bool IsExtensionControlled() const; | |
112 | |
113 // Returns true if the Preference value is currently being controlled by a | |
114 // user setting, and not by any higher-priority source. | |
115 bool IsUserControlled() const; | |
116 | |
117 // Returns true if the Preference is currently using its default value, | |
118 // and has not been set by any higher-priority source (even with the same | |
119 // value). | |
120 bool IsDefaultValue() const; | |
121 | |
122 // Returns true if the user can change the Preference value, which is the | |
123 // case if no higher-priority source than the user store controls the | |
124 // Preference. | |
125 bool IsUserModifiable() const; | |
126 | |
127 // Returns true if an extension can change the Preference value, which is | |
128 // the case if no higher-priority source than the extension store controls | |
129 // the Preference. | |
130 bool IsExtensionModifiable() const; | |
131 | 78 |
132 private: | 79 private: |
133 friend class PrefService; | 80 friend class PrefService; |
134 | 81 |
135 PrefValueStore* pref_value_store() const { | 82 PrefValueStore* pref_value_store() const { |
136 return pref_service_->pref_value_store_.get(); | 83 return pref_service_->pref_value_store_.get(); |
137 } | 84 } |
138 | 85 |
139 std::string name_; | 86 std::string name_; |
140 | 87 |
(...skipping 29 matching lines...) Expand all Loading... |
170 // incognito windows). | 117 // incognito windows). |
171 PrefService* CreateIncognitoPrefService(PrefStore* incognito_extension_prefs); | 118 PrefService* CreateIncognitoPrefService(PrefStore* incognito_extension_prefs); |
172 | 119 |
173 virtual ~PrefService(); | 120 virtual ~PrefService(); |
174 | 121 |
175 // Reloads the data from file. This should only be called when the importer | 122 // Reloads the data from file. This should only be called when the importer |
176 // is running during first run, and the main process may not change pref | 123 // is running during first run, and the main process may not change pref |
177 // values while the importer process is running. Returns true on success. | 124 // values while the importer process is running. Returns true on success. |
178 bool ReloadPersistentPrefs(); | 125 bool ReloadPersistentPrefs(); |
179 | 126 |
180 // Returns true if the preference for the given preference name is available | |
181 // and is managed. | |
182 bool IsManagedPreference(const char* pref_name) const; | |
183 | |
184 // Returns |true| if a preference with the given name is available and its | |
185 // value can be changed by the user. | |
186 bool IsUserModifiablePreference(const char* pref_name) const; | |
187 | |
188 // Lands pending writes to disk. This should only be used if we need to save | 127 // Lands pending writes to disk. This should only be used if we need to save |
189 // immediately (basically, during shutdown). | 128 // immediately (basically, during shutdown). |
190 void CommitPendingWrite(); | 129 void CommitPendingWrite(); |
191 | 130 |
192 // Make the PrefService aware of a pref. | 131 // PrefServiceBase implementation. |
193 // TODO(zea): split local state and profile prefs into their own subclasses. | 132 virtual bool IsManagedPreference(const char* pref_name) const OVERRIDE; |
194 // ---------- Local state prefs ---------- | 133 virtual bool IsUserModifiablePreference(const char* pref_name) const OVERRIDE; |
195 void RegisterBooleanPref(const char* path, bool default_value); | 134 virtual void RegisterBooleanPref(const char* path, |
196 void RegisterIntegerPref(const char* path, int default_value); | 135 bool default_value) OVERRIDE; |
197 void RegisterDoublePref(const char* path, double default_value); | 136 virtual void RegisterIntegerPref(const char* path, |
198 void RegisterStringPref(const char* path, const std::string& default_value); | 137 int default_value) OVERRIDE; |
199 void RegisterFilePathPref(const char* path, const FilePath& default_value); | 138 virtual void RegisterDoublePref(const char* path, |
200 void RegisterListPref(const char* path); | 139 double default_value) OVERRIDE; |
201 void RegisterDictionaryPref(const char* path); | 140 virtual void RegisterStringPref(const char* path, |
202 // These take ownership of the default_value: | 141 const std::string& default_value) OVERRIDE; |
203 void RegisterListPref(const char* path, | 142 virtual void RegisterFilePathPref(const char* path, |
204 base::ListValue* default_value); | 143 const FilePath& default_value) OVERRIDE; |
205 void RegisterDictionaryPref(const char* path, | 144 virtual void RegisterListPref(const char* path) OVERRIDE; |
206 base::DictionaryValue* default_value); | 145 virtual void RegisterDictionaryPref(const char* path) OVERRIDE; |
207 // These variants use a default value from the locale dll instead. | 146 virtual void RegisterListPref(const char* path, |
208 void RegisterLocalizedBooleanPref(const char* path, | 147 base::ListValue* default_value) OVERRIDE; |
209 int locale_default_message_id); | 148 virtual void RegisterDictionaryPref( |
210 void RegisterLocalizedIntegerPref(const char* path, | 149 const char* path, base::DictionaryValue* default_value) OVERRIDE; |
211 int locale_default_message_id); | 150 virtual void RegisterLocalizedBooleanPref( |
212 void RegisterLocalizedDoublePref(const char* path, | 151 const char* path, int locale_default_message_id) OVERRIDE; |
213 int locale_default_message_id); | 152 virtual void RegisterLocalizedIntegerPref( |
214 void RegisterLocalizedStringPref(const char* path, | 153 const char* path, int locale_default_message_id) OVERRIDE; |
215 int locale_default_message_id); | 154 virtual void RegisterLocalizedDoublePref( |
216 void RegisterInt64Pref(const char* path, int64 default_value); | 155 const char* path, int locale_default_message_id) OVERRIDE; |
217 | 156 virtual void RegisterLocalizedStringPref( |
218 // ---------- Profile prefs ---------- | 157 const char* path, int locale_default_message_id) OVERRIDE; |
219 // Profile prefs must specify whether the pref should be synchronized across | 158 virtual void RegisterInt64Pref(const char* path, |
220 // machines or not (see PrefSyncStatus enum above). | 159 int64 default_value) OVERRIDE; |
221 void RegisterBooleanPref(const char* path, | 160 virtual void RegisterBooleanPref(const char* path, |
222 bool default_value, | 161 bool default_value, |
223 PrefSyncStatus sync_status); | 162 PrefSyncStatus sync_status) OVERRIDE; |
224 void RegisterIntegerPref(const char* path, | 163 virtual void RegisterIntegerPref(const char* path, |
225 int default_value, | 164 int default_value, |
226 PrefSyncStatus sync_status); | 165 PrefSyncStatus sync_status) OVERRIDE; |
227 void RegisterDoublePref(const char* path, | 166 virtual void RegisterDoublePref(const char* path, |
228 double default_value, | 167 double default_value, |
229 PrefSyncStatus sync_status); | 168 PrefSyncStatus sync_status) OVERRIDE; |
230 void RegisterStringPref(const char* path, | 169 virtual void RegisterStringPref(const char* path, |
231 const std::string& default_value, | 170 const std::string& default_value, |
232 PrefSyncStatus sync_status); | 171 PrefSyncStatus sync_status) OVERRIDE; |
233 void RegisterFilePathPref(const char* path, | 172 virtual void RegisterFilePathPref(const char* path, |
234 const FilePath& default_value, | 173 const FilePath& default_value, |
235 PrefSyncStatus sync_status); | 174 PrefSyncStatus sync_status) OVERRIDE; |
236 void RegisterListPref(const char* path, PrefSyncStatus sync_status); | 175 virtual void RegisterListPref(const char* path, |
237 void RegisterDictionaryPref(const char* path, PrefSyncStatus sync_status); | 176 PrefSyncStatus sync_status) OVERRIDE; |
238 // These take ownership of the default_value: | 177 virtual void RegisterDictionaryPref(const char* path, |
239 void RegisterListPref(const char* path, | 178 PrefSyncStatus sync_status) OVERRIDE; |
240 base::ListValue* default_value, | 179 virtual void RegisterListPref(const char* path, |
241 PrefSyncStatus sync_status); | 180 base::ListValue* default_value, |
242 void RegisterDictionaryPref(const char* path, | 181 PrefSyncStatus sync_status) OVERRIDE; |
243 base::DictionaryValue* default_value, | 182 virtual void RegisterDictionaryPref(const char* path, |
244 PrefSyncStatus sync_status); | 183 base::DictionaryValue* default_value, |
245 // These variants use a default value from the locale dll instead. | 184 PrefSyncStatus sync_status) OVERRIDE; |
246 void RegisterLocalizedBooleanPref(const char* path, | 185 virtual void RegisterLocalizedBooleanPref( |
247 int locale_default_message_id, | 186 const char* path, |
248 PrefSyncStatus sync_status); | 187 int locale_default_message_id, |
249 void RegisterLocalizedIntegerPref(const char* path, | 188 PrefSyncStatus sync_status) OVERRIDE; |
250 int locale_default_message_id, | 189 virtual void RegisterLocalizedIntegerPref( |
251 PrefSyncStatus sync_status); | 190 const char* path, |
252 void RegisterLocalizedDoublePref(const char* path, | 191 int locale_default_message_id, |
253 int locale_default_message_id, | 192 PrefSyncStatus sync_status) OVERRIDE; |
254 PrefSyncStatus sync_status); | 193 virtual void RegisterLocalizedDoublePref( |
255 void RegisterLocalizedStringPref(const char* path, | 194 const char* path, |
256 int locale_default_message_id, | 195 int locale_default_message_id, |
257 PrefSyncStatus sync_status); | 196 PrefSyncStatus sync_status) OVERRIDE; |
258 void RegisterInt64Pref(const char* path, | 197 virtual void RegisterLocalizedStringPref( |
259 int64 default_value, | 198 const char* path, |
260 PrefSyncStatus sync_status); | 199 int locale_default_message_id, |
261 void RegisterUint64Pref(const char* path, | 200 PrefSyncStatus sync_status) OVERRIDE; |
262 uint64 default_value, | 201 virtual void RegisterInt64Pref(const char* path, |
263 PrefSyncStatus sync_status); | 202 int64 default_value, |
264 // Unregisters a preference. | 203 PrefSyncStatus sync_status) OVERRIDE; |
265 void UnregisterPreference(const char* path); | 204 virtual void RegisterUint64Pref(const char* path, |
266 | 205 uint64 default_value, |
267 // If the path is valid and the value at the end of the path matches the type | 206 PrefSyncStatus sync_status) OVERRIDE; |
268 // specified, it will return the specified value. Otherwise, the default | 207 virtual void UnregisterPreference(const char* path) OVERRIDE; |
269 // value (set when the pref was registered) will be returned. | 208 virtual const PrefService::Preference* FindPreference( |
270 bool GetBoolean(const char* path) const; | 209 const char* path) const OVERRIDE; |
271 int GetInteger(const char* path) const; | 210 virtual bool GetBoolean(const char* path) const OVERRIDE; |
272 double GetDouble(const char* path) const; | 211 virtual int GetInteger(const char* path) const OVERRIDE; |
273 std::string GetString(const char* path) const; | 212 virtual double GetDouble(const char* path) const OVERRIDE; |
274 FilePath GetFilePath(const char* path) const; | 213 virtual std::string GetString(const char* path) const OVERRIDE; |
275 | 214 virtual FilePath GetFilePath(const char* path) const OVERRIDE; |
276 // Returns the branch if it exists, or the registered default value otherwise. | 215 virtual const base::DictionaryValue* GetDictionary( |
277 // Note that |path| must point to a registered preference. In that case, these | 216 const char* path) const OVERRIDE; |
278 // functions will never return NULL. | 217 virtual const base::ListValue* GetList(const char* path) const OVERRIDE; |
279 const base::DictionaryValue* GetDictionary(const char* path) const; | 218 virtual void ClearPref(const char* path) OVERRIDE; |
280 const base::ListValue* GetList(const char* path) const; | 219 virtual void Set(const char* path, const base::Value& value) OVERRIDE; |
| 220 virtual void SetBoolean(const char* path, bool value) OVERRIDE; |
| 221 virtual void SetInteger(const char* path, int value) OVERRIDE; |
| 222 virtual void SetDouble(const char* path, double value) OVERRIDE; |
| 223 virtual void SetString(const char* path, const std::string& value) OVERRIDE; |
| 224 virtual void SetFilePath(const char* path, const FilePath& value) OVERRIDE; |
| 225 virtual void SetInt64(const char* path, int64 value) OVERRIDE; |
| 226 virtual int64 GetInt64(const char* path) const OVERRIDE; |
| 227 virtual void SetUint64(const char* path, uint64 value) OVERRIDE; |
| 228 virtual uint64 GetUint64(const char* path) const OVERRIDE; |
281 | 229 |
282 // Returns the value of the given preference, from the user pref store. If | 230 // Returns the value of the given preference, from the user pref store. If |
283 // the preference is not set in the user pref store, returns NULL. | 231 // the preference is not set in the user pref store, returns NULL. |
284 const base::Value* GetUserPrefValue(const char* path) const; | 232 const base::Value* GetUserPrefValue(const char* path) const; |
285 | 233 |
286 // Returns the default value of the given preference. |path| must point to a | 234 // Returns the default value of the given preference. |path| must point to a |
287 // registered preference. In that case, will never return NULL. | 235 // registered preference. In that case, will never return NULL. |
288 const base::Value* GetDefaultPrefValue(const char* path) const; | 236 const base::Value* GetDefaultPrefValue(const char* path) const; |
289 | 237 |
290 // Removes a user pref and restores the pref to its default value. | |
291 void ClearPref(const char* path); | |
292 | |
293 // If the path is valid (i.e., registered), update the pref value in the user | |
294 // prefs. | |
295 // To set the value of dictionary or list values in the pref tree use | |
296 // Set(), but to modify the value of a dictionary or list use either | |
297 // ListPrefUpdate or DictionaryPrefUpdate from scoped_user_pref_update.h. | |
298 void Set(const char* path, const base::Value& value); | |
299 void SetBoolean(const char* path, bool value); | |
300 void SetInteger(const char* path, int value); | |
301 void SetDouble(const char* path, double value); | |
302 void SetString(const char* path, const std::string& value); | |
303 void SetFilePath(const char* path, const FilePath& value); | |
304 | |
305 // Int64 helper methods that actually store the given value as a string. | |
306 // Note that if obtaining the named value via GetDictionary or GetList, the | |
307 // Value type will be TYPE_STRING. | |
308 void SetInt64(const char* path, int64 value); | |
309 int64 GetInt64(const char* path) const; | |
310 | |
311 // As above, but for unsigned values. | |
312 void SetUint64(const char* path, uint64 value); | |
313 uint64 GetUint64(const char* path) const; | |
314 | |
315 // Returns true if a value has been set for the specified path. | 238 // Returns true if a value has been set for the specified path. |
316 // NOTE: this is NOT the same as FindPreference. In particular | 239 // NOTE: this is NOT the same as FindPreference. In particular |
317 // FindPreference returns whether RegisterXXX has been invoked, where as | 240 // FindPreference returns whether RegisterXXX has been invoked, where as |
318 // this checks if a value exists for the path. | 241 // this checks if a value exists for the path. |
319 bool HasPrefPath(const char* path) const; | 242 bool HasPrefPath(const char* path) const; |
320 | 243 |
321 // Returns a dictionary with effective preference values. The ownership | 244 // Returns a dictionary with effective preference values. The ownership |
322 // is passed to the caller. | 245 // is passed to the caller. |
323 base::DictionaryValue* GetPreferenceValues() const; | 246 base::DictionaryValue* GetPreferenceValues() const; |
324 | 247 |
325 // A helper method to quickly look up a preference. Returns NULL if the | |
326 // preference is not registered. | |
327 const Preference* FindPreference(const char* pref_name) const; | |
328 | |
329 bool ReadOnly() const; | 248 bool ReadOnly() const; |
330 | 249 |
331 PrefInitializationStatus GetInitializationStatus() const; | 250 PrefInitializationStatus GetInitializationStatus() const; |
332 | 251 |
333 // syncer::SyncableService getter. | 252 // syncer::SyncableService getter. |
334 // TODO(zea): Have PrefService implement syncer::SyncableService directly. | 253 // TODO(zea): Have PrefService implement syncer::SyncableService directly. |
335 syncer::SyncableService* GetSyncableService(); | 254 syncer::SyncableService* GetSyncableService(); |
336 | 255 |
337 // Tell our PrefValueStore to update itself using |command_line|. | 256 // Tell our PrefValueStore to update itself using |command_line|. |
338 // Do not call this after having derived an incognito or per tab pref service. | 257 // Do not call this after having derived an incognito or per tab pref service. |
(...skipping 18 matching lines...) Expand all Loading... |
357 class PreferencePathComparator { | 276 class PreferencePathComparator { |
358 public: | 277 public: |
359 bool operator() (Preference* lhs, Preference* rhs) const { | 278 bool operator() (Preference* lhs, Preference* rhs) const { |
360 return lhs->name() < rhs->name(); | 279 return lhs->name() < rhs->name(); |
361 } | 280 } |
362 }; | 281 }; |
363 typedef std::set<Preference*, PreferencePathComparator> PreferenceSet; | 282 typedef std::set<Preference*, PreferencePathComparator> PreferenceSet; |
364 | 283 |
365 friend class PrefServiceMockBuilder; | 284 friend class PrefServiceMockBuilder; |
366 | 285 |
367 // Registration of pref change observers must be done using the | |
368 // PrefChangeRegistrar, which is declared as a friend here to grant it | |
369 // access to the otherwise protected members Add/RemovePrefObserver. | |
370 // PrefMember registers for preferences changes notification directly to | |
371 // avoid the storage overhead of the registrar, so its base class must be | |
372 // declared as a friend, too. | |
373 friend class PrefChangeRegistrar; | |
374 friend class subtle::PrefMemberBase; | |
375 | |
376 // Give access to ReportUserPrefChanged() and GetMutableUserPref(). | 286 // Give access to ReportUserPrefChanged() and GetMutableUserPref(). |
377 friend class subtle::ScopedUserPrefUpdateBase; | 287 friend class subtle::ScopedUserPrefUpdateBase; |
378 | 288 |
| 289 // PrefServiceBase implementation (protected in base, private here). |
| 290 virtual void AddPrefObserver(const char* path, |
| 291 content::NotificationObserver* obs) OVERRIDE; |
| 292 virtual void RemovePrefObserver(const char* path, |
| 293 content::NotificationObserver* obs) OVERRIDE; |
| 294 |
379 // Sends notification of a changed preference. This needs to be called by | 295 // Sends notification of a changed preference. This needs to be called by |
380 // a ScopedUserPrefUpdate if a DictionaryValue or ListValue is changed. | 296 // a ScopedUserPrefUpdate if a DictionaryValue or ListValue is changed. |
381 void ReportUserPrefChanged(const std::string& key); | 297 void ReportUserPrefChanged(const std::string& key); |
382 | 298 |
383 // If the pref at the given path changes, we call the observer's Observe | |
384 // method with PREF_CHANGED. Note that observers should not call these methods | |
385 // directly but rather use a PrefChangeRegistrar to make sure the observer | |
386 // gets cleaned up properly. | |
387 virtual void AddPrefObserver(const char* path, | |
388 content::NotificationObserver* obs); | |
389 virtual void RemovePrefObserver(const char* path, | |
390 content::NotificationObserver* obs); | |
391 | |
392 // Registers a new preference at |path|. The |default_value| must not be | 299 // Registers a new preference at |path|. The |default_value| must not be |
393 // NULL as it determines the preference value's type. | 300 // NULL as it determines the preference value's type. |
394 // RegisterPreference must not be called twice for the same path. | 301 // RegisterPreference must not be called twice for the same path. |
395 // This method takes ownership of |default_value|. | 302 // This method takes ownership of |default_value|. |
396 void RegisterPreference(const char* path, | 303 void RegisterPreference(const char* path, |
397 base::Value* default_value, | 304 base::Value* default_value, |
398 PrefSyncStatus sync_status); | 305 PrefSyncStatus sync_status); |
399 | 306 |
400 // Sets the value for this pref path in the user pref store and informs the | 307 // Sets the value for this pref path in the user pref store and informs the |
401 // PrefNotifier of the change. | 308 // PrefNotifier of the change. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 | 340 |
434 // Whether CreateIncognitoPrefService() or | 341 // Whether CreateIncognitoPrefService() or |
435 // CreatePrefServiceWithPerTabPrefStore() have been called to create a | 342 // CreatePrefServiceWithPerTabPrefStore() have been called to create a |
436 // "forked" PrefService. | 343 // "forked" PrefService. |
437 bool pref_service_forked_; | 344 bool pref_service_forked_; |
438 | 345 |
439 DISALLOW_COPY_AND_ASSIGN(PrefService); | 346 DISALLOW_COPY_AND_ASSIGN(PrefService); |
440 }; | 347 }; |
441 | 348 |
442 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ | 349 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ |
OLD | NEW |