Chromium Code Reviews
[email protected] (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1227)

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: Done Created 8 years, 1 month 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),
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()),
96 force_quic_port_(HttpStreamFactory::force_quic_port()),
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)) {
102 DCHECK(stream_factory); 105 DCHECK(stream_factory);
103 DCHECK(session); 106 DCHECK(session);
(...skipping 46 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 force_quic_port_ == origin_.port() && proxy_info_.is_direct();
willchan no longer on Chromium 2012/11/22 03:04:53 FWIW, I read this as forcing all requests to go to
Ryan Hamilton 2012/11/22 23:08:40 I hear ya. Naming is hard. What about --force-qu
willchan no longer on Chromium 2012/12/11 02:02:08 I prefer the latter, but both are better.
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
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(
933 HostPortProxyPair(origin_, proxy_server), net_log_, &quic_stream_,
willchan no longer on Chromium 2012/11/22 03:04:53 How does cancellation work? Hm, everyone else just
Ryan Hamilton 2012/11/22 23:08:40 Yes, I think your reading is correct. I *think* t
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
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_.reset(quic_stream_);
1022 quic_stream_ = NULL;
1023 }
1024
1000 session_->proxy_service()->ReportSuccess(proxy_info_); 1025 session_->proxy_service()->ReportSuccess(proxy_info_);
1001 next_state_ = STATE_NONE; 1026 next_state_ = STATE_NONE;
1002 return OK; 1027 return OK;
1003 } 1028 }
1004 1029
1005 int HttpStreamFactoryImpl::Job::DoRestartTunnelAuth() { 1030 int HttpStreamFactoryImpl::Job::DoRestartTunnelAuth() {
1006 next_state_ = STATE_RESTART_TUNNEL_AUTH_COMPLETE; 1031 next_state_ = STATE_RESTART_TUNNEL_AUTH_COMPLETE;
1007 ProxyClientSocket* proxy_socket = 1032 ProxyClientSocket* proxy_socket =
1008 static_cast<ProxyClientSocket*>(connection_->socket()); 1033 static_cast<ProxyClientSocket*>(connection_->socket());
1009 return proxy_socket->RestartWithAuth(io_callback_); 1034 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 | 1306 (net::LOAD_MAIN_FRAME | net::LOAD_SUB_FRAME | net::LOAD_PREFETCH |
1282 net::LOAD_IS_DOWNLOAD)) { 1307 net::LOAD_IS_DOWNLOAD)) {
1283 // Avoid pipelining resources that may be streamed for a long time. 1308 // Avoid pipelining resources that may be streamed for a long time.
1284 return false; 1309 return false;
1285 } 1310 }
1286 return stream_factory_->http_pipelined_host_pool_.IsKeyEligibleForPipelining( 1311 return stream_factory_->http_pipelined_host_pool_.IsKeyEligibleForPipelining(
1287 *http_pipelining_key_.get()); 1312 *http_pipelining_key_.get());
1288 } 1313 }
1289 1314
1290 } // namespace net 1315 } // namespace net
OLDNEW
« net/http/http_network_layer.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