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

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

Issue 1063873003: Refactor in HttpStreamFactoryImpl::Job. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nit. Created 5 years, 8 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 DCHECK(connection_.get() && connection_->socket()); 264 DCHECK(connection_.get() && connection_->socket());
265 SSLClientSocket* ssl_socket = 265 SSLClientSocket* ssl_socket =
266 static_cast<SSLClientSocket*>(connection_->socket()); 266 static_cast<SSLClientSocket*>(connection_->socket());
267 ssl_socket->GetSSLInfo(&ssl_info_); 267 ssl_socket->GetSSLInfo(&ssl_info_);
268 } 268 }
269 269
270 SpdySessionKey HttpStreamFactoryImpl::Job::GetSpdySessionKey() const { 270 SpdySessionKey HttpStreamFactoryImpl::Job::GetSpdySessionKey() const {
271 // In the case that we're using an HTTPS proxy for an HTTP url, 271 // In the case that we're using an HTTPS proxy for an HTTP url,
272 // we look for a SPDY session *to* the proxy, instead of to the 272 // we look for a SPDY session *to* the proxy, instead of to the
273 // origin server. 273 // origin server.
274 PrivacyMode privacy_mode = request_info_.privacy_mode;
275 if (IsHttpsProxyAndHttpUrl()) { 274 if (IsHttpsProxyAndHttpUrl()) {
276 return SpdySessionKey(proxy_info_.proxy_server().host_port_pair(), 275 return SpdySessionKey(proxy_info_.proxy_server().host_port_pair(),
277 ProxyServer::Direct(), 276 ProxyServer::Direct(), PRIVACY_MODE_DISABLED);
278 privacy_mode);
279 } 277 }
280 return SpdySessionKey(server_, proxy_info_.proxy_server(), privacy_mode); 278 return SpdySessionKey(server_, proxy_info_.proxy_server(),
279 request_info_.privacy_mode);
281 } 280 }
282 281
283 bool HttpStreamFactoryImpl::Job::CanUseExistingSpdySession() const { 282 bool HttpStreamFactoryImpl::Job::CanUseExistingSpdySession() const {
284 // We need to make sure that if a spdy session was created for 283 // We need to make sure that if a spdy session was created for
285 // https://somehost/ that we don't use that session for http://somehost:443/. 284 // https://somehost/ that we don't use that session for http://somehost:443/.
286 // The only time we can use an existing session is if the request URL is 285 // The only time we can use an existing session is if the request URL is
287 // https (the normal case) or if we're connection to a SPDY proxy. 286 // https (the normal case) or if we're connection to a SPDY proxy.
288 // https://crbug.com/133176 287 // https://crbug.com/133176
289 // TODO(ricea): Add "wss" back to this list when SPDY WebSocket support is 288 // TODO(ricea): Add "wss" back to this list when SPDY WebSocket support is
290 // working. 289 // working.
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 // OK, there's no available QUIC session. Let |waiting_job_| resume 793 // OK, there's no available QUIC session. Let |waiting_job_| resume
795 // if it's paused. 794 // if it's paused.
796 if (waiting_job_) { 795 if (waiting_job_) {
797 waiting_job_->Resume(this); 796 waiting_job_->Resume(this);
798 waiting_job_ = NULL; 797 waiting_job_ = NULL;
799 } 798 }
800 } 799 }
801 return rv; 800 return rv;
802 } 801 }
803 802
803 SpdySessionKey spdy_session_key = GetSpdySessionKey();
804
804 // Check first if we have a spdy session for this group. If so, then go 805 // Check first if we have a spdy session for this group. If so, then go
805 // straight to using that. 806 // straight to using that.
806 SpdySessionKey spdy_session_key = GetSpdySessionKey(); 807 if (CanUseExistingSpdySession()) {
807 base::WeakPtr<SpdySession> spdy_session = 808 base::WeakPtr<SpdySession> spdy_session =
808 session_->spdy_session_pool()->FindAvailableSession( 809 session_->spdy_session_pool()->FindAvailableSession(spdy_session_key,
809 spdy_session_key, net_log_); 810 net_log_);
810 if (spdy_session && CanUseExistingSpdySession()) { 811 if (spdy_session) {
811 // If we're preconnecting, but we already have a SpdySession, we don't 812 // If we're preconnecting, but we already have a SpdySession, we don't
812 // actually need to preconnect any sockets, so we're done. 813 // actually need to preconnect any sockets, so we're done.
813 if (IsPreconnecting()) 814 if (IsPreconnecting())
815 return OK;
816 using_spdy_ = true;
817 next_state_ = STATE_CREATE_STREAM;
818 existing_spdy_session_ = spdy_session;
814 return OK; 819 return OK;
815 using_spdy_ = true; 820 }
816 next_state_ = STATE_CREATE_STREAM; 821 }
817 existing_spdy_session_ = spdy_session; 822 if (request_ && !request_->HasSpdySessionKey() && using_ssl_) {
818 return OK;
819 } else if (request_ && !request_->HasSpdySessionKey() && using_ssl_) {
820 // Update the spdy session key for the request that launched this job. 823 // Update the spdy session key for the request that launched this job.
821 request_->SetSpdySessionKey(spdy_session_key); 824 request_->SetSpdySessionKey(spdy_session_key);
822 } 825 }
823 826
824 // OK, there's no available SPDY session. Let |waiting_job_| resume if it's 827 // OK, there's no available SPDY session. Let |waiting_job_| resume if it's
825 // paused. 828 // paused.
826
827 if (waiting_job_) { 829 if (waiting_job_) {
828 waiting_job_->Resume(this); 830 waiting_job_->Resume(this);
829 waiting_job_ = NULL; 831 waiting_job_ = NULL;
830 } 832 }
831 833
832 if (proxy_info_.is_http() || proxy_info_.is_https()) 834 if (proxy_info_.is_http() || proxy_info_.is_https())
833 establishing_tunnel_ = using_ssl_; 835 establishing_tunnel_ = using_ssl_;
834 836
835 // TODO(bnc): s/want_spdy_over_npn/expect_spdy_over_npn/ 837 // TODO(bnc): s/want_spdy_over_npn/expect_spdy_over_npn/
836 bool want_spdy_over_npn = IsAlternate(); 838 bool want_spdy_over_npn = IsAlternate();
(...skipping 24 matching lines...) Expand all
861 DCHECK(!stream_factory_->for_websockets_); 863 DCHECK(!stream_factory_->for_websockets_);
862 return PreconnectSocketsForHttpRequest( 864 return PreconnectSocketsForHttpRequest(
863 GetSocketGroup(), server_, request_info_.extra_headers, 865 GetSocketGroup(), server_, request_info_.extra_headers,
864 request_info_.load_flags, priority_, session_, proxy_info_, 866 request_info_.load_flags, priority_, session_, proxy_info_,
865 want_spdy_over_npn, server_ssl_config_, proxy_ssl_config_, 867 want_spdy_over_npn, server_ssl_config_, proxy_ssl_config_,
866 request_info_.privacy_mode, net_log_, num_streams_); 868 request_info_.privacy_mode, net_log_, num_streams_);
867 } 869 }
868 870
869 // If we can't use a SPDY session, don't bother checking for one after 871 // If we can't use a SPDY session, don't bother checking for one after
870 // the hostname is resolved. 872 // the hostname is resolved.
871 OnHostResolutionCallback resolution_callback = CanUseExistingSpdySession() ? 873 OnHostResolutionCallback resolution_callback =
872 base::Bind(&Job::OnHostResolution, session_->spdy_session_pool(), 874 CanUseExistingSpdySession()
873 GetSpdySessionKey()) : 875 ? base::Bind(&Job::OnHostResolution, session_->spdy_session_pool(),
874 OnHostResolutionCallback(); 876 spdy_session_key)
877 : OnHostResolutionCallback();
875 if (stream_factory_->for_websockets_) { 878 if (stream_factory_->for_websockets_) {
876 // TODO(ricea): Re-enable NPN when WebSockets over SPDY is supported. 879 // TODO(ricea): Re-enable NPN when WebSockets over SPDY is supported.
877 SSLConfig websocket_server_ssl_config = server_ssl_config_; 880 SSLConfig websocket_server_ssl_config = server_ssl_config_;
878 websocket_server_ssl_config.next_protos.clear(); 881 websocket_server_ssl_config.next_protos.clear();
879 return InitSocketHandleForWebSocketRequest( 882 return InitSocketHandleForWebSocketRequest(
880 GetSocketGroup(), server_, request_info_.extra_headers, 883 GetSocketGroup(), server_, request_info_.extra_headers,
881 request_info_.load_flags, priority_, session_, proxy_info_, 884 request_info_.load_flags, priority_, session_, proxy_info_,
882 want_spdy_over_npn, websocket_server_ssl_config, proxy_ssl_config_, 885 want_spdy_over_npn, websocket_server_ssl_config, proxy_ssl_config_,
883 request_info_.privacy_mode, net_log_, connection_.get(), 886 request_info_.privacy_mode, net_log_, connection_.get(),
884 resolution_callback, io_callback_); 887 resolution_callback, io_callback_);
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 request_->websocket_handshake_stream_create_helper() 1099 request_->websocket_handshake_stream_create_helper()
1097 ->CreateBasicStream(connection_.Pass(), using_proxy)); 1100 ->CreateBasicStream(connection_.Pass(), using_proxy));
1098 } else { 1101 } else {
1099 stream_.reset(new HttpBasicStream(connection_.release(), using_proxy)); 1102 stream_.reset(new HttpBasicStream(connection_.release(), using_proxy));
1100 } 1103 }
1101 return OK; 1104 return OK;
1102 } 1105 }
1103 1106
1104 CHECK(!stream_.get()); 1107 CHECK(!stream_.get());
1105 1108
1106 bool direct = true; 1109 bool direct = !IsHttpsProxyAndHttpUrl();
1107 const ProxyServer& proxy_server = proxy_info_.proxy_server();
1108 PrivacyMode privacy_mode = request_info_.privacy_mode;
1109 if (IsHttpsProxyAndHttpUrl())
1110 direct = false;
1111
1112 if (existing_spdy_session_.get()) { 1110 if (existing_spdy_session_.get()) {
1113 // We picked up an existing session, so we don't need our socket. 1111 // We picked up an existing session, so we don't need our socket.
1114 if (connection_->socket()) 1112 if (connection_->socket())
1115 connection_->socket()->Disconnect(); 1113 connection_->socket()->Disconnect();
1116 connection_->Reset(); 1114 connection_->Reset();
1117 1115
1118 int set_result = SetSpdyHttpStream(existing_spdy_session_, direct); 1116 int set_result = SetSpdyHttpStream(existing_spdy_session_, direct);
1119 existing_spdy_session_.reset(); 1117 existing_spdy_session_.reset();
1120 return set_result; 1118 return set_result;
1121 } 1119 }
1122 1120
1123 SpdySessionKey spdy_session_key(server_, proxy_server, privacy_mode);
1124 if (IsHttpsProxyAndHttpUrl()) {
1125 // If we don't have a direct SPDY session, and we're using an HTTPS
1126 // proxy, then we might have a SPDY session to the proxy.
1127 // We never use privacy mode for connection to proxy server.
1128 spdy_session_key = SpdySessionKey(proxy_server.host_port_pair(),
1129 ProxyServer::Direct(),
1130 PRIVACY_MODE_DISABLED);
1131 }
1132
1133 SpdySessionPool* spdy_pool = session_->spdy_session_pool(); 1121 SpdySessionPool* spdy_pool = session_->spdy_session_pool();
1122 SpdySessionKey spdy_session_key = GetSpdySessionKey();
1134 base::WeakPtr<SpdySession> spdy_session = 1123 base::WeakPtr<SpdySession> spdy_session =
1135 spdy_pool->FindAvailableSession(spdy_session_key, net_log_); 1124 spdy_pool->FindAvailableSession(spdy_session_key, net_log_);
1136 1125
1137 if (spdy_session) { 1126 if (spdy_session) {
1138 return SetSpdyHttpStream(spdy_session, direct); 1127 return SetSpdyHttpStream(spdy_session, direct);
1139 } 1128 }
1140 1129
1141 spdy_session = 1130 spdy_session =
1142 spdy_pool->CreateAvailableSessionFromSocket(spdy_session_key, 1131 spdy_pool->CreateAvailableSessionFromSocket(spdy_session_key,
1143 connection_.Pass(), 1132 connection_.Pass(),
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
1485 if (scheme == "https" || scheme == "wss" || IsSpdyAlternate()) 1474 if (scheme == "https" || scheme == "wss" || IsSpdyAlternate())
1486 return ClientSocketPoolManager::SSL_GROUP; 1475 return ClientSocketPoolManager::SSL_GROUP;
1487 1476
1488 if (scheme == "ftp") 1477 if (scheme == "ftp")
1489 return ClientSocketPoolManager::FTP_GROUP; 1478 return ClientSocketPoolManager::FTP_GROUP;
1490 1479
1491 return ClientSocketPoolManager::NORMAL_GROUP; 1480 return ClientSocketPoolManager::NORMAL_GROUP;
1492 } 1481 }
1493 1482
1494 } // namespace net 1483 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698