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

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

Issue 9422003: Migrate Declarative API bindings to new JSON objects generated by JSON compiler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed function naming 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/api/declarative/test_rules_registry.h" 5 #include "chrome/browser/extensions/api/declarative/test_rules_registry.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/extensions/api/declarative/declarative_api_constants.h" 9 #include "chrome/browser/extensions/api/declarative/declarative_api_constants.h"
10 10
11 namespace keys = extensions::declarative_api_constants; 11 namespace keys = extensions::declarative_api_constants;
12 12
13 namespace { 13 namespace {
14 14
15 const char kSuccess[] = ""; 15 const char kSuccess[] = "";
16 const char kRuleNotFound[] = "Rule not found."; 16 const char kRuleNotFound[] = "Rule not found.";
17 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 18 } // namespace
25 19
26 namespace extensions { 20 namespace extensions {
27 21
28 TestRulesRegistry::TestRulesRegistry() {} 22 TestRulesRegistry::TestRulesRegistry() {}
29 23
30 TestRulesRegistry::~TestRulesRegistry() {} 24 TestRulesRegistry::~TestRulesRegistry() {}
31 25
32 std::string TestRulesRegistry::AddRules( 26 std::string TestRulesRegistry::AddRules(
33 const std::string& extension_id, 27 const std::string& extension_id,
34 const std::vector<DictionaryValue*>& rules) { 28 const std::vector<linked_ptr<Rule> >& rules) {
35 // TODO(battre) this ignores the extension_id but should not. 29 // TODO(battre) this ignores the extension_id but should not.
36 for (std::vector<DictionaryValue*>::const_iterator i = 30 for (std::vector<linked_ptr<Rule> >::const_iterator i =
37 rules.begin(); i != rules.end(); ++i) { 31 rules.begin(); i != rules.end(); ++i) {
38 std::string rule_id = GetRuleId(*i); 32 std::string rule_id = *((*i)->id);
39 // TODO: relax this (check first and abort with returning false). 33 // TODO: relax this (check first and abort with returning false).
40 CHECK(rules_.find(rule_id) == rules_.end()); 34 CHECK(rules_.find(rule_id) == rules_.end());
41 rules_[rule_id] = make_linked_ptr((*i)->DeepCopy()); 35 rules_[rule_id] = *i;
42 } 36 }
43 return kSuccess; 37 return kSuccess;
44 } 38 }
45 39
46 std::string TestRulesRegistry::RemoveRules( 40 std::string TestRulesRegistry::RemoveRules(
47 const std::string& extension_id, 41 const std::string& extension_id,
48 const std::vector<std::string>& rule_identifiers) { 42 const std::vector<std::string>& rule_identifiers) {
49 // TODO(battre) this ignores the extension_id but should not. 43 // TODO(battre) this ignores the extension_id but should not.
50 for (std::vector<std::string>::const_iterator i = 44 for (std::vector<std::string>::const_iterator i =
51 rule_identifiers.begin(); i != rule_identifiers.end(); ++i) { 45 rule_identifiers.begin(); i != rule_identifiers.end(); ++i) {
52 RulesDictionary::iterator entry = rules_.find(*i); 46 RulesDictionary::iterator entry = rules_.find(*i);
53 // TODO: relax this (check first and abort with returning false). 47 // TODO: relax this (check first and abort with returning false).
54 CHECK(entry != rules_.end()); 48 CHECK(entry != rules_.end());
55 rules_.erase(entry); 49 rules_.erase(entry);
56 } 50 }
57 return kSuccess; 51 return kSuccess;
58 } 52 }
59 53
60 std::string TestRulesRegistry::RemoveAllRules(const std::string& extension_id) { 54 std::string TestRulesRegistry::RemoveAllRules(const std::string& extension_id) {
61 // TODO(battre) this ignores the extension_id but should not. 55 // TODO(battre) this ignores the extension_id but should not.
62 rules_.clear(); 56 rules_.clear();
63 return kSuccess; 57 return kSuccess;
64 } 58 }
65 59
66 std::string TestRulesRegistry::GetRules( 60 std::string TestRulesRegistry::GetRules(
67 const std::string& extension_id, 61 const std::string& extension_id,
68 const std::vector<std::string>& rule_identifiers, 62 const std::vector<std::string>& rule_identifiers,
69 std::vector<DictionaryValue*>* out) { 63 std::vector<linked_ptr<RulesRegistry::Rule> >* out) {
70 // TODO(battre) this ignores the extension_id but should not. 64 // TODO(battre) this ignores the extension_id but should not.
71 for (std::vector<std::string>::const_iterator i = rule_identifiers.begin(); 65 for (std::vector<std::string>::const_iterator i = rule_identifiers.begin();
72 i != rule_identifiers.end(); ++i) { 66 i != rule_identifiers.end(); ++i) {
73 RulesDictionary::iterator entry = rules_.find(*i); 67 RulesDictionary::iterator entry = rules_.find(*i);
74 if (entry == rules_.end()) 68 if (entry == rules_.end())
75 return kRuleNotFound; 69 return kRuleNotFound;
76 out->push_back(entry->second->DeepCopy()); 70 out->push_back(entry->second);
77 } 71 }
78 return kSuccess; 72 return kSuccess;
79 } 73 }
80 74
81 std::string TestRulesRegistry::GetAllRules( 75 std::string TestRulesRegistry::GetAllRules(
82 const std::string& extension_id, 76 const std::string& extension_id,
83 std::vector<DictionaryValue*>* out) { 77 std::vector<linked_ptr<RulesRegistry::Rule> >* out) {
84 // TODO(battre): this ignores the extension_id. 78 // TODO(battre): this ignores the extension_id.
85 for (RulesDictionary::const_iterator i = rules_.begin(); 79 for (RulesDictionary::const_iterator i = rules_.begin();
86 i != rules_.end(); ++i) 80 i != rules_.end(); ++i)
87 out->push_back(i->second->DeepCopy()); 81 out->push_back(i->second);
88 return kSuccess; 82 return kSuccess;
89 } 83 }
90 84
91 void TestRulesRegistry::OnExtensionUnloaded(const std::string& extension_id) { 85 void TestRulesRegistry::OnExtensionUnloaded(const std::string& extension_id) {
92 std::vector<std::string> no_rule_identifiers; 86 std::vector<std::string> no_rule_identifiers;
93 std::string error = RemoveRules(extension_id, no_rule_identifiers); 87 std::string error = RemoveRules(extension_id, no_rule_identifiers);
94 if (!error.empty()) 88 if (!error.empty())
95 LOG(ERROR) << error; 89 LOG(ERROR) << error;
96 } 90 }
97 91
92 content::BrowserThread::ID TestRulesRegistry::GetOwnerThread() {
93 return content::BrowserThread::UI;
94 }
95
96
98 } // namespace extensions 97 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698