| 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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 void HttpStreamFactoryImpl::Job::GetSSLInfo() { | 234 void HttpStreamFactoryImpl::Job::GetSSLInfo() { |
| 235 DCHECK(using_ssl_); | 235 DCHECK(using_ssl_); |
| 236 DCHECK(!establishing_tunnel_); | 236 DCHECK(!establishing_tunnel_); |
| 237 DCHECK(connection_.get() && connection_->socket()); | 237 DCHECK(connection_.get() && connection_->socket()); |
| 238 SSLClientSocket* ssl_socket = | 238 SSLClientSocket* ssl_socket = |
| 239 static_cast<SSLClientSocket*>(connection_->socket()); | 239 static_cast<SSLClientSocket*>(connection_->socket()); |
| 240 ssl_socket->GetSSLInfo(&ssl_info_); | 240 ssl_socket->GetSSLInfo(&ssl_info_); |
| 241 } | 241 } |
| 242 | 242 |
| 243 HostPortProxyPair HttpStreamFactoryImpl::Job::GetSpdySessionKey() const { | 243 HostPortProxyPair HttpStreamFactoryImpl::Job::GetSpdySessionKey() const { |
| 244 // In the case that we're using an HTTPS proxy for an HTTP url, |
| 245 // we look for a SPDY session *to* the proxy, instead of to the |
| 246 // origin server. |
| 244 if (IsHttpsProxyAndHttpUrl()) { | 247 if (IsHttpsProxyAndHttpUrl()) { |
| 245 return HostPortProxyPair(proxy_info_.proxy_server().host_port_pair(), | 248 return HostPortProxyPair(proxy_info_.proxy_server().host_port_pair(), |
| 246 ProxyServer::Direct()); | 249 ProxyServer::Direct()); |
| 247 } else { | 250 } else { |
| 248 return HostPortProxyPair(origin_, proxy_info_.proxy_server()); | 251 return HostPortProxyPair(origin_, proxy_info_.proxy_server()); |
| 249 } | 252 } |
| 250 } | 253 } |
| 251 | 254 |
| 255 bool HttpStreamFactoryImpl::Job::CanUseExistingSpdySession() const { |
| 256 // We need to make sure that if a spdy session was created for |
| 257 // https://somehost/ that we don't use that session for http://somehost:443/. |
| 258 // The only time we can use an existing session is if the request URL is |
| 259 // https (the normal case) or if we're connection to a SPDY proxy, or |
| 260 // if we're running with force_spdy_always_. crbug.com/133176 |
| 261 return request_info_.url.SchemeIs("https") || |
| 262 proxy_info_.proxy_server().is_https() || |
| 263 force_spdy_always_; |
| 264 } |
| 265 |
| 252 void HttpStreamFactoryImpl::Job::OnStreamReadyCallback() { | 266 void HttpStreamFactoryImpl::Job::OnStreamReadyCallback() { |
| 253 DCHECK(stream_.get()); | 267 DCHECK(stream_.get()); |
| 254 DCHECK(!IsPreconnecting()); | 268 DCHECK(!IsPreconnecting()); |
| 255 if (IsOrphaned()) { | 269 if (IsOrphaned()) { |
| 256 stream_factory_->OnOrphanedJobComplete(this); | 270 stream_factory_->OnOrphanedJobComplete(this); |
| 257 } else { | 271 } else { |
| 258 request_->Complete(was_npn_negotiated(), | 272 request_->Complete(was_npn_negotiated(), |
| 259 protocol_negotiated(), | 273 protocol_negotiated(), |
| 260 using_spdy(), | 274 using_spdy(), |
| 261 net_log_); | 275 net_log_); |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 next_state_ = STATE_INIT_CONNECTION_COMPLETE; | 658 next_state_ = STATE_INIT_CONNECTION_COMPLETE; |
| 645 | 659 |
| 646 using_ssl_ = request_info_.url.SchemeIs("https") || ShouldForceSpdySSL(); | 660 using_ssl_ = request_info_.url.SchemeIs("https") || ShouldForceSpdySSL(); |
| 647 using_spdy_ = false; | 661 using_spdy_ = false; |
| 648 | 662 |
| 649 // Check first if we have a spdy session for this group. If so, then go | 663 // Check first if we have a spdy session for this group. If so, then go |
| 650 // straight to using that. | 664 // straight to using that. |
| 651 HostPortProxyPair spdy_session_key = GetSpdySessionKey(); | 665 HostPortProxyPair spdy_session_key = GetSpdySessionKey(); |
| 652 scoped_refptr<SpdySession> spdy_session = | 666 scoped_refptr<SpdySession> spdy_session = |
| 653 session_->spdy_session_pool()->GetIfExists(spdy_session_key, net_log_); | 667 session_->spdy_session_pool()->GetIfExists(spdy_session_key, net_log_); |
| 654 if (spdy_session) { | 668 if (spdy_session && CanUseExistingSpdySession()) { |
| 655 // If we're preconnecting, but we already have a SpdySession, we don't | 669 // If we're preconnecting, but we already have a SpdySession, we don't |
| 656 // actually need to preconnect any sockets, so we're done. | 670 // actually need to preconnect any sockets, so we're done. |
| 657 if (IsPreconnecting()) | 671 if (IsPreconnecting()) |
| 658 return OK; | 672 return OK; |
| 659 using_spdy_ = true; | 673 using_spdy_ = true; |
| 660 next_state_ = STATE_CREATE_STREAM; | 674 next_state_ = STATE_CREATE_STREAM; |
| 661 existing_spdy_session_ = spdy_session; | 675 existing_spdy_session_ = spdy_session; |
| 662 return OK; | 676 return OK; |
| 663 } else if (request_ && (using_ssl_ || ShouldForceSpdyWithoutSSL())) { | 677 } else if (request_ && (using_ssl_ || ShouldForceSpdyWithoutSSL())) { |
| 664 // Update the spdy session key for the request that launched this job. | 678 // Update the spdy session key for the request that launched this job. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 request_info_.priority, | 731 request_info_.priority, |
| 718 session_, | 732 session_, |
| 719 proxy_info_, | 733 proxy_info_, |
| 720 ShouldForceSpdySSL(), | 734 ShouldForceSpdySSL(), |
| 721 want_spdy_over_npn, | 735 want_spdy_over_npn, |
| 722 server_ssl_config_, | 736 server_ssl_config_, |
| 723 proxy_ssl_config_, | 737 proxy_ssl_config_, |
| 724 net_log_, | 738 net_log_, |
| 725 num_streams_); | 739 num_streams_); |
| 726 } else { | 740 } else { |
| 741 // If we can't use a SPDY session, don't both checking for one after |
| 742 // the hostname is resolved. |
| 743 OnHostResolutionCallback resolution_callback = CanUseExistingSpdySession() ? |
| 744 base::Bind(&Job::OnHostResolution, session_->spdy_session_pool(), |
| 745 GetSpdySessionKey()) : |
| 746 OnHostResolutionCallback(); |
| 727 return InitSocketHandleForHttpRequest( | 747 return InitSocketHandleForHttpRequest( |
| 728 origin_url_, request_info_.extra_headers, request_info_.load_flags, | 748 origin_url_, request_info_.extra_headers, request_info_.load_flags, |
| 729 request_info_.priority, session_, proxy_info_, ShouldForceSpdySSL(), | 749 request_info_.priority, session_, proxy_info_, ShouldForceSpdySSL(), |
| 730 want_spdy_over_npn, server_ssl_config_, proxy_ssl_config_, net_log_, | 750 want_spdy_over_npn, server_ssl_config_, proxy_ssl_config_, net_log_, |
| 731 connection_.get(), | 751 connection_.get(), resolution_callback, io_callback_); |
| 732 //OnHostResolutionCallback(), | |
| 733 base::Bind(&Job::OnHostResolution, session_->spdy_session_pool(), | |
| 734 GetSpdySessionKey()), | |
| 735 io_callback_); | |
| 736 } | 752 } |
| 737 } | 753 } |
| 738 | 754 |
| 739 int HttpStreamFactoryImpl::Job::DoInitConnectionComplete(int result) { | 755 int HttpStreamFactoryImpl::Job::DoInitConnectionComplete(int result) { |
| 740 if (IsPreconnecting()) { | 756 if (IsPreconnecting()) { |
| 741 DCHECK_EQ(OK, result); | 757 DCHECK_EQ(OK, result); |
| 742 return OK; | 758 return OK; |
| 743 } | 759 } |
| 744 | 760 |
| 745 if (result == ERR_SPDY_SESSION_ALREADY_EXISTS) { | 761 if (result == ERR_SPDY_SESSION_ALREADY_EXISTS) { |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1265 (net::LOAD_MAIN_FRAME | net::LOAD_SUB_FRAME | net::LOAD_PREFETCH | | 1281 (net::LOAD_MAIN_FRAME | net::LOAD_SUB_FRAME | net::LOAD_PREFETCH | |
| 1266 net::LOAD_IS_DOWNLOAD)) { | 1282 net::LOAD_IS_DOWNLOAD)) { |
| 1267 // Avoid pipelining resources that may be streamed for a long time. | 1283 // Avoid pipelining resources that may be streamed for a long time. |
| 1268 return false; | 1284 return false; |
| 1269 } | 1285 } |
| 1270 return stream_factory_->http_pipelined_host_pool_.IsKeyEligibleForPipelining( | 1286 return stream_factory_->http_pipelined_host_pool_.IsKeyEligibleForPipelining( |
| 1271 *http_pipelining_key_.get()); | 1287 *http_pipelining_key_.get()); |
| 1272 } | 1288 } |
| 1273 | 1289 |
| 1274 } // namespace net | 1290 } // namespace net |
| OLD | NEW |