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

Side by Side Diff: chrome/browser/extensions/api/declarative/rules_registry_service.cc

Issue 9315010: RulesRegistry for declarative APIs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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/api/declarative/rules_registry_service.h"
6
7 #include "base/callback.h"
8 #include "base/logging.h"
9 #include "base/stl_util.h"
10 #include "chrome/common/chrome_notification_types.h"
11 #include "chrome/common/extensions/extension.h"
12 #include "content/public/browser/notification_details.h"
13 #include "content/public/browser/notification_source.h"
14
15 namespace extensions {
16
17 RulesRegistryService::RulesRegistryService() {
18 }
19
20 RulesRegistryService::~RulesRegistryService() {
21 STLDeleteContainerPairSecondPointers(
22 rule_registries_.begin(), rule_registries_.end());
23 }
24
25 void RulesRegistryService::Init(Profile* profile) {
26 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
27 content::Source<Profile>(profile));
28
29 // TODO(battre): Register various rules registries here.
30 // RegisterRuleRegistry("chrome.net", new FoobarRulesRegistry());
31 }
32
33 void RulesRegistryService::RegisterRuleRegistry(
34 const std::string& event_name,
35 scoped_ptr<RulesRegistry> rule_registry) {
36 DCHECK(rule_registries_.find(event_name) == rule_registries_.end());
37 rule_registries_[event_name] = rule_registry.release();
38 }
39
40 bool RulesRegistryService::AddRules(
41 const std::string& event_name,
42 const std::string& extension_id,
43 const std::vector<DictionaryValue*>& rules,
44 RulesRegistry::SetErrorCallback set_error_callback) {
45 DCHECK(rule_registries_.find(event_name) != rule_registries_.end());
46 // TODO(battre): Ensure that rules IDs are unique.
47 return rule_registries_[event_name]->AddRules(
48 extension_id, rules, set_error_callback);
49 }
50
51 bool RulesRegistryService::RemoveRules(
52 const std::string& event_name,
53 const std::string& extension_id,
54 const std::vector<std::string>& rule_identifiers,
55 RulesRegistry::SetErrorCallback set_error_callback) {
56 DCHECK(rule_registries_.find(event_name) != rule_registries_.end());
57 return rule_registries_[event_name]->RemoveRules(
58 extension_id, rule_identifiers, set_error_callback);
59 }
60
61 void RulesRegistryService::GetRules(
62 const std::string& event_name,
63 const std::string& extension_id,
64 const std::vector<std::string>& rule_identifiers,
65 std::vector<DictionaryValue*>* out) {
66 DCHECK(rule_registries_.find(event_name) != rule_registries_.end());
67 rule_registries_[event_name]->GetRules(extension_id, rule_identifiers, out);
68 }
69
70 void RulesRegistryService::OnExtensionUnloaded(
71 const std::string& extension_id) {
72 RulesRegistryMap::iterator i;
73 for (i = rule_registries_.begin(); i != rule_registries_.end(); ++i)
74 i->second->OnExtensionUnloaded(extension_id);
75 }
76
77 void RulesRegistryService::Observe(
78 int type,
79 const content::NotificationSource& source,
80 const content::NotificationDetails& details) {
81 switch (type) {
82 case chrome::NOTIFICATION_EXTENSION_UNLOADED: {
83 const Extension* extension =
84 content::Details<UnloadedExtensionInfo>(details)->extension;
85 OnExtensionUnloaded(extension->id());
86 break;
87 }
88 default:
89 NOTREACHED();
90 }
91 }
92
93 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698