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

Side by Side Diff: components/prefs/pref_registry_simple.cc

Issue 2784513002: Move PrefRegistrySimple to use unique_ptr<Value> (Closed)
Patch Set: Android Created 3 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
« no previous file with comments | « components/prefs/pref_registry_simple.h ('k') | components/prefs/pref_service_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "components/prefs/pref_registry_simple.h" 5 #include "components/prefs/pref_registry_simple.h"
6 6
7 #include <utility>
8
7 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/memory/ptr_util.h"
8 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
9 #include "base/values.h" 12 #include "base/values.h"
10 13
11 PrefRegistrySimple::PrefRegistrySimple() { 14 PrefRegistrySimple::PrefRegistrySimple() {
12 } 15 }
13 16
14 PrefRegistrySimple::~PrefRegistrySimple() { 17 PrefRegistrySimple::~PrefRegistrySimple() {
15 } 18 }
16 19
17 void PrefRegistrySimple::RegisterBooleanPref(const std::string& path, 20 void PrefRegistrySimple::RegisterBooleanPref(const std::string& path,
18 bool default_value) { 21 bool default_value) {
19 RegisterPrefAndNotify(path, new base::Value(default_value), 22 RegisterPrefAndNotify(path, base::MakeUnique<base::Value>(default_value),
20 NO_REGISTRATION_FLAGS); 23 NO_REGISTRATION_FLAGS);
21 } 24 }
22 25
23 void PrefRegistrySimple::RegisterIntegerPref(const std::string& path, 26 void PrefRegistrySimple::RegisterIntegerPref(const std::string& path,
24 int default_value) { 27 int default_value) {
25 RegisterPrefAndNotify(path, new base::Value(default_value), 28 RegisterPrefAndNotify(path, base::MakeUnique<base::Value>(default_value),
26 NO_REGISTRATION_FLAGS); 29 NO_REGISTRATION_FLAGS);
27 } 30 }
28 31
29 void PrefRegistrySimple::RegisterDoublePref(const std::string& path, 32 void PrefRegistrySimple::RegisterDoublePref(const std::string& path,
30 double default_value) { 33 double default_value) {
31 RegisterPrefAndNotify(path, new base::Value(default_value), 34 RegisterPrefAndNotify(path, base::MakeUnique<base::Value>(default_value),
32 NO_REGISTRATION_FLAGS); 35 NO_REGISTRATION_FLAGS);
33 } 36 }
34 37
35 void PrefRegistrySimple::RegisterStringPref(const std::string& path, 38 void PrefRegistrySimple::RegisterStringPref(const std::string& path,
36 const std::string& default_value) { 39 const std::string& default_value) {
37 RegisterPrefAndNotify(path, new base::Value(default_value), 40 RegisterPrefAndNotify(path, base::MakeUnique<base::Value>(default_value),
38 NO_REGISTRATION_FLAGS); 41 NO_REGISTRATION_FLAGS);
39 } 42 }
40 43
41 void PrefRegistrySimple::RegisterFilePathPref( 44 void PrefRegistrySimple::RegisterFilePathPref(
42 const std::string& path, 45 const std::string& path,
43 const base::FilePath& default_value) { 46 const base::FilePath& default_value) {
44 RegisterPrefAndNotify(path, new base::Value(default_value.value()), 47 RegisterPrefAndNotify(path,
48 base::MakeUnique<base::Value>(default_value.value()),
45 NO_REGISTRATION_FLAGS); 49 NO_REGISTRATION_FLAGS);
46 } 50 }
47 51
48 void PrefRegistrySimple::RegisterListPref(const std::string& path) { 52 void PrefRegistrySimple::RegisterListPref(const std::string& path) {
49 RegisterPrefAndNotify(path, new base::ListValue(), NO_REGISTRATION_FLAGS); 53 RegisterPrefAndNotify(path, base::MakeUnique<base::ListValue>(),
54 NO_REGISTRATION_FLAGS);
50 } 55 }
51 56
52 void PrefRegistrySimple::RegisterListPref(const std::string& path, 57 void PrefRegistrySimple::RegisterListPref(
53 base::ListValue* default_value) { 58 const std::string& path,
54 RegisterPrefAndNotify(path, default_value, NO_REGISTRATION_FLAGS); 59 std::unique_ptr<base::ListValue> default_value) {
60 RegisterPrefAndNotify(path, std::move(default_value), NO_REGISTRATION_FLAGS);
55 } 61 }
56 62
57 void PrefRegistrySimple::RegisterDictionaryPref(const std::string& path) { 63 void PrefRegistrySimple::RegisterDictionaryPref(const std::string& path) {
58 RegisterPrefAndNotify(path, new base::DictionaryValue(), 64 RegisterPrefAndNotify(path, base::MakeUnique<base::DictionaryValue>(),
59 NO_REGISTRATION_FLAGS); 65 NO_REGISTRATION_FLAGS);
60 } 66 }
61 67
62 void PrefRegistrySimple::RegisterDictionaryPref( 68 void PrefRegistrySimple::RegisterDictionaryPref(
63 const std::string& path, 69 const std::string& path,
64 base::DictionaryValue* default_value) { 70 std::unique_ptr<base::DictionaryValue> default_value) {
65 RegisterPrefAndNotify(path, default_value, NO_REGISTRATION_FLAGS); 71 RegisterPrefAndNotify(path, std::move(default_value), NO_REGISTRATION_FLAGS);
66 } 72 }
67 73
68 void PrefRegistrySimple::RegisterInt64Pref(const std::string& path, 74 void PrefRegistrySimple::RegisterInt64Pref(const std::string& path,
69 int64_t default_value) { 75 int64_t default_value) {
70 RegisterPrefAndNotify(path, 76 RegisterPrefAndNotify(
71 new base::Value(base::Int64ToString(default_value)), 77 path, base::MakeUnique<base::Value>(base::Int64ToString(default_value)),
72 NO_REGISTRATION_FLAGS); 78 NO_REGISTRATION_FLAGS);
73 } 79 }
74 80
75 void PrefRegistrySimple::RegisterUint64Pref(const std::string& path, 81 void PrefRegistrySimple::RegisterUint64Pref(const std::string& path,
76 uint64_t default_value) { 82 uint64_t default_value) {
77 RegisterPrefAndNotify(path, 83 RegisterPrefAndNotify(
78 new base::Value(base::Uint64ToString(default_value)), 84 path, base::MakeUnique<base::Value>(base::Uint64ToString(default_value)),
79 NO_REGISTRATION_FLAGS); 85 NO_REGISTRATION_FLAGS);
80 } 86 }
81 87
82 void PrefRegistrySimple::RegisterBooleanPref(const std::string& path, 88 void PrefRegistrySimple::RegisterBooleanPref(const std::string& path,
83 bool default_value, 89 bool default_value,
84 uint32_t flags) { 90 uint32_t flags) {
85 RegisterPrefAndNotify(path, new base::Value(default_value), flags); 91 RegisterPrefAndNotify(path, base::MakeUnique<base::Value>(default_value),
92 flags);
86 } 93 }
87 94
88 void PrefRegistrySimple::RegisterIntegerPref(const std::string& path, 95 void PrefRegistrySimple::RegisterIntegerPref(const std::string& path,
89 int default_value, 96 int default_value,
90 uint32_t flags) { 97 uint32_t flags) {
91 RegisterPrefAndNotify(path, new base::Value(default_value), flags); 98 RegisterPrefAndNotify(path, base::MakeUnique<base::Value>(default_value),
99 flags);
92 } 100 }
93 101
94 void PrefRegistrySimple::RegisterDoublePref(const std::string& path, 102 void PrefRegistrySimple::RegisterDoublePref(const std::string& path,
95 double default_value, 103 double default_value,
96 uint32_t flags) { 104 uint32_t flags) {
97 RegisterPrefAndNotify(path, new base::Value(default_value), flags); 105 RegisterPrefAndNotify(path, base::MakeUnique<base::Value>(default_value),
106 flags);
98 } 107 }
99 108
100 void PrefRegistrySimple::RegisterStringPref(const std::string& path, 109 void PrefRegistrySimple::RegisterStringPref(const std::string& path,
101 const std::string& default_value, 110 const std::string& default_value,
102 uint32_t flags) { 111 uint32_t flags) {
103 RegisterPrefAndNotify(path, new base::Value(default_value), flags); 112 RegisterPrefAndNotify(path, base::MakeUnique<base::Value>(default_value),
113 flags);
104 } 114 }
105 115
106 void PrefRegistrySimple::RegisterFilePathPref( 116 void PrefRegistrySimple::RegisterFilePathPref(
107 const std::string& path, 117 const std::string& path,
108 const base::FilePath& default_value, 118 const base::FilePath& default_value,
109 uint32_t flags) { 119 uint32_t flags) {
110 RegisterPrefAndNotify(path, new base::Value(default_value.value()), flags); 120 RegisterPrefAndNotify(
121 path, base::MakeUnique<base::Value>(default_value.value()), flags);
111 } 122 }
112 123
113 void PrefRegistrySimple::RegisterListPref(const std::string& path, 124 void PrefRegistrySimple::RegisterListPref(const std::string& path,
114 uint32_t flags) { 125 uint32_t flags) {
115 RegisterPrefAndNotify(path, new base::ListValue(), flags); 126 RegisterPrefAndNotify(path, base::MakeUnique<base::ListValue>(), flags);
116 } 127 }
117 128
118 void PrefRegistrySimple::RegisterListPref(const std::string& path, 129 void PrefRegistrySimple::RegisterListPref(
119 base::ListValue* default_value, 130 const std::string& path,
120 uint32_t flags) { 131 std::unique_ptr<base::ListValue> default_value,
121 RegisterPrefAndNotify(path, default_value, flags); 132 uint32_t flags) {
133 RegisterPrefAndNotify(path, std::move(default_value), flags);
122 } 134 }
123 135
124 void PrefRegistrySimple::RegisterDictionaryPref(const std::string& path, 136 void PrefRegistrySimple::RegisterDictionaryPref(const std::string& path,
125 uint32_t flags) { 137 uint32_t flags) {
126 RegisterPrefAndNotify(path, new base::DictionaryValue(), flags); 138 RegisterPrefAndNotify(path, base::MakeUnique<base::DictionaryValue>(), flags);
127 } 139 }
128 140
129 void PrefRegistrySimple::RegisterDictionaryPref( 141 void PrefRegistrySimple::RegisterDictionaryPref(
130 const std::string& path, 142 const std::string& path,
131 base::DictionaryValue* default_value, 143 std::unique_ptr<base::DictionaryValue> default_value,
132 uint32_t flags) { 144 uint32_t flags) {
133 RegisterPrefAndNotify(path, default_value, flags); 145 RegisterPrefAndNotify(path, std::move(default_value), flags);
134 } 146 }
135 147
136 void PrefRegistrySimple::RegisterInt64Pref(const std::string& path, 148 void PrefRegistrySimple::RegisterInt64Pref(const std::string& path,
137 int64_t default_value, 149 int64_t default_value,
138 uint32_t flags) { 150 uint32_t flags) {
139 RegisterPrefAndNotify( 151 RegisterPrefAndNotify(
140 path, new base::Value(base::Int64ToString(default_value)), flags); 152 path, base::MakeUnique<base::Value>(base::Int64ToString(default_value)),
153 flags);
141 } 154 }
142 155
143 void PrefRegistrySimple::RegisterUint64Pref(const std::string& path, 156 void PrefRegistrySimple::RegisterUint64Pref(const std::string& path,
144 uint64_t default_value, 157 uint64_t default_value,
145 uint32_t flags) { 158 uint32_t flags) {
146 RegisterPrefAndNotify( 159 RegisterPrefAndNotify(
147 path, new base::Value(base::Uint64ToString(default_value)), flags); 160 path, base::MakeUnique<base::Value>(base::Uint64ToString(default_value)),
161 flags);
148 } 162 }
149 163
150 void PrefRegistrySimple::OnPrefRegistered(const std::string& path, 164 void PrefRegistrySimple::OnPrefRegistered(const std::string& path,
151 base::Value* default_value, 165 base::Value* default_value,
152 uint32_t flags) {} 166 uint32_t flags) {}
153 167
154 void PrefRegistrySimple::RegisterPrefAndNotify(const std::string& path, 168 void PrefRegistrySimple::RegisterPrefAndNotify(
155 base::Value* default_value, 169 const std::string& path,
156 uint32_t flags) { 170 std::unique_ptr<base::Value> default_value,
157 RegisterPreference(path, default_value, flags); 171 uint32_t flags) {
158 OnPrefRegistered(path, default_value, flags); 172 base::Value* default_value_weak = default_value.get();
173 RegisterPreference(path, std::move(default_value), flags);
174 OnPrefRegistered(path, default_value_weak, flags);
159 } 175 }
OLDNEW
« no previous file with comments | « components/prefs/pref_registry_simple.h ('k') | components/prefs/pref_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698