| Index: net/spdy/spdy_websocket_stream.cc
|
| diff --git a/net/spdy/spdy_websocket_stream.cc b/net/spdy/spdy_websocket_stream.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..44c6b6a05ea29aa9953049b780b0b3a304d23939
|
| --- /dev/null
|
| +++ b/net/spdy/spdy_websocket_stream.cc
|
| @@ -0,0 +1,141 @@
|
| +// Copyright (c) 2010 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "net/spdy/spdy_websocket_stream.h"
|
| +
|
| +#include "googleurl/src/gurl.h"
|
| +#include "net/base/net_errors.h"
|
| +#include "net/base/io_buffer.h"
|
| +#include "net/spdy/spdy_framer.h"
|
| +#include "net/spdy/spdy_protocol.h"
|
| +#include "net/spdy/spdy_session.h"
|
| +#include "net/spdy/spdy_stream.h"
|
| +
|
| +namespace net {
|
| +
|
| +SpdyWebSocketStream::SpdyWebSocketStream(
|
| + SpdySession* spdy_session,
|
| + SpdyWebSocketStreamDelegate* delegate)
|
| + : stream_(NULL),
|
| + spdy_session_(spdy_session),
|
| + delegate_(delegate),
|
| + ALLOW_THIS_IN_INITIALIZER_LIST(
|
| + io_callback_(this, &SpdyWebSocketStream::OnIOCompleted)) {
|
| +}
|
| +
|
| +SpdyWebSocketStream::~SpdyWebSocketStream() {
|
| + if (stream_)
|
| + stream_->DetachDelegate();
|
| +}
|
| +
|
| +int SpdyWebSocketStream::InitializeStream(
|
| + const GURL& url,
|
| + RequestPriority request_priority,
|
| + const BoundNetLog& net_log) {
|
| + if (spdy_session_->IsClosed())
|
| + return ERR_CONNECTION_CLOSED;
|
| +
|
| + int result = spdy_session_->CreateStream(url,
|
| + request_priority,
|
| + &stream_,
|
| + net_log,
|
| + &io_callback_);
|
| + if (result != ERR_IO_PENDING)
|
| + OnSpdyStreamCreated(result);
|
| + return result;
|
| +}
|
| +
|
| +void SpdyWebSocketStream::SendRequest(
|
| + linked_ptr<spdy::SpdyHeaderBlock> headers) {
|
| + if (!stream_)
|
| + return;
|
| + stream_->set_spdy_headers(headers);
|
| + int result = stream_->SendRequest(true);
|
| + if (result < OK && result != ERR_IO_PENDING)
|
| + Close();
|
| +}
|
| +
|
| +void SpdyWebSocketStream::SendData(const char* data, int length) {
|
| + if (!stream_)
|
| + return;
|
| + IOBuffer* buf(new IOBuffer(length));
|
| + memcpy(buf->data(), data, length);
|
| + int result = stream_->WriteStreamData(buf, length, spdy::DATA_FLAG_NONE);
|
| + if (result < OK && result != ERR_IO_PENDING)
|
| + Close();
|
| +}
|
| +
|
| +void SpdyWebSocketStream::Close() {
|
| + if (spdy_session_)
|
| + spdy_session_->CancelPendingCreateStreams(&stream_);
|
| + if (stream_)
|
| + stream_->Close();
|
| +}
|
| +
|
| +bool SpdyWebSocketStream::OnSendHeadersComplete(int status) {
|
| + if (delegate_)
|
| + delegate_->OnSentSpdyHeaders(this);
|
| + return true;
|
| +}
|
| +
|
| +int SpdyWebSocketStream::OnSendBody() {
|
| + NOTREACHED();
|
| + return ERR_UNEXPECTED;
|
| +}
|
| +
|
| +bool SpdyWebSocketStream::OnSendBodyComplete(int status) {
|
| + NOTREACHED();
|
| + return true;
|
| +}
|
| +
|
| +bool SpdyWebSocketStream::IsFinishedSendingBody() {
|
| + NOTREACHED();
|
| + return true;
|
| +}
|
| +
|
| +int SpdyWebSocketStream::OnResponseReceived(
|
| + const spdy::SpdyHeaderBlock& response,
|
| + base::Time response_time, int status) {
|
| + if (!delegate_)
|
| + return ERR_ABORTED;
|
| + return delegate_->OnReceivedSpdyResponseHeader(this, response, status);
|
| +}
|
| +
|
| +void SpdyWebSocketStream::OnDataReceived(const char* data, int length) {
|
| + if (!delegate_)
|
| + return;
|
| + delegate_->OnReceivedSpdyData(this, data, length);
|
| +}
|
| +
|
| +void SpdyWebSocketStream::OnDataSent(int length) {
|
| + if (!delegate_)
|
| + return;
|
| + delegate_->OnSentSpdyData(this, length);
|
| +}
|
| +
|
| +void SpdyWebSocketStream::OnClose(int status) {
|
| + if (!delegate_)
|
| + return;
|
| + SpdyWebSocketStreamDelegate* delegate = delegate_;
|
| + delegate_ = NULL;
|
| + stream_ = NULL;
|
| + if (delegate)
|
| + delegate->OnCloseSpdyStream(this);
|
| +}
|
| +
|
| +void SpdyWebSocketStream::OnIOCompleted(int result) {
|
| + OnSpdyStreamCreated(result);
|
| +}
|
| +
|
| +void SpdyWebSocketStream::OnSpdyStreamCreated(int result) {
|
| + DCHECK_NE(ERR_IO_PENDING, result);
|
| + if (stream_)
|
| + stream_->SetDelegate(this);
|
| + if (delegate_) {
|
| + delegate_->OnCreatedSpdyStream(this, result);
|
| + }
|
| +}
|
| +
|
| +
|
| +} // namespace net
|
|
|