| 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" | 8 #include "base/callback.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/prefs/base_prefs_export.h" | 10 #include "base/prefs/base_prefs_export.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 // The way you use a PrefRegistry is that you register all required | 23 // 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 | 24 // preferences on it (via one of its subclasses), then pass it as a |
| 25 // construction parameter to PrefService. | 25 // construction parameter to PrefService. |
| 26 // | 26 // |
| 27 // Currently, registrations after constructing the PrefService will | 27 // Currently, registrations after constructing the PrefService will |
| 28 // also work, but this is being deprecated. | 28 // also work, but this is being deprecated. |
| 29 class BASE_PREFS_EXPORT PrefRegistry : public base::RefCounted<PrefRegistry> { | 29 class BASE_PREFS_EXPORT PrefRegistry : public base::RefCounted<PrefRegistry> { |
| 30 public: | 30 public: |
| 31 typedef PrefValueMap::const_iterator const_iterator; | 31 typedef PrefValueMap::const_iterator const_iterator; |
| 32 typedef base::Callback<void(const char*, base::Value*)> RegistrationCallback; | 32 typedef base::Callback<void(const char*, base::Value*)> RegistrationCallback; |
| 33 typedef base::Callback<void(const char*)> UnregistrationCallback; | |
| 34 | 33 |
| 35 PrefRegistry(); | 34 PrefRegistry(); |
| 36 | 35 |
| 37 // Gets the registered defaults. | 36 // Gets the registered defaults. |
| 38 scoped_refptr<PrefStore> defaults(); | 37 scoped_refptr<PrefStore> defaults(); |
| 39 | 38 |
| 40 // Allows iteration over defaults. | 39 // Allows iteration over defaults. |
| 41 const_iterator begin() const; | 40 const_iterator begin() const; |
| 42 const_iterator end() const; | 41 const_iterator end() const; |
| 43 | 42 |
| 44 // Exactly one callback can be set for each of two events: | 43 // Exactly one callback can be set for registration. The callback |
| 45 // Registration and unregistration. If either is set, the callback | 44 // will be invoked each time registration has been performed on this |
| 46 // will be invoked each time registration and/or unregistration has | 45 // object. |
| 47 // been performed on this object. | |
| 48 // | 46 // |
| 49 // Calling either of these methods after a callback has already been | 47 // Calling this method after a callback has already been set will |
| 50 // set will make the object forget the previous callback and use the | 48 // make the object forget the previous callback and use the new one |
| 51 // new one instead. | 49 // instead. |
| 52 void SetRegistrationCallback(const RegistrationCallback& callback); | 50 void SetRegistrationCallback(const RegistrationCallback& callback); |
| 53 void SetUnregistrationCallback(const UnregistrationCallback& callback); | |
| 54 | |
| 55 // Unregisters a preference. This is going away soon. | |
| 56 void DeprecatedUnregisterPreference(const char* path); | |
| 57 | 51 |
| 58 protected: | 52 protected: |
| 59 friend class base::RefCounted<PrefRegistry>; | 53 friend class base::RefCounted<PrefRegistry>; |
| 60 virtual ~PrefRegistry(); | 54 virtual ~PrefRegistry(); |
| 61 | 55 |
| 62 // Used by subclasses to register a default value for a preference. | 56 // Used by subclasses to register a default value for a preference. |
| 63 void RegisterPreference(const char* path, base::Value* default_value); | 57 void RegisterPreference(const char* path, base::Value* default_value); |
| 64 | 58 |
| 65 scoped_refptr<DefaultPrefStore> defaults_; | 59 scoped_refptr<DefaultPrefStore> defaults_; |
| 66 | 60 |
| 67 private: | 61 private: |
| 68 RegistrationCallback registration_callback_; | 62 RegistrationCallback registration_callback_; |
| 69 UnregistrationCallback unregistration_callback_; | |
| 70 | 63 |
| 71 DISALLOW_COPY_AND_ASSIGN(PrefRegistry); | 64 DISALLOW_COPY_AND_ASSIGN(PrefRegistry); |
| 72 }; | 65 }; |
| 73 | 66 |
| 74 #endif // BASE_PREFS_PREF_REGISTRY_H_ | 67 #endif // BASE_PREFS_PREF_REGISTRY_H_ |
| OLD | NEW |