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 |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/value_store/value_store_change.h" | 13 #include "chrome/browser/value_store/value_store_change.h" |
14 | 14 |
15 // Interface for a storage area for Value objects. | 15 // Interface for a storage area for Value objects. |
16 class ValueStore { | 16 class ValueStore { |
17 public: | 17 public: |
18 // The result of a read operation (Get). | 18 // The result of a read operation (Get). |
19 class ReadResultType { | 19 class ReadResultType { |
20 public: | 20 public: |
21 // Ownership of |settings| taken. | 21 // Ownership of |settings| taken. |
22 explicit ReadResultType(DictionaryValue* settings); | 22 explicit ReadResultType(base::DictionaryValue* settings); |
23 explicit ReadResultType(const std::string& error); | 23 explicit ReadResultType(const std::string& error); |
24 ~ReadResultType(); | 24 ~ReadResultType(); |
25 | 25 |
26 // Gets the settings read from the storage. Note that this represents | 26 // Gets the settings read from the storage. Note that this represents |
27 // the root object. If you request the value for key "foo", that value will | 27 // the root object. If you request the value for key "foo", that value will |
28 // be in |settings.foo|. | 28 // be in |settings.foo|. |
29 // Must only be called if HasError() is false. | 29 // Must only be called if HasError() is false. |
30 scoped_ptr<DictionaryValue>& settings(); | 30 scoped_ptr<base::DictionaryValue>& settings(); |
31 | 31 |
32 // Gets whether the operation failed. | 32 // Gets whether the operation failed. |
33 bool HasError() const; | 33 bool HasError() const; |
34 | 34 |
35 // Gets the error message describing the failure. | 35 // Gets the error message describing the failure. |
36 // Must only be called if HasError() is true. | 36 // Must only be called if HasError() is true. |
37 const std::string& error() const; | 37 const std::string& error() const; |
38 | 38 |
39 private: | 39 private: |
40 scoped_ptr<DictionaryValue> settings_; | 40 scoped_ptr<base::DictionaryValue> settings_; |
41 const std::string error_; | 41 const std::string error_; |
42 | 42 |
43 DISALLOW_COPY_AND_ASSIGN(ReadResultType); | 43 DISALLOW_COPY_AND_ASSIGN(ReadResultType); |
44 }; | 44 }; |
45 typedef scoped_ptr<ReadResultType> ReadResult; | 45 typedef scoped_ptr<ReadResultType> ReadResult; |
46 | 46 |
47 // The result of a write operation (Set/Remove/Clear). | 47 // The result of a write operation (Set/Remove/Clear). |
48 class WriteResultType { | 48 class WriteResultType { |
49 public: | 49 public: |
50 // Ownership of |changes| taken. | 50 // Ownership of |changes| taken. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 // Gets a single value from storage. | 117 // Gets a single value from storage. |
118 virtual ReadResult Get(const std::string& key) = 0; | 118 virtual ReadResult Get(const std::string& key) = 0; |
119 | 119 |
120 // Gets multiple values from storage. | 120 // Gets multiple values from storage. |
121 virtual ReadResult Get(const std::vector<std::string>& keys) = 0; | 121 virtual ReadResult Get(const std::vector<std::string>& keys) = 0; |
122 | 122 |
123 // Gets all values from storage. | 123 // Gets all values from storage. |
124 virtual ReadResult Get() = 0; | 124 virtual ReadResult Get() = 0; |
125 | 125 |
126 // Sets a single key to a new value. | 126 // Sets a single key to a new value. |
127 virtual WriteResult Set( | 127 virtual WriteResult Set(WriteOptions options, |
128 WriteOptions options, const std::string& key, const Value& value) = 0; | 128 const std::string& key, |
| 129 const base::Value& value) = 0; |
129 | 130 |
130 // Sets multiple keys to new values. | 131 // Sets multiple keys to new values. |
131 virtual WriteResult Set( | 132 virtual WriteResult Set( |
132 WriteOptions options, const DictionaryValue& values) = 0; | 133 WriteOptions options, const base::DictionaryValue& values) = 0; |
133 | 134 |
134 // Removes a key from the storage. | 135 // Removes a key from the storage. |
135 virtual WriteResult Remove(const std::string& key) = 0; | 136 virtual WriteResult Remove(const std::string& key) = 0; |
136 | 137 |
137 // Removes multiple keys from the storage. | 138 // Removes multiple keys from the storage. |
138 virtual WriteResult Remove(const std::vector<std::string>& keys) = 0; | 139 virtual WriteResult Remove(const std::vector<std::string>& keys) = 0; |
139 | 140 |
140 // Clears the storage. | 141 // Clears the storage. |
141 virtual WriteResult Clear() = 0; | 142 virtual WriteResult Clear() = 0; |
142 }; | 143 }; |
143 | 144 |
144 #endif // CHROME_BROWSER_VALUE_STORE_VALUE_STORE_H_ | 145 #endif // CHROME_BROWSER_VALUE_STORE_VALUE_STORE_H_ |
OLD | NEW |