OLD | NEW |
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_webrequest/webrequest_rules_
registry.h" | 5 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_
registry.h" |
6 | 6 |
7 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condit
ion.h" | 7 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condit
ion.h" |
8 #include "net/url_request/url_request.h" | 8 #include "net/url_request/url_request.h" |
9 | 9 |
10 namespace extensions { | 10 namespace extensions { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 i->second->conditions().GetURLMatcherConditionSets(&all_new_condition_sets); | 88 i->second->conditions().GetURLMatcherConditionSets(&all_new_condition_sets); |
89 } | 89 } |
90 url_matcher_.AddConditionSets(all_new_condition_sets); | 90 url_matcher_.AddConditionSets(all_new_condition_sets); |
91 | 91 |
92 return ""; | 92 return ""; |
93 } | 93 } |
94 | 94 |
95 std::string WebRequestRulesRegistry::RemoveRulesImpl( | 95 std::string WebRequestRulesRegistry::RemoveRulesImpl( |
96 const std::string& extension_id, | 96 const std::string& extension_id, |
97 const std::vector<std::string>& rule_identifiers) { | 97 const std::vector<std::string>& rule_identifiers) { |
98 return "TODO"; | 98 // URLMatcherConditionSet IDs that can be removed from URLMatcher. |
| 99 std::vector<URLMatcherConditionSet::ID> remove_from_url_matcher; |
| 100 |
| 101 for (std::vector<std::string>::const_iterator i = rule_identifiers.begin(); |
| 102 i != rule_identifiers.end(); ++i) { |
| 103 WebRequestRule::GlobalRuleId rule_id(extension_id, *i); |
| 104 |
| 105 // Skip unknown rules. |
| 106 RulesMap::iterator webrequest_rules_entry = webrequest_rules_.find(rule_id); |
| 107 if (webrequest_rules_entry == webrequest_rules_.end()) |
| 108 continue; |
| 109 |
| 110 // Remove all triggers but collect their IDs. |
| 111 std::vector<URLMatcherConditionSet> condition_sets; |
| 112 WebRequestRule* rule = webrequest_rules_entry->second.get(); |
| 113 rule->conditions().GetURLMatcherConditionSets(&condition_sets); |
| 114 for (std::vector<URLMatcherConditionSet>::iterator j = |
| 115 condition_sets.begin(); j != condition_sets.end(); ++j) { |
| 116 remove_from_url_matcher.push_back(j->id()); |
| 117 rule_triggers_.erase(j->id()); |
| 118 } |
| 119 |
| 120 // Remove reference to actual rule. |
| 121 webrequest_rules_.erase(webrequest_rules_entry); |
| 122 } |
| 123 |
| 124 // Clear URLMatcher based on condition_set_ids that are not needed any more. |
| 125 url_matcher_.RemoveConditionSets(remove_from_url_matcher); |
| 126 |
| 127 return ""; |
99 } | 128 } |
100 | 129 |
101 std::string WebRequestRulesRegistry::RemoveAllRulesImpl( | 130 std::string WebRequestRulesRegistry::RemoveAllRulesImpl( |
102 const std::string& extension_id) { | 131 const std::string& extension_id) { |
103 return "TODO"; | 132 // Search all identifiers of rules that belong to extension |extension_id|. |
| 133 std::vector<std::string> rule_identifiers; |
| 134 for (RulesMap::iterator i = webrequest_rules_.begin(); |
| 135 i != webrequest_rules_.end(); ++i) { |
| 136 const WebRequestRule::GlobalRuleId& global_rule_id = i->first; |
| 137 if (global_rule_id.first == extension_id) |
| 138 rule_identifiers.push_back(global_rule_id.second); |
| 139 } |
| 140 |
| 141 return RemoveRulesImpl(extension_id, rule_identifiers); |
104 } | 142 } |
105 | 143 |
106 content::BrowserThread::ID WebRequestRulesRegistry::GetOwnerThread() const { | 144 content::BrowserThread::ID WebRequestRulesRegistry::GetOwnerThread() const { |
107 return content::BrowserThread::IO; | 145 return content::BrowserThread::IO; |
108 } | 146 } |
109 | 147 |
| 148 bool WebRequestRulesRegistry::IsEmpty() const { |
| 149 return rule_triggers_.empty() && webrequest_rules_.empty() && |
| 150 url_matcher_.IsEmpty(); |
| 151 } |
| 152 |
110 } // namespace extensions | 153 } // namespace extensions |
OLD | NEW |