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 "chrome/browser/value_store/testing_value_store.h" | 5 #include "chrome/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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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() { |
| 128 ReadResult result = Get(); |
| 129 std::string previous_key; |
| 130 while (result->IsCorruption()) { |
| 131 if (!result->error().key.get() || *result->error().key == previous_key || |
| 132 !RestoreKey(*result->error().key)) { |
| 133 Clear(); |
| 134 result = Get(); |
| 135 break; |
| 136 } |
| 137 previous_key = *result->error().key; |
| 138 result = Get(); |
| 139 } |
| 140 return !result->IsCorruption(); |
| 141 } |
| 142 |
| 143 bool TestingValueStore::RestoreKey(const std::string& key) { |
| 144 ReadResult result = Get(key); |
| 145 if (result->IsCorruption()) |
| 146 Remove(key); |
| 147 return !Get(key)->IsCorruption(); |
| 148 } |
| 149 |
127 scoped_ptr<ValueStore::Error> TestingValueStore::TestingError() { | 150 scoped_ptr<ValueStore::Error> TestingValueStore::TestingError() { |
128 return make_scoped_ptr(new ValueStore::Error( | 151 return make_scoped_ptr(new ValueStore::Error( |
129 error_code_, kGenericErrorMessage, scoped_ptr<std::string>())); | 152 error_code_, kGenericErrorMessage, scoped_ptr<std::string>())); |
130 } | 153 } |
OLD | NEW |