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

Unified Diff: net/http/http_stream_factory_impl_job.cc

Issue 443383002: Refactor HttpStreamFactoryImpl::Job::DoCreateStream() for handling WebSocket correctly (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/http/http_stream_factory_impl_job.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_stream_factory_impl_job.cc
diff --git a/net/http/http_stream_factory_impl_job.cc b/net/http/http_stream_factory_impl_job.cc
index 53a377b2620314f487d52d1e010a247097c298d2..45d152a107945d57b624b3199a8a1baaaf6ce851 100644
--- a/net/http/http_stream_factory_impl_job.cc
+++ b/net/http/http_stream_factory_impl_job.cc
@@ -1028,6 +1028,22 @@ int HttpStreamFactoryImpl::Job::DoWaitingUserAction(int result) {
return ERR_IO_PENDING;
}
+int HttpStreamFactoryImpl::Job::SetSpdyHttpStream(
+ base::WeakPtr<SpdySession> session, bool direct) {
+ // TODO(ricea): Restore the code for WebSockets over SPDY once it's
+ // implemented.
+ if (stream_factory_->for_websockets_)
+ return ERR_NOT_IMPLEMENTED;
+
+ // TODO(willchan): Delete this code, because eventually, the
+ // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it
+ // will know when SpdySessions become available.
+
+ bool use_relative_url = direct || request_info_.url.SchemeIs("https");
+ stream_.reset(new SpdyHttpStream(session, use_relative_url));
+ return OK;
+}
+
int HttpStreamFactoryImpl::Job::DoCreateStream() {
DCHECK(connection_->socket() || existing_spdy_session_.get() || using_quic_);
@@ -1061,76 +1077,64 @@ int HttpStreamFactoryImpl::Job::DoCreateStream() {
bool direct = true;
const ProxyServer& proxy_server = proxy_info_.proxy_server();
PrivacyMode privacy_mode = request_info_.privacy_mode;
- SpdySessionKey spdy_session_key(origin_, proxy_server, privacy_mode);
- if (IsHttpsProxyAndHttpUrl()) {
- // If we don't have a direct SPDY session, and we're using an HTTPS
- // proxy, then we might have a SPDY session to the proxy.
- // We never use privacy mode for connection to proxy server.
- spdy_session_key = SpdySessionKey(proxy_server.host_port_pair(),
- ProxyServer::Direct(),
- PRIVACY_MODE_DISABLED);
+ if (IsHttpsProxyAndHttpUrl())
direct = false;
- }
- base::WeakPtr<SpdySession> spdy_session;
if (existing_spdy_session_.get()) {
// We picked up an existing session, so we don't need our socket.
if (connection_->socket())
connection_->socket()->Disconnect();
connection_->Reset();
- std::swap(spdy_session, existing_spdy_session_);
- } else {
- SpdySessionPool* spdy_pool = session_->spdy_session_pool();
- spdy_session = spdy_pool->FindAvailableSession(spdy_session_key, net_log_);
- if (!spdy_session) {
- base::WeakPtr<SpdySession> new_spdy_session =
- spdy_pool->CreateAvailableSessionFromSocket(spdy_session_key,
- connection_.Pass(),
- net_log_,
- spdy_certificate_error_,
- using_ssl_);
- if (!new_spdy_session->HasAcceptableTransportSecurity()) {
- new_spdy_session->CloseSessionOnError(
- ERR_SPDY_INADEQUATE_TRANSPORT_SECURITY, "");
- return ERR_SPDY_INADEQUATE_TRANSPORT_SECURITY;
- }
-
- new_spdy_session_ = new_spdy_session;
- spdy_session_direct_ = direct;
- const HostPortPair& host_port_pair = spdy_session_key.host_port_pair();
- base::WeakPtr<HttpServerProperties> http_server_properties =
- session_->http_server_properties();
- if (http_server_properties)
- http_server_properties->SetSupportsSpdy(host_port_pair, true);
-
- // Create a SpdyHttpStream attached to the session;
- // OnNewSpdySessionReadyCallback is not called until an event loop
- // iteration later, so if the SpdySession is closed between then, allow
- // reuse state from the underlying socket, sampled by SpdyHttpStream,
- // bubble up to the request.
- bool use_relative_url = direct || request_info_.url.SchemeIs("https");
- stream_.reset(new SpdyHttpStream(new_spdy_session_, use_relative_url));
- return OK;
- }
+ int set_result = SetSpdyHttpStream(existing_spdy_session_, direct);
+ existing_spdy_session_.reset();
+ return set_result;
}
- if (!spdy_session)
- return ERR_CONNECTION_CLOSED;
+ SpdySessionKey spdy_session_key(origin_, proxy_server, privacy_mode);
+ if (IsHttpsProxyAndHttpUrl()) {
+ // If we don't have a direct SPDY session, and we're using an HTTPS
+ // proxy, then we might have a SPDY session to the proxy.
+ // We never use privacy mode for connection to proxy server.
+ spdy_session_key = SpdySessionKey(proxy_server.host_port_pair(),
+ ProxyServer::Direct(),
+ PRIVACY_MODE_DISABLED);
+ }
- // TODO(willchan): Delete this code, because eventually, the
- // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it
- // will know when SpdySessions become available.
+ SpdySessionPool* spdy_pool = session_->spdy_session_pool();
+ base::WeakPtr<SpdySession> spdy_session =
+ spdy_pool->FindAvailableSession(spdy_session_key, net_log_);
- // TODO(ricea): Restore the code for WebSockets over SPDY once it's
- // implemented.
- if (stream_factory_->for_websockets_)
- return ERR_NOT_IMPLEMENTED;
+ if (spdy_session) {
+ return SetSpdyHttpStream(spdy_session, direct);
+ }
- bool use_relative_url = direct || request_info_.url.SchemeIs("https");
- stream_.reset(new SpdyHttpStream(spdy_session, use_relative_url));
+ spdy_session =
+ spdy_pool->CreateAvailableSessionFromSocket(spdy_session_key,
+ connection_.Pass(),
+ net_log_,
+ spdy_certificate_error_,
+ using_ssl_);
+ if (!spdy_session->HasAcceptableTransportSecurity()) {
+ spdy_session->CloseSessionOnError(
+ ERR_SPDY_INADEQUATE_TRANSPORT_SECURITY, "");
+ return ERR_SPDY_INADEQUATE_TRANSPORT_SECURITY;
+ }
- return OK;
+ new_spdy_session_ = spdy_session;
+ spdy_session_direct_ = direct;
+ const HostPortPair& host_port_pair = spdy_session_key.host_port_pair();
+ base::WeakPtr<HttpServerProperties> http_server_properties =
+ session_->http_server_properties();
+ if (http_server_properties)
+ http_server_properties->SetSupportsSpdy(host_port_pair, true);
+
+ // Create a SpdyHttpStream attached to the session;
+ // OnNewSpdySessionReadyCallback is not called until an event loop
+ // iteration later, so if the SpdySession is closed between then, allow
+ // reuse state from the underlying socket, sampled by SpdyHttpStream,
+ // bubble up to the request.
+ return SetSpdyHttpStream(new_spdy_session_, spdy_session_direct_);
}
int HttpStreamFactoryImpl::Job::DoCreateStreamComplete(int result) {
« no previous file with comments | « net/http/http_stream_factory_impl_job.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698