Chromium Code Reviews| Index: net/http/http_stream_factory_impl.cc |
| diff --git a/net/http/http_stream_factory_impl.cc b/net/http/http_stream_factory_impl.cc |
| index 47110dfd764a4d96a73680ba026e8688d712d38b..0eddca1fb2d4771d60672278fd58fa1490c7fcbb 100644 |
| --- a/net/http/http_stream_factory_impl.cc |
| +++ b/net/http/http_stream_factory_impl.cc |
| @@ -4,6 +4,8 @@ |
| #include "net/http/http_stream_factory_impl.h" |
| +#include <string> |
| + |
| #include "base/string_number_conversions.h" |
| #include "base/stl_util.h" |
| #include "googleurl/src/gurl.h" |
| @@ -16,6 +18,7 @@ |
| #include "net/http/http_server_properties.h" |
| #include "net/http/http_stream_factory_impl_job.h" |
| #include "net/http/http_stream_factory_impl_request.h" |
| +#include "net/socket/client_socket_pool_manager.h" |
|
mmenke
2013/06/10 20:26:03
nit: I don't believe this is used.
yhirano
2013/06/11 11:13:16
Done.
|
| #include "net/spdy/spdy_http_stream.h" |
| namespace net { |
| @@ -39,11 +42,13 @@ GURL UpgradeUrlToHttps(const GURL& original_url, int port) { |
| } // namespace |
| -HttpStreamFactoryImpl::HttpStreamFactoryImpl(HttpNetworkSession* session) |
| +HttpStreamFactoryImpl::HttpStreamFactoryImpl(HttpNetworkSession* session, |
| + bool for_websockets) |
| : session_(session), |
| http_pipelined_host_pool_(this, NULL, |
| session_->http_server_properties(), |
| - session_->force_http_pipelining()) {} |
| + session_->force_http_pipelining()), |
| + for_websockets_(for_websockets) {} |
| HttpStreamFactoryImpl::~HttpStreamFactoryImpl() { |
| DCHECK(request_map_.empty()); |
| @@ -68,7 +73,48 @@ HttpStreamRequest* HttpStreamFactoryImpl::RequestStream( |
| const SSLConfig& proxy_ssl_config, |
| HttpStreamRequest::Delegate* delegate, |
| const BoundNetLog& net_log) { |
| - Request* request = new Request(request_info.url, this, delegate, net_log); |
| + DCHECK(!for_websockets_); |
| + return RequestStreamInternal(request_info, |
| + priority, |
| + server_ssl_config, |
| + proxy_ssl_config, |
| + delegate, |
| + NULL, |
| + net_log); |
| +} |
| + |
| +HttpStreamRequest* HttpStreamFactoryImpl::RequestWebSocketStream( |
| + const HttpRequestInfo& request_info, |
| + RequestPriority priority, |
| + const SSLConfig& server_ssl_config, |
| + const SSLConfig& proxy_ssl_config, |
| + HttpStreamRequest::Delegate* delegate, |
| + WebSocketStreamBase::Factory* factory, |
| + const BoundNetLog& net_log) { |
| + DCHECK(for_websockets_); |
| + return RequestStreamInternal(request_info, |
| + priority, |
| + server_ssl_config, |
| + proxy_ssl_config, |
| + delegate, |
| + factory, |
| + net_log); |
| +} |
| + |
| +HttpStreamRequest* HttpStreamFactoryImpl::RequestStreamInternal( |
| + const HttpRequestInfo& request_info, |
| + RequestPriority priority, |
| + const SSLConfig& server_ssl_config, |
| + const SSLConfig& proxy_ssl_config, |
| + HttpStreamRequest::Delegate* delegate, |
| + WebSocketStreamBase::Factory* websocket_stream_factory, |
| + const BoundNetLog& net_log) { |
| + Request* request = |
| + new Request(request_info.url, |
| + this, |
| + delegate, |
| + websocket_stream_factory, |
| + net_log); |
| GURL alternate_url; |
| PortAlternateProtocolPair alternate = |
| @@ -113,6 +159,7 @@ void HttpStreamFactoryImpl::PreconnectStreams( |
| RequestPriority priority, |
| const SSLConfig& server_ssl_config, |
| const SSLConfig& proxy_ssl_config) { |
| + DCHECK(!for_websockets_); |
| GURL alternate_url; |
| PortAlternateProtocolPair alternate = |
| GetAlternateProtocolRequestFor(request_info.url, &alternate_url); |
| @@ -198,7 +245,7 @@ PortAlternateProtocolPair HttpStreamFactoryImpl::GetAlternateProtocolRequestFor( |
| // for the proxy to use to reach the original URL via TCP. But |
| // the alternate request will be going via UDP to a different port. |
| *alternate_url = original_url; |
| - } |
| + } |
| return alternate; |
| } |
| @@ -213,7 +260,7 @@ void HttpStreamFactoryImpl::OrphanJob(Job* job, const Request* request) { |
| job->Orphan(request); |
| } |
| -void HttpStreamFactoryImpl::OnSpdySessionReady( |
| +void HttpStreamFactoryImpl::OnNewSpdySessionReady( |
| scoped_refptr<SpdySession> spdy_session, |
| bool direct, |
| const SSLConfig& used_ssl_config, |
| @@ -239,12 +286,20 @@ void HttpStreamFactoryImpl::OnSpdySessionReady( |
| protocol_negotiated, |
| using_spdy, |
| net_log); |
| - bool use_relative_url = direct || request->url().SchemeIs("https"); |
| - request->OnStreamReady( |
| - NULL, |
| - used_ssl_config, |
| - used_proxy_info, |
| - new SpdyHttpStream(spdy_session.get(), use_relative_url)); |
| + if (for_websockets_) { |
| + WebSocketStreamBase::Factory* factory = |
| + request->websocket_stream_factory(); |
| + DCHECK(factory); |
| + bool use_relative_url = direct || request->url().SchemeIs("wss"); |
| + request->OnWebSocketStreamReady( |
| + NULL, used_ssl_config, used_proxy_info, |
| + factory->CreateSpdyStream(spdy_session, use_relative_url)); |
| + } else { |
| + bool use_relative_url = direct || request->url().SchemeIs("https"); |
| + request->OnStreamReady(NULL, used_ssl_config, used_proxy_info, |
| + new SpdyHttpStream(spdy_session, |
| + use_relative_url)); |
| + } |
| } |
| // TODO(mbelshe): Alert other valid requests. |
| } |