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 #ifndef CHROME_BROWSER_VALUE_STORE_VALUE_STORE_H_ | 5 #ifndef CHROME_BROWSER_VALUE_STORE_VALUE_STORE_H_ |
6 #define CHROME_BROWSER_VALUE_STORE_VALUE_STORE_H_ | 6 #define CHROME_BROWSER_VALUE_STORE_VALUE_STORE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 | 70 |
71 // The result of a read operation (Get). | 71 // The result of a read operation (Get). |
72 class ReadResultType { | 72 class ReadResultType { |
73 public: | 73 public: |
74 explicit ReadResultType(scoped_ptr<base::DictionaryValue> settings); | 74 explicit ReadResultType(scoped_ptr<base::DictionaryValue> settings); |
75 explicit ReadResultType(scoped_ptr<Error> error); | 75 explicit ReadResultType(scoped_ptr<Error> error); |
76 ~ReadResultType(); | 76 ~ReadResultType(); |
77 | 77 |
78 bool HasError() const { return error_; } | 78 bool HasError() const { return error_; } |
79 | 79 |
80 bool IsCorruption() const { | |
Matt Perry
2014/02/19 01:34:22
opt: HasCorruption or IsCorrupted would sound bett
Devlin
2014/02/19 17:43:19
I've no preference, but I think Ben originally sug
Devlin
2014/02/19 17:48:52
Done.
| |
81 return error_.get() && error_->code == CORRUPTION; | |
82 } | |
83 | |
80 // Gets the settings read from the storage. Note that this represents | 84 // Gets the settings read from the storage. Note that this represents |
81 // the root object. If you request the value for key "foo", that value will | 85 // the root object. If you request the value for key "foo", that value will |
82 // be in |settings|.|foo|. | 86 // be in |settings|.|foo|. |
83 // | 87 // |
84 // Must only be called if there is no error. | 88 // Must only be called if there is no error. |
85 base::DictionaryValue& settings() { return *settings_; } | 89 base::DictionaryValue& settings() { return *settings_; } |
86 scoped_ptr<base::DictionaryValue> PassSettings() { | 90 scoped_ptr<base::DictionaryValue> PassSettings() { |
87 return settings_.Pass(); | 91 return settings_.Pass(); |
88 } | 92 } |
89 | 93 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 WriteOptions options, const base::DictionaryValue& values) = 0; | 188 WriteOptions options, const base::DictionaryValue& values) = 0; |
185 | 189 |
186 // Removes a key from the storage. | 190 // Removes a key from the storage. |
187 virtual WriteResult Remove(const std::string& key) = 0; | 191 virtual WriteResult Remove(const std::string& key) = 0; |
188 | 192 |
189 // Removes multiple keys from the storage. | 193 // Removes multiple keys from the storage. |
190 virtual WriteResult Remove(const std::vector<std::string>& keys) = 0; | 194 virtual WriteResult Remove(const std::vector<std::string>& keys) = 0; |
191 | 195 |
192 // Clears the storage. | 196 // Clears the storage. |
193 virtual WriteResult Clear() = 0; | 197 virtual WriteResult Clear() = 0; |
198 | |
199 // In the event of corruption, the ValueStore should be able to restore | |
200 // itself. This means deleting local corrupted files. If only a few keys are | |
201 // corrupted, then some of the database may be saved. If the full database is | |
202 // corrupted, this will erase it in its entirety. | |
203 // Returns true on success, false on failure. The only way this will fail is | |
204 // if we also cannot delete the database file. | |
205 // Note: This method needs to read (and possibly delete) the whole database, | |
206 // so it is slow and should be used sparingly. | |
207 // Note: This method (and the following RestoreKey()) are rude, and do not | |
208 // make any logs, track changes, or other generally polite things. Please do | |
209 // not use these as substitutes for Clear() and Remove(). | |
210 virtual bool Restore() = 0; | |
211 | |
212 // Similar to Restore(), but for only a particular key. If the key is corrupt, | |
213 // this will forcefully remove the key. It does not look at the database on | |
214 // the whole, which makes it faster, but does not guarantee there is no | |
215 // additional corruption. | |
216 // Returns true on success, and false on failure. If false, the next step is | |
217 // probably to Restore() the whole database. | |
218 virtual bool RestoreKey(const std::string& key) = 0; | |
194 }; | 219 }; |
195 | 220 |
196 #endif // CHROME_BROWSER_VALUE_STORE_VALUE_STORE_H_ | 221 #endif // CHROME_BROWSER_VALUE_STORE_VALUE_STORE_H_ |
OLD | NEW |