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

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: Addressed comments 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/logging.h"
8 #include "base/stl_util.h"
9 #include "chrome/browser/extensions/api/declarative/initializing_rules_registry. h"
10
11 namespace extensions {
12
13 RulesRegistryService::RulesRegistryService() {}
14
15 RulesRegistryService::~RulesRegistryService() {}
16
17 void RulesRegistryService::RegisterRulesRegistry(
18 const std::string& event_name,
19 scoped_ptr<RulesRegistry> rule_registry) {
20 DCHECK(rule_registries_.find(event_name) == rule_registries_.end());
21 rule_registries_[event_name] =
22 make_linked_ptr(new InitializingRulesRegistry(rule_registry.Pass()));
23 }
24
25 bool RulesRegistryService::AddRules(
26 const std::string& event_name,
27 const std::string& extension_id,
28 const std::vector<DictionaryValue*>& rules,
29 std::string* error) {
30 if (rule_registries_.find(event_name) == rule_registries_.end()) {
31 *error = "Invalid rules registry";
32 return false;
33 }
34 return rule_registries_[event_name]->AddRules(extension_id, rules, error);
35 }
36
37 bool RulesRegistryService::RemoveRules(
38 const std::string& event_name,
39 const std::string& extension_id,
40 const std::vector<std::string>& rule_identifiers,
41 std::string* error) {
42 if (rule_registries_.find(event_name) == rule_registries_.end()) {
43 *error = "Invalid rules registry";
44 return false;
45 }
46 return rule_registries_[event_name]->RemoveRules(
47 extension_id, rule_identifiers, error);
48 }
49
50 void RulesRegistryService::GetRules(
51 const std::string& event_name,
52 const std::string& extension_id,
53 const std::vector<std::string>& rule_identifiers,
54 std::vector<DictionaryValue*>* out) {
55 if (rule_registries_.find(event_name) == rule_registries_.end())
56 return;
57 rule_registries_[event_name]->GetRules(extension_id, rule_identifiers, out);
58 }
59
60 void RulesRegistryService::OnExtensionUnloaded(
61 const std::string& extension_id) {
62 RulesRegistryMap::iterator i;
63 for (i = rule_registries_.begin(); i != rule_registries_.end(); ++i)
64 i->second->OnExtensionUnloaded(extension_id);
65 }
66
67 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698