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

Unified Diff: chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.cc

Issue 11569007: Refactoring how conditions without URL attributes are handled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Polished 1st version Created 8 years 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.cc
diff --git a/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.cc b/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.cc
index 77bc9b8f44ef22fa8bbbf5a3aa67ed9398a29687..499ddd71d6ea1267ad9aab85eaa0d3980ce173b0 100644
--- a/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.cc
+++ b/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.cc
@@ -26,7 +26,17 @@ WebRequestRulesRegistry::GetMatches(
const WebRequestRule::RequestData& request_data) {
std::set<WebRequestRule::GlobalRuleId> result;
- // Figure out for which rules the URL match conditions were fulfilled.
+ // First check for rules with a satisfied condition set without URL
Jeffrey Yasskin 2012/12/18 02:24:32 Given the next change you're making, and the decla
battre 2012/12/18 17:17:54 This is a very elegant way of dealing with this. S
vabr (Chromium) 2012/12/18 18:26:42 I implemented Jeffrey's suggestion. My only concer
+ // attributes.
+ for (std::set<const WebRequestRule*>::iterator rule =
+ rules_with_untriggered_conditions_.begin();
+ rule != rules_with_untriggered_conditions_.end(); ++rule) {
+ if (result.find((*rule)->id()) == result.end() &&
+ (*rule)->conditions().IsFulfilledWithoutURLMatcher(request_data))
+ result.insert((*rule)->id());
+ }
+
+ // Now figure out for which rules the URL match conditions were fulfilled.
typedef std::set<URLMatcherConditionSet::ID> URLMatches;
URLMatches url_matches = url_matcher_.MatchURL(request_data.request->url());
@@ -38,7 +48,8 @@ WebRequestRulesRegistry::GetMatches(
CHECK(rule_trigger != rule_triggers_.end());
WebRequestRule* rule = rule_trigger->second;
- if (rule->conditions().IsFulfilled(*url_match, request_data))
+ if (result.find(rule->id()) == result.end() &&
vabr (Chromium) 2012/12/13 12:18:06 This check spares time, because some rules might b
battre 2012/12/18 08:20:44 Use ContainsKey from base/stl_util.h?
vabr (Chromium) 2012/12/18 18:26:42 Code changed. But thanks, base/stl_util.h is a use
+ rule->conditions().IsFulfilled(*url_match, request_data))
result.insert(rule->id());
}
return result;
@@ -157,11 +168,14 @@ std::string WebRequestRulesRegistry::AddRulesImpl(
}
}
- // Register url patterns in url_matcher_.
+ // Register url patterns in |url_matcher_| and
+ // |rules_with_untriggered_conditions_|.
URLMatcherConditionSet::Vector all_new_condition_sets;
for (RulesMap::iterator i = new_webrequest_rules.begin();
i != new_webrequest_rules.end(); ++i) {
i->second->conditions().GetURLMatcherConditionSets(&all_new_condition_sets);
+ if (i->second->conditions().has_untriggered_conditions())
+ rules_with_untriggered_conditions_.insert(i->second.get());
}
url_matcher_.AddConditionSets(all_new_condition_sets);
@@ -195,8 +209,9 @@ std::string WebRequestRulesRegistry::RemoveRulesImpl(
rule_triggers_.erase((*j)->id());
}
- // Remove reference to actual rule.
Jeffrey Yasskin 2012/12/18 02:24:32 This comment should probably have read "Remove own
vabr (Chromium) 2012/12/18 18:26:42 Corrected.
+ // Remove references to the rule.
webrequest_rules_.erase(webrequest_rules_entry);
+ rules_with_untriggered_conditions_.erase(rule);
Jeffrey Yasskin 2012/12/18 02:24:32 This ought to happen before webrequest_rules_.eras
vabr (Chromium) 2012/12/18 18:26:42 Makes sense, thanks for explaining that to me. I c
}
// Clear URLMatcher based on condition_set_ids that are not needed any more.

Powered by Google App Engine
This is Rietveld 408576698