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

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

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

Powered by Google App Engine
This is Rietveld 408576698