| 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() |
| 11 : read_only_(true), | 11 : read_only_(true), |
| 12 init_complete_(false) { | 12 init_complete_(false) { |
| 13 } | 13 } |
| 14 | 14 |
| 15 bool TestingPrefStore::GetValue(const std::string& key, | 15 bool TestingPrefStore::GetValue(const std::string& key, |
| 16 const Value** value) const { | 16 const base::Value** value) const { |
| 17 return prefs_.GetValue(key, value); | 17 return prefs_.GetValue(key, value); |
| 18 } | 18 } |
| 19 | 19 |
| 20 bool TestingPrefStore::GetMutableValue(const std::string& key, | 20 bool TestingPrefStore::GetMutableValue(const std::string& key, |
| 21 Value** value) { | 21 base::Value** value) { |
| 22 return prefs_.GetValue(key, value); | 22 return prefs_.GetValue(key, value); |
| 23 } | 23 } |
| 24 | 24 |
| 25 void TestingPrefStore::AddObserver(PrefStore::Observer* observer) { | 25 void TestingPrefStore::AddObserver(PrefStore::Observer* observer) { |
| 26 observers_.AddObserver(observer); | 26 observers_.AddObserver(observer); |
| 27 } | 27 } |
| 28 | 28 |
| 29 void TestingPrefStore::RemoveObserver(PrefStore::Observer* observer) { | 29 void TestingPrefStore::RemoveObserver(PrefStore::Observer* observer) { |
| 30 observers_.RemoveObserver(observer); | 30 observers_.RemoveObserver(observer); |
| 31 } | 31 } |
| 32 | 32 |
| 33 size_t TestingPrefStore::NumberOfObservers() const { | 33 size_t TestingPrefStore::NumberOfObservers() const { |
| 34 return observers_.size(); | 34 return observers_.size(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 bool TestingPrefStore::IsInitializationComplete() const { | 37 bool TestingPrefStore::IsInitializationComplete() const { |
| 38 return init_complete_; | 38 return init_complete_; |
| 39 } | 39 } |
| 40 | 40 |
| 41 void TestingPrefStore::SetValue(const std::string& key, Value* value) { | 41 void TestingPrefStore::SetValue(const std::string& key, base::Value* value) { |
| 42 if (prefs_.SetValue(key, value)) | 42 if (prefs_.SetValue(key, value)) |
| 43 NotifyPrefValueChanged(key); | 43 NotifyPrefValueChanged(key); |
| 44 } | 44 } |
| 45 | 45 |
| 46 void TestingPrefStore::SetValueSilently(const std::string& key, Value* value) { | 46 void TestingPrefStore::SetValueSilently(const std::string& key, |
| 47 base::Value* value) { |
| 47 prefs_.SetValue(key, value); | 48 prefs_.SetValue(key, value); |
| 48 } | 49 } |
| 49 | 50 |
| 50 void TestingPrefStore::RemoveValue(const std::string& key) { | 51 void TestingPrefStore::RemoveValue(const std::string& key) { |
| 51 if (prefs_.RemoveValue(key)) | 52 if (prefs_.RemoveValue(key)) |
| 52 NotifyPrefValueChanged(key); | 53 NotifyPrefValueChanged(key); |
| 53 } | 54 } |
| 54 | 55 |
| 55 void TestingPrefStore::MarkNeedsEmptyValue(const std::string& key) { | 56 void TestingPrefStore::MarkNeedsEmptyValue(const std::string& key) { |
| 56 } | 57 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 void TestingPrefStore::SetInteger(const std::string& key, int value) { | 99 void TestingPrefStore::SetInteger(const std::string& key, int value) { |
| 99 SetValue(key, new base::FundamentalValue(value)); | 100 SetValue(key, new base::FundamentalValue(value)); |
| 100 } | 101 } |
| 101 | 102 |
| 102 void TestingPrefStore::SetBoolean(const std::string& key, bool value) { | 103 void TestingPrefStore::SetBoolean(const std::string& key, bool value) { |
| 103 SetValue(key, new base::FundamentalValue(value)); | 104 SetValue(key, new base::FundamentalValue(value)); |
| 104 } | 105 } |
| 105 | 106 |
| 106 bool TestingPrefStore::GetString(const std::string& key, | 107 bool TestingPrefStore::GetString(const std::string& key, |
| 107 std::string* value) const { | 108 std::string* value) const { |
| 108 const Value* stored_value; | 109 const base::Value* stored_value; |
| 109 if (!prefs_.GetValue(key, &stored_value) || !stored_value) | 110 if (!prefs_.GetValue(key, &stored_value) || !stored_value) |
| 110 return false; | 111 return false; |
| 111 | 112 |
| 112 return stored_value->GetAsString(value); | 113 return stored_value->GetAsString(value); |
| 113 } | 114 } |
| 114 | 115 |
| 115 bool TestingPrefStore::GetInteger(const std::string& key, int* value) const { | 116 bool TestingPrefStore::GetInteger(const std::string& key, int* value) const { |
| 116 const Value* stored_value; | 117 const base::Value* stored_value; |
| 117 if (!prefs_.GetValue(key, &stored_value) || !stored_value) | 118 if (!prefs_.GetValue(key, &stored_value) || !stored_value) |
| 118 return false; | 119 return false; |
| 119 | 120 |
| 120 return stored_value->GetAsInteger(value); | 121 return stored_value->GetAsInteger(value); |
| 121 } | 122 } |
| 122 | 123 |
| 123 bool TestingPrefStore::GetBoolean(const std::string& key, bool* value) const { | 124 bool TestingPrefStore::GetBoolean(const std::string& key, bool* value) const { |
| 124 const Value* stored_value; | 125 const base::Value* stored_value; |
| 125 if (!prefs_.GetValue(key, &stored_value) || !stored_value) | 126 if (!prefs_.GetValue(key, &stored_value) || !stored_value) |
| 126 return false; | 127 return false; |
| 127 | 128 |
| 128 return stored_value->GetAsBoolean(value); | 129 return stored_value->GetAsBoolean(value); |
| 129 } | 130 } |
| 130 | 131 |
| 131 void TestingPrefStore::set_read_only(bool read_only) { | 132 void TestingPrefStore::set_read_only(bool read_only) { |
| 132 read_only_ = read_only; | 133 read_only_ = read_only; |
| 133 } | 134 } |
| 134 | 135 |
| 135 TestingPrefStore::~TestingPrefStore() {} | 136 TestingPrefStore::~TestingPrefStore() {} |
| OLD | NEW |