Chromium Code Reviews| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 550 | 550 |
| 551 void URLRequestJob::NotifyStartError(const URLRequestStatus &status) { | 551 void URLRequestJob::NotifyStartError(const URLRequestStatus &status) { |
| 552 DCHECK(!has_handled_response_); | 552 DCHECK(!has_handled_response_); |
| 553 DCHECK(request_->status().is_io_pending()); | 553 DCHECK(request_->status().is_io_pending()); |
| 554 | 554 |
| 555 has_handled_response_ = true; | 555 has_handled_response_ = true; |
| 556 // There may be relevant information in the response info even in the | 556 // There may be relevant information in the response info even in the |
| 557 // error case. | 557 // error case. |
| 558 GetResponseInfo(&request_->response_info_); | 558 GetResponseInfo(&request_->response_info_); |
| 559 | 559 |
| 560 MaybeNotifyNetworkBytes(); | |
| 561 | |
| 560 request_->NotifyResponseStarted(status); | 562 request_->NotifyResponseStarted(status); |
| 561 // |this| may have been deleted here. | 563 // |this| may have been deleted here. |
| 562 } | 564 } |
| 563 | 565 |
| 564 void URLRequestJob::NotifyDone(const URLRequestStatus &status) { | 566 void URLRequestJob::NotifyDone(const URLRequestStatus &status) { |
| 565 DCHECK(!done_) << "Job sending done notification twice"; | 567 DCHECK(!done_) << "Job sending done notification twice"; |
| 566 if (done_) | 568 if (done_) |
| 567 return; | 569 return; |
| 568 done_ = true; | 570 done_ = true; |
| 569 | 571 |
| 570 // Unless there was an error, we should have at least tried to handle | 572 // Unless there was an error, we should have at least tried to handle |
| 571 // the response before getting here. | 573 // the response before getting here. |
| 572 DCHECK(has_handled_response_ || !status.is_success()); | 574 DCHECK(has_handled_response_ || !status.is_success()); |
| 573 | 575 |
| 574 request_->set_is_pending(false); | 576 request_->set_is_pending(false); |
| 575 // With async IO, it's quite possible to have a few outstanding | 577 // With async IO, it's quite possible to have a few outstanding |
| 576 // requests. We could receive a request to Cancel, followed shortly | 578 // requests. We could receive a request to Cancel, followed shortly |
| 577 // by a successful IO. For tracking the status(), once there is | 579 // by a successful IO. For tracking the status(), once there is |
| 578 // an error, we do not change the status back to success. To | 580 // an error, we do not change the status back to success. To |
| 579 // enforce this, only set the status if the job is so far | 581 // enforce this, only set the status if the job is so far |
| 580 // successful. | 582 // successful. |
| 581 if (request_->status().is_success()) { | 583 if (request_->status().is_success()) { |
| 582 if (status.status() == URLRequestStatus::FAILED) | 584 if (status.status() == URLRequestStatus::FAILED) |
| 583 request_->net_log().AddEventWithNetErrorCode(NetLogEventType::FAILED, | 585 request_->net_log().AddEventWithNetErrorCode(NetLogEventType::FAILED, |
| 584 status.error()); | 586 status.error()); |
| 585 request_->set_status(status); | 587 request_->set_status(status); |
| 586 } | 588 } |
| 587 | 589 |
| 588 MaybeNotifyNetworkBytes(); | |
| 589 | |
| 590 // Complete this notification later. This prevents us from re-entering the | 590 // Complete this notification later. This prevents us from re-entering the |
| 591 // delegate if we're done because of a synchronous call. | 591 // delegate if we're done because of a synchronous call. |
| 592 base::ThreadTaskRunnerHandle::Get()->PostTask( | 592 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 593 FROM_HERE, base::Bind(&URLRequestJob::CompleteNotifyDone, | 593 FROM_HERE, base::Bind(&URLRequestJob::CompleteNotifyDone, |
| 594 weak_factory_.GetWeakPtr())); | 594 weak_factory_.GetWeakPtr())); |
| 595 } | 595 } |
| 596 | 596 |
| 597 void URLRequestJob::CompleteNotifyDone() { | 597 void URLRequestJob::CompleteNotifyDone() { |
| 598 // Check if we should notify the delegate that we're done because of an error. | 598 // Check if we should notify the delegate that we're done because of an error. |
| 599 if (!request_->status().is_success()) { | 599 if (!request_->status().is_success()) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 659 void URLRequestJob::SourceStreamReadComplete(bool synchronous, int result) { | 659 void URLRequestJob::SourceStreamReadComplete(bool synchronous, int result) { |
| 660 DCHECK_NE(ERR_IO_PENDING, result); | 660 DCHECK_NE(ERR_IO_PENDING, result); |
| 661 | 661 |
| 662 if (result > 0 && request()->net_log().IsCapturing()) { | 662 if (result > 0 && request()->net_log().IsCapturing()) { |
| 663 request()->net_log().AddByteTransferEvent( | 663 request()->net_log().AddByteTransferEvent( |
| 664 NetLogEventType::URL_REQUEST_JOB_FILTERED_BYTES_READ, result, | 664 NetLogEventType::URL_REQUEST_JOB_FILTERED_BYTES_READ, result, |
| 665 pending_read_buffer_->data()); | 665 pending_read_buffer_->data()); |
| 666 } | 666 } |
| 667 pending_read_buffer_ = nullptr; | 667 pending_read_buffer_ = nullptr; |
| 668 | 668 |
| 669 MaybeNotifyNetworkBytes(); | |
|
mmenke
2016/11/03 19:07:01
Not needed, we already call this in ReadRawDataCom
Not at Google. Contact bengr
2016/11/04 00:08:12
Done.
| |
| 670 | |
| 669 if (result < 0) { | 671 if (result < 0) { |
| 670 NotifyDone(URLRequestStatus::FromError(result)); | 672 NotifyDone(URLRequestStatus::FromError(result)); |
| 671 return; | 673 return; |
| 672 } | 674 } |
| 673 | 675 |
| 674 if (result > 0) { | 676 if (result > 0) { |
| 675 postfilter_bytes_read_ += result; | 677 postfilter_bytes_read_ += result; |
| 676 if (!synchronous) | 678 if (!synchronous) |
| 677 request_->NotifyReadCompleted(result); | 679 request_->NotifyReadCompleted(result); |
| 678 return; | 680 return; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 702 // If the read completes synchronously, either success or failure, invoke | 704 // If the read completes synchronously, either success or failure, invoke |
| 703 // GatherRawReadStats so we can account for the completed read. | 705 // GatherRawReadStats so we can account for the completed read. |
| 704 GatherRawReadStats(result); | 706 GatherRawReadStats(result); |
| 705 } else { | 707 } else { |
| 706 read_raw_callback_ = callback; | 708 read_raw_callback_ = callback; |
| 707 } | 709 } |
| 708 return result; | 710 return result; |
| 709 } | 711 } |
| 710 | 712 |
| 711 void URLRequestJob::FollowRedirect(const RedirectInfo& redirect_info) { | 713 void URLRequestJob::FollowRedirect(const RedirectInfo& redirect_info) { |
| 714 MaybeNotifyNetworkBytes(); | |
|
mmenke
2016/11/03 19:07:01
This is a weird place to call this - presumably we
Not at Google. Contact bengr
2016/11/04 00:08:12
Done.
| |
| 715 | |
| 712 int rv = request_->Redirect(redirect_info); | 716 int rv = request_->Redirect(redirect_info); |
| 713 if (rv != OK) | 717 if (rv != OK) |
| 714 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); | 718 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); |
| 715 } | 719 } |
| 716 | 720 |
| 717 void URLRequestJob::GatherRawReadStats(int bytes_read) { | 721 void URLRequestJob::GatherRawReadStats(int bytes_read) { |
| 718 DCHECK(raw_read_buffer_ || bytes_read == 0); | 722 DCHECK(raw_read_buffer_ || bytes_read == 0); |
| 719 DCHECK_NE(ERR_IO_PENDING, bytes_read); | 723 DCHECK_NE(ERR_IO_PENDING, bytes_read); |
| 720 | 724 |
| 721 if (bytes_read > 0) { | 725 if (bytes_read > 0) { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 816 include_referer = base::ToLowerASCII(include_referer); | 820 include_referer = base::ToLowerASCII(include_referer); |
| 817 if (include_referer == "true" && | 821 if (include_referer == "true" && |
| 818 request_->ssl_info().token_binding_negotiated) { | 822 request_->ssl_info().token_binding_negotiated) { |
| 819 redirect_info.referred_token_binding_host = url.host(); | 823 redirect_info.referred_token_binding_host = url.host(); |
| 820 } | 824 } |
| 821 | 825 |
| 822 return redirect_info; | 826 return redirect_info; |
| 823 } | 827 } |
| 824 | 828 |
| 825 void URLRequestJob::MaybeNotifyNetworkBytes() { | 829 void URLRequestJob::MaybeNotifyNetworkBytes() { |
| 830 DCHECK(request_->is_pending()); | |
| 831 | |
| 826 if (!network_delegate_) | 832 if (!network_delegate_) |
| 827 return; | 833 return; |
| 828 | 834 |
| 829 // Report any new received bytes. | 835 // Report any new received bytes. |
| 830 int64_t total_received_bytes = GetTotalReceivedBytes(); | 836 int64_t total_received_bytes = GetTotalReceivedBytes(); |
| 831 DCHECK_GE(total_received_bytes, last_notified_total_received_bytes_); | 837 DCHECK_GE(total_received_bytes, last_notified_total_received_bytes_); |
| 832 if (total_received_bytes > last_notified_total_received_bytes_) { | 838 if (total_received_bytes > last_notified_total_received_bytes_) { |
| 833 network_delegate_->NotifyNetworkBytesReceived( | 839 network_delegate_->NotifyNetworkBytesReceived( |
| 834 request_, total_received_bytes - last_notified_total_received_bytes_); | 840 request_, total_received_bytes - last_notified_total_received_bytes_); |
| 835 } | 841 } |
| 836 last_notified_total_received_bytes_ = total_received_bytes; | 842 last_notified_total_received_bytes_ = total_received_bytes; |
| 837 | 843 |
| 838 // Report any new sent bytes. | 844 // Report any new sent bytes. |
| 839 int64_t total_sent_bytes = GetTotalSentBytes(); | 845 int64_t total_sent_bytes = GetTotalSentBytes(); |
| 840 DCHECK_GE(total_sent_bytes, last_notified_total_sent_bytes_); | 846 DCHECK_GE(total_sent_bytes, last_notified_total_sent_bytes_); |
| 841 if (total_sent_bytes > last_notified_total_sent_bytes_) { | 847 if (total_sent_bytes > last_notified_total_sent_bytes_) { |
| 842 network_delegate_->NotifyNetworkBytesSent( | 848 network_delegate_->NotifyNetworkBytesSent( |
| 843 request_, total_sent_bytes - last_notified_total_sent_bytes_); | 849 request_, total_sent_bytes - last_notified_total_sent_bytes_); |
| 844 } | 850 } |
| 845 last_notified_total_sent_bytes_ = total_sent_bytes; | 851 last_notified_total_sent_bytes_ = total_sent_bytes; |
| 846 } | 852 } |
| 847 | 853 |
| 848 } // namespace net | 854 } // namespace net |
| OLD | NEW |