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