1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
// 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(Profile* profile, ValueStore* value_store)
: store_(value_store) {
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:
case chrome::NOTIFICATION_EXTENSION_UNINSTALLED:
extension_id = content::Details<const Extension>(details).ptr()->id();
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
|