Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: chrome/browser/value_store/testing_value_store.cc

Issue 165223003: Add a Restore() method to ValueStore and make StorageAPI use it (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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->HasError() && result->error().code == CORRUPTION) {
not at google - send to devlin 2014/02/14 19:35:56 How does this class get corrupted storage? I'm su
Devlin 2014/02/18 23:55:22 Yeah...this might be overkill. My basic thought w
not at google - send to devlin 2014/02/19 21:25:29 Not worth it.
Devlin 2014/02/19 23:12:28 Done.
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->HasError() && result->error().code == CORRUPTION;
141 }
142
143 bool TestingValueStore::RestoreKey(const std::string& key) {
144 ReadResult result = Get(key);
145 if (result->HasError() && result->error().code == CORRUPTION)
146 Remove(key);
147 return Get(key)->HasError();
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698