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 IsCorrupted() const { | |
81 return error_.get() && error_->code == CORRUPTION; | |
82 } | |
83 | |
84 // Gets the settings read from the storage. Note that this represents | 80 // Gets the settings read from the storage. Note that this represents |
85 // the root object. If you request the value for key "foo", that value will | 81 // the root object. If you request the value for key "foo", that value will |
86 // be in |settings|.|foo|. | 82 // be in |settings|.|foo|. |
87 // | 83 // |
88 // Must only be called if there is no error. | 84 // Must only be called if there is no error. |
89 base::DictionaryValue& settings() { return *settings_; } | 85 base::DictionaryValue& settings() { return *settings_; } |
90 scoped_ptr<base::DictionaryValue> PassSettings() { | 86 scoped_ptr<base::DictionaryValue> PassSettings() { |
91 return settings_.Pass(); | 87 return settings_.Pass(); |
92 } | 88 } |
93 | 89 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 WriteOptions options, const base::DictionaryValue& values) = 0; | 184 WriteOptions options, const base::DictionaryValue& values) = 0; |
189 | 185 |
190 // Removes a key from the storage. | 186 // Removes a key from the storage. |
191 virtual WriteResult Remove(const std::string& key) = 0; | 187 virtual WriteResult Remove(const std::string& key) = 0; |
192 | 188 |
193 // Removes multiple keys from the storage. | 189 // Removes multiple keys from the storage. |
194 virtual WriteResult Remove(const std::vector<std::string>& keys) = 0; | 190 virtual WriteResult Remove(const std::vector<std::string>& keys) = 0; |
195 | 191 |
196 // Clears the storage. | 192 // Clears the storage. |
197 virtual WriteResult Clear() = 0; | 193 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 may be expensive; some implementations may need to read | |
206 // the entire database to restore. Use 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; | |
219 }; | 194 }; |
220 | 195 |
221 #endif // CHROME_BROWSER_VALUE_STORE_VALUE_STORE_H_ | 196 #endif // CHROME_BROWSER_VALUE_STORE_VALUE_STORE_H_ |
OLD | NEW |