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

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

Issue 267563004: Avoid issuing a Read() after draining a request. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Re-upload to see if it would make bots happy. Created 6 years, 7 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/resource_loader.h" 5 #include "content/browser/loader/resource_loader.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 } 161 }
162 } 162 }
163 163
164 void ResourceLoader::MarkAsTransferring() { 164 void ResourceLoader::MarkAsTransferring() {
165 CHECK(ResourceType::IsFrame(GetRequestInfo()->GetResourceType())) 165 CHECK(ResourceType::IsFrame(GetRequestInfo()->GetResourceType()))
166 << "Can only transfer for navigations"; 166 << "Can only transfer for navigations";
167 is_transferring_ = true; 167 is_transferring_ = true;
168 } 168 }
169 169
170 void ResourceLoader::CompleteTransfer() { 170 void ResourceLoader::CompleteTransfer() {
171 DCHECK_EQ(DEFERRED_READ, deferred_stage_); 171 // Although CrossSiteResourceHandler defers at OnResponseStarted
172 // (DEFERRED_READ), it may be seeing a replay of events via
173 // BufferedResourceHandler, and so the request itself is actually deferred at
174 // a later read stage.
175 DCHECK(DEFERRED_READ == deferred_stage_ ||
176 DEFERRED_RESPONSE_COMPLETE == deferred_stage_);
172 177
173 is_transferring_ = false; 178 is_transferring_ = false;
174 GetRequestInfo()->cross_site_handler()->ResumeResponse(); 179 GetRequestInfo()->cross_site_handler()->ResumeResponse();
175 } 180 }
176 181
177 ResourceRequestInfoImpl* ResourceLoader::GetRequestInfo() { 182 ResourceRequestInfoImpl* ResourceLoader::GetRequestInfo() {
178 return ResourceRequestInfoImpl::ForRequest(request_.get()); 183 return ResourceRequestInfoImpl::ForRequest(request_.get());
179 } 184 }
180 185
181 void ResourceLoader::ClearLoginDelegate() { 186 void ResourceLoader::ClearLoginDelegate() {
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 } 361 }
357 362
358 CompleteRead(bytes_read); 363 CompleteRead(bytes_read);
359 364
360 // If the handler cancelled or deferred the request, do not continue 365 // If the handler cancelled or deferred the request, do not continue
361 // processing the read. If cancelled, the URLRequest has already been 366 // processing the read. If cancelled, the URLRequest has already been
362 // cancelled and will schedule an erroring OnReadCompleted later. If deferred, 367 // cancelled and will schedule an erroring OnReadCompleted later. If deferred,
363 // do nothing until resumed. 368 // do nothing until resumed.
364 // 369 //
365 // Note: if bytes_read is 0 (EOF) and the handler defers, resumption will call 370 // Note: if bytes_read is 0 (EOF) and the handler defers, resumption will call
366 // Read() on the URLRequest again and get a second EOF. 371 // ResponseCompleted().
367 if (is_deferred() || !request_->status().is_success()) 372 if (is_deferred() || !request_->status().is_success())
368 return; 373 return;
369 374
370 if (bytes_read > 0) { 375 if (bytes_read > 0) {
371 StartReading(true); // Read the next chunk. 376 StartReading(true); // Read the next chunk.
372 } else { 377 } else {
373 // URLRequest reported an EOF. Call ResponseCompleted. 378 // URLRequest reported an EOF. Call ResponseCompleted.
374 DCHECK_EQ(0, bytes_read); 379 DCHECK_EQ(0, bytes_read);
375 ResponseCompleted(); 380 ResponseCompleted();
376 } 381 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 break; 424 break;
420 case DEFERRED_REDIRECT: 425 case DEFERRED_REDIRECT:
421 request_->FollowDeferredRedirect(); 426 request_->FollowDeferredRedirect();
422 break; 427 break;
423 case DEFERRED_READ: 428 case DEFERRED_READ:
424 base::MessageLoop::current()->PostTask( 429 base::MessageLoop::current()->PostTask(
425 FROM_HERE, 430 FROM_HERE,
426 base::Bind(&ResourceLoader::ResumeReading, 431 base::Bind(&ResourceLoader::ResumeReading,
427 weak_ptr_factory_.GetWeakPtr())); 432 weak_ptr_factory_.GetWeakPtr()));
428 break; 433 break;
434 case DEFERRED_RESPONSE_COMPLETE:
435 base::MessageLoop::current()->PostTask(
436 FROM_HERE,
437 base::Bind(&ResourceLoader::ResponseCompleted,
438 weak_ptr_factory_.GetWeakPtr()));
439 break;
429 case DEFERRED_FINISH: 440 case DEFERRED_FINISH:
430 // Delay self-destruction since we don't know how we were reached. 441 // Delay self-destruction since we don't know how we were reached.
431 base::MessageLoop::current()->PostTask( 442 base::MessageLoop::current()->PostTask(
432 FROM_HERE, 443 FROM_HERE,
433 base::Bind(&ResourceLoader::CallDidFinishLoading, 444 base::Bind(&ResourceLoader::CallDidFinishLoading,
434 weak_ptr_factory_.GetWeakPtr())); 445 weak_ptr_factory_.GetWeakPtr()));
435 break; 446 break;
436 } 447 }
437 } 448 }
438 449
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 void ResourceLoader::CompleteRead(int bytes_read) { 626 void ResourceLoader::CompleteRead(int bytes_read) {
616 DCHECK(bytes_read >= 0); 627 DCHECK(bytes_read >= 0);
617 DCHECK(request_->status().is_success()); 628 DCHECK(request_->status().is_success());
618 629
619 ResourceRequestInfoImpl* info = GetRequestInfo(); 630 ResourceRequestInfoImpl* info = GetRequestInfo();
620 631
621 bool defer = false; 632 bool defer = false;
622 if (!handler_->OnReadCompleted(info->GetRequestID(), bytes_read, &defer)) { 633 if (!handler_->OnReadCompleted(info->GetRequestID(), bytes_read, &defer)) {
623 Cancel(); 634 Cancel();
624 } else if (defer) { 635 } else if (defer) {
625 deferred_stage_ = DEFERRED_READ; // Read next chunk when resumed. 636 deferred_stage_ =
637 bytes_read > 0 ? DEFERRED_READ : DEFERRED_RESPONSE_COMPLETE;
626 } 638 }
627 639
628 // Note: the request may still have been cancelled while OnReadCompleted 640 // Note: the request may still have been cancelled while OnReadCompleted
629 // returns true if OnReadCompleted caused request to get cancelled 641 // returns true if OnReadCompleted caused request to get cancelled
630 // out-of-band. (In AwResourceDispatcherHostDelegate::DownloadStarting, for 642 // out-of-band. (In AwResourceDispatcherHostDelegate::DownloadStarting, for
631 // instance.) 643 // instance.)
632 } 644 }
633 645
634 void ResourceLoader::ResponseCompleted() { 646 void ResourceLoader::ResponseCompleted() {
635 VLOG(1) << "ResponseCompleted: " << request_->url().spec(); 647 VLOG(1) << "ResponseCompleted: " << request_->url().spec();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 case net::URLRequestStatus::FAILED: 707 case net::URLRequestStatus::FAILED:
696 status = STATUS_UNDEFINED; 708 status = STATUS_UNDEFINED;
697 break; 709 break;
698 } 710 }
699 711
700 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", status, STATUS_MAX); 712 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", status, STATUS_MAX);
701 } 713 }
702 } 714 }
703 715
704 } // namespace content 716 } // 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