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

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

Issue 2543633004: Fix a pair of ResourceLoader cancellation/error bugs. (Closed)
Patch Set: Fix cert tests, add out-of-band cancel tests 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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 344
345 DVLOG(1) << "OnResponseStarted: " << request_->url().spec(); 345 DVLOG(1) << "OnResponseStarted: " << request_->url().spec();
346 346
347 if (!request_->status().is_success()) { 347 if (!request_->status().is_success()) {
348 ResponseCompleted(); 348 ResponseCompleted();
349 return; 349 return;
350 } 350 }
351 351
352 CompleteResponseStarted(); 352 CompleteResponseStarted();
353 353
354 if (is_deferred()) 354 // If the handler deferred the request, it will resume the request later. If
355 // the request was cancelled, it will call back into |this| to notify it of
356 // the cancellation.
Randy Smith (Not in Mondays) 2016/12/01 20:12:52 I'm confused by this comment. We're dealing here
mmenke 2016/12/01 20:47:43 CompleteResponseStarted() will have cancelled the
Randy Smith (Not in Mondays) 2016/12/02 20:38:55 So just to confirm I understand what's going on: *
357 if (is_deferred() || !request_->status().is_success())
355 return; 358 return;
356 359
357 if (request_->status().is_success()) 360 StartReading(false); // Read the first chunk.
358 StartReading(false); // Read the first chunk.
359 else
360 ResponseCompleted();
361 } 361 }
362 362
363 void ResourceLoader::OnReadCompleted(net::URLRequest* unused, int bytes_read) { 363 void ResourceLoader::OnReadCompleted(net::URLRequest* unused, int bytes_read) {
364 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("loading"), 364 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("loading"),
365 "ResourceLoader::OnReadCompleted"); 365 "ResourceLoader::OnReadCompleted");
366 DCHECK_EQ(request_.get(), unused); 366 DCHECK_EQ(request_.get(), unused);
367 DVLOG(1) << "OnReadCompleted: \"" << request_->url().spec() << "\"" 367 DVLOG(1) << "OnReadCompleted: \"" << request_->url().spec() << "\""
368 << " bytes_read = " << bytes_read; 368 << " bytes_read = " << bytes_read;
369 369
370 // bytes_read == -1 always implies an error. 370 // bytes_read == -1 always implies an error.
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 read_deferral_start_time_ = base::TimeTicks::Now(); 556 read_deferral_start_time_ = base::TimeTicks::Now();
557 deferred_stage_ = DEFERRED_READ; // Read first chunk when resumed. 557 deferred_stage_ = DEFERRED_READ; // Read first chunk when resumed.
558 } 558 }
559 } 559 }
560 560
561 void ResourceLoader::StartReading(bool is_continuation) { 561 void ResourceLoader::StartReading(bool is_continuation) {
562 int bytes_read = 0; 562 int bytes_read = 0;
563 ReadMore(&bytes_read); 563 ReadMore(&bytes_read);
564 564
565 // If IO is pending, wait for the URLRequest to call OnReadCompleted. 565 // If IO is pending, wait for the URLRequest to call OnReadCompleted.
566 if (request_->status().is_io_pending()) 566 // On error or cancellation, wait for notification of failure.
Randy Smith (Not in Mondays) 2016/12/01 20:12:52 I'm sure I'm missing a pathway, but ReadMore inclu
Randy Smith (Not in Mondays) 2016/12/01 20:12:52 How about "... wait for arrival of ResponseComplet
mmenke 2016/12/01 20:47:43 Note that Cancel only posts that task if the reque
mmenke 2016/12/01 20:47:43 On synchronous failure, URLRequest::Read calls bac
Randy Smith (Not in Mondays) 2016/12/02 20:38:55 Wow. I keep feeling like I've gotten to the botto
567 if (request_->status().is_io_pending() || !request_->status().is_success())
567 return; 568 return;
568 569
569 if (!is_continuation || bytes_read <= 0) { 570 if (!is_continuation || bytes_read <= 0) {
570 OnReadCompleted(request_.get(), bytes_read); 571 OnReadCompleted(request_.get(), bytes_read);
571 } else { 572 } else {
572 // Else, trigger OnReadCompleted asynchronously to avoid starving the IO 573 // Else, trigger OnReadCompleted asynchronously to avoid starving the IO
573 // thread in case the URLRequest can provide data synchronously. 574 // thread in case the URLRequest can provide data synchronously.
574 base::ThreadTaskRunnerHandle::Get()->PostTask( 575 base::ThreadTaskRunnerHandle::Get()->PostTask(
575 FROM_HERE, 576 FROM_HERE,
576 base::Bind(&ResourceLoader::OnReadCompleted, 577 base::Bind(&ResourceLoader::OnReadCompleted,
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 } 722 }
722 723
723 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", status, STATUS_MAX); 724 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", status, STATUS_MAX);
724 } else if (request_->response_info().unused_since_prefetch) { 725 } else if (request_->response_info().unused_since_prefetch) {
725 TimeDelta total_time = base::TimeTicks::Now() - request_->creation_time(); 726 TimeDelta total_time = base::TimeTicks::Now() - request_->creation_time();
726 UMA_HISTOGRAM_TIMES("Net.Prefetch.TimeSpentOnPrefetchHit", total_time); 727 UMA_HISTOGRAM_TIMES("Net.Prefetch.TimeSpentOnPrefetchHit", total_time);
727 } 728 }
728 } 729 }
729 730
730 } // namespace content 731 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698