OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_STORAGE_H_ | |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_STORAGE_H_ | |
7 #pragma once | |
8 | |
9 #include "base/values.h" | |
10 | |
11 // Interface for extension settings storage classes. | |
12 // | |
13 // All asynchrous methods *must* run in a message loop, i.e. the callbacks may | |
14 // not be run from the calling method, but must be PostTask'ed (whether to | |
15 // one's own thread or to e.g. the FILE thread). | |
16 class ExtensionSettingsStorage { | |
17 public: | |
18 // Asynchronous results of Set/Get/Remove. Exactly one of OnSuccess or | |
19 // OnFailure will eventually be called. | |
20 // Callback objects will be deleted after running. | |
21 class Callback { | |
22 public: | |
23 virtual ~Callback() {} | |
24 | |
25 // Indicates the storage operation was successful. Settings value will be | |
26 // non-NULL. Ownership is passed to the callback. | |
27 virtual void OnSuccess(DictionaryValue* settings) = 0; | |
28 | |
29 // Indicates the storage operation failed. Messages describes the failure. | |
30 virtual void OnFailure(const std::string& message) = 0; | |
31 }; | |
32 | |
33 virtual ~ExtensionSettingsStorage() {} | |
34 | |
35 // The different types of extension settings storage, designed to be | |
Mihai Parparita -not on Chrome
2011/06/21 23:40:11
It doesn't quite make sense for all these to be in
not at google - send to devlin
2011/06/22 09:40:38
Done. The type() method wasn't really necessary e
| |
36 // expressed as a bitmask when returned from type(). | |
37 enum Type { | |
38 NOOP = 1 << 0, | |
39 LEVELDB = 1 << 1, | |
40 CACHED = 1 << 2 | |
41 }; | |
42 | |
43 // Gets the type, as a bitmask of Types. | |
44 // For example, a cached NOOP storage will have type NOOP|CACHED. | |
45 virtual int type() = 0; | |
46 | |
47 // Gets a single value from storage. Callback with a dictionary mapping the | |
48 // key to its value, if any. | |
49 virtual void Get(const std::string& key, Callback* callback) = 0; | |
50 | |
51 // Gets multiple values from storage. Callback with a dictionary mapping | |
52 // each key to its value, if any. | |
53 virtual void Get(const ListValue& keys, Callback* callback) = 0; | |
54 | |
55 // Gets all values from storage. Callback with a dictionary mapping every | |
56 // key to its value. | |
57 virtual void Get(Callback* callback) = 0; | |
58 | |
59 // Sets a single key to a new value. Callback with a dictionary mapping the | |
60 // key to its new value; on success, this is guaranteed to be the given key | |
61 // to the given new value. | |
62 virtual void Set(const std::string& key, const Value& value, | |
63 Callback* callback) = 0; | |
64 | |
65 // Sets multiple keys to new values. Callback with a dictionary mapping each | |
66 // key to its new value; on success, this is guaranteed to be each given key | |
67 // to its given new value. | |
68 virtual void Set(const DictionaryValue& values, Callback* callback) = 0; | |
69 | |
70 // Removes a key from the map. Callback with a dictionary mapping the key | |
71 // to its new value; on success, this will be an empty map. | |
72 virtual void Remove(const std::string& key, Callback* callback) = 0; | |
73 | |
74 // Removes multiple keys from the map. Callback with a dictionary mapping | |
75 // each key to its new value; on success, this will be an empty map. | |
76 virtual void Remove(const ListValue& keys, Callback* callback) = 0; | |
77 | |
78 // Clears the storage. Callback with a dictionary mapping every key in | |
79 // storage to its value; on success, this will be an empty map. | |
80 virtual void Clear(Callback *callback) = 0; | |
81 }; | |
82 | |
83 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_STORAGE_H_ | |
OLD | NEW |