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

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: Removed a CHECK 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 "chrome/browser/extensions/api/declarative/declarative_api_constants.h"
9
10 namespace keys = extensions::declarative_api_constants;
11
12 namespace {
13
14 std::string GetRuleId(DictionaryValue* rule) {
15 std::string rule_id;
16 CHECK(rule->GetString(keys::kId, &rule_id));
17 return rule_id;
18 }
19
20 } // namespace
21
22 namespace extensions {
23
24 TestRulesRegistry::TestRulesRegistry() {}
25
26 TestRulesRegistry::~TestRulesRegistry() {}
27
28 std::string TestRulesRegistry::AddRules(
29 const std::string& extension_id,
30 const std::vector<DictionaryValue*>& rules) {
31 // TODO(battre) this ignores the extension_id but should not.
32 for (std::vector<DictionaryValue*>::const_iterator i =
33 rules.begin(); i != rules.end(); ++i) {
34 std::string rule_id = GetRuleId(*i);
35 // TODO: relax this (check first and abort with returning false).
36 CHECK(rules_.find(rule_id) == rules_.end());
37 rules_[rule_id] = make_linked_ptr((*i)->DeepCopy());
38 }
39 return "";
40 }
41
42 std::string TestRulesRegistry::RemoveRules(
43 const std::string& extension_id,
44 const std::vector<std::string>& rule_identifiers) {
45 // TODO(battre) this ignores the extension_id but should not.
46 for (std::vector<std::string>::const_iterator i =
47 rule_identifiers.begin(); i != rule_identifiers.end(); ++i) {
48 RulesDictionary::iterator entry = rules_.find(*i);
49 // TODO: relax this (check first and abort with returning false).
50 CHECK(entry != rules_.end());
51 rules_.erase(entry);
52 }
53 return "";
54 }
55
56 std::string TestRulesRegistry::RemoveAllRules(const std::string& extension_id) {
57 // TODO(battre) this ignores the extension_id but should not.
58 rules_.clear();
59 return "";
60 }
61
62 std::string TestRulesRegistry::GetRules(
63 const std::string& extension_id,
64 const std::vector<std::string>& rule_identifiers,
65 std::vector<DictionaryValue*>* out) {
66 // TODO(battre) this ignores the extension_id but should not.
67 for (std::vector<std::string>::const_iterator i = rule_identifiers.begin();
68 i != rule_identifiers.end(); ++i) {
69 RulesDictionary::iterator entry = rules_.find(*i);
70 if (entry == rules_.end())
71 return "Rule not found.";
not at google - send to devlin 2012/02/08 22:31:18 probably should declare this as kRuleNotFound or s
72 out->push_back(entry->second->DeepCopy());
73 }
74 return "";
75 }
76
77 std::string TestRulesRegistry::GetAllRules(
78 const std::string& extension_id,
79 std::vector<DictionaryValue*>* out) {
80 // TODO(battre): this ignores the extension_id.
81 for (RulesDictionary::const_iterator i = rules_.begin();
82 i != rules_.end(); ++i)
83 out->push_back(i->second->DeepCopy());
84 return "";
85 }
86
87 void TestRulesRegistry::OnExtensionUnloaded(const std::string& extension_id) {
88 std::vector<std::string> no_rule_identifiers;
89 std::string error = RemoveRules(extension_id, no_rule_identifiers);
90 if (!error.empty())
91 LOG(ERROR) << error;
92 }
93
94 } // 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