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

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

Issue 200723004: Fix SPDY error-handling if the connection gets closed just after use. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « net/http/http_proxy_client_socket_pool.cc ('k') | net/http/http_stream_factory_impl_request.h » ('j') | 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 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 using_spdy(), 327 using_spdy(),
328 net_log_); 328 net_log_);
329 request_->OnWebSocketHandshakeStreamReady(this, 329 request_->OnWebSocketHandshakeStreamReady(this,
330 server_ssl_config_, 330 server_ssl_config_,
331 proxy_info_, 331 proxy_info_,
332 websocket_stream_.release()); 332 websocket_stream_.release());
333 // |this| may be deleted after this call. 333 // |this| may be deleted after this call.
334 } 334 }
335 335
336 void HttpStreamFactoryImpl::Job::OnNewSpdySessionReadyCallback() { 336 void HttpStreamFactoryImpl::Job::OnNewSpdySessionReadyCallback() {
337 DCHECK(!stream_.get()); 337 DCHECK(stream_.get());
338 DCHECK(!IsPreconnecting()); 338 DCHECK(!IsPreconnecting());
339 DCHECK(using_spdy()); 339 DCHECK(using_spdy());
340 if (!new_spdy_session_) 340 // Note: an event loop iteration has passed, so |new_spdy_session_| may be
341 return; 341 // NULL at this point if the SpdySession closed immediately after creation.
342 base::WeakPtr<SpdySession> spdy_session = new_spdy_session_; 342 base::WeakPtr<SpdySession> spdy_session = new_spdy_session_;
343 new_spdy_session_.reset(); 343 new_spdy_session_.reset();
344 if (IsOrphaned()) { 344 if (IsOrphaned()) {
345 stream_factory_->OnNewSpdySessionReady( 345 if (spdy_session) {
346 spdy_session, spdy_session_direct_, server_ssl_config_, proxy_info_, 346 stream_factory_->OnNewSpdySessionReady(
347 was_npn_negotiated(), protocol_negotiated(), using_spdy(), net_log_); 347 spdy_session, spdy_session_direct_, server_ssl_config_, proxy_info_,
348 was_npn_negotiated(), protocol_negotiated(), using_spdy(), net_log_);
349 }
348 stream_factory_->OnOrphanedJobComplete(this); 350 stream_factory_->OnOrphanedJobComplete(this);
349 } else { 351 } else {
350 request_->OnNewSpdySessionReady(this, spdy_session, spdy_session_direct_); 352 request_->OnNewSpdySessionReady(
353 this, stream_.Pass(), spdy_session, spdy_session_direct_);
351 } 354 }
352 // |this| may be deleted after this call. 355 // |this| may be deleted after this call.
353 } 356 }
354 357
355 void HttpStreamFactoryImpl::Job::OnStreamFailedCallback(int result) { 358 void HttpStreamFactoryImpl::Job::OnStreamFailedCallback(int result) {
356 DCHECK(!IsPreconnecting()); 359 DCHECK(!IsPreconnecting());
357 if (IsOrphaned()) 360 if (IsOrphaned())
358 stream_factory_->OnOrphanedJobComplete(this); 361 stream_factory_->OnOrphanedJobComplete(this);
359 else 362 else
360 request_->OnStreamFailed(this, result, server_ssl_config_); 363 request_->OnStreamFailed(this, result, server_ssl_config_);
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 if (existing_spdy_session_.get()) { 1118 if (existing_spdy_session_.get()) {
1116 // We picked up an existing session, so we don't need our socket. 1119 // We picked up an existing session, so we don't need our socket.
1117 if (connection_->socket()) 1120 if (connection_->socket())
1118 connection_->socket()->Disconnect(); 1121 connection_->socket()->Disconnect();
1119 connection_->Reset(); 1122 connection_->Reset();
1120 std::swap(spdy_session, existing_spdy_session_); 1123 std::swap(spdy_session, existing_spdy_session_);
1121 } else { 1124 } else {
1122 SpdySessionPool* spdy_pool = session_->spdy_session_pool(); 1125 SpdySessionPool* spdy_pool = session_->spdy_session_pool();
1123 spdy_session = spdy_pool->FindAvailableSession(spdy_session_key, net_log_); 1126 spdy_session = spdy_pool->FindAvailableSession(spdy_session_key, net_log_);
1124 if (!spdy_session) { 1127 if (!spdy_session) {
1125 int error = 1128 new_spdy_session_ =
1126 spdy_pool->CreateAvailableSessionFromSocket(spdy_session_key, 1129 spdy_pool->CreateAvailableSessionFromSocket(spdy_session_key,
1127 connection_.Pass(), 1130 connection_.Pass(),
1128 net_log_, 1131 net_log_,
1129 spdy_certificate_error_, 1132 spdy_certificate_error_,
1130 &new_spdy_session_,
1131 using_ssl_); 1133 using_ssl_);
1132 if (error != OK)
1133 return error;
1134 const HostPortPair& host_port_pair = spdy_session_key.host_port_pair(); 1134 const HostPortPair& host_port_pair = spdy_session_key.host_port_pair();
1135 base::WeakPtr<HttpServerProperties> http_server_properties = 1135 base::WeakPtr<HttpServerProperties> http_server_properties =
1136 session_->http_server_properties(); 1136 session_->http_server_properties();
1137 if (http_server_properties) 1137 if (http_server_properties)
1138 http_server_properties->SetSupportsSpdy(host_port_pair, true); 1138 http_server_properties->SetSupportsSpdy(host_port_pair, true);
1139 spdy_session_direct_ = direct; 1139 spdy_session_direct_ = direct;
1140
1141 // Create a SpdyHttpStream attached to the session;
1142 // OnNewSpdySessionReadyCallback is not called until an event loop
1143 // iteration later, so if the SpdySession is closed between then, allow
1144 // reuse state from the underlying socket, sampled by SpdyHttpStream,
1145 // bubble up to the request.
1146 bool use_relative_url = direct || request_info_.url.SchemeIs("https");
1147 stream_.reset(new SpdyHttpStream(new_spdy_session_, use_relative_url));
1148
1140 return OK; 1149 return OK;
1141 } 1150 }
1142 } 1151 }
1143 1152
1144 if (!spdy_session) 1153 if (!spdy_session)
1145 return ERR_CONNECTION_CLOSED; 1154 return ERR_CONNECTION_CLOSED;
1146 1155
1147 // TODO(willchan): Delete this code, because eventually, the 1156 // TODO(willchan): Delete this code, because eventually, the
1148 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it 1157 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it
1149 // will know when SpdySessions become available. 1158 // will know when SpdySessions become available.
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
1474 (net::LOAD_MAIN_FRAME | net::LOAD_SUB_FRAME | net::LOAD_PREFETCH | 1483 (net::LOAD_MAIN_FRAME | net::LOAD_SUB_FRAME | net::LOAD_PREFETCH |
1475 net::LOAD_IS_DOWNLOAD)) { 1484 net::LOAD_IS_DOWNLOAD)) {
1476 // Avoid pipelining resources that may be streamed for a long time. 1485 // Avoid pipelining resources that may be streamed for a long time.
1477 return false; 1486 return false;
1478 } 1487 }
1479 return stream_factory_->http_pipelined_host_pool_.IsKeyEligibleForPipelining( 1488 return stream_factory_->http_pipelined_host_pool_.IsKeyEligibleForPipelining(
1480 *http_pipelining_key_.get()); 1489 *http_pipelining_key_.get());
1481 } 1490 }
1482 1491
1483 } // namespace net 1492 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_proxy_client_socket_pool.cc ('k') | net/http/http_stream_factory_impl_request.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698