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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 const std::vector<std::string>& keys) { | 50 const std::vector<std::string>& keys) { |
51 read_count_++; | 51 read_count_++; |
52 if (!status_.ok()) | 52 if (!status_.ok()) |
53 return MakeReadResult(status_); | 53 return MakeReadResult(status_); |
54 | 54 |
55 base::DictionaryValue* settings = new base::DictionaryValue(); | 55 base::DictionaryValue* settings = new base::DictionaryValue(); |
56 for (std::vector<std::string>::const_iterator it = keys.begin(); | 56 for (std::vector<std::string>::const_iterator it = keys.begin(); |
57 it != keys.end(); ++it) { | 57 it != keys.end(); ++it) { |
58 base::Value* value = NULL; | 58 base::Value* value = NULL; |
59 if (storage_.GetWithoutPathExpansion(*it, &value)) { | 59 if (storage_.GetWithoutPathExpansion(*it, &value)) { |
60 settings->SetWithoutPathExpansion(*it, value->DeepCopy()); | 60 settings->SetWithoutPathExpansion(*it, value->CreateDeepCopy()); |
61 } | 61 } |
62 } | 62 } |
63 return MakeReadResult(base::WrapUnique(settings), status_); | 63 return MakeReadResult(base::WrapUnique(settings), status_); |
64 } | 64 } |
65 | 65 |
66 ValueStore::ReadResult TestingValueStore::Get() { | 66 ValueStore::ReadResult TestingValueStore::Get() { |
67 read_count_++; | 67 read_count_++; |
68 if (!status_.ok()) | 68 if (!status_.ok()) |
69 return MakeReadResult(status_); | 69 return MakeReadResult(status_); |
70 return MakeReadResult(base::WrapUnique(storage_.DeepCopy()), status_); | 70 return MakeReadResult(storage_.CreateDeepCopy(), status_); |
71 } | 71 } |
72 | 72 |
73 ValueStore::WriteResult TestingValueStore::Set( | 73 ValueStore::WriteResult TestingValueStore::Set( |
74 WriteOptions options, const std::string& key, const base::Value& value) { | 74 WriteOptions options, const std::string& key, const base::Value& value) { |
75 base::DictionaryValue settings; | 75 base::DictionaryValue settings; |
76 settings.SetWithoutPathExpansion(key, value.DeepCopy()); | 76 settings.SetWithoutPathExpansion(key, value.CreateDeepCopy()); |
77 return Set(options, settings); | 77 return Set(options, settings); |
78 } | 78 } |
79 | 79 |
80 ValueStore::WriteResult TestingValueStore::Set( | 80 ValueStore::WriteResult TestingValueStore::Set( |
81 WriteOptions options, const base::DictionaryValue& settings) { | 81 WriteOptions options, const base::DictionaryValue& settings) { |
82 write_count_++; | 82 write_count_++; |
83 if (!status_.ok()) | 83 if (!status_.ok()) |
84 return MakeWriteResult(status_); | 84 return MakeWriteResult(status_); |
85 | 85 |
86 std::unique_ptr<ValueStoreChangeList> changes(new ValueStoreChangeList()); | 86 std::unique_ptr<ValueStoreChangeList> changes(new ValueStoreChangeList()); |
87 for (base::DictionaryValue::Iterator it(settings); | 87 for (base::DictionaryValue::Iterator it(settings); |
88 !it.IsAtEnd(); it.Advance()) { | 88 !it.IsAtEnd(); it.Advance()) { |
89 base::Value* old_value = NULL; | 89 base::Value* old_value = NULL; |
90 if (!storage_.GetWithoutPathExpansion(it.key(), &old_value) || | 90 if (!storage_.GetWithoutPathExpansion(it.key(), &old_value) || |
91 !old_value->Equals(&it.value())) { | 91 !old_value->Equals(&it.value())) { |
92 changes->push_back( | 92 changes->push_back(ValueStoreChange( |
93 ValueStoreChange( | 93 it.key(), old_value ? old_value->CreateDeepCopy() : nullptr, |
94 it.key(), | 94 it.value().CreateDeepCopy())); |
95 old_value ? old_value->DeepCopy() : old_value, | 95 storage_.SetWithoutPathExpansion(it.key(), it.value().CreateDeepCopy()); |
96 it.value().DeepCopy())); | |
97 storage_.SetWithoutPathExpansion(it.key(), it.value().DeepCopy()); | |
98 } | 96 } |
99 } | 97 } |
100 return MakeWriteResult(std::move(changes), status_); | 98 return MakeWriteResult(std::move(changes), status_); |
101 } | 99 } |
102 | 100 |
103 ValueStore::WriteResult TestingValueStore::Remove(const std::string& key) { | 101 ValueStore::WriteResult TestingValueStore::Remove(const std::string& key) { |
104 return Remove(std::vector<std::string>(1, key)); | 102 return Remove(std::vector<std::string>(1, key)); |
105 } | 103 } |
106 | 104 |
107 ValueStore::WriteResult TestingValueStore::Remove( | 105 ValueStore::WriteResult TestingValueStore::Remove( |
108 const std::vector<std::string>& keys) { | 106 const std::vector<std::string>& keys) { |
109 write_count_++; | 107 write_count_++; |
110 if (!status_.ok()) | 108 if (!status_.ok()) |
111 return MakeWriteResult(status_); | 109 return MakeWriteResult(status_); |
112 | 110 |
113 std::unique_ptr<ValueStoreChangeList> changes(new ValueStoreChangeList()); | 111 std::unique_ptr<ValueStoreChangeList> changes(new ValueStoreChangeList()); |
114 for (std::vector<std::string>::const_iterator it = keys.begin(); | 112 for (std::vector<std::string>::const_iterator it = keys.begin(); |
115 it != keys.end(); ++it) { | 113 it != keys.end(); ++it) { |
116 std::unique_ptr<base::Value> old_value; | 114 std::unique_ptr<base::Value> old_value; |
117 if (storage_.RemoveWithoutPathExpansion(*it, &old_value)) { | 115 if (storage_.RemoveWithoutPathExpansion(*it, &old_value)) { |
118 changes->push_back(ValueStoreChange(*it, old_value.release(), NULL)); | 116 changes->push_back(ValueStoreChange(*it, std::move(old_value), nullptr)); |
119 } | 117 } |
120 } | 118 } |
121 return MakeWriteResult(std::move(changes), status_); | 119 return MakeWriteResult(std::move(changes), status_); |
122 } | 120 } |
123 | 121 |
124 ValueStore::WriteResult TestingValueStore::Clear() { | 122 ValueStore::WriteResult TestingValueStore::Clear() { |
125 std::vector<std::string> keys; | 123 std::vector<std::string> keys; |
126 for (base::DictionaryValue::Iterator it(storage_); | 124 for (base::DictionaryValue::Iterator it(storage_); |
127 !it.IsAtEnd(); it.Advance()) { | 125 !it.IsAtEnd(); it.Advance()) { |
128 keys.push_back(it.key()); | 126 keys.push_back(it.key()); |
129 } | 127 } |
130 return Remove(keys); | 128 return Remove(keys); |
131 } | 129 } |
OLD | NEW |