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

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

Issue 2771263002: Retry upon 421 status code without IP pooling. (Closed)
Patch Set: Rebase. Created 3 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
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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 163
164 HttpStreamFactoryImpl::Job::Job(Delegate* delegate, 164 HttpStreamFactoryImpl::Job::Job(Delegate* delegate,
165 JobType job_type, 165 JobType job_type,
166 HttpNetworkSession* session, 166 HttpNetworkSession* session,
167 const HttpRequestInfo& request_info, 167 const HttpRequestInfo& request_info,
168 RequestPriority priority, 168 RequestPriority priority,
169 const SSLConfig& server_ssl_config, 169 const SSLConfig& server_ssl_config,
170 const SSLConfig& proxy_ssl_config, 170 const SSLConfig& proxy_ssl_config,
171 HostPortPair destination, 171 HostPortPair destination,
172 GURL origin_url, 172 GURL origin_url,
173 bool enable_ip_based_pooling,
173 NetLog* net_log) 174 NetLog* net_log)
174 : Job(delegate, 175 : Job(delegate,
175 job_type, 176 job_type,
176 session, 177 session,
177 request_info, 178 request_info,
178 priority, 179 priority,
179 server_ssl_config, 180 server_ssl_config,
180 proxy_ssl_config, 181 proxy_ssl_config,
181 destination, 182 destination,
182 origin_url, 183 origin_url,
183 AlternativeService(), 184 AlternativeService(),
184 ProxyServer(), 185 ProxyServer(),
186 enable_ip_based_pooling,
185 net_log) {} 187 net_log) {}
186 188
187 HttpStreamFactoryImpl::Job::Job(Delegate* delegate, 189 HttpStreamFactoryImpl::Job::Job(Delegate* delegate,
188 JobType job_type, 190 JobType job_type,
189 HttpNetworkSession* session, 191 HttpNetworkSession* session,
190 const HttpRequestInfo& request_info, 192 const HttpRequestInfo& request_info,
191 RequestPriority priority, 193 RequestPriority priority,
192 const SSLConfig& server_ssl_config, 194 const SSLConfig& server_ssl_config,
193 const SSLConfig& proxy_ssl_config, 195 const SSLConfig& proxy_ssl_config,
194 HostPortPair destination, 196 HostPortPair destination,
195 GURL origin_url, 197 GURL origin_url,
196 AlternativeService alternative_service, 198 AlternativeService alternative_service,
197 const ProxyServer& alternative_proxy_server, 199 const ProxyServer& alternative_proxy_server,
200 bool enable_ip_based_pooling,
198 NetLog* net_log) 201 NetLog* net_log)
199 : request_info_(request_info), 202 : request_info_(request_info),
200 priority_(priority), 203 priority_(priority),
201 server_ssl_config_(server_ssl_config), 204 server_ssl_config_(server_ssl_config),
202 proxy_ssl_config_(proxy_ssl_config), 205 proxy_ssl_config_(proxy_ssl_config),
203 net_log_( 206 net_log_(
204 NetLogWithSource::Make(net_log, NetLogSourceType::HTTP_STREAM_JOB)), 207 NetLogWithSource::Make(net_log, NetLogSourceType::HTTP_STREAM_JOB)),
205 io_callback_(base::Bind(&Job::OnIOComplete, base::Unretained(this))), 208 io_callback_(base::Bind(&Job::OnIOComplete, base::Unretained(this))),
206 connection_(new ClientSocketHandle), 209 connection_(new ClientSocketHandle),
207 session_(session), 210 session_(session),
208 next_state_(STATE_NONE), 211 next_state_(STATE_NONE),
209 pac_request_(NULL), 212 pac_request_(NULL),
210 destination_(destination), 213 destination_(destination),
211 origin_url_(origin_url), 214 origin_url_(origin_url),
212 alternative_service_(alternative_service), 215 alternative_service_(alternative_service),
213 alternative_proxy_server_(alternative_proxy_server), 216 alternative_proxy_server_(alternative_proxy_server),
217 enable_ip_based_pooling_(enable_ip_based_pooling),
214 delegate_(delegate), 218 delegate_(delegate),
215 job_type_(job_type), 219 job_type_(job_type),
216 using_ssl_(false), 220 using_ssl_(false),
217 using_spdy_(false), 221 using_spdy_(false),
218 using_quic_(false), 222 using_quic_(false),
219 quic_request_(session_->quic_stream_factory(), 223 quic_request_(session_->quic_stream_factory(),
220 session_->http_server_properties()), 224 session_->http_server_properties()),
221 using_existing_quic_session_(false), 225 using_existing_quic_session_(false),
222 establishing_tunnel_(false), 226 establishing_tunnel_(false),
223 was_alpn_negotiated_(false), 227 was_alpn_negotiated_(false),
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 } 534 }
531 delegate_->OnPreconnectsComplete(this); 535 delegate_->OnPreconnectsComplete(this);
532 // |this| may be deleted after this call. 536 // |this| may be deleted after this call.
533 } 537 }
534 538
535 // static 539 // static
536 int HttpStreamFactoryImpl::Job::OnHostResolution( 540 int HttpStreamFactoryImpl::Job::OnHostResolution(
537 SpdySessionPool* spdy_session_pool, 541 SpdySessionPool* spdy_session_pool,
538 const SpdySessionKey& spdy_session_key, 542 const SpdySessionKey& spdy_session_key,
539 const GURL& origin_url, 543 const GURL& origin_url,
544 bool enable_ip_based_pooling,
540 const AddressList& addresses, 545 const AddressList& addresses,
541 const NetLogWithSource& net_log) { 546 const NetLogWithSource& net_log) {
542 // It is OK to dereference spdy_session_pool, because the 547 // It is OK to dereference spdy_session_pool, because the
543 // ClientSocketPoolManager will be destroyed in the same callback that 548 // ClientSocketPoolManager will be destroyed in the same callback that
544 // destroys the SpdySessionPool. 549 // destroys the SpdySessionPool.
545 return spdy_session_pool->FindAvailableSession( 550 return spdy_session_pool->FindAvailableSession(
546 spdy_session_key, origin_url, /* enable_ip_based_pooling = */ true, 551 spdy_session_key, origin_url, enable_ip_based_pooling, net_log)
547 net_log)
548 ? ERR_SPDY_SESSION_ALREADY_EXISTS 552 ? ERR_SPDY_SESSION_ALREADY_EXISTS
549 : OK; 553 : OK;
550 } 554 }
551 555
552 void HttpStreamFactoryImpl::Job::OnIOComplete(int result) { 556 void HttpStreamFactoryImpl::Job::OnIOComplete(int result) {
553 TRACE_EVENT0(kNetTracingCategory, "HttpStreamFactoryImpl::Job::OnIOComplete"); 557 TRACE_EVENT0(kNetTracingCategory, "HttpStreamFactoryImpl::Job::OnIOComplete");
554 RunLoop(result); 558 RunLoop(result);
555 } 559 }
556 560
557 int HttpStreamFactoryImpl::Job::RunLoop(int result) { 561 int HttpStreamFactoryImpl::Job::RunLoop(int result) {
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 return rv; 951 return rv;
948 } 952 }
949 953
950 SpdySessionKey spdy_session_key = GetSpdySessionKey(); 954 SpdySessionKey spdy_session_key = GetSpdySessionKey();
951 955
952 // Check first if we have a spdy session for this group. If so, then go 956 // Check first if we have a spdy session for this group. If so, then go
953 // straight to using that. 957 // straight to using that.
954 if (CanUseExistingSpdySession()) { 958 if (CanUseExistingSpdySession()) {
955 base::WeakPtr<SpdySession> spdy_session = 959 base::WeakPtr<SpdySession> spdy_session =
956 session_->spdy_session_pool()->FindAvailableSession( 960 session_->spdy_session_pool()->FindAvailableSession(
957 spdy_session_key, origin_url_, /* enable_ip_based_pooling = */ true, 961 spdy_session_key, origin_url_, enable_ip_based_pooling_, net_log_);
958 net_log_);
959 if (spdy_session) { 962 if (spdy_session) {
960 // If we're preconnecting, but we already have a SpdySession, we don't 963 // If we're preconnecting, but we already have a SpdySession, we don't
961 // actually need to preconnect any sockets, so we're done. 964 // actually need to preconnect any sockets, so we're done.
962 if (job_type_ == PRECONNECT) 965 if (job_type_ == PRECONNECT)
963 return OK; 966 return OK;
964 using_spdy_ = true; 967 using_spdy_ = true;
965 next_state_ = STATE_CREATE_STREAM; 968 next_state_ = STATE_CREATE_STREAM;
966 existing_spdy_session_ = spdy_session; 969 existing_spdy_session_ = spdy_session;
967 return OK; 970 return OK;
968 } 971 }
(...skipping 26 matching lines...) Expand all
995 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy, 998 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy,
996 server_ssl_config_, proxy_ssl_config_, request_info_.privacy_mode, 999 server_ssl_config_, proxy_ssl_config_, request_info_.privacy_mode,
997 net_log_, num_streams_); 1000 net_log_, num_streams_);
998 } 1001 }
999 1002
1000 // If we can't use a SPDY session, don't bother checking for one after 1003 // If we can't use a SPDY session, don't bother checking for one after
1001 // the hostname is resolved. 1004 // the hostname is resolved.
1002 OnHostResolutionCallback resolution_callback = 1005 OnHostResolutionCallback resolution_callback =
1003 CanUseExistingSpdySession() 1006 CanUseExistingSpdySession()
1004 ? base::Bind(&Job::OnHostResolution, session_->spdy_session_pool(), 1007 ? base::Bind(&Job::OnHostResolution, session_->spdy_session_pool(),
1005 spdy_session_key, origin_url_) 1008 spdy_session_key, origin_url_, enable_ip_based_pooling_)
1006 : OnHostResolutionCallback(); 1009 : OnHostResolutionCallback();
1007 if (delegate_->for_websockets()) { 1010 if (delegate_->for_websockets()) {
1008 // TODO(ricea): Re-enable NPN when WebSockets over SPDY is supported. 1011 // TODO(ricea): Re-enable NPN when WebSockets over SPDY is supported.
1009 SSLConfig websocket_server_ssl_config = server_ssl_config_; 1012 SSLConfig websocket_server_ssl_config = server_ssl_config_;
1010 websocket_server_ssl_config.alpn_protos.clear(); 1013 websocket_server_ssl_config.alpn_protos.clear();
1011 return InitSocketHandleForWebSocketRequest( 1014 return InitSocketHandleForWebSocketRequest(
1012 GetSocketGroup(), destination_, request_info_.extra_headers, 1015 GetSocketGroup(), destination_, request_info_.extra_headers,
1013 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy, 1016 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy,
1014 websocket_server_ssl_config, proxy_ssl_config_, 1017 websocket_server_ssl_config, proxy_ssl_config_,
1015 request_info_.privacy_mode, net_log_, connection_.get(), 1018 request_info_.privacy_mode, net_log_, connection_.get(),
(...skipping 14 matching lines...) Expand all
1030 DCHECK_EQ(OK, result); 1033 DCHECK_EQ(OK, result);
1031 return OK; 1034 return OK;
1032 } 1035 }
1033 1036
1034 if (result == ERR_SPDY_SESSION_ALREADY_EXISTS) { 1037 if (result == ERR_SPDY_SESSION_ALREADY_EXISTS) {
1035 // We found a SPDY connection after resolving the host. This is 1038 // We found a SPDY connection after resolving the host. This is
1036 // probably an IP pooled connection. 1039 // probably an IP pooled connection.
1037 SpdySessionKey spdy_session_key = GetSpdySessionKey(); 1040 SpdySessionKey spdy_session_key = GetSpdySessionKey();
1038 existing_spdy_session_ = 1041 existing_spdy_session_ =
1039 session_->spdy_session_pool()->FindAvailableSession( 1042 session_->spdy_session_pool()->FindAvailableSession(
1040 spdy_session_key, origin_url_, 1043 spdy_session_key, origin_url_, enable_ip_based_pooling_, net_log_);
1041 /* enable_ip_based_pooling = */ true, net_log_);
1042 if (existing_spdy_session_) { 1044 if (existing_spdy_session_) {
1043 using_spdy_ = true; 1045 using_spdy_ = true;
1044 next_state_ = STATE_CREATE_STREAM; 1046 next_state_ = STATE_CREATE_STREAM;
1045 } else { 1047 } else {
1046 // It is possible that the spdy session no longer exists. 1048 // It is possible that the spdy session no longer exists.
1047 ReturnToStateInitConnection(true /* close connection */); 1049 ReturnToStateInitConnection(true /* close connection */);
1048 } 1050 }
1049 return OK; 1051 return OK;
1050 } 1052 }
1051 1053
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1245 } 1247 }
1246 return OK; 1248 return OK;
1247 } 1249 }
1248 1250
1249 CHECK(!stream_.get()); 1251 CHECK(!stream_.get());
1250 1252
1251 SpdySessionKey spdy_session_key = GetSpdySessionKey(); 1253 SpdySessionKey spdy_session_key = GetSpdySessionKey();
1252 if (!existing_spdy_session_) { 1254 if (!existing_spdy_session_) {
1253 existing_spdy_session_ = 1255 existing_spdy_session_ =
1254 session_->spdy_session_pool()->FindAvailableSession( 1256 session_->spdy_session_pool()->FindAvailableSession(
1255 spdy_session_key, origin_url_, 1257 spdy_session_key, origin_url_, enable_ip_based_pooling_, net_log_);
1256 /* enable_ip_based_pooling = */ true, net_log_);
1257 } 1258 }
1258 bool direct = !IsHttpsProxyAndHttpUrl(); 1259 bool direct = !IsHttpsProxyAndHttpUrl();
1259 if (existing_spdy_session_.get()) { 1260 if (existing_spdy_session_.get()) {
1260 // We picked up an existing session, so we don't need our socket. 1261 // We picked up an existing session, so we don't need our socket.
1261 if (connection_->socket()) 1262 if (connection_->socket())
1262 connection_->socket()->Disconnect(); 1263 connection_->socket()->Disconnect();
1263 connection_->Reset(); 1264 connection_->Reset();
1264 1265
1265 int set_result = SetSpdyHttpStreamOrBidirectionalStreamImpl( 1266 int set_result = SetSpdyHttpStreamOrBidirectionalStreamImpl(
1266 existing_spdy_session_, direct); 1267 existing_spdy_session_, direct);
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
1563 1564
1564 ConnectionAttempts socket_attempts = connection_->connection_attempts(); 1565 ConnectionAttempts socket_attempts = connection_->connection_attempts();
1565 if (connection_->socket()) { 1566 if (connection_->socket()) {
1566 connection_->socket()->GetConnectionAttempts(&socket_attempts); 1567 connection_->socket()->GetConnectionAttempts(&socket_attempts);
1567 } 1568 }
1568 1569
1569 delegate_->AddConnectionAttemptsToRequest(this, socket_attempts); 1570 delegate_->AddConnectionAttemptsToRequest(this, socket_attempts);
1570 } 1571 }
1571 1572
1572 } // namespace net 1573 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698