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

Unified Diff: chrome/browser/extensions/state_store.cc

Issue 10545128: Unrevert r141537: Add extensions::StateStore and use that instead of (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix.crash Created 8 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
« no previous file with comments | « chrome/browser/extensions/state_store.h ('k') | chrome/browser/extensions/test_extension_system.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/state_store.cc
diff --git a/chrome/browser/extensions/state_store.cc b/chrome/browser/extensions/state_store.cc
new file mode 100644
index 0000000000000000000000000000000000000000..69d432e3d4fdb1d981ec3c480c570041b9137296
--- /dev/null
+++ b/chrome/browser/extensions/state_store.cc
@@ -0,0 +1,75 @@
+// Copyright (c) 2012 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.
+
+#include "chrome/browser/extensions/state_store.h"
+
+#include "chrome/common/chrome_notification_types.h"
+#include "chrome/common/extensions/extension.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/browser/notification_types.h"
+
+namespace {
+
+std::string GetFullKey(const std::string& extension_id,
+ const std::string& key) {
+ return extension_id + "." + key;
+}
+
+} // namespace
+
+namespace extensions {
+
+StateStore::StateStore(Profile* profile, const FilePath& db_path)
+ : store_(db_path) {
+ registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED,
+ content::Source<Profile>(profile));
+ registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
+ content::Source<Profile>(profile));
+}
+
+StateStore::~StateStore() {
+}
+
+void StateStore::RegisterKey(const std::string& key) {
+ registered_keys_.insert(key);
+}
+
+void StateStore::GetExtensionValue(const std::string& extension_id,
+ const std::string& key,
+ ReadCallback callback) {
+ store_.Get(GetFullKey(extension_id, key), callback);
+}
+
+void StateStore::SetExtensionValue(
+ const std::string& extension_id,
+ const std::string& key,
+ scoped_ptr<base::Value> value) {
+ store_.Set(GetFullKey(extension_id, key), value.Pass());
+}
+
+void StateStore::Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ std::string extension_id;
+
+ switch (type) {
+ case chrome::NOTIFICATION_EXTENSION_INSTALLED:
+ extension_id = content::Details<const Extension>(details).ptr()->id();
+ break;
+ case chrome::NOTIFICATION_EXTENSION_UNINSTALLED:
+ extension_id =
+ *content::Details<const std::string>(details).ptr();
+ break;
+ default:
+ NOTREACHED();
+ return;
+ }
+
+ for (std::set<std::string>::iterator key = registered_keys_.begin();
+ key != registered_keys_.end(); ++key) {
+ store_.Remove(GetFullKey(extension_id, *key));
+ }
+}
+
+} // namespace extensions
« no previous file with comments | « chrome/browser/extensions/state_store.h ('k') | chrome/browser/extensions/test_extension_system.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698