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

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

Issue 2557433005: Revert of Fix a pair of ResourceLoader cancellation/error bugs. (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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 343
344 DVLOG(1) << "OnResponseStarted: " << request_->url().spec(); 344 DVLOG(1) << "OnResponseStarted: " << request_->url().spec();
345 345
346 if (!request_->status().is_success()) { 346 if (!request_->status().is_success()) {
347 ResponseCompleted(); 347 ResponseCompleted();
348 return; 348 return;
349 } 349 }
350 350
351 CompleteResponseStarted(); 351 CompleteResponseStarted();
352 352
353 // If the handler deferred the request, it will resume the request later. If 353 if (is_deferred())
354 // the request was cancelled, the request will call back into |this| with a
355 // bogus read completed error.
356 if (is_deferred() || !request_->status().is_success())
357 return; 354 return;
358 355
359 StartReading(false); // Read the first chunk. 356 if (request_->status().is_success())
357 StartReading(false); // Read the first chunk.
358 else
359 ResponseCompleted();
360 } 360 }
361 361
362 void ResourceLoader::OnReadCompleted(net::URLRequest* unused, int bytes_read) { 362 void ResourceLoader::OnReadCompleted(net::URLRequest* unused, int bytes_read) {
363 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("loading"), 363 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("loading"),
364 "ResourceLoader::OnReadCompleted"); 364 "ResourceLoader::OnReadCompleted");
365 DCHECK_EQ(request_.get(), unused); 365 DCHECK_EQ(request_.get(), unused);
366 DVLOG(1) << "OnReadCompleted: \"" << request_->url().spec() << "\"" 366 DVLOG(1) << "OnReadCompleted: \"" << request_->url().spec() << "\""
367 << " bytes_read = " << bytes_read; 367 << " bytes_read = " << bytes_read;
368 368
369 // bytes_read == -1 always implies an error. 369 // bytes_read == -1 always implies an error.
370 if (bytes_read == -1 || !request_->status().is_success()) { 370 if (bytes_read == -1 || !request_->status().is_success()) {
371 ResponseCompleted(); 371 ResponseCompleted();
372 return; 372 return;
373 } 373 }
374 374
375 CompleteRead(bytes_read); 375 CompleteRead(bytes_read);
376 376
377 // If the handler cancelled or deferred the request, do not continue 377 // If the handler cancelled or deferred the request, do not continue
378 // processing the read. If canceled, either the request will call into |this| 378 // processing the read. If cancelled, the URLRequest has already been
379 // with a bogus read error, or, if the request was completed, a task posted 379 // cancelled and will schedule an erroring OnReadCompleted later. If deferred,
380 // from ResourceLoader::CancelREquestInternal will run OnResponseCompleted. 380 // do nothing until resumed.
381 //
382 // Note: if bytes_read is 0 (EOF) and the handler defers, resumption will call
383 // ResponseCompleted().
381 if (is_deferred() || !request_->status().is_success()) 384 if (is_deferred() || !request_->status().is_success())
382 return; 385 return;
383 386
384 if (bytes_read > 0) { 387 if (bytes_read > 0) {
385 StartReading(true); // Read the next chunk. 388 StartReading(true); // Read the next chunk.
386 } else { 389 } else {
387 // TODO(darin): Remove ScopedTracker below once crbug.com/475761 is fixed. 390 // TODO(darin): Remove ScopedTracker below once crbug.com/475761 is fixed.
388 tracked_objects::ScopedTracker tracking_profile( 391 tracked_objects::ScopedTracker tracking_profile(
389 FROM_HERE_WITH_EXPLICIT_FUNCTION("475761 ResponseCompleted()")); 392 FROM_HERE_WITH_EXPLICIT_FUNCTION("475761 ResponseCompleted()"));
390 393
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 read_deferral_start_time_ = base::TimeTicks::Now(); 555 read_deferral_start_time_ = base::TimeTicks::Now();
553 deferred_stage_ = DEFERRED_READ; // Read first chunk when resumed. 556 deferred_stage_ = DEFERRED_READ; // Read first chunk when resumed.
554 } 557 }
555 } 558 }
556 559
557 void ResourceLoader::StartReading(bool is_continuation) { 560 void ResourceLoader::StartReading(bool is_continuation) {
558 int bytes_read = 0; 561 int bytes_read = 0;
559 ReadMore(&bytes_read); 562 ReadMore(&bytes_read);
560 563
561 // If IO is pending, wait for the URLRequest to call OnReadCompleted. 564 // If IO is pending, wait for the URLRequest to call OnReadCompleted.
562 // On error or cancellation, wait for notification of failure. 565 if (request_->status().is_io_pending())
563 if (request_->status().is_io_pending() || !request_->status().is_success())
564 return; 566 return;
565 567
566 if (!is_continuation || bytes_read <= 0) { 568 if (!is_continuation || bytes_read <= 0) {
567 OnReadCompleted(request_.get(), bytes_read); 569 OnReadCompleted(request_.get(), bytes_read);
568 } else { 570 } else {
569 // Else, trigger OnReadCompleted asynchronously to avoid starving the IO 571 // Else, trigger OnReadCompleted asynchronously to avoid starving the IO
570 // thread in case the URLRequest can provide data synchronously. 572 // thread in case the URLRequest can provide data synchronously.
571 base::ThreadTaskRunnerHandle::Get()->PostTask( 573 base::ThreadTaskRunnerHandle::Get()->PostTask(
572 FROM_HERE, 574 FROM_HERE,
573 base::Bind(&ResourceLoader::OnReadCompleted, 575 base::Bind(&ResourceLoader::OnReadCompleted,
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", prefetch_status, 737 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", prefetch_status,
736 STATUS_MAX); 738 STATUS_MAX);
737 } 739 }
738 } else if (request_->response_info().unused_since_prefetch) { 740 } else if (request_->response_info().unused_since_prefetch) {
739 TimeDelta total_time = base::TimeTicks::Now() - request_->creation_time(); 741 TimeDelta total_time = base::TimeTicks::Now() - request_->creation_time();
740 UMA_HISTOGRAM_TIMES("Net.Prefetch.TimeSpentOnPrefetchHit", total_time); 742 UMA_HISTOGRAM_TIMES("Net.Prefetch.TimeSpentOnPrefetchHit", total_time);
741 } 743 }
742 } 744 }
743 745
744 } // namespace content 746 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/intercepting_resource_handler_unittest.cc ('k') | content/browser/loader/resource_loader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698