Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(361)

Side by Side Diff: net/http/http_stream_factory_impl_job.cc

Issue 11416058: Integrating the QuicStreamFactory into the network stack. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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),
94 quic_request_(session_->quic_stream_factory()),
92 force_spdy_always_(HttpStreamFactory::force_spdy_always()), 95 force_spdy_always_(HttpStreamFactory::force_spdy_always()),
93 force_spdy_over_ssl_(HttpStreamFactory::force_spdy_over_ssl()), 96 force_spdy_over_ssl_(HttpStreamFactory::force_spdy_over_ssl()),
94 spdy_certificate_error_(OK), 97 spdy_certificate_error_(OK),
95 establishing_tunnel_(false), 98 establishing_tunnel_(false),
96 was_npn_negotiated_(false), 99 was_npn_negotiated_(false),
97 protocol_negotiated_(kProtoUnknown), 100 protocol_negotiated_(kProtoUnknown),
98 num_streams_(0), 101 num_streams_(0),
99 spdy_session_direct_(false), 102 spdy_session_direct_(false),
100 existing_available_pipeline_(false), 103 existing_available_pipeline_(false),
101 ALLOW_THIS_IN_INITIALIZER_LIST(ptr_factory_(this)) { 104 ALLOW_THIS_IN_INITIALIZER_LIST(ptr_factory_(this)) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 next_state_ = STATE_RESTART_TUNNEL_AUTH; 153 next_state_ = STATE_RESTART_TUNNEL_AUTH;
151 stream_.reset(); 154 stream_.reset();
152 return RunLoop(OK); 155 return RunLoop(OK);
153 } 156 }
154 157
155 LoadState HttpStreamFactoryImpl::Job::GetLoadState() const { 158 LoadState HttpStreamFactoryImpl::Job::GetLoadState() const {
156 switch (next_state_) { 159 switch (next_state_) {
157 case STATE_RESOLVE_PROXY_COMPLETE: 160 case STATE_RESOLVE_PROXY_COMPLETE:
158 return session_->proxy_service()->GetLoadState(pac_request_); 161 return session_->proxy_service()->GetLoadState(pac_request_);
159 case STATE_CREATE_STREAM_COMPLETE: 162 case STATE_CREATE_STREAM_COMPLETE:
160 return connection_->GetLoadState(); 163 return using_quic_ ? LOAD_STATE_CONNECTING : connection_->GetLoadState();
161 case STATE_INIT_CONNECTION_COMPLETE: 164 case STATE_INIT_CONNECTION_COMPLETE:
162 return LOAD_STATE_SENDING_REQUEST; 165 return LOAD_STATE_SENDING_REQUEST;
163 default: 166 default:
164 return LOAD_STATE_IDLE; 167 return LOAD_STATE_IDLE;
165 } 168 }
166 } 169 }
167 170
168 void HttpStreamFactoryImpl::Job::MarkAsAlternate(const GURL& original_url) { 171 void HttpStreamFactoryImpl::Job::MarkAsAlternate(const GURL& original_url) {
169 DCHECK(!original_url_.get()); 172 DCHECK(!original_url_.get());
170 original_url_.reset(new GURL(original_url)); 173 original_url_.reset(new GURL(original_url));
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 bool HttpStreamFactoryImpl::Job::ShouldForceSpdySSL() const { 634 bool HttpStreamFactoryImpl::Job::ShouldForceSpdySSL() const {
632 bool rv = force_spdy_always_ && force_spdy_over_ssl_; 635 bool rv = force_spdy_always_ && force_spdy_over_ssl_;
633 return rv && !HttpStreamFactory::HasSpdyExclusion(origin_); 636 return rv && !HttpStreamFactory::HasSpdyExclusion(origin_);
634 } 637 }
635 638
636 bool HttpStreamFactoryImpl::Job::ShouldForceSpdyWithoutSSL() const { 639 bool HttpStreamFactoryImpl::Job::ShouldForceSpdyWithoutSSL() const {
637 bool rv = force_spdy_always_ && !force_spdy_over_ssl_; 640 bool rv = force_spdy_always_ && !force_spdy_over_ssl_;
638 return rv && !HttpStreamFactory::HasSpdyExclusion(origin_); 641 return rv && !HttpStreamFactory::HasSpdyExclusion(origin_);
639 } 642 }
640 643
644 bool HttpStreamFactoryImpl::Job::ShouldForceQuic() const {
645 return session_->params().force_quic_when_origin_has_port == origin_.port()
646 && proxy_info_.is_direct();
647 }
648
641 int HttpStreamFactoryImpl::Job::DoWaitForJob() { 649 int HttpStreamFactoryImpl::Job::DoWaitForJob() {
642 DCHECK(blocking_job_); 650 DCHECK(blocking_job_);
643 next_state_ = STATE_WAIT_FOR_JOB_COMPLETE; 651 next_state_ = STATE_WAIT_FOR_JOB_COMPLETE;
644 return ERR_IO_PENDING; 652 return ERR_IO_PENDING;
645 } 653 }
646 654
647 int HttpStreamFactoryImpl::Job::DoWaitForJobComplete(int result) { 655 int HttpStreamFactoryImpl::Job::DoWaitForJobComplete(int result) {
648 DCHECK(!blocking_job_); 656 DCHECK(!blocking_job_);
649 DCHECK_EQ(OK, result); 657 DCHECK_EQ(OK, result);
650 next_state_ = STATE_INIT_CONNECTION; 658 next_state_ = STATE_INIT_CONNECTION;
651 return OK; 659 return OK;
652 } 660 }
653 661
654 int HttpStreamFactoryImpl::Job::DoInitConnection() { 662 int HttpStreamFactoryImpl::Job::DoInitConnection() {
655 DCHECK(!blocking_job_); 663 DCHECK(!blocking_job_);
656 DCHECK(!connection_->is_initialized()); 664 DCHECK(!connection_->is_initialized());
657 DCHECK(proxy_info_.proxy_server().is_valid()); 665 DCHECK(proxy_info_.proxy_server().is_valid());
658 next_state_ = STATE_INIT_CONNECTION_COMPLETE; 666 next_state_ = STATE_INIT_CONNECTION_COMPLETE;
659 667
660 using_ssl_ = request_info_.url.SchemeIs("https") || ShouldForceSpdySSL(); 668 using_ssl_ = request_info_.url.SchemeIs("https") || ShouldForceSpdySSL();
661 using_spdy_ = false; 669 using_spdy_ = false;
662 670
671 if (ShouldForceQuic()) {
672 next_state_ = STATE_CREATE_STREAM;
673 using_quic_ = true;
674 return OK;
675 }
676
663 // Check first if we have a spdy session for this group. If so, then go 677 // Check first if we have a spdy session for this group. If so, then go
664 // straight to using that. 678 // straight to using that.
665 HostPortProxyPair spdy_session_key = GetSpdySessionKey(); 679 HostPortProxyPair spdy_session_key = GetSpdySessionKey();
666 scoped_refptr<SpdySession> spdy_session = 680 scoped_refptr<SpdySession> spdy_session =
667 session_->spdy_session_pool()->GetIfExists(spdy_session_key, net_log_); 681 session_->spdy_session_pool()->GetIfExists(spdy_session_key, net_log_);
668 if (spdy_session && CanUseExistingSpdySession()) { 682 if (spdy_session && CanUseExistingSpdySession()) {
669 // If we're preconnecting, but we already have a SpdySession, we don't 683 // If we're preconnecting, but we already have a SpdySession, we don't
670 // actually need to preconnect any sockets, so we're done. 684 // actually need to preconnect any sockets, so we're done.
671 if (IsPreconnecting()) 685 if (IsPreconnecting())
672 return OK; 686 return OK;
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 // This state indicates that the stream request is in a partially 910 // This state indicates that the stream request is in a partially
897 // completed state, and we've called back to the delegate for more 911 // completed state, and we've called back to the delegate for more
898 // information. 912 // information.
899 913
900 // We're always waiting here for the delegate to call us back. 914 // We're always waiting here for the delegate to call us back.
901 return ERR_IO_PENDING; 915 return ERR_IO_PENDING;
902 } 916 }
903 917
904 int HttpStreamFactoryImpl::Job::DoCreateStream() { 918 int HttpStreamFactoryImpl::Job::DoCreateStream() {
905 DCHECK(connection_->socket() || existing_spdy_session_ || 919 DCHECK(connection_->socket() || existing_spdy_session_ ||
906 existing_available_pipeline_); 920 existing_available_pipeline_ || using_quic_);
907 921
908 next_state_ = STATE_CREATE_STREAM_COMPLETE; 922 next_state_ = STATE_CREATE_STREAM_COMPLETE;
909 923
910 // We only set the socket motivation if we're the first to use 924 // 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 925 // this socket. Is there a race for two SPDY requests? We really
912 // need to plumb this through to the connect level. 926 // need to plumb this through to the connect level.
913 if (connection_->socket() && !connection_->is_reused()) 927 if (connection_->socket() && !connection_->is_reused())
914 SetSocketMotivation(); 928 SetSocketMotivation();
915 929
916 const ProxyServer& proxy_server = proxy_info_.proxy_server(); 930 const ProxyServer& proxy_server = proxy_info_.proxy_server();
917 931
932 if (using_quic_) {
933 return quic_request_.Request(HostPortProxyPair(origin_, proxy_server),
934 net_log_, 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
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 stream_ = quic_request_.ReleaseStream();
1021 }
1022
1000 session_->proxy_service()->ReportSuccess(proxy_info_); 1023 session_->proxy_service()->ReportSuccess(proxy_info_);
1001 next_state_ = STATE_NONE; 1024 next_state_ = STATE_NONE;
1002 return OK; 1025 return OK;
1003 } 1026 }
1004 1027
1005 int HttpStreamFactoryImpl::Job::DoRestartTunnelAuth() { 1028 int HttpStreamFactoryImpl::Job::DoRestartTunnelAuth() {
1006 next_state_ = STATE_RESTART_TUNNEL_AUTH_COMPLETE; 1029 next_state_ = STATE_RESTART_TUNNEL_AUTH_COMPLETE;
1007 ProxyClientSocket* proxy_socket = 1030 ProxyClientSocket* proxy_socket =
1008 static_cast<ProxyClientSocket*>(connection_->socket()); 1031 static_cast<ProxyClientSocket*>(connection_->socket());
1009 return proxy_socket->RestartWithAuth(io_callback_); 1032 return proxy_socket->RestartWithAuth(io_callback_);
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1281 (net::LOAD_MAIN_FRAME | net::LOAD_SUB_FRAME | net::LOAD_PREFETCH | 1304 (net::LOAD_MAIN_FRAME | net::LOAD_SUB_FRAME | net::LOAD_PREFETCH |
1282 net::LOAD_IS_DOWNLOAD)) { 1305 net::LOAD_IS_DOWNLOAD)) {
1283 // Avoid pipelining resources that may be streamed for a long time. 1306 // Avoid pipelining resources that may be streamed for a long time.
1284 return false; 1307 return false;
1285 } 1308 }
1286 return stream_factory_->http_pipelined_host_pool_.IsKeyEligibleForPipelining( 1309 return stream_factory_->http_pipelined_host_pool_.IsKeyEligibleForPipelining(
1287 *http_pipelining_key_.get()); 1310 *http_pipelining_key_.get());
1288 } 1311 }
1289 1312
1290 } // namespace net 1313 } // namespace net
OLDNEW
« chrome/common/chrome_switches.h ('K') | « net/http/http_stream_factory_impl_job.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698