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

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 d9e7f24501c343475d710f6f46e36c65404c3c77..22771506d96cb3ed9060bdd0e6107e9a4dc7aa8c 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"
@@ -291,6 +293,42 @@ void HttpStreamFactoryImpl::Job::OnStreamReadyCallback() {
// |this| may be deleted after this call.
}
+void HttpStreamFactoryImpl::Job::OnSocketReadyCallback() {
+ DCHECK(request_->for_websocket());
+ DCHECK(connection_.get());
+ DCHECK(!IsPreconnecting());
+ if (IsOrphaned()) {
+ stream_factory_->OnOrphanedJobComplete(this);
+ } else {
+ request_->Complete(was_npn_negotiated(),
+ protocol_negotiated(),
+ using_spdy(),
+ net_log_);
+ request_->OnSocketReady(this, server_ssl_config_, proxy_info_,
+ connection_.release());
+ }
+ // |this| may be deleted after this call.
+}
+
+void HttpStreamFactoryImpl::Job::OnSpdySessionReadyForWSCallback() {
+ DCHECK(request_->for_websocket());
+ DCHECK(spdy_session_to_pass_);
+ DCHECK(!IsPreconnecting());
+ scoped_refptr<SpdySession> session = spdy_session_to_pass_;
+ spdy_session_to_pass_ = NULL;
+ if (IsOrphaned()) {
+ stream_factory_->OnOrphanedJobComplete(this);
+ } else {
+ request_->Complete(was_npn_negotiated(),
+ protocol_negotiated(),
+ using_spdy(),
+ net_log_);
+ request_->OnSpdySessionReadyForWS(this, server_ssl_config_, proxy_info_,
+ session);
+ }
+ // |this| may be deleted after this call.
+}
+
void HttpStreamFactoryImpl::Job::OnSpdySessionReadyCallback() {
DCHECK(!stream_.get());
DCHECK(!IsPreconnecting());
@@ -477,7 +515,23 @@ int HttpStreamFactoryImpl::Job::RunLoop(int result) {
case OK:
next_state_ = STATE_DONE;
- if (new_spdy_session_) {
+ if (request_->for_websocket()) {
+ if (connection_) {
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(
+ &HttpStreamFactoryImpl::Job::OnSocketReadyCallback,
+ ptr_factory_.GetWeakPtr()));
+ } else if (spdy_session_to_pass_) {
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(
+ &HttpStreamFactoryImpl::Job::OnSpdySessionReadyForWSCallback,
+ ptr_factory_.GetWeakPtr()));
+ } else {
+ return ERR_FAILED;
+ }
+ } else if (new_spdy_session_) {
MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(
@@ -854,9 +908,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();
}
@@ -974,6 +1028,9 @@ int HttpStreamFactoryImpl::Job::DoCreateStream() {
CreateStreamOnExistingPipeline(
*http_pipelining_key_.get()));
tyoshino (SeeGerritForStatus) 2013/05/15 04:29:34 have you checked that a request for ws doesn't ent
yhirano 2013/05/15 06:09:52 No, I haven't. I modified IsRequestEligibleForPipe
CHECK(stream_.get());
+ } else if (request_->for_websocket()) {
+ // Do nothing.
+ // connection_ will be passed to the delegate.
} else if (!using_proxy && IsRequestEligibleForPipelining()) {
// TODO(simonjam): Support proxies.
stream_.reset(
@@ -1028,6 +1085,10 @@ int HttpStreamFactoryImpl::Job::DoCreateStream() {
if (http_server_properties)
http_server_properties->SetSupportsSpdy(host_port_pair, true);
spdy_session_direct_ = direct;
+ if (request_->for_websocket()) {
+ DCHECK(!spdy_session_to_pass_);
+ spdy_session_to_pass_.swap(new_spdy_session_);
+ }
return OK;
}
}
@@ -1035,6 +1096,12 @@ int HttpStreamFactoryImpl::Job::DoCreateStream() {
if (spdy_session->IsClosed())
return ERR_CONNECTION_CLOSED;
+ if (request_->for_websocket()) {
+ DCHECK(!spdy_session_to_pass_);
+ spdy_session_to_pass_.swap(spdy_session);
+ return OK;
+ }
+
// TODO(willchan): Delete this code, because eventually, the
// HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it
// will know when SpdySessions become available.

Powered by Google App Engine
This is Rietveld 408576698