| 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/quic/chromium/quic_http_stream.h" | 5 #include "net/quic/chromium/quic_http_stream.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 return true; | 101 return true; |
| 102 } | 102 } |
| 103 // Now compare the client request for matching. | 103 // Now compare the client request for matching. |
| 104 return vary_data.MatchesRequest(client_request_info, | 104 return vary_data.MatchesRequest(client_request_info, |
| 105 *promise_response_info.headers.get()); | 105 *promise_response_info.headers.get()); |
| 106 } | 106 } |
| 107 | 107 |
| 108 void QuicHttpStream::OnRendezvousResult(QuicSpdyStream* stream) { | 108 void QuicHttpStream::OnRendezvousResult(QuicSpdyStream* stream) { |
| 109 push_handle_ = nullptr; | 109 push_handle_ = nullptr; |
| 110 if (stream) { | 110 if (stream) { |
| 111 stream_ = static_cast<QuicChromiumClientStream*>(stream); | 111 stream_ = |
| 112 stream_->SetDelegate(this); | 112 static_cast<QuicChromiumClientStream*>(stream)->CreateHandle(this); |
| 113 } | 113 } |
| 114 | 114 |
| 115 // callback_ should only be non-null in the case of asynchronous | 115 // callback_ should only be non-null in the case of asynchronous |
| 116 // rendezvous; i.e. |Try()| returned QUIC_PENDING. | 116 // rendezvous; i.e. |Try()| returned QUIC_PENDING. |
| 117 if (callback_.is_null()) | 117 if (callback_.is_null()) |
| 118 return; | 118 return; |
| 119 | 119 |
| 120 DCHECK_EQ(STATE_HANDLE_PROMISE_COMPLETE, next_state_); | 120 DCHECK_EQ(STATE_HANDLE_PROMISE_COMPLETE, next_state_); |
| 121 if (!stream) { | 121 if (!stream) { |
| 122 // rendezvous has failed so proceed as with a non-push request. | 122 // rendezvous has failed so proceed as with a non-push request. |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 user_buffer_ = buf; | 351 user_buffer_ = buf; |
| 352 user_buffer_len_ = buf_len; | 352 user_buffer_len_ = buf_len; |
| 353 return ERR_IO_PENDING; | 353 return ERR_IO_PENDING; |
| 354 } | 354 } |
| 355 | 355 |
| 356 void QuicHttpStream::Close(bool /*not_reusable*/) { | 356 void QuicHttpStream::Close(bool /*not_reusable*/) { |
| 357 session_error_ = ERR_ABORTED; | 357 session_error_ = ERR_ABORTED; |
| 358 SaveResponseStatus(); | 358 SaveResponseStatus(); |
| 359 // Note: the not_reusable flag has no meaning for QUIC streams. | 359 // Note: the not_reusable flag has no meaning for QUIC streams. |
| 360 if (stream_) { | 360 if (stream_) { |
| 361 stream_->SetDelegate(nullptr); | 361 stream_->ClearDelegate(); |
| 362 stream_->Reset(QUIC_STREAM_CANCELLED); | 362 stream_->Reset(QUIC_STREAM_CANCELLED); |
| 363 } | 363 } |
| 364 ResetStream(); | 364 ResetStream(); |
| 365 } | 365 } |
| 366 | 366 |
| 367 bool QuicHttpStream::IsResponseBodyComplete() const { | 367 bool QuicHttpStream::IsResponseBodyComplete() const { |
| 368 return next_state_ == STATE_OPEN && !stream_; | 368 return next_state_ == STATE_OPEN && !stream_; |
| 369 } | 369 } |
| 370 | 370 |
| 371 bool QuicHttpStream::IsConnectionReused() const { | 371 bool QuicHttpStream::IsConnectionReused() const { |
| 372 // TODO(rch): do something smarter here. | 372 // TODO(rch): do something smarter here. |
| 373 return stream_ && stream_->id() > 1; | 373 return stream_ && stream_->id() > 1; |
| 374 } | 374 } |
| 375 | 375 |
| 376 int64_t QuicHttpStream::GetTotalReceivedBytes() const { | 376 int64_t QuicHttpStream::GetTotalReceivedBytes() const { |
| 377 // TODO(sclittle): Currently, this only includes headers and response body | 377 // TODO(sclittle): Currently, this only includes headers and response body |
| 378 // bytes. Change this to include QUIC overhead as well. | 378 // bytes. Change this to include QUIC overhead as well. |
| 379 int64_t total_received_bytes = headers_bytes_received_; | 379 int64_t total_received_bytes = headers_bytes_received_; |
| 380 if (stream_) { | 380 if (stream_) { |
| 381 DCHECK_LE(stream_->sequencer()->NumBytesConsumed(), | 381 DCHECK_LE(stream_->NumBytesConsumed(), stream_->stream_bytes_read()); |
| 382 stream_->stream_bytes_read()); | |
| 383 // Only count the uniquely received bytes. | 382 // Only count the uniquely received bytes. |
| 384 total_received_bytes += stream_->sequencer()->NumBytesConsumed(); | 383 total_received_bytes += stream_->NumBytesConsumed(); |
| 385 } else { | 384 } else { |
| 386 total_received_bytes += closed_stream_received_bytes_; | 385 total_received_bytes += closed_stream_received_bytes_; |
| 387 } | 386 } |
| 388 return total_received_bytes; | 387 return total_received_bytes; |
| 389 } | 388 } |
| 390 | 389 |
| 391 int64_t QuicHttpStream::GetTotalSentBytes() const { | 390 int64_t QuicHttpStream::GetTotalSentBytes() const { |
| 392 // TODO(sclittle): Currently, this only includes request headers and body | 391 // TODO(sclittle): Currently, this only includes request headers and body |
| 393 // bytes. Change this to include QUIC overhead as well. | 392 // bytes. Change this to include QUIC overhead as well. |
| 394 int64_t total_sent_bytes = headers_bytes_sent_; | 393 int64_t total_sent_bytes = headers_bytes_sent_; |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 } | 663 } |
| 665 | 664 |
| 666 int QuicHttpStream::DoReadRequestBodyComplete(int rv) { | 665 int QuicHttpStream::DoReadRequestBodyComplete(int rv) { |
| 667 // If the stream is already closed, don't continue. | 666 // If the stream is already closed, don't continue. |
| 668 if (!stream_) | 667 if (!stream_) |
| 669 return GetResponseStatus(); | 668 return GetResponseStatus(); |
| 670 | 669 |
| 671 // |rv| is the result of read from the request body from the last call to | 670 // |rv| is the result of read from the request body from the last call to |
| 672 // DoSendBody(). | 671 // DoSendBody(). |
| 673 if (rv < 0) { | 672 if (rv < 0) { |
| 674 stream_->SetDelegate(nullptr); | 673 stream_->ClearDelegate(); |
| 675 stream_->Reset(QUIC_ERROR_PROCESSING_STREAM); | 674 stream_->Reset(QUIC_ERROR_PROCESSING_STREAM); |
| 676 ResetStream(); | 675 ResetStream(); |
| 677 return rv; | 676 return rv; |
| 678 } | 677 } |
| 679 | 678 |
| 680 request_body_buf_ = new DrainableIOBuffer(raw_request_body_buf_.get(), rv); | 679 request_body_buf_ = new DrainableIOBuffer(raw_request_body_buf_.get(), rv); |
| 681 if (rv == 0) { // Reached the end. | 680 if (rv == 0) { // Reached the end. |
| 682 DCHECK(request_body_stream_->IsEOF()); | 681 DCHECK(request_body_stream_->IsEOF()); |
| 683 } | 682 } |
| 684 | 683 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 int QuicHttpStream::ReadAvailableData(IOBuffer* buf, int buf_len) { | 756 int QuicHttpStream::ReadAvailableData(IOBuffer* buf, int buf_len) { |
| 758 int rv = stream_->Read(buf, buf_len); | 757 int rv = stream_->Read(buf, buf_len); |
| 759 // TODO(rtenneti): Temporary fix for crbug.com/585591. Added a check for null | 758 // TODO(rtenneti): Temporary fix for crbug.com/585591. Added a check for null |
| 760 // |stream_| to fix crash bug. Delete |stream_| check and histogram after fix | 759 // |stream_| to fix crash bug. Delete |stream_| check and histogram after fix |
| 761 // is merged. | 760 // is merged. |
| 762 bool null_stream = stream_ == nullptr; | 761 bool null_stream = stream_ == nullptr; |
| 763 UMA_HISTOGRAM_BOOLEAN("Net.QuicReadAvailableData.NullStream", null_stream); | 762 UMA_HISTOGRAM_BOOLEAN("Net.QuicReadAvailableData.NullStream", null_stream); |
| 764 if (null_stream) | 763 if (null_stream) |
| 765 return rv; | 764 return rv; |
| 766 if (stream_->IsDoneReading()) { | 765 if (stream_->IsDoneReading()) { |
| 767 stream_->SetDelegate(nullptr); | 766 stream_->ClearDelegate(); |
| 768 stream_->OnFinRead(); | 767 stream_->OnFinRead(); |
| 769 SetResponseStatus(OK); | 768 SetResponseStatus(OK); |
| 770 ResetStream(); | 769 ResetStream(); |
| 771 } | 770 } |
| 772 return rv; | 771 return rv; |
| 773 } | 772 } |
| 774 | 773 |
| 775 void QuicHttpStream::ResetStream() { | 774 void QuicHttpStream::ResetStream() { |
| 776 if (push_handle_) { | 775 if (push_handle_) { |
| 777 push_handle_->Cancel(); | 776 push_handle_->Cancel(); |
| 778 push_handle_ = nullptr; | 777 push_handle_ = nullptr; |
| 779 } | 778 } |
| 780 if (!stream_) | 779 if (!stream_) |
| 781 return; | 780 return; |
| 782 DCHECK_LE(stream_->sequencer()->NumBytesConsumed(), | 781 DCHECK_LE(stream_->NumBytesConsumed(), stream_->stream_bytes_read()); |
| 783 stream_->stream_bytes_read()); | |
| 784 // Only count the uniquely received bytes. | 782 // Only count the uniquely received bytes. |
| 785 closed_stream_received_bytes_ = stream_->sequencer()->NumBytesConsumed(); | 783 closed_stream_received_bytes_ = stream_->NumBytesConsumed(); |
| 786 closed_stream_sent_bytes_ = stream_->stream_bytes_written(); | 784 closed_stream_sent_bytes_ = stream_->stream_bytes_written(); |
| 787 closed_is_first_stream_ = stream_->IsFirstStream(); | 785 closed_is_first_stream_ = stream_->IsFirstStream(); |
| 786 stream_->ClearDelegate(); |
| 788 stream_ = nullptr; | 787 stream_ = nullptr; |
| 789 | 788 |
| 790 // If |request_body_stream_| is non-NULL, Reset it, to abort any in progress | 789 // If |request_body_stream_| is non-NULL, Reset it, to abort any in progress |
| 791 // read. | 790 // read. |
| 792 if (request_body_stream_) | 791 if (request_body_stream_) |
| 793 request_body_stream_->Reset(); | 792 request_body_stream_->Reset(); |
| 794 } | 793 } |
| 795 | 794 |
| 796 int QuicHttpStream::GetResponseStatus() { | 795 int QuicHttpStream::GetResponseStatus() { |
| 797 SaveResponseStatus(); | 796 SaveResponseStatus(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 quic_stream_error_ != QUIC_STREAM_CONNECTION_ERROR) { | 830 quic_stream_error_ != QUIC_STREAM_CONNECTION_ERROR) { |
| 832 return ERR_QUIC_PROTOCOL_ERROR; | 831 return ERR_QUIC_PROTOCOL_ERROR; |
| 833 } | 832 } |
| 834 | 833 |
| 835 DCHECK_NE(QUIC_HANDSHAKE_TIMEOUT, quic_connection_error_); | 834 DCHECK_NE(QUIC_HANDSHAKE_TIMEOUT, quic_connection_error_); |
| 836 | 835 |
| 837 return ERR_QUIC_PROTOCOL_ERROR; | 836 return ERR_QUIC_PROTOCOL_ERROR; |
| 838 } | 837 } |
| 839 | 838 |
| 840 } // namespace net | 839 } // namespace net |
| OLD | NEW |