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

Unified Diff: chrome/browser/extensions/extension_settings.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.h
diff --git a/chrome/browser/extensions/extension_settings.h b/chrome/browser/extensions/extension_settings.h
new file mode 100644
index 0000000000000000000000000000000000000000..c8bb296f43a42ffe0a4a18055eda5d7176a11051
--- /dev/null
+++ b/chrome/browser/extensions/extension_settings.h
@@ -0,0 +1,55 @@
+// 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_H_
+#define CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_H_
+#pragma once
+
+#include "base/file_path.h"
+#include "chrome/browser/extensions/extension_settings_storage.h"
Mihai Parparita -not on Chrome 2011/06/21 23:40:11 Can you just forward declare ExtensionSettingsStor
not at google - send to devlin 2011/06/22 09:40:38 Done.
+#include "third_party/leveldb/include/leveldb/db.h"
Mihai Parparita -not on Chrome 2011/06/21 23:40:11 Doesn't seem like you need this include at all.
not at google - send to devlin 2011/06/22 09:40:38 Done.
+
+// Manages ExtensionSettingsStorage objects for extensions.
+class ExtensionSettings {
+ public:
+ // File path is the base of the extension settings directory.
+ // The databases will be at base_path/extension_id.
+ explicit ExtensionSettings(const FilePath& base_path);
+ ~ExtensionSettings();
+
+ // Callback for the GetStorage() methods. The callback will always be Run()
+ // from a PostMessage to the UI thread, even if the storage area is cached.
+ class Callback {
+ public:
+ virtual ~Callback() {}
+
+ // Called when the storage area is available. Ownership of the object
+ // remains with the ExtensionSettings object.
+ virtual void Run(ExtensionSettingsStorage* storage) = 0;
+ };
+
+ // Gets the storage area for a given extension.
+ // By default this will be of type LEVELDB|CACHED, but on failure to create
+ // a leveldb instance will fall back to NOOP|CACHED.
Mihai Parparita -not on Chrome 2011/06/21 23:40:11 I'm not sure that the fallback behavior is a great
not at google - send to devlin 2011/06/22 09:40:38 What should the failure behaviour be then? Just e
+ // Callback objects will be deleted when used.
+ void GetStorage(const std::string& extension_id, Callback* callback);
+
+ // Gets a storage area for a given extension, with a specific type, either
+ // NOOP, LEVELDB, NOOP|CACHED, or LEVELDB|CACHED.
+ // Use this for testing; if the given type fails to be created (e.g. if
+ // leveldb creation fails) then a DCHECK will fail.
+ // Callback objects will be deleted when used.
+ void GetStorageForTesting(int type, const std::string& extension_id,
+ Callback* callback);
+
+ private:
Mihai Parparita -not on Chrome 2011/06/21 23:40:11 Should add DISALLOW_COPY_AND_ASSIGN.
not at google - send to devlin 2011/06/22 09:40:38 Done.
+ // Attempts to get and callback with an existing storage area. Returns
+ // whether storage existed and the callback run.
+ bool GetExistingStorage(const std::string& extension_id, Callback* callback);
+
+ const FilePath base_path_;
+ std::map<std::string, ExtensionSettingsStorage*> storage_objs_;
+};
+
+#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_H_

Powered by Google App Engine
This is Rietveld 408576698