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

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

Issue 2597563002: Revert of Move ResourceHandler deferred actions ahead of external protocol handling. (Closed)
Patch Set: Created 4 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 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/resource_loader.h" 5 #include "content/browser/loader/resource_loader.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 if (login_delegate_.get()) 150 if (login_delegate_.get())
151 login_delegate_->OnRequestCancelled(); 151 login_delegate_->OnRequestCancelled();
152 ssl_client_auth_handler_.reset(); 152 ssl_client_auth_handler_.reset();
153 153
154 // Run ResourceHandler destructor before we tear-down the rest of our state 154 // Run ResourceHandler destructor before we tear-down the rest of our state
155 // as the ResourceHandler may want to inspect the URLRequest and other state. 155 // as the ResourceHandler may want to inspect the URLRequest and other state.
156 handler_.reset(); 156 handler_.reset();
157 } 157 }
158 158
159 void ResourceLoader::StartRequest() { 159 void ResourceLoader::StartRequest() {
160 if (delegate_->HandleExternalProtocol(this, request_->url())) {
161 CancelAndIgnore();
162 return;
163 }
164
160 // Give the handler a chance to delay the URLRequest from being started. 165 // Give the handler a chance to delay the URLRequest from being started.
161 bool defer_start = false; 166 bool defer_start = false;
162 if (!handler_->OnWillStart(request_->url(), &defer_start)) { 167 if (!handler_->OnWillStart(request_->url(), &defer_start)) {
163 Cancel(); 168 Cancel();
164 return; 169 return;
165 } 170 }
166 171
167 TRACE_EVENT_WITH_FLOW0("loading", "ResourceLoader::StartRequest", this, 172 TRACE_EVENT_WITH_FLOW0("loading", "ResourceLoader::StartRequest", this,
168 TRACE_EVENT_FLAG_FLOW_OUT); 173 TRACE_EVENT_FLAG_FLOW_OUT);
169 if (defer_start) { 174 if (defer_start) {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 info->GetChildID(), redirect_info.new_url)) { 266 info->GetChildID(), redirect_info.new_url)) {
262 DVLOG(1) << "Denied unauthorized request for " 267 DVLOG(1) << "Denied unauthorized request for "
263 << redirect_info.new_url.possibly_invalid_spec(); 268 << redirect_info.new_url.possibly_invalid_spec();
264 269
265 // Tell the renderer that this request was disallowed. 270 // Tell the renderer that this request was disallowed.
266 Cancel(); 271 Cancel();
267 return; 272 return;
268 } 273 }
269 } 274 }
270 275
276 if (delegate_->HandleExternalProtocol(this, redirect_info.new_url)) {
277 // The request is complete so we can remove it.
278 CancelAndIgnore();
279 return;
280 }
281
271 scoped_refptr<ResourceResponse> response = new ResourceResponse(); 282 scoped_refptr<ResourceResponse> response = new ResourceResponse();
272 PopulateResourceResponse(info, request_.get(), response.get()); 283 PopulateResourceResponse(info, request_.get(), response.get());
273 delegate_->DidReceiveRedirect(this, redirect_info.new_url, response.get()); 284 delegate_->DidReceiveRedirect(this, redirect_info.new_url, response.get());
274 if (!handler_->OnRequestRedirected(redirect_info, response.get(), defer)) { 285 if (!handler_->OnRequestRedirected(redirect_info, response.get(), defer)) {
275 Cancel(); 286 Cancel();
276 } else if (*defer) { 287 } else if (*defer) {
277 deferred_stage_ = DEFERRED_REDIRECT; // Follow redirect when resumed. 288 deferred_stage_ = DEFERRED_REDIRECT; // Follow redirect when resumed.
278 DCHECK(deferred_redirect_url_.is_empty());
279 deferred_redirect_url_ = redirect_info.new_url;
280 } else if (delegate_->HandleExternalProtocol(this, redirect_info.new_url)) {
281 // The request is complete so we can remove it.
282 CancelAndIgnore();
283 return;
284 } 289 }
285 } 290 }
286 291
287 void ResourceLoader::OnAuthRequired(net::URLRequest* unused, 292 void ResourceLoader::OnAuthRequired(net::URLRequest* unused,
288 net::AuthChallengeInfo* auth_info) { 293 net::AuthChallengeInfo* auth_info) {
289 DCHECK_EQ(request_.get(), unused); 294 DCHECK_EQ(request_.get(), unused);
290 295
291 ResourceRequestInfoImpl* info = GetRequestInfo(); 296 ResourceRequestInfoImpl* info = GetRequestInfo();
292 if (info->do_not_prompt_for_login()) { 297 if (info->do_not_prompt_for_login()) {
293 request_->CancelAuth(); 298 request_->CancelAuth();
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 DeferredStage stage = deferred_stage_; 443 DeferredStage stage = deferred_stage_;
439 deferred_stage_ = DEFERRED_NONE; 444 deferred_stage_ = DEFERRED_NONE;
440 switch (stage) { 445 switch (stage) {
441 case DEFERRED_NONE: 446 case DEFERRED_NONE:
442 NOTREACHED(); 447 NOTREACHED();
443 break; 448 break;
444 case DEFERRED_START: 449 case DEFERRED_START:
445 StartRequestInternal(); 450 StartRequestInternal();
446 break; 451 break;
447 case DEFERRED_REDIRECT: 452 case DEFERRED_REDIRECT:
448 FollowDeferredRedirectInternal(); 453 request_->FollowDeferredRedirect();
449 break; 454 break;
450 case DEFERRED_READ: 455 case DEFERRED_READ:
451 base::ThreadTaskRunnerHandle::Get()->PostTask( 456 base::ThreadTaskRunnerHandle::Get()->PostTask(
452 FROM_HERE, base::Bind(&ResourceLoader::ResumeReading, 457 FROM_HERE, base::Bind(&ResourceLoader::ResumeReading,
453 weak_ptr_factory_.GetWeakPtr())); 458 weak_ptr_factory_.GetWeakPtr()));
454 break; 459 break;
455 case DEFERRED_RESPONSE_COMPLETE: 460 case DEFERRED_RESPONSE_COMPLETE:
456 base::ThreadTaskRunnerHandle::Get()->PostTask( 461 base::ThreadTaskRunnerHandle::Get()->PostTask(
457 FROM_HERE, base::Bind(&ResourceLoader::ResponseCompleted, 462 FROM_HERE, base::Bind(&ResourceLoader::ResponseCompleted,
458 weak_ptr_factory_.GetWeakPtr())); 463 weak_ptr_factory_.GetWeakPtr()));
459 break; 464 break;
460 case DEFERRED_FINISH: 465 case DEFERRED_FINISH:
461 // Delay self-destruction since we don't know how we were reached. 466 // Delay self-destruction since we don't know how we were reached.
462 base::ThreadTaskRunnerHandle::Get()->PostTask( 467 base::ThreadTaskRunnerHandle::Get()->PostTask(
463 FROM_HERE, base::Bind(&ResourceLoader::CallDidFinishLoading, 468 FROM_HERE, base::Bind(&ResourceLoader::CallDidFinishLoading,
464 weak_ptr_factory_.GetWeakPtr())); 469 weak_ptr_factory_.GetWeakPtr()));
465 break; 470 break;
466 } 471 }
467 } 472 }
468 473
469 void ResourceLoader::Cancel() { 474 void ResourceLoader::Cancel() {
470 CancelRequest(false); 475 CancelRequest(false);
471 } 476 }
472 477
473 void ResourceLoader::StartRequestInternal() { 478 void ResourceLoader::StartRequestInternal() {
474 DCHECK(!request_->is_pending()); 479 DCHECK(!request_->is_pending());
475 480
476 // Note: at this point any possible deferred start actions are already over.
477
478 if (!request_->status().is_success()) { 481 if (!request_->status().is_success()) {
479 return; 482 return;
480 } 483 }
481 484
482 if (delegate_->HandleExternalProtocol(this, request_->url())) {
483 CancelAndIgnore();
484 return;
485 }
486
487 started_request_ = true; 485 started_request_ = true;
488 request_->Start(); 486 request_->Start();
489 487
490 delegate_->DidStartRequest(this); 488 delegate_->DidStartRequest(this);
491 } 489 }
492 490
493 void ResourceLoader::CancelRequestInternal(int error, bool from_renderer) { 491 void ResourceLoader::CancelRequestInternal(int error, bool from_renderer) {
494 DVLOG(1) << "CancelRequestInternal: " << request_->url().spec(); 492 DVLOG(1) << "CancelRequestInternal: " << request_->url().spec();
495 493
496 ResourceRequestInfoImpl* info = GetRequestInfo(); 494 ResourceRequestInfoImpl* info = GetRequestInfo();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 if (!was_pending) { 527 if (!was_pending) {
530 // If the request isn't in flight, then we won't get an asynchronous 528 // If the request isn't in flight, then we won't get an asynchronous
531 // notification from the request, so we have to signal ourselves to finish 529 // notification from the request, so we have to signal ourselves to finish
532 // this request. 530 // this request.
533 base::ThreadTaskRunnerHandle::Get()->PostTask( 531 base::ThreadTaskRunnerHandle::Get()->PostTask(
534 FROM_HERE, base::Bind(&ResourceLoader::ResponseCompleted, 532 FROM_HERE, base::Bind(&ResourceLoader::ResponseCompleted,
535 weak_ptr_factory_.GetWeakPtr())); 533 weak_ptr_factory_.GetWeakPtr()));
536 } 534 }
537 } 535 }
538 536
539 void ResourceLoader::FollowDeferredRedirectInternal() {
540 DCHECK(!deferred_redirect_url_.is_empty());
541 GURL redirect_url = deferred_redirect_url_;
542 deferred_redirect_url_ = GURL();
543 if (delegate_->HandleExternalProtocol(this, deferred_redirect_url_)) {
544 CancelAndIgnore();
545 } else {
546 request_->FollowDeferredRedirect();
547 }
548 }
549
550 void ResourceLoader::CompleteResponseStarted() { 537 void ResourceLoader::CompleteResponseStarted() {
551 ResourceRequestInfoImpl* info = GetRequestInfo(); 538 ResourceRequestInfoImpl* info = GetRequestInfo();
552 scoped_refptr<ResourceResponse> response = new ResourceResponse(); 539 scoped_refptr<ResourceResponse> response = new ResourceResponse();
553 PopulateResourceResponse(info, request_.get(), response.get()); 540 PopulateResourceResponse(info, request_.get(), response.get());
554 541
555 delegate_->DidReceiveResponse(this); 542 delegate_->DidReceiveResponse(this);
556 543
557 // TODO(darin): Remove ScopedTracker below once crbug.com/475761 is fixed. 544 // TODO(darin): Remove ScopedTracker below once crbug.com/475761 is fixed.
558 tracked_objects::ScopedTracker tracking_profile( 545 tracked_objects::ScopedTracker tracking_profile(
559 FROM_HERE_WITH_EXPLICIT_FUNCTION("475761 OnResponseStarted()")); 546 FROM_HERE_WITH_EXPLICIT_FUNCTION("475761 OnResponseStarted()"));
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", prefetch_status, 727 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", prefetch_status,
741 STATUS_MAX); 728 STATUS_MAX);
742 } 729 }
743 } else if (request_->response_info().unused_since_prefetch) { 730 } else if (request_->response_info().unused_since_prefetch) {
744 TimeDelta total_time = base::TimeTicks::Now() - request_->creation_time(); 731 TimeDelta total_time = base::TimeTicks::Now() - request_->creation_time();
745 UMA_HISTOGRAM_TIMES("Net.Prefetch.TimeSpentOnPrefetchHit", total_time); 732 UMA_HISTOGRAM_TIMES("Net.Prefetch.TimeSpentOnPrefetchHit", total_time);
746 } 733 }
747 } 734 }
748 735
749 } // namespace content 736 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/resource_loader.h ('k') | content/browser/loader/resource_loader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698