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

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

Issue 9315010: RulesRegistry for declarative APIs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed comiler errors 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/test_rules_registry.h"
6
7 #include "base/logging.h"
8 #include "base/values.h"
9 #include "chrome/browser/extensions/api/declarative/declarative_api_constants.h"
10
11 namespace keys = extensions::declarative_api_constants;
12
13 namespace {
14
15 const char kSuccess[] = "";
16 const char kRuleNotFound[] = "Rule not found.";
17
18 std::string GetRuleId(DictionaryValue* rule) {
19 std::string rule_id;
20 CHECK(rule->GetString(keys::kId, &rule_id));
21 return rule_id;
22 }
23
24 } // namespace
25
26 namespace extensions {
27
28 TestRulesRegistry::TestRulesRegistry() {}
29
30 TestRulesRegistry::~TestRulesRegistry() {}
31
32 std::string TestRulesRegistry::AddRules(
33 const std::string& extension_id,
34 const std::vector<DictionaryValue*>& rules) {
35 // TODO(battre) this ignores the extension_id but should not.
36 for (std::vector<DictionaryValue*>::const_iterator i =
37 rules.begin(); i != rules.end(); ++i) {
38 std::string rule_id = GetRuleId(*i);
39 // TODO: relax this (check first and abort with returning false).
40 CHECK(rules_.find(rule_id) == rules_.end());
41 rules_[rule_id] = make_linked_ptr((*i)->DeepCopy());
42 }
43 return kSuccess;
44 }
45
46 std::string TestRulesRegistry::RemoveRules(
47 const std::string& extension_id,
48 const std::vector<std::string>& rule_identifiers) {
49 // TODO(battre) this ignores the extension_id but should not.
50 for (std::vector<std::string>::const_iterator i =
51 rule_identifiers.begin(); i != rule_identifiers.end(); ++i) {
52 RulesDictionary::iterator entry = rules_.find(*i);
53 // TODO: relax this (check first and abort with returning false).
54 CHECK(entry != rules_.end());
55 rules_.erase(entry);
56 }
57 return kSuccess;
58 }
59
60 std::string TestRulesRegistry::RemoveAllRules(const std::string& extension_id) {
61 // TODO(battre) this ignores the extension_id but should not.
62 rules_.clear();
63 return kSuccess;
64 }
65
66 std::string TestRulesRegistry::GetRules(
67 const std::string& extension_id,
68 const std::vector<std::string>& rule_identifiers,
69 std::vector<DictionaryValue*>* out) {
70 // TODO(battre) this ignores the extension_id but should not.
71 for (std::vector<std::string>::const_iterator i = rule_identifiers.begin();
72 i != rule_identifiers.end(); ++i) {
73 RulesDictionary::iterator entry = rules_.find(*i);
74 if (entry == rules_.end())
75 return kRuleNotFound;
76 out->push_back(entry->second->DeepCopy());
77 }
78 return kSuccess;
79 }
80
81 std::string TestRulesRegistry::GetAllRules(
82 const std::string& extension_id,
83 std::vector<DictionaryValue*>* out) {
84 // TODO(battre): this ignores the extension_id.
85 for (RulesDictionary::const_iterator i = rules_.begin();
86 i != rules_.end(); ++i)
87 out->push_back(i->second->DeepCopy());
88 return kSuccess;
89 }
90
91 void TestRulesRegistry::OnExtensionUnloaded(const std::string& extension_id) {
92 std::vector<std::string> no_rule_identifiers;
93 std::string error = RemoveRules(extension_id, no_rule_identifiers);
94 if (!error.empty())
95 LOG(ERROR) << error;
96 }
97
98 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/declarative/test_rules_registry.h ('k') | chrome/browser/extensions/extension_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698