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

Unified Diff: chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.h

Issue 11569007: Refactoring how conditions without URL attributes are handled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Triggers back in ConditionSet 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_condition.h
diff --git a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.h b/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.h
index 922dba7f111ffdc12352c2e06703c3fa828e3197..3048f70c946fc5c0136810ef3c371fe1faf420ab 100644
--- a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.h
+++ b/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.h
@@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDITION_H_
#define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDITION_H_
+#include <set>
#include <string>
#include <vector>
@@ -47,22 +48,21 @@ class WebRequestCondition {
const base::Value& condition,
std::string* error);
- // Returns whether the request is a match, given that the URLMatcher found
- // a match for |url_matcher_conditions_|.
- bool IsFulfilled(const WebRequestRule::RequestData& request_data) const;
+ // Returns whether the request matches this condition. |url_matches| lists
+ // the IDs that match the request's URL.
+ bool IsFulfilled(const std::set<URLMatcherConditionSet::ID>& url_matches,
+ const WebRequestRule::RequestData& request_data) const;
// Returns a URLMatcherConditionSet::ID which is the canonical representation
// for all URL patterns that need to be matched by this WebRequestCondition.
// This ID is registered in a URLMatcher that can inform us in case of a
// match.
URLMatcherConditionSet::ID url_matcher_condition_set_id() const {
+ DCHECK(url_matcher_conditions_.get());
return url_matcher_conditions_->id();
}
- // Returns the set of conditions that are checked on the URL. This is the
- // primary trigger for WebRequestCondition and therefore never empty.
- // (If it was empty, the URLMatcher would never notify us about network
- // requests which might fulfill the entire WebRequestCondition).
+ // Returns the set of conditions that are checked on the URL. May be NULL.
scoped_refptr<URLMatcherConditionSet> url_matcher_condition_set() const {
return url_matcher_conditions_;
}
@@ -78,7 +78,11 @@ class WebRequestCondition {
int stages() const { return applicable_request_stages_; }
private:
+ // Represents the 'url' attribute of this condition. If NULL, then there was
+ // no 'url' attribute in this condition.
scoped_refptr<URLMatcherConditionSet> url_matcher_conditions_;
+
+ // All non-UrlFilter attributes of this condition.
WebRequestConditionAttributes condition_attributes_;
// Bit vector indicating all RequestStage during which all
@@ -96,7 +100,6 @@ class WebRequestConditionSet {
typedef std::vector<linked_ptr<json_schema_compiler::any::Any> > AnyVector;
typedef std::vector<linked_ptr<WebRequestCondition> > Conditions;
- explicit WebRequestConditionSet(const Conditions& conditions);
~WebRequestConditionSet();
// Factory method that creates an WebRequestConditionSet according to the JSON
@@ -111,25 +114,34 @@ class WebRequestConditionSet {
return conditions_;
}
- // Returns whether any condition in the condition set is fulfilled
- // based on a match |url_match| and the value of |request_data.request|.
- // This function should be called for each URLMatcherConditionSet::ID
- // that was found by the URLMatcher to ensure that the each trigger in
- // |match_triggers_| is found.
+ // Returns whether any condition in the condition set is fulfilled based on
+ // matches in |url_matches| and the value of |request_data.request|. This
+ // function should be called for a ConditionSet if any Condition in the
+ // ConditionSet was triggered by a url match or if the ConditionSet contains
+ // a Condition without a UrlFilter.
bool IsFulfilled(
- URLMatcherConditionSet::ID url_match,
+ const std::set<URLMatcherConditionSet::ID>& url_matches,
const WebRequestRule::RequestData& request_data) const;
// Appends the URLMatcherConditionSet from all conditions to |condition_sets|.
void GetURLMatcherConditionSets(
URLMatcherConditionSet::Vector* condition_sets) const;
- private:
- Conditions conditions_;
+ // Returns whether there are some conditions without UrlFilter attributes.
+ bool HasConditionsWithoutUrls() const;
- typedef std::map<URLMatcherConditionSet::ID, WebRequestCondition*>
+ private:
+ typedef std::map<URLMatcherConditionSet::ID, const WebRequestCondition*>
Jeffrey Yasskin 2012/12/19 19:10:52 For optimal memory use and performance, this ought
vabr (Chromium) 2012/12/20 08:57:13 I'm not sure I understand. If we iterate over a ma
Jeffrey Yasskin 2012/12/20 18:15:38 The vector's elements should be std::pair<URLMatch
MatchTriggers;
- MatchTriggers match_triggers_;
+
+ WebRequestConditionSet(
+ const Conditions& conditions,
+ const MatchTriggers& match_triggers,
+ const std::vector<const WebRequestCondition*> conditions_without_urls);
Jeffrey Yasskin 2012/12/19 19:10:52 You forgot an & on conditions_without_urls. (Ther
vabr (Chromium) 2012/12/20 08:57:13 Done.
+
+ const MatchTriggers match_triggers_;
+ const Conditions conditions_;
+ const std::vector<const WebRequestCondition*> conditions_without_urls_;
DISALLOW_COPY_AND_ASSIGN(WebRequestConditionSet);
};

Powered by Google App Engine
This is Rietveld 408576698