| 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 #ifndef BASE_PREFS_PREF_REGISTRY_H_ | 5 #ifndef BASE_PREFS_PREF_REGISTRY_H_ |
| 6 #define BASE_PREFS_PREF_REGISTRY_H_ | 6 #define BASE_PREFS_PREF_REGISTRY_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | |
| 9 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 10 #include "base/prefs/base_prefs_export.h" | 9 #include "base/prefs/base_prefs_export.h" |
| 11 #include "base/prefs/pref_value_map.h" | 10 #include "base/prefs/pref_value_map.h" |
| 12 | 11 |
| 13 namespace base { | 12 namespace base { |
| 14 class Value; | 13 class Value; |
| 15 } | 14 } |
| 16 | 15 |
| 17 class DefaultPrefStore; | 16 class DefaultPrefStore; |
| 18 class PrefStore; | 17 class PrefStore; |
| 19 | 18 |
| 20 // Preferences need to be registered with a type and default value | 19 // Preferences need to be registered with a type and default value |
| 21 // before they are used. | 20 // before they are used. |
| 22 // | 21 // |
| 23 // The way you use a PrefRegistry is that you register all required | 22 // The way you use a PrefRegistry is that you register all required |
| 24 // preferences on it (via one of its subclasses), then pass it as a | 23 // preferences on it (via one of its subclasses), then pass it as a |
| 25 // construction parameter to PrefService. | 24 // construction parameter to PrefService. |
| 26 // | 25 // |
| 27 // Currently, registrations after constructing the PrefService will | 26 // Currently, registrations after constructing the PrefService will |
| 28 // also work, but this is being deprecated. | 27 // also work, but this is being deprecated. |
| 29 class BASE_PREFS_EXPORT PrefRegistry : public base::RefCounted<PrefRegistry> { | 28 class BASE_PREFS_EXPORT PrefRegistry : public base::RefCounted<PrefRegistry> { |
| 30 public: | 29 public: |
| 31 typedef PrefValueMap::const_iterator const_iterator; | 30 typedef PrefValueMap::const_iterator const_iterator; |
| 32 typedef base::Callback<void(const char*, base::Value*)> RegistrationCallback; | |
| 33 | 31 |
| 34 PrefRegistry(); | 32 PrefRegistry(); |
| 35 | 33 |
| 36 // Gets the registered defaults. | 34 // Gets the registered defaults. |
| 37 scoped_refptr<PrefStore> defaults(); | 35 scoped_refptr<PrefStore> defaults(); |
| 38 | 36 |
| 39 // Allows iteration over defaults. | 37 // Allows iteration over defaults. |
| 40 const_iterator begin() const; | 38 const_iterator begin() const; |
| 41 const_iterator end() const; | 39 const_iterator end() const; |
| 42 | 40 |
| 43 // Changes the default value for a preference. Takes ownership of |value|. | 41 // Changes the default value for a preference. Takes ownership of |value|. |
| 44 // | 42 // |
| 45 // |pref_name| must be a previously registered preference. | 43 // |pref_name| must be a previously registered preference. |
| 46 void SetDefaultPrefValue(const char* pref_name, base::Value* value); | 44 void SetDefaultPrefValue(const char* pref_name, base::Value* value); |
| 47 | 45 |
| 48 // Exactly one callback can be set for registration. The callback | |
| 49 // will be invoked each time registration has been performed on this | |
| 50 // object. | |
| 51 // | |
| 52 // Calling this method after a callback has already been set will | |
| 53 // make the object forget the previous callback and use the new one | |
| 54 // instead. | |
| 55 void SetRegistrationCallback(const RegistrationCallback& callback); | |
| 56 | |
| 57 protected: | 46 protected: |
| 58 friend class base::RefCounted<PrefRegistry>; | 47 friend class base::RefCounted<PrefRegistry>; |
| 59 virtual ~PrefRegistry(); | 48 virtual ~PrefRegistry(); |
| 60 | 49 |
| 61 // Used by subclasses to register a default value for a preference. | 50 // Used by subclasses to register a default value for a preference. |
| 62 void RegisterPreference(const char* path, base::Value* default_value); | 51 void RegisterPreference(const char* path, base::Value* default_value); |
| 63 | 52 |
| 64 scoped_refptr<DefaultPrefStore> defaults_; | 53 scoped_refptr<DefaultPrefStore> defaults_; |
| 65 | 54 |
| 66 private: | 55 private: |
| 67 RegistrationCallback registration_callback_; | |
| 68 | |
| 69 DISALLOW_COPY_AND_ASSIGN(PrefRegistry); | 56 DISALLOW_COPY_AND_ASSIGN(PrefRegistry); |
| 70 }; | 57 }; |
| 71 | 58 |
| 72 #endif // BASE_PREFS_PREF_REGISTRY_H_ | 59 #endif // BASE_PREFS_PREF_REGISTRY_H_ |
| OLD | NEW |