summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_settings_storage.h
diff options
context:
space:
mode:
authorkalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-10 09:24:20 +0000
committerkalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-10 09:24:20 +0000
commitb7f853e287243acb1ab3a381eb8559ad0fc199ef (patch)
tree0aae6c2cb39fbe19f5eb55ec5a3018f8bc980b0f /chrome/browser/extensions/extension_settings_storage.h
parent36ae85801ef391088be39b770228e4aafa7dbd74 (diff)
downloadchromium_src-b7f853e287243acb1ab3a381eb8559ad0fc199ef.zip
chromium_src-b7f853e287243acb1ab3a381eb8559ad0fc199ef.tar.gz
chromium_src-b7f853e287243acb1ab3a381eb8559ad0fc199ef.tar.bz2
Implement an initial extension settings API.
Some general notes: - It's a lot of code for a single review, about 1.5K lines (plus tests, plus those generated docs, = 3.5K). Apologies. But it's close to the minimal amount of useful functionality. I've left some TODOs in the code to fix up soon. - No integration-style tests, but I'll start writing those now. Works from within a browser though. - Sync not hooked up yet, of course. - Ditto events. - Ditto thinking about incognito mode. - Ditto fun bugs like what happens if you set key "foo.bar" to "baz". - This is the first significant amount of C++ code I've ever written... so don't hold back. - The docs (i.e. my changes to extension_api.json) are a little incomplete, and I'm aware of that. A summary of the implementation: - There is an ExtensionSettings factory-type object which hands out ExtensionSettingsStorage areas for extensions. You may notice that I basically did the same thing that ExtensionPreferences does (so, lives with the profile, etc). - ExtensionSettingsStorage is a pure interface, with three implementations. - the main leveldb implementation. - a caching decorator, designed to sit on top of the leveldb implementation. - a "no-op" implementation which gives a trivial in-memory storage area when wrapped with a cache. This is used in the cases where the leveldb database fails to initialise (ExtensionSettings handles this). - and note that my plan is, when hooking up sync, that this will be implemented as another decorator. - ... the code is pretty well documented so not much else to say. For testing, turns out gtest is pretty snazzy. There are a bunch of test fixtrues in extension_settings_storage_unittest.h, so that 3 different configurations are tested: leveldb, leveldb + cache, and no-op + cache. BUG=47327 TEST=unit tests provided Review URL: http://codereview.chromium.org/7189029 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96159 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_settings_storage.h')
-rw-r--r--chrome/browser/extensions/extension_settings_storage.h83
1 files changed, 83 insertions, 0 deletions
diff --git a/chrome/browser/extensions/extension_settings_storage.h b/chrome/browser/extensions/extension_settings_storage.h
new file mode 100644
index 0000000..b1542c4
--- /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;
+ };
+
+ // The different types of extension settings storage.
+ enum Type {
+ NONE,
+ NOOP,
+ LEVELDB
+ };
+
+ virtual ~ExtensionSettingsStorage() {}
+
+ // Destroys this settings storage object. This is needed as a separate
+ // interface method as opposed to just using the destructor, since
+ // destruction may need to be done asynchronously (e.g. on the FILE thread).
+ virtual void DeleteSoon() = 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_