OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/value_store/testing_value_store.h" | 5 #include "extensions/browser/value_store/testing_value_store.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 | 8 |
9 namespace { | 9 namespace { |
10 | 10 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 | 42 |
43 ValueStore::ReadResult TestingValueStore::Get( | 43 ValueStore::ReadResult TestingValueStore::Get( |
44 const std::vector<std::string>& keys) { | 44 const std::vector<std::string>& keys) { |
45 read_count_++; | 45 read_count_++; |
46 if (error_code_ != OK) | 46 if (error_code_ != OK) |
47 return MakeReadResult(TestingError()); | 47 return MakeReadResult(TestingError()); |
48 | 48 |
49 base::DictionaryValue* settings = new base::DictionaryValue(); | 49 base::DictionaryValue* settings = new base::DictionaryValue(); |
50 for (std::vector<std::string>::const_iterator it = keys.begin(); | 50 for (std::vector<std::string>::const_iterator it = keys.begin(); |
51 it != keys.end(); ++it) { | 51 it != keys.end(); ++it) { |
52 base::Value* value = NULL; | 52 base::Value* value = nullptr; |
53 if (storage_.GetWithoutPathExpansion(*it, &value)) { | 53 if (storage_.GetWithoutPathExpansion(*it, &value)) { |
54 settings->SetWithoutPathExpansion(*it, value->DeepCopy()); | 54 settings->SetWithoutPathExpansion(*it, value->DeepCopy()); |
55 } | 55 } |
56 } | 56 } |
57 return MakeReadResult(make_scoped_ptr(settings)); | 57 return MakeReadResult(make_scoped_ptr(settings)); |
58 } | 58 } |
59 | 59 |
60 ValueStore::ReadResult TestingValueStore::Get() { | 60 ValueStore::ReadResult TestingValueStore::Get() { |
61 read_count_++; | 61 read_count_++; |
62 if (error_code_ != OK) | 62 if (error_code_ != OK) |
(...skipping 10 matching lines...) Expand all Loading... |
73 | 73 |
74 ValueStore::WriteResult TestingValueStore::Set( | 74 ValueStore::WriteResult TestingValueStore::Set( |
75 WriteOptions options, const base::DictionaryValue& settings) { | 75 WriteOptions options, const base::DictionaryValue& settings) { |
76 write_count_++; | 76 write_count_++; |
77 if (error_code_ != OK) | 77 if (error_code_ != OK) |
78 return MakeWriteResult(TestingError()); | 78 return MakeWriteResult(TestingError()); |
79 | 79 |
80 scoped_ptr<ValueStoreChangeList> changes(new ValueStoreChangeList()); | 80 scoped_ptr<ValueStoreChangeList> changes(new ValueStoreChangeList()); |
81 for (base::DictionaryValue::Iterator it(settings); | 81 for (base::DictionaryValue::Iterator it(settings); |
82 !it.IsAtEnd(); it.Advance()) { | 82 !it.IsAtEnd(); it.Advance()) { |
83 base::Value* old_value = NULL; | 83 base::Value* old_value = nullptr; |
84 if (!storage_.GetWithoutPathExpansion(it.key(), &old_value) || | 84 if (!storage_.GetWithoutPathExpansion(it.key(), &old_value) || |
85 !old_value->Equals(&it.value())) { | 85 !old_value->Equals(&it.value())) { |
86 changes->push_back( | 86 changes->push_back( |
87 ValueStoreChange( | 87 ValueStoreChange( |
88 it.key(), | 88 it.key(), |
89 old_value ? old_value->DeepCopy() : old_value, | 89 old_value ? old_value->DeepCopy() : old_value, |
90 it.value().DeepCopy())); | 90 it.value().DeepCopy())); |
91 storage_.SetWithoutPathExpansion(it.key(), it.value().DeepCopy()); | 91 storage_.SetWithoutPathExpansion(it.key(), it.value().DeepCopy()); |
92 } | 92 } |
93 } | 93 } |
94 return MakeWriteResult(changes.Pass()); | 94 return MakeWriteResult(changes.Pass()); |
95 } | 95 } |
96 | 96 |
97 ValueStore::WriteResult TestingValueStore::Remove(const std::string& key) { | 97 ValueStore::WriteResult TestingValueStore::Remove(const std::string& key) { |
98 return Remove(std::vector<std::string>(1, key)); | 98 return Remove(std::vector<std::string>(1, key)); |
99 } | 99 } |
100 | 100 |
101 ValueStore::WriteResult TestingValueStore::Remove( | 101 ValueStore::WriteResult TestingValueStore::Remove( |
102 const std::vector<std::string>& keys) { | 102 const std::vector<std::string>& keys) { |
103 write_count_++; | 103 write_count_++; |
104 if (error_code_ != OK) | 104 if (error_code_ != OK) |
105 return MakeWriteResult(TestingError()); | 105 return MakeWriteResult(TestingError()); |
106 | 106 |
107 scoped_ptr<ValueStoreChangeList> changes(new ValueStoreChangeList()); | 107 scoped_ptr<ValueStoreChangeList> changes(new ValueStoreChangeList()); |
108 for (std::vector<std::string>::const_iterator it = keys.begin(); | 108 for (std::vector<std::string>::const_iterator it = keys.begin(); |
109 it != keys.end(); ++it) { | 109 it != keys.end(); ++it) { |
110 scoped_ptr<base::Value> old_value; | 110 scoped_ptr<base::Value> old_value; |
111 if (storage_.RemoveWithoutPathExpansion(*it, &old_value)) { | 111 if (storage_.RemoveWithoutPathExpansion(*it, &old_value)) { |
112 changes->push_back(ValueStoreChange(*it, old_value.release(), NULL)); | 112 changes->push_back(ValueStoreChange(*it, old_value.release(), nullptr)); |
113 } | 113 } |
114 } | 114 } |
115 return MakeWriteResult(changes.Pass()); | 115 return MakeWriteResult(changes.Pass()); |
116 } | 116 } |
117 | 117 |
118 ValueStore::WriteResult TestingValueStore::Clear() { | 118 ValueStore::WriteResult TestingValueStore::Clear() { |
119 std::vector<std::string> keys; | 119 std::vector<std::string> keys; |
120 for (base::DictionaryValue::Iterator it(storage_); | 120 for (base::DictionaryValue::Iterator it(storage_); |
121 !it.IsAtEnd(); it.Advance()) { | 121 !it.IsAtEnd(); it.Advance()) { |
122 keys.push_back(it.key()); | 122 keys.push_back(it.key()); |
123 } | 123 } |
124 return Remove(keys); | 124 return Remove(keys); |
125 } | 125 } |
126 | 126 |
127 bool TestingValueStore::Restore() { | 127 bool TestingValueStore::Restore() { |
128 return true; | 128 return true; |
129 } | 129 } |
130 | 130 |
131 bool TestingValueStore::RestoreKey(const std::string& key) { | 131 bool TestingValueStore::RestoreKey(const std::string& key) { |
132 return true; | 132 return true; |
133 } | 133 } |
134 | 134 |
135 scoped_ptr<ValueStore::Error> TestingValueStore::TestingError() { | 135 scoped_ptr<ValueStore::Error> TestingValueStore::TestingError() { |
136 return make_scoped_ptr(new ValueStore::Error( | 136 return make_scoped_ptr(new ValueStore::Error( |
137 error_code_, kGenericErrorMessage, scoped_ptr<std::string>())); | 137 error_code_, kGenericErrorMessage, scoped_ptr<std::string>())); |
138 } | 138 } |
OLD | NEW |