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

Unified Diff: net/http/http_stream_factory_impl.cc

Issue 14813024: Introduce RequestWebSocketStream into HttpStreamFactory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 7 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
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 d86c690ef48ee8e272a28f334d823298a96cbefb..39a9b2e6f755b4ea8e0af48451eed76d45e9fc1c 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"
#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,9 +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, 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.
}
@@ -293,4 +351,35 @@ void HttpStreamFactoryImpl::AbortPipelinedRequestsWithKey(
}
}
+int HttpStreamFactoryImpl::InitSocketHandleForHttpRequest(
+ const GURL& request_url,
+ const HttpRequestInfo& request_info,
+ RequestPriority request_priority,
+ const ProxyInfo& proxy_info,
+ bool force_spdy_over_ssl,
+ bool want_spdy_over_npn,
+ const SSLConfig& ssl_config_for_origin,
+ const SSLConfig& ssl_config_for_proxy,
+ const BoundNetLog& net_log,
+ ClientSocketHandle* socket_handle,
+ const OnHostResolutionCallback& resolution_callback,
+ const CompletionCallback& callback) {
+ return ::net::InitSocketHandleForHttpRequest(
mmenke 2013/05/28 21:22:37 nit: leading "::" not needed.
yhirano 2013/05/30 04:44:32 Deleted.
+ request_url,
+ request_info.extra_headers,
+ request_info.load_flags,
+ request_priority,
+ session_,
+ proxy_info,
+ force_spdy_over_ssl,
+ want_spdy_over_npn,
+ ssl_config_for_origin,
+ ssl_config_for_proxy,
+ request_info.privacy_mode,
+ net_log,
+ socket_handle,
+ resolution_callback,
+ callback);
+}
+
} // namespace net

Powered by Google App Engine
This is Rietveld 408576698