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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 #include "chrome/browser/extensions/state_store.h"
6
7 #include "chrome/common/chrome_notification_types.h"
8 #include "chrome/common/extensions/extension.h"
9 #include "content/public/browser/notification_service.h"
10 #include "content/public/browser/notification_types.h"
11
12 namespace {
13
14 std::string GetFullKey(const std::string& extension_id,
15 const std::string& key) {
16 return extension_id + "." + key;
17 }
18
19 } // namespace
20
21 namespace extensions {
22
23 StateStore::StateStore(Profile* profile, const FilePath& db_path)
24 : store_(db_path) {
25 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED,
26 content::Source<Profile>(profile));
27 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
28 content::Source<Profile>(profile));
29 }
30
31 StateStore::~StateStore() {
32 }
33
34 void StateStore::RegisterKey(const std::string& key) {
35 registered_keys_.insert(key);
36 }
37
38 void StateStore::GetExtensionValue(const std::string& extension_id,
39 const std::string& key,
40 ReadCallback callback) {
41 store_.Get(GetFullKey(extension_id, key), callback);
42 }
43
44 void StateStore::SetExtensionValue(
45 const std::string& extension_id,
46 const std::string& key,
47 scoped_ptr<base::Value> value) {
48 store_.Set(GetFullKey(extension_id, key), value.Pass());
49 }
50
51 void StateStore::Observe(int type,
52 const content::NotificationSource& source,
53 const content::NotificationDetails& details) {
54 std::string extension_id;
55
56 switch (type) {
57 case chrome::NOTIFICATION_EXTENSION_INSTALLED:
58 extension_id = content::Details<const Extension>(details).ptr()->id();
59 break;
60 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED:
61 extension_id =
62 *content::Details<const std::string>(details).ptr();
63 break;
64 default:
65 NOTREACHED();
66 return;
67 }
68
69 for (std::set<std::string>::iterator key = registered_keys_.begin();
70 key != registered_keys_.end(); ++key) {
71 store_.Remove(GetFullKey(extension_id, *key));
72 }
73 }
74
75 } // namespace extensions
OLDNEW
« 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