OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_EXTENSIONS_EXTENSION_SETTINGS_STORAGE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_STORAGE_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_STORAGE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_STORAGE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 | 10 |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 | 14 |
15 // Interface for extension settings storage classes. | 15 // Interface for extension settings storage classes. |
16 // | 16 // |
17 // All methods *must* be run on the FILE thread, inclusing construction and | 17 // All methods *must* be run on the FILE thread, inclusing construction and |
18 // destructions. | 18 // destructions. |
19 class ExtensionSettingsStorage { | 19 class ExtensionSettingsStorage { |
20 public: | 20 public: |
21 // The result of an operation. | 21 // The result of an operation. |
22 // | 22 // |
23 // Supports lightweight copying. | 23 // Supports lightweight copying. |
24 class Result { | 24 class Result { |
25 public: | 25 public: |
26 // Ownership of |settings| and |changed_keys| taken. | 26 // Ownership of all arguments are taken. |
27 // |settings| may be NULL when the result is for an operation which | 27 // |settings| may be NULL when the result is for an operation which |
28 // generates no setting values (e.g. Remove(), Clear()). | 28 // generates no setting values (e.g. Remove(), Clear()). |
29 // |changed_keys| may be NULL when the result is for an operation which | 29 // |changed_keys| and |old_settings| may be NULL when the result is for an |
30 // cannot change settings (e.g. Get()). | 30 // operation which cannot change settings (e.g. Get()). |
31 Result(DictionaryValue* settings, std::set<std::string>* changed_keys); | 31 Result( |
32 DictionaryValue* settings, | |
33 DictionaryValue* old_settings, | |
34 std::set<std::string>* changed_keys); | |
32 explicit Result(const std::string& error); | 35 explicit Result(const std::string& error); |
33 ~Result(); | 36 ~Result(); |
34 | 37 |
35 // The dictionary result of the computation. NULL does not imply invalid; | 38 // The dictionary result of the computation. NULL does not imply invalid; |
36 // HasError() should be used to test this. | 39 // HasError() should be used to test this. |
37 // Ownership remains with with the Result. | 40 // Ownership remains with this. |
38 DictionaryValue* GetSettings() const; | 41 DictionaryValue* GetSettings() const; |
akalin
2011/10/12 22:26:30
return const pointer?
not at google - send to devlin
2011/10/13 06:40:43
Done.
| |
39 | 42 |
40 // Gets the list of setting keys which changed as a result of the | 43 // Gets the set of setting keys which changed as a result of the |
41 // computation. This includes all settings that existed and removed, all | 44 // computation. This includes all settings that existed and removed, all |
42 // settings which changed when set, and all setting keys cleared. | 45 // settings which changed when set, and all setting keys cleared. May be |
43 // May be NULL for operations which cannot change settings, such as Get(). | 46 // NULL for operations which cannot change settings, such as Get(). |
44 std::set<std::string>* GetChangedKeys() const; | 47 std::set<std::string>* GetChangedKeys() const; |
akalin
2011/10/12 22:26:30
const pointer?
not at google - send to devlin
2011/10/13 06:40:43
Done.
| |
45 | 48 |
49 // Gets the value of a setting prior to the operation which generated | |
50 // this Result, or NULL if the setting had no original value. | |
51 // Ownerships remains with this. | |
52 // Returns false if this Result was from an operation which didn't modify | |
53 // the settings (such as Get()), in which case old_value will be untouched. | |
54 bool GetOldValue(const std::string& key, Value** old_value) const; | |
akalin
2011/10/12 22:26:30
the user of this class doesn't distinguish between
not at google - send to devlin
2011/10/13 06:40:43
Done.
| |
55 | |
56 // Like GetOldValue, but gets the new value. | |
57 bool GetNewValue(const std::string& key, Value** new_value) const; | |
akalin
2011/10/12 22:26:30
here too
not at google - send to devlin
2011/10/13 06:40:43
Done.
| |
58 | |
46 // Whether there was an error in the computation. If so, the results of | 59 // Whether there was an error in the computation. If so, the results of |
47 // GetSettings and ReleaseSettings are not valid. | 60 // GetSettings and ReleaseSettings are not valid. |
48 bool HasError() const; | 61 bool HasError() const; |
49 | 62 |
50 // Gets the error message, if any. | 63 // Gets the error message, if any. |
51 const std::string& GetError() const; | 64 const std::string& GetError() const; |
52 | 65 |
53 private: | 66 private: |
54 struct Inner : public base::RefCountedThreadSafe<Inner> { | 67 struct Inner : public base::RefCountedThreadSafe<Inner> { |
55 // Empty error implies no error. | 68 // Empty error implies no error. |
56 Inner( | 69 Inner( |
57 DictionaryValue* settings, | 70 DictionaryValue* settings, |
71 DictionaryValue* old_settings, | |
58 std::set<std::string>* changed_keys, | 72 std::set<std::string>* changed_keys, |
59 const std::string& error); | 73 const std::string& error); |
60 ~Inner(); | 74 ~Inner(); |
61 | 75 |
62 const scoped_ptr<DictionaryValue> settings_; | 76 const scoped_ptr<DictionaryValue> settings_; |
77 const scoped_ptr<DictionaryValue> old_settings_; | |
63 const scoped_ptr<std::set<std::string> > changed_keys_; | 78 const scoped_ptr<std::set<std::string> > changed_keys_; |
64 const std::string error_; | 79 const std::string error_; |
65 }; | 80 }; |
66 | 81 |
67 const scoped_refptr<Inner> inner_; | 82 const scoped_refptr<Inner> inner_; |
68 }; | 83 }; |
69 | 84 |
70 virtual ~ExtensionSettingsStorage() {} | 85 virtual ~ExtensionSettingsStorage() {} |
71 | 86 |
72 // Gets a single value from storage. | 87 // Gets a single value from storage. |
(...skipping 23 matching lines...) Expand all Loading... | |
96 // Removes multiple keys from the storage. | 111 // Removes multiple keys from the storage. |
97 // If successful, result value is NULL. | 112 // If successful, result value is NULL. |
98 virtual Result Remove(const std::vector<std::string>& keys) = 0; | 113 virtual Result Remove(const std::vector<std::string>& keys) = 0; |
99 | 114 |
100 // Clears the storage. | 115 // Clears the storage. |
101 // If successful, result value is NULL. | 116 // If successful, result value is NULL. |
102 virtual Result Clear() = 0; | 117 virtual Result Clear() = 0; |
103 }; | 118 }; |
104 | 119 |
105 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_STORAGE_H_ | 120 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_STORAGE_H_ |
OLD | NEW |