OLD | NEW |
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 // 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 #ifndef CHROME_BROWSER_PREFS_PREF_SERVICE_H_ | 7 #ifndef CHROME_BROWSER_PREFS_PREF_SERVICE_H_ |
8 #define CHROME_BROWSER_PREFS_PREF_SERVICE_H_ | 8 #define CHROME_BROWSER_PREFS_PREF_SERVICE_H_ |
9 #pragma once | 9 #pragma once |
10 | 10 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 | 160 |
161 // If the path is valid and the value at the end of the path matches the type | 161 // If the path is valid and the value at the end of the path matches the type |
162 // specified, it will return the specified value. Otherwise, the default | 162 // specified, it will return the specified value. Otherwise, the default |
163 // value (set when the pref was registered) will be returned. | 163 // value (set when the pref was registered) will be returned. |
164 bool GetBoolean(const char* path) const; | 164 bool GetBoolean(const char* path) const; |
165 int GetInteger(const char* path) const; | 165 int GetInteger(const char* path) const; |
166 double GetReal(const char* path) const; | 166 double GetReal(const char* path) const; |
167 std::string GetString(const char* path) const; | 167 std::string GetString(const char* path) const; |
168 FilePath GetFilePath(const char* path) const; | 168 FilePath GetFilePath(const char* path) const; |
169 | 169 |
170 // Returns the branch if it exists. If it's not a branch or the branch does | 170 // Returns the branch if it exists, or the registered default value otherwise. |
171 // not exist, returns NULL. | 171 // Note that |path| must point to a registered preference. In that case, these |
| 172 // functions will never return NULL. |
172 const DictionaryValue* GetDictionary(const char* path) const; | 173 const DictionaryValue* GetDictionary(const char* path) const; |
173 const ListValue* GetList(const char* path) const; | 174 const ListValue* GetList(const char* path) const; |
174 | 175 |
175 // Removes a user pref and restores the pref to its default value. | 176 // Removes a user pref and restores the pref to its default value. |
176 void ClearPref(const char* path); | 177 void ClearPref(const char* path); |
177 | 178 |
178 // If the path is valid (i.e., registered), update the pref value in the user | 179 // If the path is valid (i.e., registered), update the pref value in the user |
179 // prefs. Seting a null value on a preference of List or Dictionary type is | 180 // prefs. Seting a null value on a preference of List or Dictionary type is |
180 // equivalent to removing the user value for that preference, allowing the | 181 // equivalent to removing the user value for that preference, allowing the |
181 // default value to take effect unless another value takes precedence. | 182 // default value to take effect unless another value takes precedence. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 PrefService(const PrefService& original, | 268 PrefService(const PrefService& original, |
268 PrefStore* incognito_extension_prefs); | 269 PrefStore* incognito_extension_prefs); |
269 | 270 |
270 // If the pref at the given path changes, we call the observer's Observe | 271 // If the pref at the given path changes, we call the observer's Observe |
271 // method with PREF_CHANGED. Note that observers should not call these methods | 272 // method with PREF_CHANGED. Note that observers should not call these methods |
272 // directly but rather use a PrefChangeRegistrar to make sure the observer | 273 // directly but rather use a PrefChangeRegistrar to make sure the observer |
273 // gets cleaned up properly. | 274 // gets cleaned up properly. |
274 virtual void AddPrefObserver(const char* path, NotificationObserver* obs); | 275 virtual void AddPrefObserver(const char* path, NotificationObserver* obs); |
275 virtual void RemovePrefObserver(const char* path, NotificationObserver* obs); | 276 virtual void RemovePrefObserver(const char* path, NotificationObserver* obs); |
276 | 277 |
277 // Add a preference to the PreferenceMap. If the pref already exists, return | 278 // Registers a new preference at |path|. The |default_value| must not be |
278 // false. This method takes ownership of |default_value|. | 279 // NULL as it determines the preference value's type. |
| 280 // RegisterPreference must not be called twice for the same path. |
| 281 // This method takes ownership of |default_value|. |
279 void RegisterPreference(const char* path, Value* default_value); | 282 void RegisterPreference(const char* path, Value* default_value); |
280 | 283 |
281 // Sets the value for this pref path in the user pref store and informs the | 284 // Sets the value for this pref path in the user pref store and informs the |
282 // PrefNotifier of the change. | 285 // PrefNotifier of the change. |
283 void SetUserPrefValue(const char* path, Value* new_value); | 286 void SetUserPrefValue(const char* path, Value* new_value); |
284 | 287 |
285 // Load preferences from storage, attempting to diagnose and handle errors. | 288 // Load preferences from storage, attempting to diagnose and handle errors. |
286 // This should only be called from the constructor. | 289 // This should only be called from the constructor. |
287 void InitFromStorage(); | 290 void InitFromStorage(); |
288 | 291 |
289 // The PrefValueStore provides prioritized preference values. It is created | 292 // The PrefValueStore provides prioritized preference values. It is created |
290 // and owned by this PrefService. Subclasses may access it for unit testing. | 293 // and owned by this PrefService. Subclasses may access it for unit testing. |
291 scoped_ptr<PrefValueStore> pref_value_store_; | 294 scoped_ptr<PrefValueStore> pref_value_store_; |
292 | 295 |
293 // Pref Stores and profile that we passed to the PrefValueStore. | 296 // Pref Stores and profile that we passed to the PrefValueStore. |
294 scoped_refptr<PersistentPrefStore> user_pref_store_; | 297 scoped_refptr<PersistentPrefStore> user_pref_store_; |
295 scoped_refptr<DefaultPrefStore> default_store_; | 298 scoped_refptr<DefaultPrefStore> default_store_; |
296 | 299 |
297 // Local cache of registered Preference objects. The default_store_ | 300 // Local cache of registered Preference objects. The default_store_ |
298 // is authoritative with respect to what the types and default values | 301 // is authoritative with respect to what the types and default values |
299 // of registered preferences are. | 302 // of registered preferences are. |
300 mutable PreferenceSet prefs_; | 303 mutable PreferenceSet prefs_; |
301 | 304 |
302 DISALLOW_COPY_AND_ASSIGN(PrefService); | 305 DISALLOW_COPY_AND_ASSIGN(PrefService); |
303 }; | 306 }; |
304 | 307 |
305 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ | 308 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ |
OLD | NEW |