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

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

Issue 18546008: [SPDY] Use WeakPtr<SpdySession> everywhere but SpdySessionPool (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix test, other minor formatting/comment changes Created 7 years, 5 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_stream_factory_impl_job.h ('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 <string> 8 #include <string>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/stl_util.h" 13 #include "base/stl_util.h"
13 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
14 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
15 #include "base/values.h" 16 #include "base/values.h"
16 #include "build/build_config.h" 17 #include "build/build_config.h"
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 server_ssl_config_, 324 server_ssl_config_,
324 proxy_info_, 325 proxy_info_,
325 websocket_stream_.release()); 326 websocket_stream_.release());
326 // |this| may be deleted after this call. 327 // |this| may be deleted after this call.
327 } 328 }
328 329
329 void HttpStreamFactoryImpl::Job::OnNewSpdySessionReadyCallback() { 330 void HttpStreamFactoryImpl::Job::OnNewSpdySessionReadyCallback() {
330 DCHECK(!stream_.get()); 331 DCHECK(!stream_.get());
331 DCHECK(!IsPreconnecting()); 332 DCHECK(!IsPreconnecting());
332 DCHECK(using_spdy()); 333 DCHECK(using_spdy());
333 DCHECK(new_spdy_session_.get()); 334 if (!new_spdy_session_)
334 scoped_refptr<SpdySession> spdy_session = new_spdy_session_; 335 return;
335 new_spdy_session_ = NULL; 336 base::WeakPtr<SpdySession> spdy_session = new_spdy_session_;
337 new_spdy_session_.reset();
336 if (IsOrphaned()) { 338 if (IsOrphaned()) {
337 stream_factory_->OnNewSpdySessionReady( 339 stream_factory_->OnNewSpdySessionReady(
338 spdy_session, spdy_session_direct_, server_ssl_config_, proxy_info_, 340 spdy_session, spdy_session_direct_, server_ssl_config_, proxy_info_,
339 was_npn_negotiated(), protocol_negotiated(), using_spdy(), net_log_); 341 was_npn_negotiated(), protocol_negotiated(), using_spdy(), net_log_);
340 stream_factory_->OnOrphanedJobComplete(this); 342 stream_factory_->OnOrphanedJobComplete(this);
341 } else { 343 } else {
342 request_->OnNewSpdySessionReady(this, spdy_session, spdy_session_direct_); 344 request_->OnNewSpdySessionReady(this, spdy_session, spdy_session_direct_);
343 } 345 }
344 // |this| may be deleted after this call. 346 // |this| may be deleted after this call.
345 } 347 }
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 waiting_job_->Resume(this); 757 waiting_job_->Resume(this);
756 waiting_job_ = NULL; 758 waiting_job_ = NULL;
757 } 759 }
758 } 760 }
759 return rv; 761 return rv;
760 } 762 }
761 763
762 // Check first if we have a spdy session for this group. If so, then go 764 // Check first if we have a spdy session for this group. If so, then go
763 // straight to using that. 765 // straight to using that.
764 SpdySessionKey spdy_session_key = GetSpdySessionKey(); 766 SpdySessionKey spdy_session_key = GetSpdySessionKey();
765 scoped_refptr<SpdySession> spdy_session = 767 base::WeakPtr<SpdySession> spdy_session =
766 session_->spdy_session_pool()->FindAvailableSession( 768 session_->spdy_session_pool()->FindAvailableSession(
767 spdy_session_key, net_log_); 769 spdy_session_key, net_log_);
768 if (spdy_session && CanUseExistingSpdySession()) { 770 if (spdy_session && CanUseExistingSpdySession()) {
769 // If we're preconnecting, but we already have a SpdySession, we don't 771 // If we're preconnecting, but we already have a SpdySession, we don't
770 // actually need to preconnect any sockets, so we're done. 772 // actually need to preconnect any sockets, so we're done.
771 if (IsPreconnecting()) 773 if (IsPreconnecting())
772 return OK; 774 return OK;
773 using_spdy_ = true; 775 using_spdy_ = true;
774 next_state_ = STATE_CREATE_STREAM; 776 next_state_ = STATE_CREATE_STREAM;
775 existing_spdy_session_ = spdy_session; 777 existing_spdy_session_ = spdy_session;
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 if (IsHttpsProxyAndHttpUrl()) { 1092 if (IsHttpsProxyAndHttpUrl()) {
1091 // If we don't have a direct SPDY session, and we're using an HTTPS 1093 // If we don't have a direct SPDY session, and we're using an HTTPS
1092 // proxy, then we might have a SPDY session to the proxy. 1094 // proxy, then we might have a SPDY session to the proxy.
1093 // We never use privacy mode for connection to proxy server. 1095 // We never use privacy mode for connection to proxy server.
1094 spdy_session_key = SpdySessionKey(proxy_server.host_port_pair(), 1096 spdy_session_key = SpdySessionKey(proxy_server.host_port_pair(),
1095 ProxyServer::Direct(), 1097 ProxyServer::Direct(),
1096 kPrivacyModeDisabled); 1098 kPrivacyModeDisabled);
1097 direct = false; 1099 direct = false;
1098 } 1100 }
1099 1101
1100 scoped_refptr<SpdySession> spdy_session; 1102 base::WeakPtr<SpdySession> spdy_session;
1101 if (existing_spdy_session_.get()) { 1103 if (existing_spdy_session_.get()) {
1102 // We picked up an existing session, so we don't need our socket. 1104 // We picked up an existing session, so we don't need our socket.
1103 if (connection_->socket()) 1105 if (connection_->socket())
1104 connection_->socket()->Disconnect(); 1106 connection_->socket()->Disconnect();
1105 connection_->Reset(); 1107 connection_->Reset();
1106 spdy_session.swap(existing_spdy_session_); 1108 std::swap(spdy_session, existing_spdy_session_);
1107 } else { 1109 } else {
1108 SpdySessionPool* spdy_pool = session_->spdy_session_pool(); 1110 SpdySessionPool* spdy_pool = session_->spdy_session_pool();
1109 spdy_session = spdy_pool->FindAvailableSession(spdy_session_key, net_log_); 1111 spdy_session = spdy_pool->FindAvailableSession(spdy_session_key, net_log_);
1110 if (!spdy_session) { 1112 if (!spdy_session) {
1111 int error = 1113 int error =
1112 spdy_pool->CreateAvailableSessionFromSocket(spdy_session_key, 1114 spdy_pool->CreateAvailableSessionFromSocket(spdy_session_key,
1113 connection_.Pass(), 1115 connection_.Pass(),
1114 net_log_, 1116 net_log_,
1115 spdy_certificate_error_, 1117 spdy_certificate_error_,
1116 &new_spdy_session_, 1118 &new_spdy_session_,
1117 using_ssl_); 1119 using_ssl_);
1118 if (error != OK) 1120 if (error != OK)
1119 return error; 1121 return error;
1120 const HostPortPair& host_port_pair = spdy_session_key.host_port_pair(); 1122 const HostPortPair& host_port_pair = spdy_session_key.host_port_pair();
1121 base::WeakPtr<HttpServerProperties> http_server_properties = 1123 base::WeakPtr<HttpServerProperties> http_server_properties =
1122 session_->http_server_properties(); 1124 session_->http_server_properties();
1123 if (http_server_properties) 1125 if (http_server_properties)
1124 http_server_properties->SetSupportsSpdy(host_port_pair, true); 1126 http_server_properties->SetSupportsSpdy(host_port_pair, true);
1125 spdy_session_direct_ = direct; 1127 spdy_session_direct_ = direct;
1126 return OK; 1128 return OK;
1127 } 1129 }
1128 } 1130 }
1129 1131
1130 if (spdy_session->IsClosed()) 1132 if (!spdy_session)
1131 return ERR_CONNECTION_CLOSED; 1133 return ERR_CONNECTION_CLOSED;
1132 1134
1133 // TODO(willchan): Delete this code, because eventually, the 1135 // TODO(willchan): Delete this code, because eventually, the
1134 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it 1136 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it
1135 // will know when SpdySessions become available. 1137 // will know when SpdySessions become available.
1136 1138
1137 if (stream_factory_->for_websockets_) { 1139 if (stream_factory_->for_websockets_) {
1138 DCHECK(request_); 1140 DCHECK(request_);
1139 DCHECK(request_->websocket_stream_factory()); 1141 DCHECK(request_->websocket_stream_factory());
1140 bool use_relative_url = direct || request_info_.url.SchemeIs("wss"); 1142 bool use_relative_url = direct || request_info_.url.SchemeIs("wss");
1141 websocket_stream_.reset( 1143 websocket_stream_.reset(
1142 request_->websocket_stream_factory()->CreateSpdyStream( 1144 request_->websocket_stream_factory()->CreateSpdyStream(
1143 spdy_session.get(), use_relative_url)); 1145 spdy_session, use_relative_url));
1144 } else { 1146 } else {
1145 bool use_relative_url = direct || request_info_.url.SchemeIs("https"); 1147 bool use_relative_url = direct || request_info_.url.SchemeIs("https");
1146 stream_.reset(new SpdyHttpStream(spdy_session.get(), use_relative_url)); 1148 stream_.reset(new SpdyHttpStream(spdy_session, use_relative_url));
1147 } 1149 }
1148 return OK; 1150 return OK;
1149 } 1151 }
1150 1152
1151 int HttpStreamFactoryImpl::Job::DoCreateStreamComplete(int result) { 1153 int HttpStreamFactoryImpl::Job::DoCreateStreamComplete(int result) {
1152 if (result < 0) 1154 if (result < 0)
1153 return result; 1155 return result;
1154 1156
1155 session_->proxy_service()->ReportSuccess(proxy_info_); 1157 session_->proxy_service()->ReportSuccess(proxy_info_);
1156 next_state_ = STATE_NONE; 1158 next_state_ = STATE_NONE;
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
1464 (net::LOAD_MAIN_FRAME | net::LOAD_SUB_FRAME | net::LOAD_PREFETCH | 1466 (net::LOAD_MAIN_FRAME | net::LOAD_SUB_FRAME | net::LOAD_PREFETCH |
1465 net::LOAD_IS_DOWNLOAD)) { 1467 net::LOAD_IS_DOWNLOAD)) {
1466 // Avoid pipelining resources that may be streamed for a long time. 1468 // Avoid pipelining resources that may be streamed for a long time.
1467 return false; 1469 return false;
1468 } 1470 }
1469 return stream_factory_->http_pipelined_host_pool_.IsKeyEligibleForPipelining( 1471 return stream_factory_->http_pipelined_host_pool_.IsKeyEligibleForPipelining(
1470 *http_pipelining_key_.get()); 1472 *http_pipelining_key_.get());
1471 } 1473 }
1472 1474
1473 } // namespace net 1475 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_stream_factory_impl_job.h ('k') | net/http/http_stream_factory_impl_request.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698