| 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 <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condit
ion.h" | 9 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condit
ion.h" |
| 10 #include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h" | 10 #include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h" |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 } | 158 } |
| 159 | 159 |
| 160 // Register url patterns in url_matcher_. | 160 // Register url patterns in url_matcher_. |
| 161 URLMatcherConditionSet::Vector all_new_condition_sets; | 161 URLMatcherConditionSet::Vector all_new_condition_sets; |
| 162 for (RulesMap::iterator i = new_webrequest_rules.begin(); | 162 for (RulesMap::iterator i = new_webrequest_rules.begin(); |
| 163 i != new_webrequest_rules.end(); ++i) { | 163 i != new_webrequest_rules.end(); ++i) { |
| 164 i->second->conditions().GetURLMatcherConditionSets(&all_new_condition_sets); | 164 i->second->conditions().GetURLMatcherConditionSets(&all_new_condition_sets); |
| 165 } | 165 } |
| 166 url_matcher_.AddConditionSets(all_new_condition_sets); | 166 url_matcher_.AddConditionSets(all_new_condition_sets); |
| 167 | 167 |
| 168 ClearCacheOnNavigation(); |
| 169 |
| 168 return ""; | 170 return ""; |
| 169 } | 171 } |
| 170 | 172 |
| 171 std::string WebRequestRulesRegistry::RemoveRulesImpl( | 173 std::string WebRequestRulesRegistry::RemoveRulesImpl( |
| 172 const std::string& extension_id, | 174 const std::string& extension_id, |
| 173 const std::vector<std::string>& rule_identifiers) { | 175 const std::vector<std::string>& rule_identifiers) { |
| 174 // URLMatcherConditionSet IDs that can be removed from URLMatcher. | 176 // URLMatcherConditionSet IDs that can be removed from URLMatcher. |
| 175 std::vector<URLMatcherConditionSet::ID> remove_from_url_matcher; | 177 std::vector<URLMatcherConditionSet::ID> remove_from_url_matcher; |
| 176 | 178 |
| 177 for (std::vector<std::string>::const_iterator i = rule_identifiers.begin(); | 179 for (std::vector<std::string>::const_iterator i = rule_identifiers.begin(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 193 rule_triggers_.erase((*j)->id()); | 195 rule_triggers_.erase((*j)->id()); |
| 194 } | 196 } |
| 195 | 197 |
| 196 // Remove reference to actual rule. | 198 // Remove reference to actual rule. |
| 197 webrequest_rules_.erase(webrequest_rules_entry); | 199 webrequest_rules_.erase(webrequest_rules_entry); |
| 198 } | 200 } |
| 199 | 201 |
| 200 // Clear URLMatcher based on condition_set_ids that are not needed any more. | 202 // Clear URLMatcher based on condition_set_ids that are not needed any more. |
| 201 url_matcher_.RemoveConditionSets(remove_from_url_matcher); | 203 url_matcher_.RemoveConditionSets(remove_from_url_matcher); |
| 202 | 204 |
| 205 ClearCacheOnNavigation(); |
| 206 |
| 203 return ""; | 207 return ""; |
| 204 } | 208 } |
| 205 | 209 |
| 206 std::string WebRequestRulesRegistry::RemoveAllRulesImpl( | 210 std::string WebRequestRulesRegistry::RemoveAllRulesImpl( |
| 207 const std::string& extension_id) { | 211 const std::string& extension_id) { |
| 208 // Search all identifiers of rules that belong to extension |extension_id|. | 212 // Search all identifiers of rules that belong to extension |extension_id|. |
| 209 std::vector<std::string> rule_identifiers; | 213 std::vector<std::string> rule_identifiers; |
| 210 for (RulesMap::iterator i = webrequest_rules_.begin(); | 214 for (RulesMap::iterator i = webrequest_rules_.begin(); |
| 211 i != webrequest_rules_.end(); ++i) { | 215 i != webrequest_rules_.end(); ++i) { |
| 212 const WebRequestRule::GlobalRuleId& global_rule_id = i->first; | 216 const WebRequestRule::GlobalRuleId& global_rule_id = i->first; |
| 213 if (global_rule_id.first == extension_id) | 217 if (global_rule_id.first == extension_id) |
| 214 rule_identifiers.push_back(global_rule_id.second); | 218 rule_identifiers.push_back(global_rule_id.second); |
| 215 } | 219 } |
| 216 | 220 |
| 221 // No need to call ClearCacheOnNavigation() here because RemoveRulesImpl |
| 222 // takes care of that. |
| 217 return RemoveRulesImpl(extension_id, rule_identifiers); | 223 return RemoveRulesImpl(extension_id, rule_identifiers); |
| 218 } | 224 } |
| 219 | 225 |
| 220 content::BrowserThread::ID WebRequestRulesRegistry::GetOwnerThread() const { | 226 content::BrowserThread::ID WebRequestRulesRegistry::GetOwnerThread() const { |
| 221 return content::BrowserThread::IO; | 227 return content::BrowserThread::IO; |
| 222 } | 228 } |
| 223 | 229 |
| 224 bool WebRequestRulesRegistry::IsEmpty() const { | 230 bool WebRequestRulesRegistry::IsEmpty() const { |
| 225 return rule_triggers_.empty() && webrequest_rules_.empty() && | 231 return rule_triggers_.empty() && webrequest_rules_.empty() && |
| 226 url_matcher_.IsEmpty(); | 232 url_matcher_.IsEmpty(); |
| 227 } | 233 } |
| 228 | 234 |
| 229 WebRequestRulesRegistry::~WebRequestRulesRegistry() {} | 235 WebRequestRulesRegistry::~WebRequestRulesRegistry() {} |
| 230 | 236 |
| 231 base::Time WebRequestRulesRegistry::GetExtensionInstallationTime( | 237 base::Time WebRequestRulesRegistry::GetExtensionInstallationTime( |
| 232 const std::string& extension_id) const { | 238 const std::string& extension_id) const { |
| 233 if (!extension_info_map_.get()) // May be NULL during testing. | 239 if (!extension_info_map_.get()) // May be NULL during testing. |
| 234 return base::Time(); | 240 return base::Time(); |
| 235 | 241 |
| 236 return extension_info_map_->GetInstallTime(extension_id); | 242 return extension_info_map_->GetInstallTime(extension_id); |
| 237 } | 243 } |
| 238 | 244 |
| 245 void WebRequestRulesRegistry::ClearCacheOnNavigation() { |
| 246 extension_web_request_api_helpers::ClearCacheOnNavigation(); |
| 247 } |
| 248 |
| 239 } // namespace extensions | 249 } // namespace extensions |
| OLD | NEW |