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/quic_client_session.h" | 5 #include "net/quic/quic_client_session.h" |
| 6 | 6 |
| 7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/metrics/sparse_histogram.h" | 10 #include "base/metrics/sparse_histogram.h" |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 QuicConnection* connection, | 131 QuicConnection* connection, |
| 132 scoped_ptr<DatagramClientSocket> socket, | 132 scoped_ptr<DatagramClientSocket> socket, |
| 133 scoped_ptr<QuicDefaultPacketWriter> writer, | 133 scoped_ptr<QuicDefaultPacketWriter> writer, |
| 134 QuicStreamFactory* stream_factory, | 134 QuicStreamFactory* stream_factory, |
| 135 QuicCryptoClientStreamFactory* crypto_client_stream_factory, | 135 QuicCryptoClientStreamFactory* crypto_client_stream_factory, |
| 136 scoped_ptr<QuicServerInfo> server_info, | 136 scoped_ptr<QuicServerInfo> server_info, |
| 137 const QuicServerId& server_id, | 137 const QuicServerId& server_id, |
| 138 const QuicConfig& config, | 138 const QuicConfig& config, |
| 139 uint32 max_flow_control_receive_window_bytes, | 139 uint32 max_flow_control_receive_window_bytes, |
| 140 QuicCryptoClientConfig* crypto_config, | 140 QuicCryptoClientConfig* crypto_config, |
| 141 base::TaskRunner* task_runner, | |
| 141 NetLog* net_log) | 142 NetLog* net_log) |
| 142 : QuicClientSessionBase(connection, | 143 : QuicClientSessionBase(connection, |
| 143 max_flow_control_receive_window_bytes, | 144 max_flow_control_receive_window_bytes, |
| 144 config), | 145 config), |
| 145 require_confirmation_(false), | 146 require_confirmation_(false), |
| 146 stream_factory_(stream_factory), | 147 stream_factory_(stream_factory), |
| 147 socket_(socket.Pass()), | 148 socket_(socket.Pass()), |
| 148 writer_(writer.Pass()), | 149 writer_(writer.Pass()), |
| 149 read_buffer_(new IOBufferWithSize(kMaxPacketSize)), | 150 read_buffer_(new IOBufferWithSize(kMaxPacketSize)), |
| 150 server_info_(server_info.Pass()), | 151 server_info_(server_info.Pass()), |
| 151 read_pending_(false), | 152 read_pending_(false), |
| 152 num_total_streams_(0), | 153 num_total_streams_(0), |
| 154 task_runner_(task_runner), | |
| 153 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_QUIC_SESSION)), | 155 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_QUIC_SESSION)), |
| 154 logger_(net_log_), | 156 logger_(net_log_), |
| 155 num_packets_read_(0), | 157 num_packets_read_(0), |
| 156 going_away_(false), | 158 going_away_(false), |
| 157 weak_factory_(this) { | 159 weak_factory_(this) { |
| 158 crypto_stream_.reset( | 160 crypto_stream_.reset( |
| 159 crypto_client_stream_factory ? | 161 crypto_client_stream_factory ? |
| 160 crypto_client_stream_factory->CreateQuicCryptoClientStream( | 162 crypto_client_stream_factory->CreateQuicCryptoClientStream( |
| 161 server_id, this, crypto_config) : | 163 server_id, this, crypto_config) : |
| 162 new QuicCryptoClientStream(server_id, this, | 164 new QuicCryptoClientStream(server_id, this, |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 429 int QuicClientSession::CryptoConnect(bool require_confirmation, | 431 int QuicClientSession::CryptoConnect(bool require_confirmation, |
| 430 const CompletionCallback& callback) { | 432 const CompletionCallback& callback) { |
| 431 require_confirmation_ = require_confirmation; | 433 require_confirmation_ = require_confirmation; |
| 432 RecordHandshakeState(STATE_STARTED); | 434 RecordHandshakeState(STATE_STARTED); |
| 433 if (!crypto_stream_->CryptoConnect()) { | 435 if (!crypto_stream_->CryptoConnect()) { |
| 434 // TODO(wtc): change crypto_stream_.CryptoConnect() to return a | 436 // TODO(wtc): change crypto_stream_.CryptoConnect() to return a |
| 435 // QuicErrorCode and map it to a net error code. | 437 // QuicErrorCode and map it to a net error code. |
| 436 return ERR_CONNECTION_FAILED; | 438 return ERR_CONNECTION_FAILED; |
| 437 } | 439 } |
| 438 | 440 |
| 439 bool can_notify = require_confirmation_ ? | 441 if (IsCryptoHandshakeConfirmed()) |
| 440 IsCryptoHandshakeConfirmed() : IsEncryptionEstablished(); | |
| 441 if (can_notify) { | |
| 442 return OK; | 442 return OK; |
| 443 | |
| 444 // Unless we require handshake confirmation, activate the session if | |
| 445 // we have established initial encryption. | |
| 446 if (!require_confirmation_ && IsEncryptionEstablished()) { | |
| 447 // To mitigate the effects of hanging 0-RTT connections, set up a timer to | |
| 448 // cancel any requests, if the handshake takes too long. | |
| 449 task_runner_->PostDelayedTask( | |
| 450 FROM_HERE, | |
| 451 base::Bind(&QuicClientSession::OnConnectTimeout, | |
| 452 weak_factory_.GetWeakPtr()), | |
| 453 base::TimeDelta::FromMilliseconds(300)); | |
|
ramant (doing other things)
2014/06/05 22:27:18
overly nit: wondering if 300ms is long enough for
ramant (doing other things)
2014/06/05 22:33:47
I like this change. Should we do a similar change
Ryan Hamilton
2014/06/05 22:47:51
Possibly. Of course, we're reading the configs fro
Ryan Hamilton
2014/06/05 22:47:51
It's a good question! :> The short answer is that
| |
| 454 return OK; | |
| 455 | |
| 443 } | 456 } |
| 444 | 457 |
| 445 callback_ = callback; | 458 callback_ = callback; |
| 446 return ERR_IO_PENDING; | 459 return ERR_IO_PENDING; |
| 447 } | 460 } |
| 448 | 461 |
| 462 int QuicClientSession::ResumeCryptoConnect(const CompletionCallback& callback) { | |
| 463 | |
| 464 if (IsCryptoHandshakeConfirmed()) | |
| 465 return OK; | |
| 466 | |
| 467 if (!connection()->connected()) | |
| 468 return ERR_QUIC_HANDSHAKE_FAILED; | |
| 469 | |
| 470 callback_ = callback; | |
| 471 return ERR_IO_PENDING; | |
| 472 } | |
| 473 | |
| 449 int QuicClientSession::GetNumSentClientHellos() const { | 474 int QuicClientSession::GetNumSentClientHellos() const { |
| 450 return crypto_stream_->num_sent_client_hellos(); | 475 return crypto_stream_->num_sent_client_hellos(); |
| 451 } | 476 } |
| 452 | 477 |
| 453 bool QuicClientSession::CanPool(const std::string& hostname) const { | 478 bool QuicClientSession::CanPool(const std::string& hostname) const { |
| 454 // TODO(rch): When QUIC supports channel ID or client certificates, this | 479 // TODO(rch): When QUIC supports channel ID or client certificates, this |
| 455 // logic will need to be revised. | 480 // logic will need to be revised. |
| 456 DCHECK(connection()->connected()); | 481 DCHECK(connection()->connected()); |
| 457 SSLInfo ssl_info; | 482 SSLInfo ssl_info; |
| 458 bool unused = false; | 483 bool unused = false; |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 793 if (!going_away_) | 818 if (!going_away_) |
| 794 RecordUnexpectedNotGoingAway(NOTIFY_FACTORY_OF_SESSION_CLOSED); | 819 RecordUnexpectedNotGoingAway(NOTIFY_FACTORY_OF_SESSION_CLOSED); |
| 795 | 820 |
| 796 going_away_ = true; | 821 going_away_ = true; |
| 797 DCHECK_EQ(0u, GetNumOpenStreams()); | 822 DCHECK_EQ(0u, GetNumOpenStreams()); |
| 798 // Will delete |this|. | 823 // Will delete |this|. |
| 799 if (stream_factory_) | 824 if (stream_factory_) |
| 800 stream_factory_->OnSessionClosed(this); | 825 stream_factory_->OnSessionClosed(this); |
| 801 } | 826 } |
| 802 | 827 |
| 828 void QuicClientSession::OnConnectTimeout() { | |
| 829 DCHECK(callback_.is_null()); | |
| 830 DCHECK(IsEncryptionEstablished()); | |
| 831 | |
| 832 if (IsCryptoHandshakeConfirmed()) | |
| 833 return; | |
| 834 | |
| 835 if (stream_factory_) | |
| 836 stream_factory_->OnSessionConnectTimeout(this); | |
| 837 CloseAllStreams(ERR_QUIC_HANDSHAKE_FAILED); | |
| 838 } | |
| 839 | |
| 803 } // namespace net | 840 } // namespace net |
| OLD | NEW |