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

Unified Diff: net/websockets/websocket_job.cc

Issue 6961007: WebSocket over SPDY. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: rebased Created 9 years, 6 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/websockets/websocket_job.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/websockets/websocket_job.cc
diff --git a/net/websockets/websocket_job.cc b/net/websockets/websocket_job.cc
index 77fc0582304cef9499f3bc6f46fac3161f97fc12..f98e1570bf93099445aa0769451086d0d3b0ee27 100644
--- a/net/websockets/websocket_job.cc
+++ b/net/websockets/websocket_job.cc
@@ -280,6 +280,69 @@ void WebSocketJob::OnError(const SocketStream* socket, int error) {
delegate_->OnError(socket, error);
}
+void WebSocketJob::OnCreatedSpdyStream(int result) {
+ if (state_ == CLOSED) {
+ spdy_websocket_stream_.reset();
+ //DoCallback(ERR_ABORTED);
+ return;
+ }
+ DCHECK(spdy_websocket_stream_.get());
+ DCHECK(socket_.get());
+ DCHECK_NE(ERR_IO_PENDING, result);
+ spdy_websocket_stream_.reset();
+ //DoCallback(result);
+}
+
+void WebSocketJob::OnSentSpdyHeaders(int result) {
+ // TODO(toyoshim): Error handling on result.
+ if (state_ != CONNECTING)
+ return;
+ if (delegate_)
+ delegate_->OnSentData(
+ socket_,
+ handshake_request_->original_length());
+ handshake_request_.reset();
+}
+
+int WebSocketJob::OnReceivedSpdyResponseHeader(
+ const spdy::SpdyHeaderBlock& headers, int status) {
+ DCHECK_NE(INITIALIZED, state_);
+ if (state_ != CONNECTING)
+ return status;
+ if (status != OK)
+ return status;
+ // TODO(toyoshim): Fallback to non-spdy connection?
+ handshake_response_->ParseResponseHeaderBlock(headers, challenge_);
+
+ SaveCookiesAndNotifyHeaderComplete();
+ return OK;
+}
+
+void WebSocketJob::OnSentSpdyData(int amount_sent) {
+ DCHECK_NE(INITIALIZED, state_);
+ DCHECK_NE(CONNECTING, state_);
+ if (state_ == CLOSED)
+ return;
+ if (!spdy_websocket_stream_.get())
+ return;
+ OnSentData(socket_, amount_sent);
+}
+
+void WebSocketJob::OnReceivedSpdyData(const char* data, int length) {
+ DCHECK_NE(INITIALIZED, state_);
+ DCHECK_NE(CONNECTING, state_);
+ if (state_ == CLOSED)
+ return;
+ if (!spdy_websocket_stream_.get())
+ return;
+ OnReceivedData(socket_, data, length);
+}
+
+void WebSocketJob::OnCloseSpdyStream() {
+ spdy_websocket_stream_.reset();
+ OnClose(socket_);
+}
+
bool WebSocketJob::SendHandshakeRequest(const char* data, int len) {
DCHECK_EQ(state_, CONNECTING);
if (started_to_send_handshake_request_)
@@ -317,14 +380,22 @@ void WebSocketJob::AddCookieHeaderAndSend() {
}
}
- const std::string& handshake_request = handshake_request_->GetRawRequest();
- handshake_request_sent_ = 0;
- socket_->net_log()->AddEvent(
- NetLog::TYPE_WEB_SOCKET_SEND_REQUEST_HEADERS,
- make_scoped_refptr(
- new NetLogWebSocketHandshakeParameter(handshake_request)));
- socket_->SendData(handshake_request.data(),
- handshake_request.size());
+ if (spdy_websocket_stream_.get()) {
+ linked_ptr<spdy::SpdyHeaderBlock> headers(new spdy::SpdyHeaderBlock);
+ handshake_request_->GetRequestHeaderBlock(
+ socket_->url(), headers.get(), &challenge_);
+ spdy_websocket_stream_->SendRequest(headers);
+ } else {
+ const std::string& handshake_request =
+ handshake_request_->GetRawRequest();
+ handshake_request_sent_ = 0;
+ socket_->net_log()->AddEvent(
+ NetLog::TYPE_WEB_SOCKET_SEND_REQUEST_HEADERS,
+ make_scoped_refptr(
+ new NetLogWebSocketHandshakeParameter(handshake_request)));
+ socket_->SendData(handshake_request.data(),
+ handshake_request.size());
+ }
}
}
@@ -464,8 +535,17 @@ int WebSocketJob::TrySpdyStream() {
const HostPortProxyPair pair(HostPortPair::FromURL(socket_->url()),
socket_->proxy_server());
if (spdy_pool->HasSession(pair)) {
- // TODO(toyoshim): Switch to SpdyWebSocketStream here by returning
- // ERR_PROTOCOL_SWITCHED.
+ scoped_refptr<SpdySession> spdy_session =
+ spdy_pool->Get(pair, *socket_->net_log());
+
+ spdy_websocket_stream_.reset(
+ new SpdyWebSocketStream(spdy_session, this));
+
+ int result = spdy_websocket_stream_->InitializeStream(
+ socket_->url(), MEDIUM, *socket_->net_log());
+ if (result == OK)
+ return ERR_PROTOCOL_SWITCHED;
+ return result;
}
}
}
@@ -505,13 +585,19 @@ void WebSocketJob::RetryPendingIO() {
}
bool WebSocketJob::SendDataInternal(const char* data, int length) {
- // TODO(toyoshim): Call protocol specific SendData().
+ if (spdy_websocket_stream_.get()) {
+ // TODO(toyoshim): Error handling.
+ spdy_websocket_stream_->SendData(data, length);
+ return true;
+ }
return socket_->SendData(data, length);
}
void WebSocketJob::CloseInternal() {
- // TODO(toyoshim): Call protocol specific Close().
- socket_->Close();
+ if (spdy_websocket_stream_.get())
+ spdy_websocket_stream_->Close();
+ else
+ socket_->Close();
}
void WebSocketJob::SendPending() {
« no previous file with comments | « net/websockets/websocket_job.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698