| 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() {
|
|
|