Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 bool TestRulesRegistry::AddRules( | |
| 29 const std::string& extension_id, | |
| 30 const std::vector<DictionaryValue*>& rules, | |
| 31 std::string* error) { | |
| 32 // TODO(battre) this ignores the extension_id but should not. | |
| 33 for (std::vector<DictionaryValue*>::const_iterator i = | |
| 34 rules.begin(); i != rules.end(); ++i) { | |
| 35 std::string rule_id = GetRuleId(*i); | |
| 36 // TODO: relax this (check first and abort with returning false). | |
| 37 CHECK(rules_.find(rule_id) == rules_.end()); | |
| 38 rules_[rule_id] = make_linked_ptr((*i)->DeepCopy()); | |
| 39 } | |
| 40 return true; | |
| 41 } | |
| 42 | |
| 43 bool TestRulesRegistry::RemoveRules( | |
| 44 const std::string& extension_id, | |
| 45 const std::vector<std::string>& rule_identifiers, | |
| 46 std::string* error) { | |
| 47 // TODO(battre) this ignores the extension_id but should not. | |
| 48 for (std::vector<std::string>::const_iterator i = | |
| 49 rule_identifiers.begin(); i != rule_identifiers.end(); ++i) { | |
| 50 RulesDictionary::iterator entry = rules_.find(*i); | |
| 51 // TODO: relax this (check first and abort with returning false). | |
| 52 CHECK(entry != rules_.end()); | |
| 53 rules_.erase(entry); | |
| 54 } | |
| 55 return true; | |
| 56 } | |
| 57 | |
| 58 bool TestRulesRegistry::RemoveAllRules( | |
| 59 const std::string& extension_id, | |
| 60 std::string* error) { | |
| 61 // TODO(battre) this ignores the extension_id but should not. | |
| 62 rules_.clear(); | |
| 63 return true; | |
| 64 } | |
| 65 | |
| 66 void 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 CHECK(entry != rules_.end()); | |
|
not at google - send to devlin
2012/02/07 23:54:57
not sure, similar comment here as to the NOTREACHE
battre
2012/02/08 12:49:54
Done. (Note though that this is part of the testin
not at google - send to devlin
2012/02/08 22:31:18
Ah, right, of course.
| |
| 75 out->push_back(entry->second->DeepCopy()); | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 void TestRulesRegistry::GetAllRules( | |
| 80 const std::string& extension_id, | |
| 81 std::vector<DictionaryValue*>* out) { | |
| 82 // TODO(battre): this ignores the extension_id. | |
| 83 for (RulesDictionary::const_iterator i = rules_.begin(); | |
| 84 i != rules_.end(); ++i) | |
| 85 out->push_back(i->second->DeepCopy()); | |
| 86 } | |
| 87 | |
| 88 void TestRulesRegistry::OnExtensionUnloaded(const std::string& extension_id) { | |
| 89 std::vector<std::string> no_rule_identifiers; | |
| 90 std::string error; | |
| 91 if (!RemoveRules(extension_id, no_rule_identifiers, &error)) | |
| 92 LOG(ERROR) << error; | |
| 93 } | |
| 94 | |
| 95 } // namespace extensions | |
| OLD | NEW |