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 #include "components/prefs/testing_pref_store.h" | 5 #include "components/prefs/testing_pref_store.h" |
6 | 6 |
| 7 #include <memory> |
7 #include <utility> | 8 #include <utility> |
8 | 9 |
9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/ptr_util.h" |
10 #include "base/values.h" | 11 #include "base/values.h" |
11 | 12 |
12 TestingPrefStore::TestingPrefStore() | 13 TestingPrefStore::TestingPrefStore() |
13 : read_only_(true), | 14 : read_only_(true), |
14 read_success_(true), | 15 read_success_(true), |
15 read_error_(PersistentPrefStore::PREF_READ_ERROR_NONE), | 16 read_error_(PersistentPrefStore::PREF_READ_ERROR_NONE), |
16 block_async_read_(false), | 17 block_async_read_(false), |
17 pending_async_read_(false), | 18 pending_async_read_(false), |
18 init_complete_(false), | 19 init_complete_(false), |
19 committed_(true) {} | 20 committed_(true) {} |
(...skipping 18 matching lines...) Expand all Loading... |
38 | 39 |
39 bool TestingPrefStore::HasObservers() const { | 40 bool TestingPrefStore::HasObservers() const { |
40 return observers_.might_have_observers(); | 41 return observers_.might_have_observers(); |
41 } | 42 } |
42 | 43 |
43 bool TestingPrefStore::IsInitializationComplete() const { | 44 bool TestingPrefStore::IsInitializationComplete() const { |
44 return init_complete_; | 45 return init_complete_; |
45 } | 46 } |
46 | 47 |
47 void TestingPrefStore::SetValue(const std::string& key, | 48 void TestingPrefStore::SetValue(const std::string& key, |
48 scoped_ptr<base::Value> value, | 49 std::unique_ptr<base::Value> value, |
49 uint32_t flags) { | 50 uint32_t flags) { |
50 if (prefs_.SetValue(key, std::move(value))) { | 51 if (prefs_.SetValue(key, std::move(value))) { |
51 committed_ = false; | 52 committed_ = false; |
52 NotifyPrefValueChanged(key); | 53 NotifyPrefValueChanged(key); |
53 } | 54 } |
54 } | 55 } |
55 | 56 |
56 void TestingPrefStore::SetValueSilently(const std::string& key, | 57 void TestingPrefStore::SetValueSilently(const std::string& key, |
57 scoped_ptr<base::Value> value, | 58 std::unique_ptr<base::Value> value, |
58 uint32_t flags) { | 59 uint32_t flags) { |
59 if (prefs_.SetValue(key, std::move(value))) | 60 if (prefs_.SetValue(key, std::move(value))) |
60 committed_ = false; | 61 committed_ = false; |
61 } | 62 } |
62 | 63 |
63 void TestingPrefStore::RemoveValue(const std::string& key, uint32_t flags) { | 64 void TestingPrefStore::RemoveValue(const std::string& key, uint32_t flags) { |
64 if (prefs_.RemoveValue(key)) { | 65 if (prefs_.RemoveValue(key)) { |
65 committed_ = false; | 66 committed_ = false; |
66 NotifyPrefValueChanged(key); | 67 NotifyPrefValueChanged(key); |
67 } | 68 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 Observer, observers_, OnInitializationCompleted(read_success_)); | 111 Observer, observers_, OnInitializationCompleted(read_success_)); |
111 } | 112 } |
112 | 113 |
113 void TestingPrefStore::ReportValueChanged(const std::string& key, | 114 void TestingPrefStore::ReportValueChanged(const std::string& key, |
114 uint32_t flags) { | 115 uint32_t flags) { |
115 FOR_EACH_OBSERVER(Observer, observers_, OnPrefValueChanged(key)); | 116 FOR_EACH_OBSERVER(Observer, observers_, OnPrefValueChanged(key)); |
116 } | 117 } |
117 | 118 |
118 void TestingPrefStore::SetString(const std::string& key, | 119 void TestingPrefStore::SetString(const std::string& key, |
119 const std::string& value) { | 120 const std::string& value) { |
120 SetValue(key, make_scoped_ptr(new base::StringValue(value)), | 121 SetValue(key, base::WrapUnique(new base::StringValue(value)), |
121 DEFAULT_PREF_WRITE_FLAGS); | 122 DEFAULT_PREF_WRITE_FLAGS); |
122 } | 123 } |
123 | 124 |
124 void TestingPrefStore::SetInteger(const std::string& key, int value) { | 125 void TestingPrefStore::SetInteger(const std::string& key, int value) { |
125 SetValue(key, make_scoped_ptr(new base::FundamentalValue(value)), | 126 SetValue(key, base::WrapUnique(new base::FundamentalValue(value)), |
126 DEFAULT_PREF_WRITE_FLAGS); | 127 DEFAULT_PREF_WRITE_FLAGS); |
127 } | 128 } |
128 | 129 |
129 void TestingPrefStore::SetBoolean(const std::string& key, bool value) { | 130 void TestingPrefStore::SetBoolean(const std::string& key, bool value) { |
130 SetValue(key, make_scoped_ptr(new base::FundamentalValue(value)), | 131 SetValue(key, base::WrapUnique(new base::FundamentalValue(value)), |
131 DEFAULT_PREF_WRITE_FLAGS); | 132 DEFAULT_PREF_WRITE_FLAGS); |
132 } | 133 } |
133 | 134 |
134 bool TestingPrefStore::GetString(const std::string& key, | 135 bool TestingPrefStore::GetString(const std::string& key, |
135 std::string* value) const { | 136 std::string* value) const { |
136 const base::Value* stored_value; | 137 const base::Value* stored_value; |
137 if (!prefs_.GetValue(key, &stored_value) || !stored_value) | 138 if (!prefs_.GetValue(key, &stored_value) || !stored_value) |
138 return false; | 139 return false; |
139 | 140 |
140 return stored_value->GetAsString(value); | 141 return stored_value->GetAsString(value); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 read_success_ = read_success; | 177 read_success_ = read_success; |
177 } | 178 } |
178 | 179 |
179 void TestingPrefStore::set_read_error( | 180 void TestingPrefStore::set_read_error( |
180 PersistentPrefStore::PrefReadError read_error) { | 181 PersistentPrefStore::PrefReadError read_error) { |
181 DCHECK(!init_complete_); | 182 DCHECK(!init_complete_); |
182 read_error_ = read_error; | 183 read_error_ = read_error; |
183 } | 184 } |
184 | 185 |
185 TestingPrefStore::~TestingPrefStore() {} | 186 TestingPrefStore::~TestingPrefStore() {} |
OLD | NEW |