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

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 // Returns whether |request| is a match, given that the URLMatcher found 49 // Returns whether the request is a match, given that the URLMatcher found
50 // a match for |url_matcher_conditions_|. 50 // a match for |url_matcher_conditions_|.
51 bool IsFulfilled(net::URLRequest* request, RequestStages request_stage) const; 51 bool IsFulfilled(const WebRequestRule::RequestData& request_data) const;
52 52
53 // Returns a URLMatcherConditionSet::ID which is the canonical representation 53 // Returns a URLMatcherConditionSet::ID which is the canonical representation
54 // for all URL patterns that need to be matched by this WebRequestCondition. 54 // 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 55 // This ID is registered in a URLMatcher that can inform us in case of a
56 // match. 56 // match.
57 URLMatcherConditionSet::ID url_matcher_condition_set_id() const { 57 URLMatcherConditionSet::ID url_matcher_condition_set_id() const {
58 return url_matcher_conditions_->id(); 58 return url_matcher_conditions_->id();
59 } 59 }
60 60
61 // Returns the set of conditions that are checked on the URL. This is the 61 // Returns the set of conditions that are checked on the URL. This is the
62 // primary trigger for WebRequestCondition and therefore never empty. 62 // primary trigger for WebRequestCondition and therefore never empty.
63 // (If it was empty, the URLMatcher would never notify us about network 63 // (If it was empty, the URLMatcher would never notify us about network
64 // requests which might fulfill the entire WebRequestCondition). 64 // requests which might fulfill the entire WebRequestCondition).
65 scoped_refptr<URLMatcherConditionSet> url_matcher_condition_set() const { 65 scoped_refptr<URLMatcherConditionSet> url_matcher_condition_set() const {
66 return url_matcher_conditions_; 66 return url_matcher_conditions_;
67 } 67 }
68 68
69 private: 69 private:
70 scoped_refptr<URLMatcherConditionSet> url_matcher_conditions_; 70 scoped_refptr<URLMatcherConditionSet> url_matcher_conditions_;
71 WebRequestConditionAttributes condition_attributes_; 71 WebRequestConditionAttributes condition_attributes_;
72 72
73 // Bit vector indicating all RequestStages during which all 73 // Bit vector indicating all RequestStage during which all
74 // |condition_attributes_| can be evaluated. 74 // |condition_attributes_| can be evaluated.
75 int applicable_request_stages_; 75 int applicable_request_stages_;
76 76
77 DISALLOW_COPY_AND_ASSIGN(WebRequestCondition); 77 DISALLOW_COPY_AND_ASSIGN(WebRequestCondition);
78 }; 78 };
79 79
80 // This class stores a set of conditions that may be part of a WebRequestRule. 80 // 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 81 // If any condition is fulfilled, the WebRequestActions of the WebRequestRule
82 // can be triggered. 82 // can be triggered.
83 class WebRequestConditionSet { 83 class WebRequestConditionSet {
(...skipping 10 matching lines...) Expand all
94 static scoped_ptr<WebRequestConditionSet> Create( 94 static scoped_ptr<WebRequestConditionSet> Create(
95 URLMatcherConditionFactory* url_matcher_condition_factory, 95 URLMatcherConditionFactory* url_matcher_condition_factory,
96 const AnyVector& conditions, 96 const AnyVector& conditions,
97 std::string* error); 97 std::string* error);
98 98
99 const std::vector<linked_ptr<WebRequestCondition> >& conditions() const { 99 const std::vector<linked_ptr<WebRequestCondition> >& conditions() const {
100 return conditions_; 100 return conditions_;
101 } 101 }
102 102
103 // Returns whether any condition in the condition set is fulfilled 103 // Returns whether any condition in the condition set is fulfilled
104 // based on a match |url_match| and the value of |request|. This function 104 // based on a match |url_match| and the value of |request_data.request|.
105 // should be called for each URLMatcherConditionSet::ID that was found 105 // This function should be called for each URLMatcherConditionSet::ID
106 // by the URLMatcher to ensure that the each trigger in |match_triggers_| is 106 // that was found by the URLMatcher to ensure that the each trigger in
107 // found. 107 // |match_triggers_| is found.
108 bool IsFulfilled(URLMatcherConditionSet::ID url_match, 108 bool IsFulfilled(
109 net::URLRequest* request, 109 URLMatcherConditionSet::ID url_match,
110 RequestStages request_stage) const; 110 const WebRequestRule::RequestData& request_data) const;
111 111
112 // Appends the URLMatcherConditionSet from all conditions to |condition_sets|. 112 // Appends the URLMatcherConditionSet from all conditions to |condition_sets|.
113 void GetURLMatcherConditionSets( 113 void GetURLMatcherConditionSets(
114 URLMatcherConditionSet::Vector* condition_sets) const; 114 URLMatcherConditionSet::Vector* condition_sets) const;
115 115
116 private: 116 private:
117 typedef std::vector<linked_ptr<WebRequestCondition> > Conditions; 117 typedef std::vector<linked_ptr<WebRequestCondition> > Conditions;
118 Conditions conditions_; 118 Conditions conditions_;
119 119
120 typedef std::map<URLMatcherConditionSet::ID, WebRequestCondition*> 120 typedef std::map<URLMatcherConditionSet::ID, WebRequestCondition*>
121 MatchTriggers; 121 MatchTriggers;
122 MatchTriggers match_triggers_; 122 MatchTriggers match_triggers_;
123 123
124 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionSet); 124 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionSet);
125 }; 125 };
126 126
127 } // namespace extensions 127 } // namespace extensions
128 128
129 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDI TION_H_ 129 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDI TION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698