Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1378)

Unified Diff: chrome/browser/extensions/extension_settings_storage.h

Issue 7189029: Implement an initial extension settings API. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Change where extension settings are saved, update TODO, api test Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_settings_storage.h
diff --git a/chrome/browser/extensions/extension_settings_storage.h b/chrome/browser/extensions/extension_settings_storage.h
new file mode 100644
index 0000000000000000000000000000000000000000..365ac4502ea7243bb14fca838ca3f283d342940b
--- /dev/null
+++ b/chrome/browser/extensions/extension_settings_storage.h
@@ -0,0 +1,83 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_STORAGE_H_
+#define CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_STORAGE_H_
+#pragma once
+
+#include "base/values.h"
+
+// Interface for extension settings storage classes.
+//
+// All asynchrous methods *must* run in a message loop, i.e. the callbacks may
+// not be run from the calling method, but must be PostTask'ed (whether to
+// one's own thread or to e.g. the FILE thread).
+class ExtensionSettingsStorage {
+ public:
+ // Asynchronous results of Set/Get/Remove. Exactly one of OnSuccess or
+ // OnFailure will eventually be called.
+ // Callback objects will be deleted after running.
+ class Callback {
+ public:
+ virtual ~Callback() {}
+
+ // Indicates the storage operation was successful. Settings value will be
+ // non-NULL. Ownership is passed to the callback.
+ virtual void OnSuccess(DictionaryValue* settings) = 0;
+
+ // Indicates the storage operation failed. Messages describes the failure.
+ virtual void OnFailure(const std::string& message) = 0;
+ };
+
+ virtual ~ExtensionSettingsStorage() {}
+
+ // 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
+ // expressed as a bitmask when returned from type().
+ enum Type {
+ NOOP = 1 << 0,
+ LEVELDB = 1 << 1,
+ CACHED = 1 << 2
+ };
+
+ // Gets the type, as a bitmask of Types.
+ // For example, a cached NOOP storage will have type NOOP|CACHED.
+ virtual int type() = 0;
+
+ // Gets a single value from storage. Callback with a dictionary mapping the
+ // key to its value, if any.
+ virtual void Get(const std::string& key, Callback* callback) = 0;
+
+ // Gets multiple values from storage. Callback with a dictionary mapping
+ // each key to its value, if any.
+ virtual void Get(const ListValue& keys, Callback* callback) = 0;
+
+ // Gets all values from storage. Callback with a dictionary mapping every
+ // key to its value.
+ virtual void Get(Callback* callback) = 0;
+
+ // Sets a single key to a new value. Callback with a dictionary mapping the
+ // key to its new value; on success, this is guaranteed to be the given key
+ // to the given new value.
+ virtual void Set(const std::string& key, const Value& value,
+ Callback* callback) = 0;
+
+ // Sets multiple keys to new values. Callback with a dictionary mapping each
+ // key to its new value; on success, this is guaranteed to be each given key
+ // to its given new value.
+ virtual void Set(const DictionaryValue& values, Callback* callback) = 0;
+
+ // Removes a key from the map. Callback with a dictionary mapping the key
+ // to its new value; on success, this will be an empty map.
+ virtual void Remove(const std::string& key, Callback* callback) = 0;
+
+ // Removes multiple keys from the map. Callback with a dictionary mapping
+ // each key to its new value; on success, this will be an empty map.
+ virtual void Remove(const ListValue& keys, Callback* callback) = 0;
+
+ // Clears the storage. Callback with a dictionary mapping every key in
+ // storage to its value; on success, this will be an empty map.
+ virtual void Clear(Callback *callback) = 0;
+};
+
+#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_STORAGE_H_

Powered by Google App Engine
This is Rietveld 408576698