Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: base/prefs/pref_registry.h

Issue 1096833003: Convert PrefSyncStatus into PrefRegistrationFlags (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/prefs/base_prefs_export.h" 9 #include "base/prefs/base_prefs_export.h"
10 #include "base/prefs/pref_value_map.h" 10 #include "base/prefs/pref_value_map.h"
11 11
12 namespace base { 12 namespace base {
13 class Value; 13 class Value;
14 } 14 }
15 15
16 class DefaultPrefStore; 16 class DefaultPrefStore;
17 class PrefStore; 17 class PrefStore;
18 18
19 // Preferences need to be registered with a type and default value 19 // Preferences need to be registered with a type and default value
20 // before they are used. 20 // before they are used.
21 // 21 //
22 // 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
23 // 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
24 // construction parameter to PrefService. 24 // construction parameter to PrefService.
25 // 25 //
26 // Currently, registrations after constructing the PrefService will 26 // Currently, registrations after constructing the PrefService will
27 // also work, but this is being deprecated. 27 // also work, but this is being deprecated.
28 class BASE_PREFS_EXPORT PrefRegistry : public base::RefCounted<PrefRegistry> { 28 class BASE_PREFS_EXPORT PrefRegistry : public base::RefCounted<PrefRegistry> {
29 public: 29 public:
30 // Registration flags that can be specified which impact how the pref will
31 // behave or be stored. This will be passed in a bitmask when the pref is
32 // registered. Subclasses of PrefRegistry can specify their own flags. Care
33 // must be taken to ensure none of these overlap with the flags below.
34 enum PrefRegistrationFlags {
35 // No flags are specified.
36 NO_REGISTRATION_FLAGS = 0,
37
38 // The first 8 bits are reserved for subclasses of PrefRegistry to use.
39 };
40
30 typedef PrefValueMap::const_iterator const_iterator; 41 typedef PrefValueMap::const_iterator const_iterator;
42 typedef std::map<std::string, uint32> PrefRegistrationFlagsMap;
31 43
32 PrefRegistry(); 44 PrefRegistry();
33 45
46 // Retrieve the set of registration flags for the given preference. The return
47 // value is a bitmask of PrefRegistrationFlags.
48 uint32 GetRegistrationFlags(const std::string& pref_name) const;
49
34 // Gets the registered defaults. 50 // Gets the registered defaults.
35 scoped_refptr<PrefStore> defaults(); 51 scoped_refptr<PrefStore> defaults();
36 52
37 // Allows iteration over defaults. 53 // Allows iteration over defaults.
38 const_iterator begin() const; 54 const_iterator begin() const;
39 const_iterator end() const; 55 const_iterator end() const;
40 56
41 // Changes the default value for a preference. Takes ownership of |value|. 57 // Changes the default value for a preference. Takes ownership of |value|.
42 // 58 //
43 // |pref_name| must be a previously registered preference. 59 // |pref_name| must be a previously registered preference.
44 void SetDefaultPrefValue(const std::string& pref_name, base::Value* value); 60 void SetDefaultPrefValue(const std::string& pref_name, base::Value* value);
45 61
46 protected: 62 protected:
47 friend class base::RefCounted<PrefRegistry>; 63 friend class base::RefCounted<PrefRegistry>;
48 virtual ~PrefRegistry(); 64 virtual ~PrefRegistry();
49 65
50 // Used by subclasses to register a default value for a preference. 66 // Used by subclasses to register a default value and registration flags for
51 void RegisterPreference(const std::string& path, base::Value* default_value); 67 // a preference. |flags| is a bitmask of |PrefRegistrationFlags|.
68 void RegisterPreference(const std::string& path,
69 base::Value* default_value,
70 uint32 flags);
52 71
53 scoped_refptr<DefaultPrefStore> defaults_; 72 scoped_refptr<DefaultPrefStore> defaults_;
54 73
74 // A map of pref name to a bitmask of PrefRegistrationFlags.
75 PrefRegistrationFlagsMap registration_flags_;
76
55 private: 77 private:
56 DISALLOW_COPY_AND_ASSIGN(PrefRegistry); 78 DISALLOW_COPY_AND_ASSIGN(PrefRegistry);
57 }; 79 };
58 80
59 #endif // BASE_PREFS_PREF_REGISTRY_H_ 81 #endif // BASE_PREFS_PREF_REGISTRY_H_
OLDNEW
« no previous file with comments | « no previous file | base/prefs/pref_registry.cc » ('j') | components/pref_registry/pref_registry_syncable.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698