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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 } | 43 } |
| 44 | 44 |
| 45 } // namespace | 45 } // namespace |
| 46 | 46 |
| 47 QuicHttpStream::QuicHttpStream( | 47 QuicHttpStream::QuicHttpStream( |
| 48 const base::WeakPtr<QuicChromiumClientSession>& session, | 48 const base::WeakPtr<QuicChromiumClientSession>& session, |
| 49 HttpServerProperties* http_server_properties) | 49 HttpServerProperties* http_server_properties) |
| 50 : MultiplexedHttpStream(MultiplexedSessionHandle(session)), | 50 : MultiplexedHttpStream(MultiplexedSessionHandle(session)), |
| 51 next_state_(STATE_NONE), | 51 next_state_(STATE_NONE), |
| 52 session_(session), | 52 session_(session), |
| 53 server_id_(session->server_id()), | |
| 53 http_server_properties_(http_server_properties), | 54 http_server_properties_(http_server_properties), |
| 54 quic_version_(session->GetQuicVersion()), | 55 quic_version_(session->GetQuicVersion()), |
| 55 session_error_(ERR_UNEXPECTED), | 56 session_error_(ERR_UNEXPECTED), |
| 56 was_handshake_confirmed_(session->IsCryptoHandshakeConfirmed()), | 57 was_handshake_confirmed_(session->IsCryptoHandshakeConfirmed()), |
| 57 stream_(nullptr), | 58 stream_(nullptr), |
| 58 request_info_(nullptr), | 59 request_info_(nullptr), |
| 59 request_body_stream_(nullptr), | 60 request_body_stream_(nullptr), |
| 60 priority_(MINIMUM_PRIORITY), | 61 priority_(MINIMUM_PRIORITY), |
| 61 response_info_(nullptr), | 62 response_info_(nullptr), |
| 62 has_response_status_(false), | 63 has_response_status_(false), |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 | 316 |
| 316 return rv > 0 ? OK : rv; | 317 return rv > 0 ? OK : rv; |
| 317 } | 318 } |
| 318 | 319 |
| 319 int QuicHttpStream::ReadResponseHeaders(const CompletionCallback& callback) { | 320 int QuicHttpStream::ReadResponseHeaders(const CompletionCallback& callback) { |
| 320 CHECK(callback_.is_null()); | 321 CHECK(callback_.is_null()); |
| 321 CHECK(!callback.is_null()); | 322 CHECK(!callback.is_null()); |
| 322 | 323 |
| 323 if (stream_ == nullptr) | 324 if (stream_ == nullptr) |
| 324 return GetResponseStatus(); | 325 return GetResponseStatus(); |
| 325 | |
| 326 // Check if we already have the response headers. If so, return synchronously. | 326 // Check if we already have the response headers. If so, return synchronously. |
| 327 if (response_headers_received_) | 327 if (response_headers_received_) |
| 328 return OK; | 328 return OK; |
| 329 | 329 |
| 330 // Still waiting for the response, return IO_PENDING. | 330 // Still waiting for the response, return IO_PENDING. |
| 331 CHECK(callback_.is_null()); | 331 CHECK(callback_.is_null()); |
| 332 callback_ = callback; | 332 callback_ = callback; |
| 333 return ERR_IO_PENDING; | 333 return ERR_IO_PENDING; |
| 334 } | 334 } |
| 335 | 335 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 357 if (rv != ERR_IO_PENDING) | 357 if (rv != ERR_IO_PENDING) |
| 358 return rv; | 358 return rv; |
| 359 | 359 |
| 360 callback_ = callback; | 360 callback_ = callback; |
| 361 user_buffer_ = buf; | 361 user_buffer_ = buf; |
| 362 user_buffer_len_ = buf_len; | 362 user_buffer_len_ = buf_len; |
| 363 return ERR_IO_PENDING; | 363 return ERR_IO_PENDING; |
| 364 } | 364 } |
| 365 | 365 |
| 366 void QuicHttpStream::Close(bool /*not_reusable*/) { | 366 void QuicHttpStream::Close(bool /*not_reusable*/) { |
| 367 session_error_ = ERR_ABORTED; | |
| 367 SaveResponseStatus(); | 368 SaveResponseStatus(); |
| 368 // Note: the not_reusable flag has no meaning for QUIC streams. | 369 // Note: the not_reusable flag has no meaning for QUIC streams. |
| 369 if (stream_) { | 370 if (stream_) { |
| 370 stream_->SetDelegate(nullptr); | 371 stream_->SetDelegate(nullptr); |
| 371 stream_->Reset(QUIC_STREAM_CANCELLED); | 372 stream_->Reset(QUIC_STREAM_CANCELLED); |
| 372 } | 373 } |
| 373 ResetStream(); | 374 ResetStream(); |
| 374 } | 375 } |
| 375 | 376 |
| 376 bool QuicHttpStream::IsResponseBodyComplete() const { | 377 bool QuicHttpStream::IsResponseBodyComplete() const { |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 849 void QuicHttpStream::SaveResponseStatus() { | 850 void QuicHttpStream::SaveResponseStatus() { |
| 850 if (!has_response_status_) | 851 if (!has_response_status_) |
| 851 SetResponseStatus(ComputeResponseStatus()); | 852 SetResponseStatus(ComputeResponseStatus()); |
| 852 } | 853 } |
| 853 | 854 |
| 854 void QuicHttpStream::SetResponseStatus(int response_status) { | 855 void QuicHttpStream::SetResponseStatus(int response_status) { |
| 855 has_response_status_ = true; | 856 has_response_status_ = true; |
| 856 response_status_ = response_status; | 857 response_status_ = response_status; |
| 857 } | 858 } |
| 858 | 859 |
| 860 // Returns true if |error| is possibly caused by the network | |
| 861 bool IsPossiblyNetworkError(QuicErrorCode error) { | |
|
Jana
2017/04/07 21:59:29
You don't need this function anymore, do you?
Ryan Hamilton
2017/04/07 22:37:20
Right! Good point. I should move this comment to t
| |
| 862 // QUIC connections should not timeout while there are open streams, | |
| 863 // since PING frames are sent to prevent timeouts. If, however, the | |
| 864 // connection timed out while this stream was open then QUIC traffic | |
| 865 // has become blackholed. | |
| 866 return error == QUIC_NETWORK_IDLE_TIMEOUT || error == QUIC_TOO_MANY_RTOS; | |
| 867 } | |
| 868 | |
| 859 int QuicHttpStream::ComputeResponseStatus() const { | 869 int QuicHttpStream::ComputeResponseStatus() const { |
| 860 DCHECK(!has_response_status_); | 870 DCHECK(!has_response_status_); |
| 861 | 871 |
| 862 // If the handshake has failed this will be handled by the | 872 // If the handshake has failed this will be handled by the QuicStreamFactory |
| 863 // QuicStreamFactory and HttpStreamFactory to mark QUIC as broken. | 873 // and HttpStreamFactory to mark QUIC as broken if TCP is actually working. |
| 864 if (!was_handshake_confirmed_) | 874 if (!was_handshake_confirmed_) |
| 865 return ERR_QUIC_HANDSHAKE_FAILED; | 875 return ERR_QUIC_HANDSHAKE_FAILED; |
| 866 | 876 |
| 867 // If the session was aborted by a higher layer, simply use that error code. | 877 // If the session was aborted by a higher layer, simply use that error code. |
| 868 if (session_error_ != ERR_UNEXPECTED) | 878 if (session_error_ != ERR_UNEXPECTED) |
| 869 return session_error_; | 879 return session_error_; |
| 870 | 880 |
| 871 // If |response_info_| is null then the request has not been sent, so | 881 // If |response_info_| is null then the request has not been sent, so |
| 872 // return ERR_CONNECTION_CLOSED to permit HttpNetworkTransaction to | 882 // return ERR_CONNECTION_CLOSED to permit HttpNetworkTransaction to |
| 873 // retry the request. | 883 // retry the request. |
| 874 if (!response_info_) | 884 if (!response_info_) |
| 875 return ERR_CONNECTION_CLOSED; | 885 return ERR_CONNECTION_CLOSED; |
| 876 | 886 |
| 887 // Explicit stream error are always fatal. | |
| 888 if (quic_stream_error_ != QUIC_STREAM_NO_ERROR && | |
| 889 quic_stream_error_ != QUIC_STREAM_CONNECTION_ERROR) { | |
| 890 return ERR_QUIC_PROTOCOL_ERROR; | |
| 891 } | |
| 892 | |
| 893 DCHECK_NE(QUIC_HANDSHAKE_TIMEOUT, quic_connection_error_); | |
| 894 | |
| 895 // If the headers have not been received and QUIC is now broken, return | |
| 896 // ERR_QUIC_BROKEN_ERROR to permit HttpNetworkTransaction to retry the request | |
| 897 // over TCP. | |
| 898 if (!response_headers_received_ && | |
| 899 http_server_properties_->IsAlternativeServiceBroken(AlternativeService( | |
| 900 kProtoQUIC, server_id_.host(), server_id_.port()))) { | |
| 901 return ERR_QUIC_BROKEN_ERROR; | |
| 902 } | |
| 903 | |
| 877 return ERR_QUIC_PROTOCOL_ERROR; | 904 return ERR_QUIC_PROTOCOL_ERROR; |
| 878 } | 905 } |
| 879 | 906 |
| 880 } // namespace net | 907 } // namespace net |
| OLD | NEW |