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

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

Issue 398903002: Plumb redirect info out of net, through content, and into child processes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: darin comments Created 6 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 | Annotate | Revision Log
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 "content/browser/loader/resource_request_info_impl.h" 7 #include "content/browser/loader/resource_request_info_impl.h"
8 #include "content/public/browser/resource_throttle.h" 8 #include "content/public/browser/resource_throttle.h"
9 #include "content/public/common/resource_response.h" 9 #include "content/public/common/resource_response.h"
10 #include "net/url_request/url_request.h" 10 #include "net/url_request/url_request.h"
(...skipping 13 matching lines...) Expand all
24 throttles_[i]->set_controller(this); 24 throttles_[i]->set_controller(this);
25 // Throttles must have a name, as otherwise, bugs where a throttle fails 25 // Throttles must have a name, as otherwise, bugs where a throttle fails
26 // to resume a request can be very difficult to debug. 26 // to resume a request can be very difficult to debug.
27 DCHECK(throttles_[i]->GetNameForLogging()); 27 DCHECK(throttles_[i]->GetNameForLogging());
28 } 28 }
29 } 29 }
30 30
31 ThrottlingResourceHandler::~ThrottlingResourceHandler() { 31 ThrottlingResourceHandler::~ThrottlingResourceHandler() {
32 } 32 }
33 33
34 bool ThrottlingResourceHandler::OnRequestRedirected(const GURL& new_url, 34 bool ThrottlingResourceHandler::OnRequestRedirected(
35 ResourceResponse* response, 35 const net::RedirectInfo& redirect_info,
36 bool* defer) { 36 ResourceResponse* response,
37 bool* defer) {
37 DCHECK(!cancelled_by_resource_throttle_); 38 DCHECK(!cancelled_by_resource_throttle_);
38 39
39 *defer = false; 40 *defer = false;
40 while (next_index_ < throttles_.size()) { 41 while (next_index_ < throttles_.size()) {
41 int index = next_index_; 42 int index = next_index_;
42 throttles_[index]->WillRedirectRequest(new_url, defer); 43 throttles_[index]->WillRedirectRequest(redirect_info.new_url, defer);
43 next_index_++; 44 next_index_++;
44 if (cancelled_by_resource_throttle_) 45 if (cancelled_by_resource_throttle_)
45 return false; 46 return false;
46 if (*defer) { 47 if (*defer) {
47 OnRequestDefered(index); 48 OnRequestDefered(index);
48 deferred_stage_ = DEFERRED_REDIRECT; 49 deferred_stage_ = DEFERRED_REDIRECT;
49 deferred_url_ = new_url; 50 deferred_redirect_ = redirect_info;
50 deferred_response_ = response; 51 deferred_response_ = response;
51 return true; // Do not cancel. 52 return true; // Do not cancel.
52 } 53 }
53 } 54 }
54 55
55 next_index_ = 0; // Reset for next time. 56 next_index_ = 0; // Reset for next time.
56 57
57 return next_handler_->OnRequestRedirected(new_url, response, defer); 58 return next_handler_->OnRequestRedirected(redirect_info, response, defer);
58 } 59 }
59 60
60 bool ThrottlingResourceHandler::OnWillStart(const GURL& url, bool* defer) { 61 bool ThrottlingResourceHandler::OnWillStart(const GURL& url, bool* defer) {
61 DCHECK(!cancelled_by_resource_throttle_); 62 DCHECK(!cancelled_by_resource_throttle_);
62 63
63 *defer = false; 64 *defer = false;
64 while (next_index_ < throttles_.size()) { 65 while (next_index_ < throttles_.size()) {
65 int index = next_index_; 66 int index = next_index_;
66 throttles_[index]->WillStartRequest(defer); 67 throttles_[index]->WillStartRequest(defer);
67 next_index_++; 68 next_index_++;
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 if (!OnBeforeNetworkStart(url, &defer)) { 193 if (!OnBeforeNetworkStart(url, &defer)) {
193 controller()->Cancel(); 194 controller()->Cancel();
194 } else if (!defer) { 195 } else if (!defer) {
195 controller()->Resume(); 196 controller()->Resume();
196 } 197 }
197 } 198 }
198 199
199 void ThrottlingResourceHandler::ResumeRedirect() { 200 void ThrottlingResourceHandler::ResumeRedirect() {
200 DCHECK(!cancelled_by_resource_throttle_); 201 DCHECK(!cancelled_by_resource_throttle_);
201 202
202 GURL new_url = deferred_url_; 203 net::RedirectInfo redirect_info = deferred_redirect_;
203 deferred_url_ = GURL(); 204 deferred_redirect_ = net::RedirectInfo();
204 scoped_refptr<ResourceResponse> response; 205 scoped_refptr<ResourceResponse> response;
205 deferred_response_.swap(response); 206 deferred_response_.swap(response);
206 207
207 bool defer = false; 208 bool defer = false;
208 if (!OnRequestRedirected(new_url, response.get(), &defer)) { 209 if (!OnRequestRedirected(redirect_info, response.get(), &defer)) {
209 controller()->Cancel(); 210 controller()->Cancel();
210 } else if (!defer) { 211 } else if (!defer) {
211 controller()->Resume(); 212 controller()->Resume();
212 } 213 }
213 } 214 }
214 215
215 void ThrottlingResourceHandler::ResumeResponse() { 216 void ThrottlingResourceHandler::ResumeResponse() {
216 DCHECK(!cancelled_by_resource_throttle_); 217 DCHECK(!cancelled_by_resource_throttle_);
217 218
218 scoped_refptr<ResourceResponse> response; 219 scoped_refptr<ResourceResponse> response;
219 deferred_response_.swap(response); 220 deferred_response_.swap(response);
220 221
221 bool defer = false; 222 bool defer = false;
222 if (!OnResponseStarted(response.get(), &defer)) { 223 if (!OnResponseStarted(response.get(), &defer)) {
223 controller()->Cancel(); 224 controller()->Cancel();
224 } else if (!defer) { 225 } else if (!defer) {
225 controller()->Resume(); 226 controller()->Resume();
226 } 227 }
227 } 228 }
228 229
229 void ThrottlingResourceHandler::OnRequestDefered(int throttle_index) { 230 void ThrottlingResourceHandler::OnRequestDefered(int throttle_index) {
230 request()->LogBlockedBy(throttles_[throttle_index]->GetNameForLogging()); 231 request()->LogBlockedBy(throttles_[throttle_index]->GetNameForLogging());
231 } 232 }
232 233
233 } // namespace content 234 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/throttling_resource_handler.h ('k') | content/browser/service_worker/service_worker_url_request_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698