| 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/cpu.h" | 9 #include "base/cpu.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 const BoundNetLog& net_log) | 227 const BoundNetLog& net_log) |
| 228 : io_state_(STATE_RESOLVE_HOST), | 228 : io_state_(STATE_RESOLVE_HOST), |
| 229 factory_(factory), | 229 factory_(factory), |
| 230 host_resolver_(host_resolver), | 230 host_resolver_(host_resolver), |
| 231 server_id_(host_port_pair, is_https, privacy_mode), | 231 server_id_(host_port_pair, is_https, privacy_mode), |
| 232 is_post_(method == "POST"), | 232 is_post_(method == "POST"), |
| 233 was_alternate_protocol_recently_broken_( | 233 was_alternate_protocol_recently_broken_( |
| 234 was_alternate_protocol_recently_broken), | 234 was_alternate_protocol_recently_broken), |
| 235 server_info_(server_info), | 235 server_info_(server_info), |
| 236 net_log_(net_log), | 236 net_log_(net_log), |
| 237 session_(NULL), | 237 session_(nullptr), |
| 238 weak_factory_(this) {} | 238 weak_factory_(this) {} |
| 239 | 239 |
| 240 QuicStreamFactory::Job::Job(QuicStreamFactory* factory, | 240 QuicStreamFactory::Job::Job(QuicStreamFactory* factory, |
| 241 HostResolver* host_resolver, | 241 HostResolver* host_resolver, |
| 242 QuicClientSession* session, | 242 QuicClientSession* session, |
| 243 QuicServerId server_id) | 243 QuicServerId server_id) |
| 244 : io_state_(STATE_RESUME_CONNECT), | 244 : io_state_(STATE_RESUME_CONNECT), |
| 245 factory_(factory), | 245 factory_(factory), |
| 246 host_resolver_(host_resolver), // unused | 246 host_resolver_(host_resolver), // unused |
| 247 server_id_(server_id), | 247 server_id_(server_id), |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 int QuicStreamFactory::Job::DoConnectComplete(int rv) { | 411 int QuicStreamFactory::Job::DoConnectComplete(int rv) { |
| 412 if (rv != OK) | 412 if (rv != OK) |
| 413 return rv; | 413 return rv; |
| 414 | 414 |
| 415 DCHECK(!factory_->HasActiveSession(server_id_)); | 415 DCHECK(!factory_->HasActiveSession(server_id_)); |
| 416 // There may well now be an active session for this IP. If so, use the | 416 // There may well now be an active session for this IP. If so, use the |
| 417 // existing session instead. | 417 // existing session instead. |
| 418 AddressList address(session_->connection()->peer_address()); | 418 AddressList address(session_->connection()->peer_address()); |
| 419 if (factory_->OnResolution(server_id_, address)) { | 419 if (factory_->OnResolution(server_id_, address)) { |
| 420 session_->connection()->SendConnectionClose(QUIC_CONNECTION_IP_POOLED); | 420 session_->connection()->SendConnectionClose(QUIC_CONNECTION_IP_POOLED); |
| 421 session_ = NULL; | 421 session_ = nullptr; |
| 422 return OK; | 422 return OK; |
| 423 } | 423 } |
| 424 | 424 |
| 425 factory_->ActivateSession(server_id_, session_); | 425 factory_->ActivateSession(server_id_, session_); |
| 426 | 426 |
| 427 return OK; | 427 return OK; |
| 428 } | 428 } |
| 429 | 429 |
| 430 QuicStreamRequest::QuicStreamRequest(QuicStreamFactory* factory) | 430 QuicStreamRequest::QuicStreamRequest(QuicStreamFactory* factory) |
| 431 : factory_(factory) {} | 431 : factory_(factory) {} |
| (...skipping 13 matching lines...) Expand all Loading... |
| 445 DCHECK(callback_.is_null()); | 445 DCHECK(callback_.is_null()); |
| 446 DCHECK(factory_); | 446 DCHECK(factory_); |
| 447 int rv = factory_->Create(host_port_pair, is_https, privacy_mode, method, | 447 int rv = factory_->Create(host_port_pair, is_https, privacy_mode, method, |
| 448 net_log, this); | 448 net_log, this); |
| 449 if (rv == ERR_IO_PENDING) { | 449 if (rv == ERR_IO_PENDING) { |
| 450 host_port_pair_ = host_port_pair; | 450 host_port_pair_ = host_port_pair; |
| 451 is_https_ = is_https; | 451 is_https_ = is_https; |
| 452 net_log_ = net_log; | 452 net_log_ = net_log; |
| 453 callback_ = callback; | 453 callback_ = callback; |
| 454 } else { | 454 } else { |
| 455 factory_ = NULL; | 455 factory_ = nullptr; |
| 456 } | 456 } |
| 457 if (rv == OK) | 457 if (rv == OK) |
| 458 DCHECK(stream_); | 458 DCHECK(stream_); |
| 459 return rv; | 459 return rv; |
| 460 } | 460 } |
| 461 | 461 |
| 462 void QuicStreamRequest::set_stream(scoped_ptr<QuicHttpStream> stream) { | 462 void QuicStreamRequest::set_stream(scoped_ptr<QuicHttpStream> stream) { |
| 463 DCHECK(stream); | 463 DCHECK(stream); |
| 464 stream_ = stream.Pass(); | 464 stream_ = stream.Pass(); |
| 465 } | 465 } |
| 466 | 466 |
| 467 void QuicStreamRequest::OnRequestComplete(int rv) { | 467 void QuicStreamRequest::OnRequestComplete(int rv) { |
| 468 factory_ = NULL; | 468 factory_ = nullptr; |
| 469 callback_.Run(rv); | 469 callback_.Run(rv); |
| 470 } | 470 } |
| 471 | 471 |
| 472 scoped_ptr<QuicHttpStream> QuicStreamRequest::ReleaseStream() { | 472 scoped_ptr<QuicHttpStream> QuicStreamRequest::ReleaseStream() { |
| 473 DCHECK(stream_); | 473 DCHECK(stream_); |
| 474 return stream_.Pass(); | 474 return stream_.Pass(); |
| 475 } | 475 } |
| 476 | 476 |
| 477 QuicStreamFactory::QuicStreamFactory( | 477 QuicStreamFactory::QuicStreamFactory( |
| 478 HostResolver* host_resolver, | 478 HostResolver* host_resolver, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 489 const QuicVersionVector& supported_versions, | 489 const QuicVersionVector& supported_versions, |
| 490 bool enable_port_selection, | 490 bool enable_port_selection, |
| 491 bool always_require_handshake_confirmation, | 491 bool always_require_handshake_confirmation, |
| 492 bool disable_connection_pooling, | 492 bool disable_connection_pooling, |
| 493 const QuicTagVector& connection_options) | 493 const QuicTagVector& connection_options) |
| 494 : require_confirmation_(true), | 494 : require_confirmation_(true), |
| 495 host_resolver_(host_resolver), | 495 host_resolver_(host_resolver), |
| 496 client_socket_factory_(client_socket_factory), | 496 client_socket_factory_(client_socket_factory), |
| 497 http_server_properties_(http_server_properties), | 497 http_server_properties_(http_server_properties), |
| 498 transport_security_state_(transport_security_state), | 498 transport_security_state_(transport_security_state), |
| 499 quic_server_info_factory_(NULL), | 499 quic_server_info_factory_(nullptr), |
| 500 quic_crypto_client_stream_factory_(quic_crypto_client_stream_factory), | 500 quic_crypto_client_stream_factory_(quic_crypto_client_stream_factory), |
| 501 random_generator_(random_generator), | 501 random_generator_(random_generator), |
| 502 clock_(clock), | 502 clock_(clock), |
| 503 max_packet_length_(max_packet_length), | 503 max_packet_length_(max_packet_length), |
| 504 config_(InitializeQuicConfig(connection_options)), | 504 config_(InitializeQuicConfig(connection_options)), |
| 505 supported_versions_(supported_versions), | 505 supported_versions_(supported_versions), |
| 506 enable_port_selection_(enable_port_selection), | 506 enable_port_selection_(enable_port_selection), |
| 507 always_require_handshake_confirmation_( | 507 always_require_handshake_confirmation_( |
| 508 always_require_handshake_confirmation), | 508 always_require_handshake_confirmation), |
| 509 disable_connection_pooling_(disable_connection_pooling), | 509 disable_connection_pooling_(disable_connection_pooling), |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 return OK; | 558 return OK; |
| 559 } | 559 } |
| 560 | 560 |
| 561 if (HasActiveJob(server_id)) { | 561 if (HasActiveJob(server_id)) { |
| 562 Job* job = active_jobs_[server_id]; | 562 Job* job = active_jobs_[server_id]; |
| 563 active_requests_[request] = job; | 563 active_requests_[request] = job; |
| 564 job_requests_map_[job].insert(request); | 564 job_requests_map_[job].insert(request); |
| 565 return ERR_IO_PENDING; | 565 return ERR_IO_PENDING; |
| 566 } | 566 } |
| 567 | 567 |
| 568 QuicServerInfo* quic_server_info = NULL; | 568 QuicServerInfo* quic_server_info = nullptr; |
| 569 if (quic_server_info_factory_) { | 569 if (quic_server_info_factory_) { |
| 570 QuicCryptoClientConfig::CachedState* cached = | 570 QuicCryptoClientConfig::CachedState* cached = |
| 571 crypto_config_.LookupOrCreate(server_id); | 571 crypto_config_.LookupOrCreate(server_id); |
| 572 DCHECK(cached); | 572 DCHECK(cached); |
| 573 if (cached->IsEmpty()) { | 573 if (cached->IsEmpty()) { |
| 574 quic_server_info = quic_server_info_factory_->GetForServer(server_id); | 574 quic_server_info = quic_server_info_factory_->GetForServer(server_id); |
| 575 } | 575 } |
| 576 } | 576 } |
| 577 bool was_alternate_protocol_recently_broken = | 577 bool was_alternate_protocol_recently_broken = |
| 578 http_server_properties_ && | 578 http_server_properties_ && |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 // profile which can not be deleted via callbacks. | 646 // profile which can not be deleted via callbacks. |
| 647 request->OnRequestComplete(rv); | 647 request->OnRequestComplete(rv); |
| 648 } | 648 } |
| 649 active_jobs_.erase(job->server_id()); | 649 active_jobs_.erase(job->server_id()); |
| 650 job_requests_map_.erase(job); | 650 job_requests_map_.erase(job); |
| 651 delete job; | 651 delete job; |
| 652 return; | 652 return; |
| 653 } | 653 } |
| 654 | 654 |
| 655 // Returns a newly created QuicHttpStream owned by the caller, if a | 655 // Returns a newly created QuicHttpStream owned by the caller, if a |
| 656 // matching session already exists. Returns NULL otherwise. | 656 // matching session already exists. Returns nullptr otherwise. |
| 657 scoped_ptr<QuicHttpStream> QuicStreamFactory::CreateIfSessionExists( | 657 scoped_ptr<QuicHttpStream> QuicStreamFactory::CreateIfSessionExists( |
| 658 const QuicServerId& server_id, | 658 const QuicServerId& server_id, |
| 659 const BoundNetLog& net_log) { | 659 const BoundNetLog& net_log) { |
| 660 if (!HasActiveSession(server_id)) { | 660 if (!HasActiveSession(server_id)) { |
| 661 DVLOG(1) << "No active session"; | 661 DVLOG(1) << "No active session"; |
| 662 return scoped_ptr<QuicHttpStream>(); | 662 return scoped_ptr<QuicHttpStream>(); |
| 663 } | 663 } |
| 664 | 664 |
| 665 QuicClientSession* session = active_sessions_[server_id]; | 665 QuicClientSession* session = active_sessions_[server_id]; |
| 666 DCHECK(session); | 666 DCHECK(session); |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 config.SetInitialCongestionWindowToSend( | 902 config.SetInitialCongestionWindowToSend( |
| 903 server_id.is_https() ? kServerSecureInitialCongestionWindow | 903 server_id.is_https() ? kServerSecureInitialCongestionWindow |
| 904 : kServerInecureInitialCongestionWindow); | 904 : kServerInecureInitialCongestionWindow); |
| 905 config.SetInitialFlowControlWindowToSend(kInitialReceiveWindowSize); | 905 config.SetInitialFlowControlWindowToSend(kInitialReceiveWindowSize); |
| 906 config.SetInitialStreamFlowControlWindowToSend(kInitialReceiveWindowSize); | 906 config.SetInitialStreamFlowControlWindowToSend(kInitialReceiveWindowSize); |
| 907 config.SetInitialSessionFlowControlWindowToSend(kInitialReceiveWindowSize); | 907 config.SetInitialSessionFlowControlWindowToSend(kInitialReceiveWindowSize); |
| 908 if (http_server_properties_) { | 908 if (http_server_properties_) { |
| 909 const HttpServerProperties::NetworkStats* stats = | 909 const HttpServerProperties::NetworkStats* stats = |
| 910 http_server_properties_->GetServerNetworkStats( | 910 http_server_properties_->GetServerNetworkStats( |
| 911 server_id.host_port_pair()); | 911 server_id.host_port_pair()); |
| 912 if (stats != NULL) { | 912 if (stats != nullptr) { |
| 913 config.SetInitialRoundTripTimeUsToSend(stats->srtt.InMicroseconds()); | 913 config.SetInitialRoundTripTimeUsToSend(stats->srtt.InMicroseconds()); |
| 914 } | 914 } |
| 915 } | 915 } |
| 916 | 916 |
| 917 *session = new QuicClientSession( | 917 *session = new QuicClientSession( |
| 918 connection, socket.Pass(), this, transport_security_state_, | 918 connection, socket.Pass(), this, transport_security_state_, |
| 919 server_info.Pass(), config, | 919 server_info.Pass(), config, |
| 920 base::MessageLoop::current()->message_loop_proxy().get(), | 920 base::MessageLoop::current()->message_loop_proxy().get(), |
| 921 net_log.net_log()); | 921 net_log.net_log()); |
| 922 all_sessions_[*session] = server_id; // owning pointer | 922 all_sessions_[*session] = server_id; // owning pointer |
| 923 (*session)->InitializeSession(server_id, &crypto_config_, | 923 (*session)->InitializeSession(server_id, &crypto_config_, |
| 924 quic_crypto_client_stream_factory_); | 924 quic_crypto_client_stream_factory_); |
| 925 bool closed_during_initialize = | 925 bool closed_during_initialize = |
| 926 !ContainsKey(all_sessions_, *session) || | 926 !ContainsKey(all_sessions_, *session) || |
| 927 !(*session)->connection()->connected(); | 927 !(*session)->connection()->connected(); |
| 928 UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.ClosedDuringInitializeSession", | 928 UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.ClosedDuringInitializeSession", |
| 929 closed_during_initialize); | 929 closed_during_initialize); |
| 930 if (closed_during_initialize) { | 930 if (closed_during_initialize) { |
| 931 DLOG(DFATAL) << "Session closed during initialize"; | 931 DLOG(DFATAL) << "Session closed during initialize"; |
| 932 *session = NULL; | 932 *session = nullptr; |
| 933 return ERR_CONNECTION_CLOSED; | 933 return ERR_CONNECTION_CLOSED; |
| 934 } | 934 } |
| 935 return OK; | 935 return OK; |
| 936 } | 936 } |
| 937 | 937 |
| 938 bool QuicStreamFactory::HasActiveJob(const QuicServerId& key) const { | 938 bool QuicStreamFactory::HasActiveJob(const QuicServerId& key) const { |
| 939 return ContainsKey(active_jobs_, key); | 939 return ContainsKey(active_jobs_, key); |
| 940 } | 940 } |
| 941 | 941 |
| 942 void QuicStreamFactory::ActivateSession( | 942 void QuicStreamFactory::ActivateSession( |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1025 http_server_properties_->ClearAlternateProtocol(server); | 1025 http_server_properties_->ClearAlternateProtocol(server); |
| 1026 http_server_properties_->SetAlternateProtocol( | 1026 http_server_properties_->SetAlternateProtocol( |
| 1027 server, alternate.port, alternate.protocol, 1); | 1027 server, alternate.port, alternate.protocol, 1); |
| 1028 DCHECK_EQ(QUIC, | 1028 DCHECK_EQ(QUIC, |
| 1029 http_server_properties_->GetAlternateProtocol(server).protocol); | 1029 http_server_properties_->GetAlternateProtocol(server).protocol); |
| 1030 DCHECK(http_server_properties_->WasAlternateProtocolRecentlyBroken( | 1030 DCHECK(http_server_properties_->WasAlternateProtocolRecentlyBroken( |
| 1031 server)); | 1031 server)); |
| 1032 } | 1032 } |
| 1033 | 1033 |
| 1034 } // namespace net | 1034 } // namespace net |
| OLD | NEW |