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 COMPONENTS_PREFS_PREF_REGISTRY_SIMPLE_H_ | 5 #ifndef COMPONENTS_PREFS_PREF_REGISTRY_SIMPLE_H_ |
6 #define COMPONENTS_PREFS_PREF_REGISTRY_SIMPLE_H_ | 6 #define COMPONENTS_PREFS_PREF_REGISTRY_SIMPLE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
| 10 #include <memory> |
10 #include <string> | 11 #include <string> |
11 | 12 |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "components/prefs/base_prefs_export.h" | 14 #include "components/prefs/base_prefs_export.h" |
14 #include "components/prefs/pref_registry.h" | 15 #include "components/prefs/pref_registry.h" |
15 | 16 |
16 namespace base { | 17 namespace base { |
17 class DictionaryValue; | 18 class DictionaryValue; |
18 class FilePath; | 19 class FilePath; |
19 class ListValue; | 20 class ListValue; |
20 } | 21 } |
21 | 22 |
22 // A simple implementation of PrefRegistry. | 23 // A simple implementation of PrefRegistry. |
23 class COMPONENTS_PREFS_EXPORT PrefRegistrySimple : public PrefRegistry { | 24 class COMPONENTS_PREFS_EXPORT PrefRegistrySimple : public PrefRegistry { |
24 public: | 25 public: |
25 PrefRegistrySimple(); | 26 PrefRegistrySimple(); |
26 | 27 |
27 void RegisterBooleanPref(const std::string& path, bool default_value); | 28 void RegisterBooleanPref(const std::string& path, bool default_value); |
28 void RegisterIntegerPref(const std::string& path, int default_value); | 29 void RegisterIntegerPref(const std::string& path, int default_value); |
29 void RegisterDoublePref(const std::string& path, double default_value); | 30 void RegisterDoublePref(const std::string& path, double default_value); |
30 void RegisterStringPref(const std::string& path, | 31 void RegisterStringPref(const std::string& path, |
31 const std::string& default_value); | 32 const std::string& default_value); |
32 void RegisterFilePathPref(const std::string& path, | 33 void RegisterFilePathPref(const std::string& path, |
33 const base::FilePath& default_value); | 34 const base::FilePath& default_value); |
34 void RegisterListPref(const std::string& path); | 35 void RegisterListPref(const std::string& path); |
35 void RegisterDictionaryPref(const std::string& path); | 36 void RegisterDictionaryPref(const std::string& path); |
36 void RegisterListPref(const std::string& path, | 37 void RegisterListPref(const std::string& path, |
37 base::ListValue* default_value); | 38 std::unique_ptr<base::ListValue> default_value); |
38 void RegisterDictionaryPref(const std::string& path, | 39 void RegisterDictionaryPref( |
39 base::DictionaryValue* default_value); | 40 const std::string& path, |
| 41 std::unique_ptr<base::DictionaryValue> default_value); |
40 void RegisterInt64Pref(const std::string& path, int64_t default_value); | 42 void RegisterInt64Pref(const std::string& path, int64_t default_value); |
41 void RegisterUint64Pref(const std::string&, uint64_t default_value); | 43 void RegisterUint64Pref(const std::string&, uint64_t default_value); |
42 | 44 |
43 // Versions of registration functions that accept PrefRegistrationFlags. | 45 // Versions of registration functions that accept PrefRegistrationFlags. |
44 // |flags| is a bitmask of PrefRegistrationFlags. | 46 // |flags| is a bitmask of PrefRegistrationFlags. |
45 void RegisterBooleanPref(const std::string&, | 47 void RegisterBooleanPref(const std::string&, |
46 bool default_value, | 48 bool default_value, |
47 uint32_t flags); | 49 uint32_t flags); |
48 void RegisterIntegerPref(const std::string&, | 50 void RegisterIntegerPref(const std::string&, |
49 int default_value, | 51 int default_value, |
50 uint32_t flags); | 52 uint32_t flags); |
51 void RegisterDoublePref(const std::string&, | 53 void RegisterDoublePref(const std::string&, |
52 double default_value, | 54 double default_value, |
53 uint32_t flags); | 55 uint32_t flags); |
54 void RegisterStringPref(const std::string&, | 56 void RegisterStringPref(const std::string&, |
55 const std::string& default_value, | 57 const std::string& default_value, |
56 uint32_t flags); | 58 uint32_t flags); |
57 void RegisterFilePathPref(const std::string&, | 59 void RegisterFilePathPref(const std::string&, |
58 const base::FilePath& default_value, | 60 const base::FilePath& default_value, |
59 uint32_t flags); | 61 uint32_t flags); |
60 void RegisterListPref(const std::string&, uint32_t flags); | 62 void RegisterListPref(const std::string&, uint32_t flags); |
61 void RegisterDictionaryPref(const std::string&, uint32_t flags); | 63 void RegisterDictionaryPref(const std::string&, uint32_t flags); |
62 void RegisterListPref(const std::string&, | 64 void RegisterListPref(const std::string&, |
63 base::ListValue* default_value, | 65 std::unique_ptr<base::ListValue> default_value, |
64 uint32_t flags); | 66 uint32_t flags); |
65 void RegisterDictionaryPref(const std::string&, | 67 void RegisterDictionaryPref( |
66 base::DictionaryValue* default_value, | 68 const std::string&, |
67 uint32_t flags); | 69 std::unique_ptr<base::DictionaryValue> default_value, |
| 70 uint32_t flags); |
68 void RegisterInt64Pref(const std::string&, | 71 void RegisterInt64Pref(const std::string&, |
69 int64_t default_value, | 72 int64_t default_value, |
70 uint32_t flags); | 73 uint32_t flags); |
71 void RegisterUint64Pref(const std::string&, | 74 void RegisterUint64Pref(const std::string&, |
72 uint64_t default_value, | 75 uint64_t default_value, |
73 uint32_t flags); | 76 uint32_t flags); |
74 | 77 |
75 protected: | 78 protected: |
76 ~PrefRegistrySimple() override; | 79 ~PrefRegistrySimple() override; |
77 | 80 |
78 // Allows subclasses to hook into pref registration. | 81 // Allows subclasses to hook into pref registration. |
79 virtual void OnPrefRegistered(const std::string&, | 82 virtual void OnPrefRegistered(const std::string&, |
80 base::Value* default_value, | 83 base::Value* default_value, |
81 uint32_t flags); | 84 uint32_t flags); |
82 | 85 |
83 private: | 86 private: |
84 void RegisterPrefAndNotify(const std::string&, | 87 void RegisterPrefAndNotify(const std::string&, |
85 base::Value* default_value, | 88 std::unique_ptr<base::Value> default_value, |
86 uint32_t flags); | 89 uint32_t flags); |
87 | 90 |
88 DISALLOW_COPY_AND_ASSIGN(PrefRegistrySimple); | 91 DISALLOW_COPY_AND_ASSIGN(PrefRegistrySimple); |
89 }; | 92 }; |
90 | 93 |
91 #endif // COMPONENTS_PREFS_PREF_REGISTRY_SIMPLE_H_ | 94 #endif // COMPONENTS_PREFS_PREF_REGISTRY_SIMPLE_H_ |
OLD | NEW |