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

Side by Side Diff: content/browser/loader/throttling_resource_handler.cc

Issue 2164113002: Remove ResourceHandler::OnBeforeNetworkStart (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Oops Created 4 years, 5 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 #include "content/browser/loader/throttling_resource_handler.h" 5 #include "content/browser/loader/throttling_resource_handler.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "content/browser/loader/resource_request_info_impl.h" 9 #include "content/browser/loader/resource_request_info_impl.h"
10 #include "content/public/browser/resource_throttle.h" 10 #include "content/public/browser/resource_throttle.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 deferred_url_ = url; 76 deferred_url_ = url;
77 return true; // Do not cancel. 77 return true; // Do not cancel.
78 } 78 }
79 } 79 }
80 80
81 next_index_ = 0; // Reset for next time. 81 next_index_ = 0; // Reset for next time.
82 82
83 return next_handler_->OnWillStart(url, defer); 83 return next_handler_->OnWillStart(url, defer);
84 } 84 }
85 85
86 bool ThrottlingResourceHandler::OnBeforeNetworkStart(const GURL& url,
87 bool* defer) {
88 DCHECK(!cancelled_by_resource_throttle_);
89
90 *defer = false;
91 while (next_index_ < throttles_.size()) {
92 int index = next_index_;
93 throttles_[index]->WillStartUsingNetwork(defer);
94 next_index_++;
95 if (cancelled_by_resource_throttle_)
96 return false;
97 if (*defer) {
98 OnRequestDefered(index);
99 deferred_stage_ = DEFERRED_NETWORK_START;
100 deferred_url_ = url;
101 return true; // Do not cancel.
102 }
103 }
104
105 next_index_ = 0; // Reset for next time.
106
107 return next_handler_->OnBeforeNetworkStart(url, defer);
108 }
109
110 bool ThrottlingResourceHandler::OnResponseStarted(ResourceResponse* response, 86 bool ThrottlingResourceHandler::OnResponseStarted(ResourceResponse* response,
111 bool* defer) { 87 bool* defer) {
112 DCHECK(!cancelled_by_resource_throttle_); 88 DCHECK(!cancelled_by_resource_throttle_);
113 89
114 while (next_index_ < throttles_.size()) { 90 while (next_index_ < throttles_.size()) {
115 int index = next_index_; 91 int index = next_index_;
116 throttles_[index]->WillProcessResponse(defer); 92 throttles_[index]->WillProcessResponse(defer);
117 next_index_++; 93 next_index_++;
118 if (cancelled_by_resource_throttle_) 94 if (cancelled_by_resource_throttle_)
119 return false; 95 return false;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 deferred_stage_ = DEFERRED_NONE; 128 deferred_stage_ = DEFERRED_NONE;
153 // Clear information about the throttle that delayed the request. 129 // Clear information about the throttle that delayed the request.
154 request()->LogUnblocked(); 130 request()->LogUnblocked();
155 switch (last_deferred_stage) { 131 switch (last_deferred_stage) {
156 case DEFERRED_NONE: 132 case DEFERRED_NONE:
157 NOTREACHED(); 133 NOTREACHED();
158 break; 134 break;
159 case DEFERRED_START: 135 case DEFERRED_START:
160 ResumeStart(); 136 ResumeStart();
161 break; 137 break;
162 case DEFERRED_NETWORK_START:
163 ResumeNetworkStart();
164 break;
165 case DEFERRED_REDIRECT: 138 case DEFERRED_REDIRECT:
166 ResumeRedirect(); 139 ResumeRedirect();
167 break; 140 break;
168 case DEFERRED_RESPONSE: 141 case DEFERRED_RESPONSE:
169 ResumeResponse(); 142 ResumeResponse();
170 break; 143 break;
171 } 144 }
172 } 145 }
173 146
174 void ThrottlingResourceHandler::ResumeStart() { 147 void ThrottlingResourceHandler::ResumeStart() {
175 DCHECK(!cancelled_by_resource_throttle_); 148 DCHECK(!cancelled_by_resource_throttle_);
176 149
177 GURL url = deferred_url_; 150 GURL url = deferred_url_;
178 deferred_url_ = GURL(); 151 deferred_url_ = GURL();
179 152
180 bool defer = false; 153 bool defer = false;
181 if (!OnWillStart(url, &defer)) { 154 if (!OnWillStart(url, &defer)) {
182 controller()->Cancel(); 155 controller()->Cancel();
183 } else if (!defer) { 156 } else if (!defer) {
184 controller()->Resume(); 157 controller()->Resume();
185 } 158 }
186 } 159 }
187 160
188 void ThrottlingResourceHandler::ResumeNetworkStart() {
189 DCHECK(!cancelled_by_resource_throttle_);
190
191 GURL url = deferred_url_;
192 deferred_url_ = GURL();
193
194 bool defer = false;
195 if (!OnBeforeNetworkStart(url, &defer)) {
196 controller()->Cancel();
197 } else if (!defer) {
198 controller()->Resume();
199 }
200 }
201
202 void ThrottlingResourceHandler::ResumeRedirect() { 161 void ThrottlingResourceHandler::ResumeRedirect() {
203 DCHECK(!cancelled_by_resource_throttle_); 162 DCHECK(!cancelled_by_resource_throttle_);
204 163
205 net::RedirectInfo redirect_info = deferred_redirect_; 164 net::RedirectInfo redirect_info = deferred_redirect_;
206 deferred_redirect_ = net::RedirectInfo(); 165 deferred_redirect_ = net::RedirectInfo();
207 scoped_refptr<ResourceResponse> response; 166 scoped_refptr<ResourceResponse> response;
208 deferred_response_.swap(response); 167 deferred_response_.swap(response);
209 168
210 bool defer = false; 169 bool defer = false;
211 if (!OnRequestRedirected(redirect_info, response.get(), &defer)) { 170 if (!OnRequestRedirected(redirect_info, response.get(), &defer)) {
(...skipping 15 matching lines...) Expand all
227 } else if (!defer) { 186 } else if (!defer) {
228 controller()->Resume(); 187 controller()->Resume();
229 } 188 }
230 } 189 }
231 190
232 void ThrottlingResourceHandler::OnRequestDefered(int throttle_index) { 191 void ThrottlingResourceHandler::OnRequestDefered(int throttle_index) {
233 request()->LogBlockedBy(throttles_[throttle_index]->GetNameForLogging()); 192 request()->LogBlockedBy(throttles_[throttle_index]->GetNameForLogging());
234 } 193 }
235 194
236 } // namespace content 195 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/throttling_resource_handler.h ('k') | content/public/browser/resource_throttle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698