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_stream_factory.h" | 5 #include "net/quic/quic_stream_factory.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 } | 191 } |
192 | 192 |
193 scoped_ptr<QuicHttpStream> QuicStreamRequest::ReleaseStream() { | 193 scoped_ptr<QuicHttpStream> QuicStreamRequest::ReleaseStream() { |
194 DCHECK(stream_); | 194 DCHECK(stream_); |
195 return stream_.Pass(); | 195 return stream_.Pass(); |
196 } | 196 } |
197 | 197 |
198 int QuicStreamFactory::Job::DoConnect() { | 198 int QuicStreamFactory::Job::DoConnect() { |
199 io_state_ = STATE_CONNECT_COMPLETE; | 199 io_state_ = STATE_CONNECT_COMPLETE; |
200 | 200 |
201 session_ = factory_->CreateSession(host_port_proxy_pair_.first.host(), | 201 session_ = factory_->CreateSession(host_port_proxy_pair_, address_list_, |
202 address_list_, net_log_); | 202 net_log_); |
203 session_->StartReading(); | 203 session_->StartReading(); |
204 int rv = session_->CryptoConnect( | 204 int rv = session_->CryptoConnect( |
205 base::Bind(&QuicStreamFactory::Job::OnIOComplete, | 205 base::Bind(&QuicStreamFactory::Job::OnIOComplete, |
206 base::Unretained(this))); | 206 base::Unretained(this))); |
207 return rv; | 207 return rv; |
208 } | 208 } |
209 | 209 |
210 int QuicStreamFactory::Job::DoConnectComplete(int rv) { | 210 int QuicStreamFactory::Job::DoConnectComplete(int rv) { |
211 if (rv != OK) | 211 if (rv != OK) |
212 return rv; | 212 return rv; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 } | 353 } |
354 return list; | 354 return list; |
355 } | 355 } |
356 | 356 |
357 bool QuicStreamFactory::HasActiveSession( | 357 bool QuicStreamFactory::HasActiveSession( |
358 const HostPortProxyPair& host_port_proxy_pair) { | 358 const HostPortProxyPair& host_port_proxy_pair) { |
359 return ContainsKey(active_sessions_, host_port_proxy_pair); | 359 return ContainsKey(active_sessions_, host_port_proxy_pair); |
360 } | 360 } |
361 | 361 |
362 QuicClientSession* QuicStreamFactory::CreateSession( | 362 QuicClientSession* QuicStreamFactory::CreateSession( |
363 const std::string& host, | 363 const HostPortProxyPair& host_port_proxy_pair, |
364 const AddressList& address_list, | 364 const AddressList& address_list, |
365 const BoundNetLog& net_log) { | 365 const BoundNetLog& net_log) { |
366 QuicGuid guid = random_generator_->RandUint64(); | 366 QuicGuid guid = random_generator_->RandUint64(); |
367 IPEndPoint addr = *address_list.begin(); | 367 IPEndPoint addr = *address_list.begin(); |
368 DatagramClientSocket* socket = | 368 DatagramClientSocket* socket = |
369 client_socket_factory_->CreateDatagramClientSocket( | 369 client_socket_factory_->CreateDatagramClientSocket( |
370 DatagramSocket::DEFAULT_BIND, base::Bind(&base::RandInt), | 370 DatagramSocket::DEFAULT_BIND, base::Bind(&base::RandInt), |
371 net_log.net_log(), net_log.source()); | 371 net_log.net_log(), net_log.source()); |
372 socket->Connect(addr); | 372 socket->Connect(addr); |
373 socket->GetLocalAddress(&addr); | 373 socket->GetLocalAddress(&addr); |
374 | 374 |
375 QuicConnectionHelper* helper = new QuicConnectionHelper( | 375 QuicConnectionHelper* helper = new QuicConnectionHelper( |
376 MessageLoop::current()->message_loop_proxy(), | 376 MessageLoop::current()->message_loop_proxy(), |
377 clock_.get(), random_generator_, socket); | 377 clock_.get(), random_generator_, socket); |
378 | 378 |
379 QuicConnection* connection = new QuicConnection(guid, addr, helper, false); | 379 QuicConnection* connection = new QuicConnection(guid, addr, helper, false); |
| 380 |
| 381 QuicCryptoClientConfig* crypto_config = |
| 382 GetOrCreateCryptoConfig(host_port_proxy_pair); |
| 383 DCHECK(crypto_config); |
| 384 |
380 QuicClientSession* session = | 385 QuicClientSession* session = |
381 new QuicClientSession(connection, socket, this, | 386 new QuicClientSession(connection, socket, this, |
382 quic_crypto_client_stream_factory_, host, | 387 quic_crypto_client_stream_factory_, |
383 net_log.net_log()); | 388 host_port_proxy_pair.first.host(), |
| 389 crypto_config, net_log.net_log()); |
384 all_sessions_.insert(session); // owning pointer | 390 all_sessions_.insert(session); // owning pointer |
385 return session; | 391 return session; |
386 } | 392 } |
387 | 393 |
388 bool QuicStreamFactory::HasActiveJob( | 394 bool QuicStreamFactory::HasActiveJob( |
389 const HostPortProxyPair& host_port_proxy_pair) { | 395 const HostPortProxyPair& host_port_proxy_pair) { |
390 return ContainsKey(active_jobs_, host_port_proxy_pair); | 396 return ContainsKey(active_jobs_, host_port_proxy_pair); |
391 } | 397 } |
392 | 398 |
393 void QuicStreamFactory::ActivateSession( | 399 void QuicStreamFactory::ActivateSession( |
394 const HostPortProxyPair& host_port_proxy_pair, | 400 const HostPortProxyPair& host_port_proxy_pair, |
395 QuicClientSession* session) { | 401 QuicClientSession* session) { |
396 DCHECK(!HasActiveSession(host_port_proxy_pair)); | 402 DCHECK(!HasActiveSession(host_port_proxy_pair)); |
397 active_sessions_[host_port_proxy_pair] = session; | 403 active_sessions_[host_port_proxy_pair] = session; |
398 session_aliases_[session].insert(host_port_proxy_pair); | 404 session_aliases_[session].insert(host_port_proxy_pair); |
399 } | 405 } |
400 | 406 |
| 407 QuicCryptoClientConfig* QuicStreamFactory::GetOrCreateCryptoConfig( |
| 408 const HostPortProxyPair& host_port_proxy_pair) { |
| 409 QuicCryptoClientConfig* crypto_config; |
| 410 if (ContainsKey(all_crypto_configs_, host_port_proxy_pair)) { |
| 411 crypto_config = all_crypto_configs_[host_port_proxy_pair]; |
| 412 DCHECK(crypto_config); |
| 413 } else { |
| 414 crypto_config = new QuicCryptoClientConfig(); |
| 415 crypto_config->SetDefaults(); |
| 416 all_crypto_configs_[host_port_proxy_pair] = crypto_config; |
| 417 } |
| 418 return crypto_config; |
| 419 } |
401 | 420 |
402 } // namespace net | 421 } // namespace net |
OLD | NEW |