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

Unified Diff: net/http/http_stream_factory_impl_job.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_job.cc
diff --git a/net/http/http_stream_factory_impl_job.cc b/net/http/http_stream_factory_impl_job.cc
index 34eb217ee9e771c3773a45d864565a942bafe998..542e4c446dec2a714aea3c2af2a88cfcbb23878e 100644
--- a/net/http/http_stream_factory_impl_job.cc
+++ b/net/http/http_stream_factory_impl_job.cc
@@ -4,6 +4,8 @@
#include "net/http/http_stream_factory_impl_job.h"
+#include <string>
+
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/logging.h"
@@ -281,6 +283,7 @@ bool HttpStreamFactoryImpl::Job::CanUseExistingSpdySession() const {
void HttpStreamFactoryImpl::Job::OnStreamReadyCallback() {
DCHECK(stream_.get());
DCHECK(!IsPreconnecting());
+ DCHECK(!stream_factory_->for_websocket_);
if (IsOrphaned()) {
stream_factory_->OnOrphanedJobComplete(this);
} else {
@@ -294,7 +297,26 @@ void HttpStreamFactoryImpl::Job::OnStreamReadyCallback() {
// |this| may be deleted after this call.
}
-void HttpStreamFactoryImpl::Job::OnSpdySessionReadyCallback() {
+void HttpStreamFactoryImpl::Job::OnWebSocketStreamReadyCallback() {
+ DCHECK(!IsPreconnecting());
+ DCHECK(stream_factory_->for_websocket_);
+ DCHECK(websocket_stream_);
+ if (IsOrphaned()) {
+ stream_factory_->OnOrphanedJobComplete(this);
+ } else {
+ request_->Complete(was_npn_negotiated(),
+ protocol_negotiated(),
+ using_spdy(),
+ net_log_);
+ request_->OnWebSocketStreamReady(this,
+ server_ssl_config_,
+ proxy_info_,
+ websocket_stream_.release());
+ }
+ // |this| may be deleted after this call.
+}
+
+void HttpStreamFactoryImpl::Job::OnNewSpdySessionReadyCallback() {
DCHECK(!stream_.get());
DCHECK(!IsPreconnecting());
DCHECK(using_spdy());
@@ -302,12 +324,12 @@ void HttpStreamFactoryImpl::Job::OnSpdySessionReadyCallback() {
scoped_refptr<SpdySession> spdy_session = new_spdy_session_;
new_spdy_session_ = NULL;
if (IsOrphaned()) {
- stream_factory_->OnSpdySessionReady(
+ stream_factory_->OnNewSpdySessionReady(
spdy_session, spdy_session_direct_, server_ssl_config_, proxy_info_,
was_npn_negotiated(), protocol_negotiated(), using_spdy(), net_log_);
stream_factory_->OnOrphanedJobComplete(this);
} else {
- request_->OnSpdySessionReady(this, spdy_session, spdy_session_direct_);
+ request_->OnNewSpdySessionReady(this, spdy_session, spdy_session_direct_);
}
// |this| may be deleted after this call.
}
@@ -368,7 +390,7 @@ void HttpStreamFactoryImpl::Job::OnHttpsProxyTunnelResponseCallback(
void HttpStreamFactoryImpl::Job::OnPreconnectsComplete() {
DCHECK(!request_);
if (new_spdy_session_) {
- stream_factory_->OnSpdySessionReady(
+ stream_factory_->OnNewSpdySessionReady(
new_spdy_session_, spdy_session_direct_, server_ssl_config_,
proxy_info_, was_npn_negotiated(), protocol_negotiated(), using_spdy(),
net_log_);
@@ -444,7 +466,7 @@ int HttpStreamFactoryImpl::Job::RunLoop(int result) {
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(
- &HttpStreamFactoryImpl::Job::OnNeedsProxyAuthCallback,
+ &Job::OnNeedsProxyAuthCallback,
ptr_factory_.GetWeakPtr(),
*tunnel_auth_response,
proxy_socket->GetAuthController()));
@@ -455,7 +477,7 @@ int HttpStreamFactoryImpl::Job::RunLoop(int result) {
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(
- &HttpStreamFactoryImpl::Job::OnNeedsClientAuthCallback,
+ &Job::OnNeedsClientAuthCallback,
ptr_factory_.GetWeakPtr(),
connection_->ssl_error_response_info().cert_request_info));
return ERR_IO_PENDING;
@@ -471,7 +493,7 @@ int HttpStreamFactoryImpl::Job::RunLoop(int result) {
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(
- &HttpStreamFactoryImpl::Job::OnHttpsProxyTunnelResponseCallback,
+ &Job::OnHttpsProxyTunnelResponseCallback,
ptr_factory_.GetWeakPtr(),
*proxy_socket->GetConnectResponseInfo(),
proxy_socket->CreateConnectResponseStream()));
@@ -484,13 +506,29 @@ int HttpStreamFactoryImpl::Job::RunLoop(int result) {
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(
- &HttpStreamFactoryImpl::Job::OnSpdySessionReadyCallback,
+ &Job::OnNewSpdySessionReadyCallback,
ptr_factory_.GetWeakPtr()));
+ } else if (stream_factory_->for_websocket_) {
+ if (websocket_stream_) {
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(
+ &Job::OnWebSocketStreamReadyCallback,
+ ptr_factory_.GetWeakPtr()));
+ } else {
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(
+ &Job::OnStreamFailedCallback,
+ ptr_factory_.GetWeakPtr(),
+ result));
mmenke 2013/05/24 14:53:22 Calling OnStreamFailedCallback with a result of OK
mmenke 2013/05/24 16:44:43 On second thought, perhaps just a DCHECK instead o
yhirano 2013/05/27 09:21:32 Done.
+ return ERR_IO_PENDING;
+ }
} else {
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(
- &HttpStreamFactoryImpl::Job::OnStreamReadyCallback,
+ &Job::OnStreamReadyCallback,
ptr_factory_.GetWeakPtr()));
}
return ERR_IO_PENDING;
@@ -499,7 +537,7 @@ int HttpStreamFactoryImpl::Job::RunLoop(int result) {
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(
- &HttpStreamFactoryImpl::Job::OnStreamFailedCallback,
+ &Job::OnStreamFailedCallback,
ptr_factory_.GetWeakPtr(),
result));
return ERR_IO_PENDING;
@@ -861,9 +899,9 @@ int HttpStreamFactoryImpl::Job::DoInitConnectionComplete(int result) {
SSLClientSocket::NextProtoFromString(proto);
protocol_negotiated_ = protocol_negotiated;
net_log_.AddEvent(
- NetLog::TYPE_HTTP_STREAM_REQUEST_PROTO,
- base::Bind(&NetLogHttpStreamProtoCallback,
- status, &proto, &server_protos));
+ NetLog::TYPE_HTTP_STREAM_REQUEST_PROTO,
+ base::Bind(&NetLogHttpStreamProtoCallback,
+ status, &proto, &server_protos));
if (ssl_socket->was_spdy_negotiated())
SwitchToSpdyMode();
}
@@ -979,10 +1017,16 @@ int HttpStreamFactoryImpl::Job::DoCreateStream() {
request_info_.url.SchemeIs("ftp"));
if (stream_factory_->http_pipelined_host_pool_.
IsExistingPipelineAvailableForKey(*http_pipelining_key_.get())) {
+ DCHECK(!stream_factory_->for_websocket_);
stream_.reset(stream_factory_->http_pipelined_host_pool_.
CreateStreamOnExistingPipeline(
*http_pipelining_key_.get()));
CHECK(stream_.get());
+ } else if (stream_factory_->for_websocket_) {
+ DCHECK(request_ && request_->websocket_stream_factory());
+ websocket_stream_.reset(
+ request_->websocket_stream_factory()->CreateBasicStream(
+ connection_.release(), using_proxy));
} else if (!using_proxy && IsRequestEligibleForPipelining()) {
// TODO(simonjam): Support proxies.
stream_.reset(
@@ -1051,8 +1095,15 @@ int HttpStreamFactoryImpl::Job::DoCreateStream() {
// 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(spdy_session, use_relative_url));
+ if (stream_factory_->for_websocket_) {
+ bool use_relative_url = direct || request_info_.url.SchemeIs("wss");
+ websocket_stream_.reset(
+ request_->websocket_stream_factory()->CreateSpdyStream(
+ spdy_session, use_relative_url));
+ } else {
+ bool use_relative_url = direct || request_info_.url.SchemeIs("https");
+ stream_.reset(new SpdyHttpStream(spdy_session, use_relative_url));
+ }
return OK;
}
@@ -1353,6 +1404,9 @@ bool HttpStreamFactoryImpl::Job::IsRequestEligibleForPipelining() {
if (IsPreconnecting() || !request_) {
return false;
}
+ if (stream_factory_->for_websocket_) {
+ return false;
+ }
if (session_->force_http_pipelining()) {
return true;
}

Powered by Google App Engine
This is Rietveld 408576698