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/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 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 350 // stream to outlive the request_info_'s owner. | 350 // stream to outlive the request_info_'s owner. |
| 351 // Only allowed when Read state machine starts. It is safe to reset it at | 351 // Only allowed when Read state machine starts. It is safe to reset it at |
| 352 // this point since request_info_->upload_data_stream is also not needed | 352 // this point since request_info_->upload_data_stream is also not needed |
| 353 // anymore. | 353 // anymore. |
| 354 request_info_ = nullptr; | 354 request_info_ = nullptr; |
| 355 | 355 |
| 356 // If the stream is already closed, there is no body to read. | 356 // If the stream is already closed, there is no body to read. |
| 357 if (!stream_) | 357 if (!stream_) |
| 358 return GetResponseStatus(); | 358 return GetResponseStatus(); |
| 359 | 359 |
| 360 int rv = ReadAvailableData(buf, buf_len); | 360 int rv = stream_->ReadBody(buf, buf_len, |
| 361 if (rv != ERR_IO_PENDING) | 361 base::Bind(&QuicHttpStream::OnReadBodyComplete, |
| 362 weak_factory_.GetWeakPtr())); | |
| 363 if (rv == ERR_IO_PENDING) { | |
| 364 callback_ = callback; | |
| 365 user_buffer_ = buf; | |
| 366 user_buffer_len_ = buf_len; | |
| 367 return ERR_IO_PENDING; | |
| 368 } | |
| 369 | |
| 370 if (rv < 0) | |
| 362 return rv; | 371 return rv; |
| 363 | 372 |
| 364 callback_ = callback; | 373 return HandleReadComplete(rv); |
| 365 user_buffer_ = buf; | |
| 366 user_buffer_len_ = buf_len; | |
| 367 return ERR_IO_PENDING; | |
| 368 } | 374 } |
| 369 | 375 |
| 370 void QuicHttpStream::Close(bool /*not_reusable*/) { | 376 void QuicHttpStream::Close(bool /*not_reusable*/) { |
| 371 session_error_ = ERR_ABORTED; | 377 session_error_ = ERR_ABORTED; |
| 372 SaveResponseStatus(); | 378 SaveResponseStatus(); |
| 373 // Note: the not_reusable flag has no meaning for QUIC streams. | 379 // Note: the not_reusable flag has no meaning for QUIC streams. |
| 374 if (stream_) { | 380 if (stream_) { |
| 375 stream_->ClearDelegate(); | 381 stream_->ClearDelegate(); |
| 376 stream_->Reset(QUIC_STREAM_CANCELLED); | 382 stream_->Reset(QUIC_STREAM_CANCELLED); |
| 377 } | 383 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 465 | 471 |
| 466 // QuicHttpStream ignores trailers. | 472 // QuicHttpStream ignores trailers. |
| 467 if (stream_->IsDoneReading()) { | 473 if (stream_->IsDoneReading()) { |
| 468 // Close the read side. If the write side has been closed, this will | 474 // Close the read side. If the write side has been closed, this will |
| 469 // invoke QuicHttpStream::OnClose to reset the stream. | 475 // invoke QuicHttpStream::OnClose to reset the stream. |
| 470 stream_->OnFinRead(); | 476 stream_->OnFinRead(); |
| 471 SetResponseStatus(OK); | 477 SetResponseStatus(OK); |
| 472 } | 478 } |
| 473 } | 479 } |
| 474 | 480 |
| 475 void QuicHttpStream::OnDataAvailable() { | |
| 476 if (callback_.is_null()) { | |
| 477 // Data is available, but can't be delivered | |
| 478 return; | |
| 479 } | |
| 480 | |
| 481 CHECK(user_buffer_.get()); | |
| 482 CHECK_NE(0, user_buffer_len_); | |
| 483 int rv = ReadAvailableData(user_buffer_.get(), user_buffer_len_); | |
| 484 if (rv == ERR_IO_PENDING) { | |
| 485 // This was a spurrious notification. Wait for the next one. | |
| 486 return; | |
| 487 } | |
| 488 | |
| 489 CHECK(!callback_.is_null()); | |
| 490 user_buffer_ = nullptr; | |
| 491 user_buffer_len_ = 0; | |
| 492 DoCallback(rv); | |
| 493 } | |
| 494 | |
| 495 void QuicHttpStream::OnClose() { | 481 void QuicHttpStream::OnClose() { |
| 496 quic_connection_error_ = stream_->connection_error(); | 482 quic_connection_error_ = stream_->connection_error(); |
| 497 quic_stream_error_ = stream_->stream_error(); | 483 quic_stream_error_ = stream_->stream_error(); |
| 498 SaveResponseStatus(); | 484 SaveResponseStatus(); |
| 499 | 485 |
| 500 ResetStream(); | 486 ResetStream(); |
| 501 // If already in DoLoop(), |callback_| will be handled when DoLoop() exits. | 487 // If already in DoLoop(), |callback_| will be handled when DoLoop() exits. |
| 502 if (in_loop_) | 488 if (in_loop_) |
| 503 return; | 489 return; |
| 504 | 490 |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 761 response_info_->response_time = base::Time::Now(); | 747 response_info_->response_time = base::Time::Now(); |
| 762 response_info_->request_time = request_time_; | 748 response_info_->request_time = request_time_; |
| 763 response_headers_received_ = true; | 749 response_headers_received_ = true; |
| 764 | 750 |
| 765 // Populate |connect_timing_| when response headers are received. This should | 751 // Populate |connect_timing_| when response headers are received. This should |
| 766 // take care of 0-RTT where request is sent before handshake is confirmed. | 752 // take care of 0-RTT where request is sent before handshake is confirmed. |
| 767 connect_timing_ = quic_session()->GetConnectTiming(); | 753 connect_timing_ = quic_session()->GetConnectTiming(); |
| 768 return OK; | 754 return OK; |
| 769 } | 755 } |
| 770 | 756 |
| 771 int QuicHttpStream::ReadAvailableData(IOBuffer* buf, int buf_len) { | 757 void QuicHttpStream::OnReadBodyComplete(int rv) { |
| 772 int rv = stream_->Read(buf, buf_len); | 758 CHECK(callback_); |
| 773 // TODO(rtenneti): Temporary fix for crbug.com/585591. Added a check for null | 759 user_buffer_ = nullptr; |
| 774 // |stream_| to fix crash bug. Delete |stream_| check and histogram after fix | 760 user_buffer_len_ = 0; |
| 775 // is merged. | 761 rv = HandleReadComplete(rv); |
| 776 bool null_stream = stream_ == nullptr; | 762 DoCallback(rv); |
| 777 UMA_HISTOGRAM_BOOLEAN("Net.QuicReadAvailableData.NullStream", null_stream); | 763 } |
|
xunjieli
2017/05/12 15:22:22
Could you mark this histogram as deprecated in his
| |
| 778 if (null_stream) | 764 |
| 779 return rv; | 765 int QuicHttpStream::HandleReadComplete(int rv) { |
| 780 if (stream_->IsDoneReading()) { | 766 if (stream_->IsDoneReading()) { |
| 781 stream_->ClearDelegate(); | 767 stream_->ClearDelegate(); |
| 782 stream_->OnFinRead(); | 768 stream_->OnFinRead(); |
| 783 SetResponseStatus(OK); | 769 SetResponseStatus(OK); |
| 784 ResetStream(); | 770 ResetStream(); |
| 785 } | 771 } |
| 786 return rv; | 772 return rv; |
| 787 } | 773 } |
| 788 | 774 |
| 789 void QuicHttpStream::ResetStream() { | 775 void QuicHttpStream::ResetStream() { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 845 quic_stream_error_ != QUIC_STREAM_CONNECTION_ERROR) { | 831 quic_stream_error_ != QUIC_STREAM_CONNECTION_ERROR) { |
| 846 return ERR_QUIC_PROTOCOL_ERROR; | 832 return ERR_QUIC_PROTOCOL_ERROR; |
| 847 } | 833 } |
| 848 | 834 |
| 849 DCHECK_NE(QUIC_HANDSHAKE_TIMEOUT, quic_connection_error_); | 835 DCHECK_NE(QUIC_HANDSHAKE_TIMEOUT, quic_connection_error_); |
| 850 | 836 |
| 851 return ERR_QUIC_PROTOCOL_ERROR; | 837 return ERR_QUIC_PROTOCOL_ERROR; |
| 852 } | 838 } |
| 853 | 839 |
| 854 } // namespace net | 840 } // namespace net |
| OLD | NEW |