| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 82 QuicClientSession::QuicClientSession( | 82 QuicClientSession::QuicClientSession( | 
| 83     QuicConnection* connection, | 83     QuicConnection* connection, | 
| 84     DatagramClientSocket* socket, | 84     DatagramClientSocket* socket, | 
| 85     QuicStreamFactory* stream_factory, | 85     QuicStreamFactory* stream_factory, | 
| 86     QuicCryptoClientStreamFactory* crypto_client_stream_factory, | 86     QuicCryptoClientStreamFactory* crypto_client_stream_factory, | 
| 87     const string& server_hostname, | 87     const string& server_hostname, | 
| 88     const QuicConfig& config, | 88     const QuicConfig& config, | 
| 89     QuicCryptoClientConfig* crypto_config, | 89     QuicCryptoClientConfig* crypto_config, | 
| 90     NetLog* net_log) | 90     NetLog* net_log) | 
| 91     : QuicSession(connection, config, false), | 91     : QuicSession(connection, config, false), | 
| 92       weak_factory_(this), | 92       require_confirmation_(false), | 
| 93       stream_factory_(stream_factory), | 93       stream_factory_(stream_factory), | 
| 94       socket_(socket), | 94       socket_(socket), | 
| 95       read_buffer_(new IOBufferWithSize(kMaxPacketSize)), | 95       read_buffer_(new IOBufferWithSize(kMaxPacketSize)), | 
| 96       read_pending_(false), | 96       read_pending_(false), | 
| 97       num_total_streams_(0), | 97       num_total_streams_(0), | 
| 98       net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_QUIC_SESSION)), | 98       net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_QUIC_SESSION)), | 
| 99       logger_(net_log_) { | 99       logger_(net_log_), | 
|  | 100       weak_factory_(this) { | 
| 100   crypto_stream_.reset( | 101   crypto_stream_.reset( | 
| 101       crypto_client_stream_factory ? | 102       crypto_client_stream_factory ? | 
| 102           crypto_client_stream_factory->CreateQuicCryptoClientStream( | 103           crypto_client_stream_factory->CreateQuicCryptoClientStream( | 
| 103               server_hostname, this, crypto_config) : | 104               server_hostname, this, crypto_config) : | 
| 104           new QuicCryptoClientStream(server_hostname, this, crypto_config)); | 105           new QuicCryptoClientStream(server_hostname, this, crypto_config)); | 
| 105 | 106 | 
| 106   connection->set_debug_visitor(&logger_); | 107   connection->set_debug_visitor(&logger_); | 
| 107   // TODO(rch): pass in full host port proxy pair | 108   // TODO(rch): pass in full host port proxy pair | 
| 108   net_log_.BeginEvent( | 109   net_log_.BeginEvent( | 
| 109       NetLog::TYPE_QUIC_SESSION, | 110       NetLog::TYPE_QUIC_SESSION, | 
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 202 | 203 | 
| 203 QuicCryptoClientStream* QuicClientSession::GetCryptoStream() { | 204 QuicCryptoClientStream* QuicClientSession::GetCryptoStream() { | 
| 204   return crypto_stream_.get(); | 205   return crypto_stream_.get(); | 
| 205 }; | 206 }; | 
| 206 | 207 | 
| 207 bool QuicClientSession::GetSSLInfo(SSLInfo* ssl_info) { | 208 bool QuicClientSession::GetSSLInfo(SSLInfo* ssl_info) { | 
| 208   DCHECK(crypto_stream_.get()); | 209   DCHECK(crypto_stream_.get()); | 
| 209   return crypto_stream_->GetSSLInfo(ssl_info); | 210   return crypto_stream_->GetSSLInfo(ssl_info); | 
| 210 } | 211 } | 
| 211 | 212 | 
| 212 int QuicClientSession::CryptoConnect(const CompletionCallback& callback) { | 213 int QuicClientSession::CryptoConnect(bool require_confirmation, | 
|  | 214                                      const CompletionCallback& callback) { | 
|  | 215   require_confirmation_ = require_confirmation; | 
| 213   RecordHandshakeState(STATE_STARTED); | 216   RecordHandshakeState(STATE_STARTED); | 
| 214   if (!crypto_stream_->CryptoConnect()) { | 217   if (!crypto_stream_->CryptoConnect()) { | 
| 215     // TODO(wtc): change crypto_stream_.CryptoConnect() to return a | 218     // TODO(wtc): change crypto_stream_.CryptoConnect() to return a | 
| 216     // QuicErrorCode and map it to a net error code. | 219     // QuicErrorCode and map it to a net error code. | 
| 217     return ERR_CONNECTION_FAILED; | 220     return ERR_CONNECTION_FAILED; | 
| 218   } | 221   } | 
| 219 | 222 | 
| 220   if (IsEncryptionEstablished()) { | 223   bool can_notify = require_confirmation_ ? | 
|  | 224       IsCryptoHandshakeConfirmed() : IsEncryptionEstablished(); | 
|  | 225   if (can_notify) { | 
| 221     return OK; | 226     return OK; | 
| 222   } | 227   } | 
| 223 | 228 | 
| 224   callback_ = callback; | 229   callback_ = callback; | 
| 225   return ERR_IO_PENDING; | 230   return ERR_IO_PENDING; | 
| 226 } | 231 } | 
| 227 | 232 | 
| 228 ReliableQuicStream* QuicClientSession::CreateIncomingReliableStream( | 233 ReliableQuicStream* QuicClientSession::CreateIncomingReliableStream( | 
| 229     QuicStreamId id) { | 234     QuicStreamId id) { | 
| 230   DLOG(ERROR) << "Server push not supported"; | 235   DLOG(ERROR) << "Server push not supported"; | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
| 243     stream_requests_.pop_front(); | 248     stream_requests_.pop_front(); | 
| 244     request->OnRequestCompleteSuccess(CreateOutgoingReliableStreamImpl()); | 249     request->OnRequestCompleteSuccess(CreateOutgoingReliableStreamImpl()); | 
| 245   } | 250   } | 
| 246 | 251 | 
| 247   if (GetNumOpenStreams() == 0) { | 252   if (GetNumOpenStreams() == 0) { | 
| 248     stream_factory_->OnIdleSession(this); | 253     stream_factory_->OnIdleSession(this); | 
| 249   } | 254   } | 
| 250 } | 255 } | 
| 251 | 256 | 
| 252 void QuicClientSession::OnCryptoHandshakeEvent(CryptoHandshakeEvent event) { | 257 void QuicClientSession::OnCryptoHandshakeEvent(CryptoHandshakeEvent event) { | 
| 253   if (!callback_.is_null()) { | 258   if (!callback_.is_null() && | 
|  | 259       (!require_confirmation_ || event == HANDSHAKE_CONFIRMED)) { | 
| 254     // TODO(rtenneti): Currently for all CryptoHandshakeEvent events, callback_ | 260     // TODO(rtenneti): Currently for all CryptoHandshakeEvent events, callback_ | 
| 255     // could be called because there are no error events in CryptoHandshakeEvent | 261     // could be called because there are no error events in CryptoHandshakeEvent | 
| 256     // enum. If error events are added to CryptoHandshakeEvent, then the | 262     // enum. If error events are added to CryptoHandshakeEvent, then the | 
| 257     // following code needs to changed. | 263     // following code needs to changed. | 
| 258     base::ResetAndReturn(&callback_).Run(OK); | 264     base::ResetAndReturn(&callback_).Run(OK); | 
| 259   } | 265   } | 
| 260   QuicSession::OnCryptoHandshakeEvent(event); | 266   QuicSession::OnCryptoHandshakeEvent(event); | 
| 261 } | 267 } | 
| 262 | 268 | 
| 263 void QuicClientSession::ConnectionClose(QuicErrorCode error, bool from_peer) { | 269 void QuicClientSession::ConnectionClose(QuicErrorCode error, bool from_peer) { | 
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 372 } | 378 } | 
| 373 | 379 | 
| 374 void QuicClientSession::NotifyFactoryOfSessionClose() { | 380 void QuicClientSession::NotifyFactoryOfSessionClose() { | 
| 375   DCHECK_EQ(0u, GetNumOpenStreams()); | 381   DCHECK_EQ(0u, GetNumOpenStreams()); | 
| 376   DCHECK(stream_factory_); | 382   DCHECK(stream_factory_); | 
| 377   // Will delete |this|. | 383   // Will delete |this|. | 
| 378   stream_factory_->OnSessionClose(this); | 384   stream_factory_->OnSessionClose(this); | 
| 379 } | 385 } | 
| 380 | 386 | 
| 381 }  // namespace net | 387 }  // namespace net | 
| OLD | NEW | 
|---|