| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 // A helper class to store all the information associated with a preference. | 49 // A helper class to store all the information associated with a preference. |
| 50 class Preference { | 50 class Preference { |
| 51 public: | 51 public: |
| 52 | 52 |
| 53 // The type of the preference is determined by the type with which it is | 53 // The type of the preference is determined by the type with which it is |
| 54 // registered. This type needs to be a boolean, integer, double, string, | 54 // registered. This type needs to be a boolean, integer, double, string, |
| 55 // dictionary (a branch), or list. You shouldn't need to construct this on | 55 // dictionary (a branch), or list. You shouldn't need to construct this on |
| 56 // your own; use the PrefService::Register*Pref methods instead. | 56 // your own; use the PrefService::Register*Pref methods instead. |
| 57 Preference(const PrefService* service, | 57 Preference(const PrefService* service, |
| 58 const char* name, | 58 const char* name, |
| 59 base::Value::ValueType type); | 59 base::Value::Type type); |
| 60 ~Preference() {} | 60 ~Preference() {} |
| 61 | 61 |
| 62 // Returns the name of the Preference (i.e., the key, e.g., | 62 // Returns the name of the Preference (i.e., the key, e.g., |
| 63 // browser.window_placement). | 63 // browser.window_placement). |
| 64 const std::string name() const { return name_; } | 64 const std::string name() const { return name_; } |
| 65 | 65 |
| 66 // Returns the registered type of the preference. | 66 // Returns the registered type of the preference. |
| 67 base::Value::ValueType GetType() const; | 67 base::Value::Type GetType() const; |
| 68 | 68 |
| 69 // Returns the value of the Preference, falling back to the registered | 69 // Returns the value of the Preference, falling back to the registered |
| 70 // default value if no other has been set. | 70 // default value if no other has been set. |
| 71 const base::Value* GetValue() const; | 71 const base::Value* GetValue() const; |
| 72 | 72 |
| 73 // Returns true if the Preference is managed, i.e. set by an admin policy. | 73 // Returns true if the Preference is managed, i.e. set by an admin policy. |
| 74 // Since managed prefs have the highest priority, this also indicates | 74 // Since managed prefs have the highest priority, this also indicates |
| 75 // whether the pref is actually being controlled by the policy setting. | 75 // whether the pref is actually being controlled by the policy setting. |
| 76 bool IsManaged() const; | 76 bool IsManaged() const; |
| 77 | 77 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 108 | 108 |
| 109 private: | 109 private: |
| 110 friend class PrefService; | 110 friend class PrefService; |
| 111 | 111 |
| 112 PrefValueStore* pref_value_store() const { | 112 PrefValueStore* pref_value_store() const { |
| 113 return pref_service_->pref_value_store_.get(); | 113 return pref_service_->pref_value_store_.get(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 std::string name_; | 116 std::string name_; |
| 117 | 117 |
| 118 base::Value::ValueType type_; | 118 base::Value::Type type_; |
| 119 | 119 |
| 120 // Reference to the PrefService in which this pref was created. | 120 // Reference to the PrefService in which this pref was created. |
| 121 const PrefService* pref_service_; | 121 const PrefService* pref_service_; |
| 122 | 122 |
| 123 DISALLOW_COPY_AND_ASSIGN(Preference); | 123 DISALLOW_COPY_AND_ASSIGN(Preference); |
| 124 }; | 124 }; |
| 125 | 125 |
| 126 // Factory method that creates a new instance of a PrefService with the | 126 // Factory method that creates a new instance of a PrefService with the |
| 127 // applicable PrefStores. The |pref_filename| points to the user preference | 127 // applicable PrefStores. The |pref_filename| points to the user preference |
| 128 // file. This is the usual way to create a new PrefService. | 128 // file. This is the usual way to create a new PrefService. |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 void InitFromStorage(bool async); | 368 void InitFromStorage(bool async); |
| 369 | 369 |
| 370 // Used to set the value of dictionary or list values in the user pref store. | 370 // Used to set the value of dictionary or list values in the user pref store. |
| 371 // This will create a dictionary or list if one does not exist in the user | 371 // This will create a dictionary or list if one does not exist in the user |
| 372 // pref store. This method returns NULL only if you're requesting an | 372 // pref store. This method returns NULL only if you're requesting an |
| 373 // unregistered pref or a non-dict/non-list pref. | 373 // unregistered pref or a non-dict/non-list pref. |
| 374 // |type| may only be Values::TYPE_DICTIONARY or Values::TYPE_LIST and | 374 // |type| may only be Values::TYPE_DICTIONARY or Values::TYPE_LIST and |
| 375 // |path| must point to a registered preference of type |type|. | 375 // |path| must point to a registered preference of type |type|. |
| 376 // Ownership of the returned value remains at the user pref store. | 376 // Ownership of the returned value remains at the user pref store. |
| 377 base::Value* GetMutableUserPref(const char* path, | 377 base::Value* GetMutableUserPref(const char* path, |
| 378 base::Value::ValueType type); | 378 base::Value::Type type); |
| 379 | 379 |
| 380 // The PrefValueStore provides prioritized preference values. It is created | 380 // The PrefValueStore provides prioritized preference values. It is created |
| 381 // and owned by this PrefService. Subclasses may access it for unit testing. | 381 // and owned by this PrefService. Subclasses may access it for unit testing. |
| 382 scoped_ptr<PrefValueStore> pref_value_store_; | 382 scoped_ptr<PrefValueStore> pref_value_store_; |
| 383 | 383 |
| 384 // Pref Stores and profile that we passed to the PrefValueStore. | 384 // Pref Stores and profile that we passed to the PrefValueStore. |
| 385 scoped_refptr<PersistentPrefStore> user_pref_store_; | 385 scoped_refptr<PersistentPrefStore> user_pref_store_; |
| 386 scoped_refptr<DefaultPrefStore> default_store_; | 386 scoped_refptr<DefaultPrefStore> default_store_; |
| 387 | 387 |
| 388 // Local cache of registered Preference objects. The default_store_ | 388 // Local cache of registered Preference objects. The default_store_ |
| 389 // is authoritative with respect to what the types and default values | 389 // is authoritative with respect to what the types and default values |
| 390 // of registered preferences are. | 390 // of registered preferences are. |
| 391 mutable PreferenceSet prefs_; | 391 mutable PreferenceSet prefs_; |
| 392 | 392 |
| 393 // The model associator that maintains the links with the sync db. | 393 // The model associator that maintains the links with the sync db. |
| 394 scoped_ptr<PrefModelAssociator> pref_sync_associator_; | 394 scoped_ptr<PrefModelAssociator> pref_sync_associator_; |
| 395 | 395 |
| 396 DISALLOW_COPY_AND_ASSIGN(PrefService); | 396 DISALLOW_COPY_AND_ASSIGN(PrefService); |
| 397 }; | 397 }; |
| 398 | 398 |
| 399 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ | 399 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ |
| OLD | NEW |