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

Side by Side Diff: chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.h

Issue 10831150: Refactor request parameters into RequestData struct. Also make RequestStage singular. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: ; Created 8 years, 4 months 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 unified diff | Download patch
OLDNEW
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 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDITIO N_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDITIO N_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDITIO N_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDITIO N_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 28 matching lines...) Expand all
39 const WebRequestConditionAttributes& condition_attributes); 39 const WebRequestConditionAttributes& condition_attributes);
40 ~WebRequestCondition(); 40 ~WebRequestCondition();
41 41
42 // Factory method that instantiates a WebRequestCondition according to 42 // Factory method that instantiates a WebRequestCondition according to
43 // the description |condition| passed by the extension API. 43 // the description |condition| passed by the extension API.
44 static scoped_ptr<WebRequestCondition> Create( 44 static scoped_ptr<WebRequestCondition> Create(
45 URLMatcherConditionFactory* url_matcher_condition_factory, 45 URLMatcherConditionFactory* url_matcher_condition_factory,
46 const base::Value& condition, 46 const base::Value& condition,
47 std::string* error); 47 std::string* error);
48 48
49 // TODO(yoz): fix ALL the comments
49 // Returns whether |request| is a match, given that the URLMatcher found 50 // Returns whether |request| is a match, given that the URLMatcher found
50 // a match for |url_matcher_conditions_|. 51 // a match for |url_matcher_conditions_|.
51 bool IsFulfilled(net::URLRequest* request, RequestStages request_stage) const; 52 bool IsFulfilled(const WebRequestRule::RequestData& request_data) const;
52 53
53 // Returns a URLMatcherConditionSet::ID which is the canonical representation 54 // Returns a URLMatcherConditionSet::ID which is the canonical representation
54 // for all URL patterns that need to be matched by this WebRequestCondition. 55 // for all URL patterns that need to be matched by this WebRequestCondition.
55 // This ID is registered in a URLMatcher that can inform us in case of a 56 // This ID is registered in a URLMatcher that can inform us in case of a
56 // match. 57 // match.
57 URLMatcherConditionSet::ID url_matcher_condition_set_id() const { 58 URLMatcherConditionSet::ID url_matcher_condition_set_id() const {
58 return url_matcher_conditions_->id(); 59 return url_matcher_conditions_->id();
59 } 60 }
60 61
61 // Returns the set of conditions that are checked on the URL. This is the 62 // Returns the set of conditions that are checked on the URL. This is the
62 // primary trigger for WebRequestCondition and therefore never empty. 63 // primary trigger for WebRequestCondition and therefore never empty.
63 // (If it was empty, the URLMatcher would never notify us about network 64 // (If it was empty, the URLMatcher would never notify us about network
64 // requests which might fulfill the entire WebRequestCondition). 65 // requests which might fulfill the entire WebRequestCondition).
65 scoped_refptr<URLMatcherConditionSet> url_matcher_condition_set() const { 66 scoped_refptr<URLMatcherConditionSet> url_matcher_condition_set() const {
66 return url_matcher_conditions_; 67 return url_matcher_conditions_;
67 } 68 }
68 69
69 private: 70 private:
70 scoped_refptr<URLMatcherConditionSet> url_matcher_conditions_; 71 scoped_refptr<URLMatcherConditionSet> url_matcher_conditions_;
71 WebRequestConditionAttributes condition_attributes_; 72 WebRequestConditionAttributes condition_attributes_;
72 73
73 // Bit vector indicating all RequestStages during which all 74 // Bit vector indicating all RequestStage during which all
74 // |condition_attributes_| can be evaluated. 75 // |condition_attributes_| can be evaluated.
75 int applicable_request_stages_; 76 int applicable_request_stages_;
76 77
77 DISALLOW_COPY_AND_ASSIGN(WebRequestCondition); 78 DISALLOW_COPY_AND_ASSIGN(WebRequestCondition);
78 }; 79 };
79 80
80 // This class stores a set of conditions that may be part of a WebRequestRule. 81 // This class stores a set of conditions that may be part of a WebRequestRule.
81 // If any condition is fulfilled, the WebRequestActions of the WebRequestRule 82 // If any condition is fulfilled, the WebRequestActions of the WebRequestRule
82 // can be triggered. 83 // can be triggered.
83 class WebRequestConditionSet { 84 class WebRequestConditionSet {
(...skipping 14 matching lines...) Expand all
98 99
99 const std::vector<linked_ptr<WebRequestCondition> >& conditions() const { 100 const std::vector<linked_ptr<WebRequestCondition> >& conditions() const {
100 return conditions_; 101 return conditions_;
101 } 102 }
102 103
103 // Returns whether any condition in the condition set is fulfilled 104 // Returns whether any condition in the condition set is fulfilled
104 // based on a match |url_match| and the value of |request|. This function 105 // based on a match |url_match| and the value of |request|. This function
105 // should be called for each URLMatcherConditionSet::ID that was found 106 // should be called for each URLMatcherConditionSet::ID that was found
106 // by the URLMatcher to ensure that the each trigger in |match_triggers_| is 107 // by the URLMatcher to ensure that the each trigger in |match_triggers_| is
107 // found. 108 // found.
108 bool IsFulfilled(URLMatcherConditionSet::ID url_match, 109 bool IsFulfilled(
109 net::URLRequest* request, 110 URLMatcherConditionSet::ID url_match,
110 RequestStages request_stage) const; 111 const WebRequestRule::RequestData& request_data) const;
111 112
112 // Appends the URLMatcherConditionSet from all conditions to |condition_sets|. 113 // Appends the URLMatcherConditionSet from all conditions to |condition_sets|.
113 void GetURLMatcherConditionSets( 114 void GetURLMatcherConditionSets(
114 URLMatcherConditionSet::Vector* condition_sets) const; 115 URLMatcherConditionSet::Vector* condition_sets) const;
115 116
116 private: 117 private:
117 typedef std::vector<linked_ptr<WebRequestCondition> > Conditions; 118 typedef std::vector<linked_ptr<WebRequestCondition> > Conditions;
118 Conditions conditions_; 119 Conditions conditions_;
119 120
120 typedef std::map<URLMatcherConditionSet::ID, WebRequestCondition*> 121 typedef std::map<URLMatcherConditionSet::ID, WebRequestCondition*>
121 MatchTriggers; 122 MatchTriggers;
122 MatchTriggers match_triggers_; 123 MatchTriggers match_triggers_;
123 124
124 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionSet); 125 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionSet);
125 }; 126 };
126 127
127 } // namespace extensions 128 } // namespace extensions
128 129
129 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDI TION_H_ 130 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDI TION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698