| 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 "base/prefs/testing_pref_store.h" | 5 #include "base/prefs/testing_pref_store.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 | 9 |
| 10 TestingPrefStore::TestingPrefStore() | 10 TestingPrefStore::TestingPrefStore() |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 bool TestingPrefStore::HasObservers() const { | 37 bool TestingPrefStore::HasObservers() const { |
| 38 return observers_.might_have_observers(); | 38 return observers_.might_have_observers(); |
| 39 } | 39 } |
| 40 | 40 |
| 41 bool TestingPrefStore::IsInitializationComplete() const { | 41 bool TestingPrefStore::IsInitializationComplete() const { |
| 42 return init_complete_; | 42 return init_complete_; |
| 43 } | 43 } |
| 44 | 44 |
| 45 void TestingPrefStore::SetValue(const std::string& key, | 45 void TestingPrefStore::SetValue(const std::string& key, |
| 46 base::Value* value, | 46 scoped_ptr<base::Value> value, |
| 47 uint32 flags) { | 47 uint32 flags) { |
| 48 if (prefs_.SetValue(key, value)) { | 48 if (prefs_.SetValue(key, value.Pass())) { |
| 49 committed_ = false; | 49 committed_ = false; |
| 50 NotifyPrefValueChanged(key); | 50 NotifyPrefValueChanged(key); |
| 51 } | 51 } |
| 52 } | 52 } |
| 53 | 53 |
| 54 void TestingPrefStore::SetValueSilently(const std::string& key, | 54 void TestingPrefStore::SetValueSilently(const std::string& key, |
| 55 base::Value* value, | 55 scoped_ptr<base::Value> value, |
| 56 uint32 flags) { | 56 uint32 flags) { |
| 57 if (prefs_.SetValue(key, value)) | 57 if (prefs_.SetValue(key, value.Pass())) |
| 58 committed_ = false; | 58 committed_ = false; |
| 59 } | 59 } |
| 60 | 60 |
| 61 void TestingPrefStore::RemoveValue(const std::string& key, uint32 flags) { | 61 void TestingPrefStore::RemoveValue(const std::string& key, uint32 flags) { |
| 62 if (prefs_.RemoveValue(key)) { | 62 if (prefs_.RemoveValue(key)) { |
| 63 committed_ = false; | 63 committed_ = false; |
| 64 NotifyPrefValueChanged(key); | 64 NotifyPrefValueChanged(key); |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 | 67 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 Observer, observers_, OnInitializationCompleted(read_success_)); | 108 Observer, observers_, OnInitializationCompleted(read_success_)); |
| 109 } | 109 } |
| 110 | 110 |
| 111 void TestingPrefStore::ReportValueChanged(const std::string& key, | 111 void TestingPrefStore::ReportValueChanged(const std::string& key, |
| 112 uint32 flags) { | 112 uint32 flags) { |
| 113 FOR_EACH_OBSERVER(Observer, observers_, OnPrefValueChanged(key)); | 113 FOR_EACH_OBSERVER(Observer, observers_, OnPrefValueChanged(key)); |
| 114 } | 114 } |
| 115 | 115 |
| 116 void TestingPrefStore::SetString(const std::string& key, | 116 void TestingPrefStore::SetString(const std::string& key, |
| 117 const std::string& value) { | 117 const std::string& value) { |
| 118 SetValue(key, new base::StringValue(value), DEFAULT_PREF_WRITE_FLAGS); | 118 SetValue(key, make_scoped_ptr(new base::StringValue(value)), |
| 119 DEFAULT_PREF_WRITE_FLAGS); |
| 119 } | 120 } |
| 120 | 121 |
| 121 void TestingPrefStore::SetInteger(const std::string& key, int value) { | 122 void TestingPrefStore::SetInteger(const std::string& key, int value) { |
| 122 SetValue(key, new base::FundamentalValue(value), DEFAULT_PREF_WRITE_FLAGS); | 123 SetValue(key, make_scoped_ptr(new base::FundamentalValue(value)), |
| 124 DEFAULT_PREF_WRITE_FLAGS); |
| 123 } | 125 } |
| 124 | 126 |
| 125 void TestingPrefStore::SetBoolean(const std::string& key, bool value) { | 127 void TestingPrefStore::SetBoolean(const std::string& key, bool value) { |
| 126 SetValue(key, new base::FundamentalValue(value), DEFAULT_PREF_WRITE_FLAGS); | 128 SetValue(key, make_scoped_ptr(new base::FundamentalValue(value)), |
| 129 DEFAULT_PREF_WRITE_FLAGS); |
| 127 } | 130 } |
| 128 | 131 |
| 129 bool TestingPrefStore::GetString(const std::string& key, | 132 bool TestingPrefStore::GetString(const std::string& key, |
| 130 std::string* value) const { | 133 std::string* value) const { |
| 131 const base::Value* stored_value; | 134 const base::Value* stored_value; |
| 132 if (!prefs_.GetValue(key, &stored_value) || !stored_value) | 135 if (!prefs_.GetValue(key, &stored_value) || !stored_value) |
| 133 return false; | 136 return false; |
| 134 | 137 |
| 135 return stored_value->GetAsString(value); | 138 return stored_value->GetAsString(value); |
| 136 } | 139 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 167 read_success_ = read_success; | 170 read_success_ = read_success; |
| 168 } | 171 } |
| 169 | 172 |
| 170 void TestingPrefStore::set_read_error( | 173 void TestingPrefStore::set_read_error( |
| 171 PersistentPrefStore::PrefReadError read_error) { | 174 PersistentPrefStore::PrefReadError read_error) { |
| 172 DCHECK(!init_complete_); | 175 DCHECK(!init_complete_); |
| 173 read_error_ = read_error; | 176 read_error_ = read_error; |
| 174 } | 177 } |
| 175 | 178 |
| 176 TestingPrefStore::~TestingPrefStore() {} | 179 TestingPrefStore::~TestingPrefStore() {} |
| OLD | NEW |