OLD | NEW |
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 "net/url_request/url_request_job.h" | 5 #include "net/url_request/url_request_job.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 | 372 |
373 bool URLRequestJob::CanEnablePrivacyMode() const { | 373 bool URLRequestJob::CanEnablePrivacyMode() const { |
374 return request_->CanEnablePrivacyMode(); | 374 return request_->CanEnablePrivacyMode(); |
375 } | 375 } |
376 | 376 |
377 void URLRequestJob::NotifyBeforeNetworkStart(bool* defer) { | 377 void URLRequestJob::NotifyBeforeNetworkStart(bool* defer) { |
378 request_->NotifyBeforeNetworkStart(defer); | 378 request_->NotifyBeforeNetworkStart(defer); |
379 } | 379 } |
380 | 380 |
381 void URLRequestJob::NotifyHeadersComplete() { | 381 void URLRequestJob::NotifyHeadersComplete() { |
382 if (!request_->has_delegate()) | |
383 return; // The request was destroyed, so there is no more work to do. | |
384 | |
385 if (has_handled_response_) | 382 if (has_handled_response_) |
386 return; | 383 return; |
387 | 384 |
388 // This should not be called on error, and the job type should have cleared | 385 // This should not be called on error, and the job type should have cleared |
389 // IO_PENDING state before calling this method. | 386 // IO_PENDING state before calling this method. |
390 // TODO(mmenke): Change this to a DCHECK once https://crbug.com/508900 is | 387 // TODO(mmenke): Change this to a DCHECK once https://crbug.com/508900 is |
391 // resolved. | 388 // resolved. |
392 CHECK(request_->status().is_success()); | 389 CHECK(request_->status().is_success()); |
393 | 390 |
394 // Initialize to the current time, and let the subclass optionally override | 391 // Initialize to the current time, and let the subclass optionally override |
(...skipping 18 matching lines...) Expand all Loading... |
413 // code must return immediately. | 410 // code must return immediately. |
414 base::WeakPtr<URLRequestJob> weak_this(weak_factory_.GetWeakPtr()); | 411 base::WeakPtr<URLRequestJob> weak_this(weak_factory_.GetWeakPtr()); |
415 | 412 |
416 RedirectInfo redirect_info = | 413 RedirectInfo redirect_info = |
417 ComputeRedirectInfo(new_location, http_status_code); | 414 ComputeRedirectInfo(new_location, http_status_code); |
418 bool defer_redirect = false; | 415 bool defer_redirect = false; |
419 request_->NotifyReceivedRedirect(redirect_info, &defer_redirect); | 416 request_->NotifyReceivedRedirect(redirect_info, &defer_redirect); |
420 | 417 |
421 // Ensure that the request wasn't detached, destroyed, or canceled in | 418 // Ensure that the request wasn't detached, destroyed, or canceled in |
422 // NotifyReceivedRedirect. | 419 // NotifyReceivedRedirect. |
423 if (!weak_this || !request_->has_delegate() || | 420 if (!weak_this || !request_->status().is_success()) |
424 !request_->status().is_success()) { | |
425 return; | 421 return; |
426 } | |
427 | 422 |
428 if (defer_redirect) { | 423 if (defer_redirect) { |
429 deferred_redirect_info_ = redirect_info; | 424 deferred_redirect_info_ = redirect_info; |
430 } else { | 425 } else { |
431 FollowRedirect(redirect_info); | 426 FollowRedirect(redirect_info); |
432 } | 427 } |
433 return; | 428 return; |
434 } | 429 } |
435 | 430 |
436 if (NeedsAuth()) { | 431 if (NeedsAuth()) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 *count = 0; | 470 *count = 0; |
476 } | 471 } |
477 } | 472 } |
478 | 473 |
479 void URLRequestJob::ReadRawDataComplete(int result) { | 474 void URLRequestJob::ReadRawDataComplete(int result) { |
480 // TODO(cbentzel): Remove ScopedTracker below once crbug.com/475755 is fixed. | 475 // TODO(cbentzel): Remove ScopedTracker below once crbug.com/475755 is fixed. |
481 tracked_objects::ScopedTracker tracking_profile( | 476 tracked_objects::ScopedTracker tracking_profile( |
482 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 477 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
483 "475755 URLRequestJob::RawReadCompleted")); | 478 "475755 URLRequestJob::RawReadCompleted")); |
484 | 479 |
485 if (!request_->has_delegate()) | |
486 return; // The request was destroyed, so there is no more work to do. | |
487 | |
488 // TODO(darin): Bug 1004233. Re-enable this test once all of the chrome | 480 // TODO(darin): Bug 1004233. Re-enable this test once all of the chrome |
489 // unit_tests have been fixed to not trip this. | 481 // unit_tests have been fixed to not trip this. |
490 #if 0 | 482 #if 0 |
491 DCHECK(!request_->status().is_io_pending()); | 483 DCHECK(!request_->status().is_io_pending()); |
492 #endif | 484 #endif |
493 // The headers should be complete before reads complete | 485 // The headers should be complete before reads complete |
494 DCHECK(has_handled_response_); | 486 DCHECK(has_handled_response_); |
495 | 487 |
496 Error error; | 488 Error error; |
497 int bytes_read; | 489 int bytes_read; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 | 599 |
608 // Complete this notification later. This prevents us from re-entering the | 600 // Complete this notification later. This prevents us from re-entering the |
609 // delegate if we're done because of a synchronous call. | 601 // delegate if we're done because of a synchronous call. |
610 base::ThreadTaskRunnerHandle::Get()->PostTask( | 602 base::ThreadTaskRunnerHandle::Get()->PostTask( |
611 FROM_HERE, base::Bind(&URLRequestJob::CompleteNotifyDone, | 603 FROM_HERE, base::Bind(&URLRequestJob::CompleteNotifyDone, |
612 weak_factory_.GetWeakPtr())); | 604 weak_factory_.GetWeakPtr())); |
613 } | 605 } |
614 | 606 |
615 void URLRequestJob::CompleteNotifyDone() { | 607 void URLRequestJob::CompleteNotifyDone() { |
616 // Check if we should notify the delegate that we're done because of an error. | 608 // Check if we should notify the delegate that we're done because of an error. |
617 if (!request_->status().is_success() && request_->has_delegate()) { | 609 if (!request_->status().is_success()) { |
618 // We report the error differently depending on whether we've called | 610 // We report the error differently depending on whether we've called |
619 // OnResponseStarted yet. | 611 // OnResponseStarted yet. |
620 if (has_handled_response_) { | 612 if (has_handled_response_) { |
621 // We signal the error by calling OnReadComplete with a bytes_read of -1. | 613 // We signal the error by calling OnReadComplete with a bytes_read of -1. |
622 request_->NotifyReadCompleted(-1); | 614 request_->NotifyReadCompleted(-1); |
623 } else { | 615 } else { |
624 has_handled_response_ = true; | 616 has_handled_response_ = true; |
625 request_->NotifyResponseStarted(); | 617 request_->NotifyResponseStarted(); |
626 } | 618 } |
627 } | 619 } |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
967 int64_t total_sent_bytes = GetTotalSentBytes(); | 959 int64_t total_sent_bytes = GetTotalSentBytes(); |
968 DCHECK_GE(total_sent_bytes, last_notified_total_sent_bytes_); | 960 DCHECK_GE(total_sent_bytes, last_notified_total_sent_bytes_); |
969 if (total_sent_bytes > last_notified_total_sent_bytes_) { | 961 if (total_sent_bytes > last_notified_total_sent_bytes_) { |
970 network_delegate_->NotifyNetworkBytesSent( | 962 network_delegate_->NotifyNetworkBytesSent( |
971 request_, total_sent_bytes - last_notified_total_sent_bytes_); | 963 request_, total_sent_bytes - last_notified_total_sent_bytes_); |
972 } | 964 } |
973 last_notified_total_sent_bytes_ = total_sent_bytes; | 965 last_notified_total_sent_bytes_ = total_sent_bytes; |
974 } | 966 } |
975 | 967 |
976 } // namespace net | 968 } // namespace net |
OLD | NEW |