| 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 24 matching lines...) Expand all Loading... |
| 35 } | 35 } |
| 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, base::Value* value) { | 45 void TestingPrefStore::SetValue(const std::string& key, |
| 46 base::Value* value, |
| 47 uint32 flags) { |
| 46 if (prefs_.SetValue(key, value)) { | 48 if (prefs_.SetValue(key, value)) { |
| 47 committed_ = false; | 49 committed_ = false; |
| 48 NotifyPrefValueChanged(key); | 50 NotifyPrefValueChanged(key); |
| 49 } | 51 } |
| 50 } | 52 } |
| 51 | 53 |
| 52 void TestingPrefStore::SetValueSilently(const std::string& key, | 54 void TestingPrefStore::SetValueSilently(const std::string& key, |
| 53 base::Value* value) { | 55 base::Value* value, |
| 56 uint32 flags) { |
| 54 if (prefs_.SetValue(key, value)) | 57 if (prefs_.SetValue(key, value)) |
| 55 committed_ = false; | 58 committed_ = false; |
| 56 } | 59 } |
| 57 | 60 |
| 58 void TestingPrefStore::RemoveValue(const std::string& key) { | 61 void TestingPrefStore::RemoveValue(const std::string& key, uint32 flags) { |
| 59 if (prefs_.RemoveValue(key)) { | 62 if (prefs_.RemoveValue(key)) { |
| 60 committed_ = false; | 63 committed_ = false; |
| 61 NotifyPrefValueChanged(key); | 64 NotifyPrefValueChanged(key); |
| 62 } | 65 } |
| 63 } | 66 } |
| 64 | 67 |
| 65 bool TestingPrefStore::ReadOnly() const { | 68 bool TestingPrefStore::ReadOnly() const { |
| 66 return read_only_; | 69 return read_only_; |
| 67 } | 70 } |
| 68 | 71 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 96 | 99 |
| 97 void TestingPrefStore::NotifyInitializationCompleted() { | 100 void TestingPrefStore::NotifyInitializationCompleted() { |
| 98 DCHECK(!init_complete_); | 101 DCHECK(!init_complete_); |
| 99 init_complete_ = true; | 102 init_complete_ = true; |
| 100 if (read_success_ && read_error_ != PREF_READ_ERROR_NONE && error_delegate_) | 103 if (read_success_ && read_error_ != PREF_READ_ERROR_NONE && error_delegate_) |
| 101 error_delegate_->OnError(read_error_); | 104 error_delegate_->OnError(read_error_); |
| 102 FOR_EACH_OBSERVER( | 105 FOR_EACH_OBSERVER( |
| 103 Observer, observers_, OnInitializationCompleted(read_success_)); | 106 Observer, observers_, OnInitializationCompleted(read_success_)); |
| 104 } | 107 } |
| 105 | 108 |
| 106 void TestingPrefStore::ReportValueChanged(const std::string& key) { | 109 void TestingPrefStore::ReportValueChanged(const std::string& key, |
| 110 uint32 flags) { |
| 107 FOR_EACH_OBSERVER(Observer, observers_, OnPrefValueChanged(key)); | 111 FOR_EACH_OBSERVER(Observer, observers_, OnPrefValueChanged(key)); |
| 108 } | 112 } |
| 109 | 113 |
| 110 void TestingPrefStore::SetString(const std::string& key, | 114 void TestingPrefStore::SetString(const std::string& key, |
| 111 const std::string& value) { | 115 const std::string& value) { |
| 112 SetValue(key, new base::StringValue(value)); | 116 SetValue(key, new base::StringValue(value), DEFAULT_PREF_WRITE_FLAGS); |
| 113 } | 117 } |
| 114 | 118 |
| 115 void TestingPrefStore::SetInteger(const std::string& key, int value) { | 119 void TestingPrefStore::SetInteger(const std::string& key, int value) { |
| 116 SetValue(key, new base::FundamentalValue(value)); | 120 SetValue(key, new base::FundamentalValue(value), DEFAULT_PREF_WRITE_FLAGS); |
| 117 } | 121 } |
| 118 | 122 |
| 119 void TestingPrefStore::SetBoolean(const std::string& key, bool value) { | 123 void TestingPrefStore::SetBoolean(const std::string& key, bool value) { |
| 120 SetValue(key, new base::FundamentalValue(value)); | 124 SetValue(key, new base::FundamentalValue(value), DEFAULT_PREF_WRITE_FLAGS); |
| 121 } | 125 } |
| 122 | 126 |
| 123 bool TestingPrefStore::GetString(const std::string& key, | 127 bool TestingPrefStore::GetString(const std::string& key, |
| 124 std::string* value) const { | 128 std::string* value) const { |
| 125 const base::Value* stored_value; | 129 const base::Value* stored_value; |
| 126 if (!prefs_.GetValue(key, &stored_value) || !stored_value) | 130 if (!prefs_.GetValue(key, &stored_value) || !stored_value) |
| 127 return false; | 131 return false; |
| 128 | 132 |
| 129 return stored_value->GetAsString(value); | 133 return stored_value->GetAsString(value); |
| 130 } | 134 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 161 read_success_ = read_success; | 165 read_success_ = read_success; |
| 162 } | 166 } |
| 163 | 167 |
| 164 void TestingPrefStore::set_read_error( | 168 void TestingPrefStore::set_read_error( |
| 165 PersistentPrefStore::PrefReadError read_error) { | 169 PersistentPrefStore::PrefReadError read_error) { |
| 166 DCHECK(!init_complete_); | 170 DCHECK(!init_complete_); |
| 167 read_error_ = read_error; | 171 read_error_ = read_error; |
| 168 } | 172 } |
| 169 | 173 |
| 170 TestingPrefStore::~TestingPrefStore() {} | 174 TestingPrefStore::~TestingPrefStore() {} |
| OLD | NEW |