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/http/http_stream_factory_impl_job.h" | 5 #include "net/http/http_stream_factory_impl_job.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "net/http/http_pipelined_connection.h" | 21 #include "net/http/http_pipelined_connection.h" |
22 #include "net/http/http_pipelined_host.h" | 22 #include "net/http/http_pipelined_host.h" |
23 #include "net/http/http_pipelined_host_pool.h" | 23 #include "net/http/http_pipelined_host_pool.h" |
24 #include "net/http/http_pipelined_stream.h" | 24 #include "net/http/http_pipelined_stream.h" |
25 #include "net/http/http_proxy_client_socket.h" | 25 #include "net/http/http_proxy_client_socket.h" |
26 #include "net/http/http_proxy_client_socket_pool.h" | 26 #include "net/http/http_proxy_client_socket_pool.h" |
27 #include "net/http/http_request_info.h" | 27 #include "net/http/http_request_info.h" |
28 #include "net/http/http_server_properties.h" | 28 #include "net/http/http_server_properties.h" |
29 #include "net/http/http_stream_factory.h" | 29 #include "net/http/http_stream_factory.h" |
30 #include "net/http/http_stream_factory_impl_request.h" | 30 #include "net/http/http_stream_factory_impl_request.h" |
31 #include "net/quic/quic_http_stream.h" | |
31 #include "net/socket/client_socket_handle.h" | 32 #include "net/socket/client_socket_handle.h" |
32 #include "net/socket/client_socket_pool.h" | 33 #include "net/socket/client_socket_pool.h" |
33 #include "net/socket/client_socket_pool_manager.h" | 34 #include "net/socket/client_socket_pool_manager.h" |
34 #include "net/socket/socks_client_socket_pool.h" | 35 #include "net/socket/socks_client_socket_pool.h" |
35 #include "net/socket/ssl_client_socket.h" | 36 #include "net/socket/ssl_client_socket.h" |
36 #include "net/socket/ssl_client_socket_pool.h" | 37 #include "net/socket/ssl_client_socket_pool.h" |
37 #include "net/spdy/spdy_http_stream.h" | 38 #include "net/spdy/spdy_http_stream.h" |
38 #include "net/spdy/spdy_session.h" | 39 #include "net/spdy/spdy_session.h" |
39 #include "net/spdy/spdy_session_pool.h" | 40 #include "net/spdy/spdy_session_pool.h" |
40 | 41 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 base::Bind(&Job::OnIOComplete, base::Unretained(this)))), | 83 base::Bind(&Job::OnIOComplete, base::Unretained(this)))), |
83 connection_(new ClientSocketHandle), | 84 connection_(new ClientSocketHandle), |
84 session_(session), | 85 session_(session), |
85 stream_factory_(stream_factory), | 86 stream_factory_(stream_factory), |
86 next_state_(STATE_NONE), | 87 next_state_(STATE_NONE), |
87 pac_request_(NULL), | 88 pac_request_(NULL), |
88 blocking_job_(NULL), | 89 blocking_job_(NULL), |
89 waiting_job_(NULL), | 90 waiting_job_(NULL), |
90 using_ssl_(false), | 91 using_ssl_(false), |
91 using_spdy_(false), | 92 using_spdy_(false), |
93 using_quic_(false), | |
92 force_spdy_always_(HttpStreamFactory::force_spdy_always()), | 94 force_spdy_always_(HttpStreamFactory::force_spdy_always()), |
93 force_spdy_over_ssl_(HttpStreamFactory::force_spdy_over_ssl()), | 95 force_spdy_over_ssl_(HttpStreamFactory::force_spdy_over_ssl()), |
94 spdy_certificate_error_(OK), | 96 spdy_certificate_error_(OK), |
95 establishing_tunnel_(false), | 97 establishing_tunnel_(false), |
96 was_npn_negotiated_(false), | 98 was_npn_negotiated_(false), |
97 protocol_negotiated_(kProtoUnknown), | 99 protocol_negotiated_(kProtoUnknown), |
98 num_streams_(0), | 100 num_streams_(0), |
99 spdy_session_direct_(false), | 101 spdy_session_direct_(false), |
100 existing_available_pipeline_(false), | 102 existing_available_pipeline_(false), |
101 ALLOW_THIS_IN_INITIALIZER_LIST(ptr_factory_(this)) { | 103 ALLOW_THIS_IN_INITIALIZER_LIST(ptr_factory_(this)) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 next_state_ = STATE_RESTART_TUNNEL_AUTH; | 152 next_state_ = STATE_RESTART_TUNNEL_AUTH; |
151 stream_.reset(); | 153 stream_.reset(); |
152 return RunLoop(OK); | 154 return RunLoop(OK); |
153 } | 155 } |
154 | 156 |
155 LoadState HttpStreamFactoryImpl::Job::GetLoadState() const { | 157 LoadState HttpStreamFactoryImpl::Job::GetLoadState() const { |
156 switch (next_state_) { | 158 switch (next_state_) { |
157 case STATE_RESOLVE_PROXY_COMPLETE: | 159 case STATE_RESOLVE_PROXY_COMPLETE: |
158 return session_->proxy_service()->GetLoadState(pac_request_); | 160 return session_->proxy_service()->GetLoadState(pac_request_); |
159 case STATE_CREATE_STREAM_COMPLETE: | 161 case STATE_CREATE_STREAM_COMPLETE: |
160 return connection_->GetLoadState(); | 162 return using_quic_ ? LOAD_STATE_CONNECTING : connection_->GetLoadState(); |
161 case STATE_INIT_CONNECTION_COMPLETE: | 163 case STATE_INIT_CONNECTION_COMPLETE: |
162 return LOAD_STATE_SENDING_REQUEST; | 164 return LOAD_STATE_SENDING_REQUEST; |
163 default: | 165 default: |
164 return LOAD_STATE_IDLE; | 166 return LOAD_STATE_IDLE; |
165 } | 167 } |
166 } | 168 } |
167 | 169 |
168 void HttpStreamFactoryImpl::Job::MarkAsAlternate(const GURL& original_url) { | 170 void HttpStreamFactoryImpl::Job::MarkAsAlternate(const GURL& original_url) { |
169 DCHECK(!original_url_.get()); | 171 DCHECK(!original_url_.get()); |
170 original_url_.reset(new GURL(original_url)); | 172 original_url_.reset(new GURL(original_url)); |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
631 bool HttpStreamFactoryImpl::Job::ShouldForceSpdySSL() const { | 633 bool HttpStreamFactoryImpl::Job::ShouldForceSpdySSL() const { |
632 bool rv = force_spdy_always_ && force_spdy_over_ssl_; | 634 bool rv = force_spdy_always_ && force_spdy_over_ssl_; |
633 return rv && !HttpStreamFactory::HasSpdyExclusion(origin_); | 635 return rv && !HttpStreamFactory::HasSpdyExclusion(origin_); |
634 } | 636 } |
635 | 637 |
636 bool HttpStreamFactoryImpl::Job::ShouldForceSpdyWithoutSSL() const { | 638 bool HttpStreamFactoryImpl::Job::ShouldForceSpdyWithoutSSL() const { |
637 bool rv = force_spdy_always_ && !force_spdy_over_ssl_; | 639 bool rv = force_spdy_always_ && !force_spdy_over_ssl_; |
638 return rv && !HttpStreamFactory::HasSpdyExclusion(origin_); | 640 return rv && !HttpStreamFactory::HasSpdyExclusion(origin_); |
639 } | 641 } |
640 | 642 |
643 bool HttpStreamFactoryImpl::Job::ShouldForceQuic() const { | |
644 return session_->params().force_quic_port == origin_.port() | |
645 && proxy_info_.is_direct(); | |
646 } | |
647 | |
641 int HttpStreamFactoryImpl::Job::DoWaitForJob() { | 648 int HttpStreamFactoryImpl::Job::DoWaitForJob() { |
642 DCHECK(blocking_job_); | 649 DCHECK(blocking_job_); |
643 next_state_ = STATE_WAIT_FOR_JOB_COMPLETE; | 650 next_state_ = STATE_WAIT_FOR_JOB_COMPLETE; |
644 return ERR_IO_PENDING; | 651 return ERR_IO_PENDING; |
645 } | 652 } |
646 | 653 |
647 int HttpStreamFactoryImpl::Job::DoWaitForJobComplete(int result) { | 654 int HttpStreamFactoryImpl::Job::DoWaitForJobComplete(int result) { |
648 DCHECK(!blocking_job_); | 655 DCHECK(!blocking_job_); |
649 DCHECK_EQ(OK, result); | 656 DCHECK_EQ(OK, result); |
650 next_state_ = STATE_INIT_CONNECTION; | 657 next_state_ = STATE_INIT_CONNECTION; |
651 return OK; | 658 return OK; |
652 } | 659 } |
653 | 660 |
654 int HttpStreamFactoryImpl::Job::DoInitConnection() { | 661 int HttpStreamFactoryImpl::Job::DoInitConnection() { |
655 DCHECK(!blocking_job_); | 662 DCHECK(!blocking_job_); |
656 DCHECK(!connection_->is_initialized()); | 663 DCHECK(!connection_->is_initialized()); |
657 DCHECK(proxy_info_.proxy_server().is_valid()); | 664 DCHECK(proxy_info_.proxy_server().is_valid()); |
658 next_state_ = STATE_INIT_CONNECTION_COMPLETE; | 665 next_state_ = STATE_INIT_CONNECTION_COMPLETE; |
659 | 666 |
660 using_ssl_ = request_info_.url.SchemeIs("https") || ShouldForceSpdySSL(); | 667 using_ssl_ = request_info_.url.SchemeIs("https") || ShouldForceSpdySSL(); |
661 using_spdy_ = false; | 668 using_spdy_ = false; |
662 | 669 |
670 if (ShouldForceQuic()) { | |
671 next_state_ = STATE_CREATE_STREAM; | |
672 using_quic_ = true; | |
673 return OK; | |
674 } | |
675 | |
663 // Check first if we have a spdy session for this group. If so, then go | 676 // Check first if we have a spdy session for this group. If so, then go |
664 // straight to using that. | 677 // straight to using that. |
665 HostPortProxyPair spdy_session_key = GetSpdySessionKey(); | 678 HostPortProxyPair spdy_session_key = GetSpdySessionKey(); |
666 scoped_refptr<SpdySession> spdy_session = | 679 scoped_refptr<SpdySession> spdy_session = |
667 session_->spdy_session_pool()->GetIfExists(spdy_session_key, net_log_); | 680 session_->spdy_session_pool()->GetIfExists(spdy_session_key, net_log_); |
668 if (spdy_session && CanUseExistingSpdySession()) { | 681 if (spdy_session && CanUseExistingSpdySession()) { |
669 // If we're preconnecting, but we already have a SpdySession, we don't | 682 // If we're preconnecting, but we already have a SpdySession, we don't |
670 // actually need to preconnect any sockets, so we're done. | 683 // actually need to preconnect any sockets, so we're done. |
671 if (IsPreconnecting()) | 684 if (IsPreconnecting()) |
672 return OK; | 685 return OK; |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
896 // This state indicates that the stream request is in a partially | 909 // This state indicates that the stream request is in a partially |
897 // completed state, and we've called back to the delegate for more | 910 // completed state, and we've called back to the delegate for more |
898 // information. | 911 // information. |
899 | 912 |
900 // We're always waiting here for the delegate to call us back. | 913 // We're always waiting here for the delegate to call us back. |
901 return ERR_IO_PENDING; | 914 return ERR_IO_PENDING; |
902 } | 915 } |
903 | 916 |
904 int HttpStreamFactoryImpl::Job::DoCreateStream() { | 917 int HttpStreamFactoryImpl::Job::DoCreateStream() { |
905 DCHECK(connection_->socket() || existing_spdy_session_ || | 918 DCHECK(connection_->socket() || existing_spdy_session_ || |
906 existing_available_pipeline_); | 919 existing_available_pipeline_ || using_quic_); |
907 | 920 |
908 next_state_ = STATE_CREATE_STREAM_COMPLETE; | 921 next_state_ = STATE_CREATE_STREAM_COMPLETE; |
909 | 922 |
910 // We only set the socket motivation if we're the first to use | 923 // We only set the socket motivation if we're the first to use |
911 // this socket. Is there a race for two SPDY requests? We really | 924 // this socket. Is there a race for two SPDY requests? We really |
912 // need to plumb this through to the connect level. | 925 // need to plumb this through to the connect level. |
913 if (connection_->socket() && !connection_->is_reused()) | 926 if (connection_->socket() && !connection_->is_reused()) |
914 SetSocketMotivation(); | 927 SetSocketMotivation(); |
915 | 928 |
916 const ProxyServer& proxy_server = proxy_info_.proxy_server(); | 929 const ProxyServer& proxy_server = proxy_info_.proxy_server(); |
917 | 930 |
931 if (using_quic_) { | |
932 return session_->quic_stream_factory()->Create( | |
willchan no longer on Chromium
2012/12/11 02:02:08
This is blocked on the other CL I guess.
Ryan Hamilton
2012/12/11 20:03:05
Indeed. (Though I've rebased to to integrate the
| |
933 HostPortProxyPair(origin_, proxy_server), net_log_, &quic_stream_, | |
934 io_callback_); | |
935 } | |
936 | |
918 if (!using_spdy_) { | 937 if (!using_spdy_) { |
919 bool using_proxy = (proxy_info_.is_http() || proxy_info_.is_https()) && | 938 bool using_proxy = (proxy_info_.is_http() || proxy_info_.is_https()) && |
920 request_info_.url.SchemeIs("http"); | 939 request_info_.url.SchemeIs("http"); |
921 if (stream_factory_->http_pipelined_host_pool_. | 940 if (stream_factory_->http_pipelined_host_pool_. |
922 IsExistingPipelineAvailableForKey(*http_pipelining_key_.get())) { | 941 IsExistingPipelineAvailableForKey(*http_pipelining_key_.get())) { |
923 stream_.reset(stream_factory_->http_pipelined_host_pool_. | 942 stream_.reset(stream_factory_->http_pipelined_host_pool_. |
924 CreateStreamOnExistingPipeline( | 943 CreateStreamOnExistingPipeline( |
925 *http_pipelining_key_.get())); | 944 *http_pipelining_key_.get())); |
926 CHECK(stream_.get()); | 945 CHECK(stream_.get()); |
927 } else if (!using_proxy && IsRequestEligibleForPipelining()) { | 946 } else if (!using_proxy && IsRequestEligibleForPipelining()) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
990 | 1009 |
991 bool use_relative_url = direct || request_info_.url.SchemeIs("https"); | 1010 bool use_relative_url = direct || request_info_.url.SchemeIs("https"); |
992 stream_.reset(new SpdyHttpStream(spdy_session, use_relative_url)); | 1011 stream_.reset(new SpdyHttpStream(spdy_session, use_relative_url)); |
993 return OK; | 1012 return OK; |
994 } | 1013 } |
995 | 1014 |
996 int HttpStreamFactoryImpl::Job::DoCreateStreamComplete(int result) { | 1015 int HttpStreamFactoryImpl::Job::DoCreateStreamComplete(int result) { |
997 if (result < 0) | 1016 if (result < 0) |
998 return result; | 1017 return result; |
999 | 1018 |
1019 if (using_quic_) { | |
1020 CHECK(quic_stream_); | |
1021 stream_ = quic_stream_.Pass(); | |
1022 } | |
1023 | |
1000 session_->proxy_service()->ReportSuccess(proxy_info_); | 1024 session_->proxy_service()->ReportSuccess(proxy_info_); |
1001 next_state_ = STATE_NONE; | 1025 next_state_ = STATE_NONE; |
1002 return OK; | 1026 return OK; |
1003 } | 1027 } |
1004 | 1028 |
1005 int HttpStreamFactoryImpl::Job::DoRestartTunnelAuth() { | 1029 int HttpStreamFactoryImpl::Job::DoRestartTunnelAuth() { |
1006 next_state_ = STATE_RESTART_TUNNEL_AUTH_COMPLETE; | 1030 next_state_ = STATE_RESTART_TUNNEL_AUTH_COMPLETE; |
1007 ProxyClientSocket* proxy_socket = | 1031 ProxyClientSocket* proxy_socket = |
1008 static_cast<ProxyClientSocket*>(connection_->socket()); | 1032 static_cast<ProxyClientSocket*>(connection_->socket()); |
1009 return proxy_socket->RestartWithAuth(io_callback_); | 1033 return proxy_socket->RestartWithAuth(io_callback_); |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1281 (net::LOAD_MAIN_FRAME | net::LOAD_SUB_FRAME | net::LOAD_PREFETCH | | 1305 (net::LOAD_MAIN_FRAME | net::LOAD_SUB_FRAME | net::LOAD_PREFETCH | |
1282 net::LOAD_IS_DOWNLOAD)) { | 1306 net::LOAD_IS_DOWNLOAD)) { |
1283 // Avoid pipelining resources that may be streamed for a long time. | 1307 // Avoid pipelining resources that may be streamed for a long time. |
1284 return false; | 1308 return false; |
1285 } | 1309 } |
1286 return stream_factory_->http_pipelined_host_pool_.IsKeyEligibleForPipelining( | 1310 return stream_factory_->http_pipelined_host_pool_.IsKeyEligibleForPipelining( |
1287 *http_pipelining_key_.get()); | 1311 *http_pipelining_key_.get()); |
1288 } | 1312 } |
1289 | 1313 |
1290 } // namespace net | 1314 } // namespace net |
OLD | NEW |