diff options
author | ricea@chromium.org <ricea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-23 13:47:01 +0000 |
---|---|---|
committer | ricea@chromium.org <ricea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-23 13:47:01 +0000 |
commit | 693ebf370811fabc6d9dc7ca1682a182998adce3 (patch) | |
tree | 8d57531048236bb194fc12e9a1a3ffd80d71cd43 /net/websockets | |
parent | a6358f2b505bb5f1f0e58f6ced9080b98cd15240 (diff) | |
download | chromium_src-693ebf370811fabc6d9dc7ca1682a182998adce3.zip chromium_src-693ebf370811fabc6d9dc7ca1682a182998adce3.tar.gz chromium_src-693ebf370811fabc6d9dc7ca1682a182998adce3.tar.bz2 |
Changes to class hierachy to prepare for WebSocketBasicHandshakeStream.
See https://codereview.chromium.org/25417005/ for the in-progress development of WebSocketBasicHandshakeStream.
See
design doc at
https://docs.google.com/a/google.com/document/d/1AH2lRR2i2Wf4yODgckgdsvZeuGwpbvsvMGLnAMUXUbM/edit
for the reasoning behind the changes.
This CL does not include the renaming of WebSocketStreamBase to WebSocketHandshakeStreamBase. This decision is a bit arbitrary.
BUG=303568
TEST=net_unittests
Review URL: https://codereview.chromium.org/26872005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@230399 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/websockets')
-rw-r--r-- | net/websockets/websocket_basic_stream.cc | 22 | ||||
-rw-r--r-- | net/websockets/websocket_basic_stream.h | 12 | ||||
-rw-r--r-- | net/websockets/websocket_channel_test.cc | 19 | ||||
-rw-r--r-- | net/websockets/websocket_deflate_stream.cc | 31 | ||||
-rw-r--r-- | net/websockets/websocket_deflate_stream.h | 9 | ||||
-rw-r--r-- | net/websockets/websocket_deflate_stream_test.cc | 20 | ||||
-rw-r--r-- | net/websockets/websocket_stream.cc | 2 | ||||
-rw-r--r-- | net/websockets/websocket_stream.h | 39 | ||||
-rw-r--r-- | net/websockets/websocket_stream_base.h | 24 |
9 files changed, 25 insertions, 153 deletions
diff --git a/net/websockets/websocket_basic_stream.cc b/net/websockets/websocket_basic_stream.cc index d3b1c40..fa598d0 100644 --- a/net/websockets/websocket_basic_stream.cc +++ b/net/websockets/websocket_basic_stream.cc @@ -50,8 +50,7 @@ int CalculateSerializedSizeAndTurnOnMaskBit( const int kMaximumTotalSize = std::numeric_limits<int>::max(); int total_size = 0; - for (WebSocketFrameIterator it = frames->begin(); - it != frames->end(); ++it) { + for (WebSocketFrameIterator it = frames->begin(); it != frames->end(); ++it) { WebSocketFrame* frame = *it; // Force the masked bit on. frame->header.masked = true; @@ -137,8 +136,7 @@ int WebSocketBasicStream::WriteFrames(ScopedVector<WebSocketFrame>* frames, char* dest = combined_buffer->data(); int remaining_size = total_size; - for (WebSocketFrameIterator it = frames->begin(); - it != frames->end(); ++it) { + for (WebSocketFrameIterator it = frames->begin(); it != frames->end(); ++it) { WebSocketFrame* frame = *it; WebSocketMaskingKey mask = generate_websocket_masking_key_(); int result = @@ -173,22 +171,6 @@ std::string WebSocketBasicStream::GetSubProtocol() const { std::string WebSocketBasicStream::GetExtensions() const { return extensions_; } -int WebSocketBasicStream::SendHandshakeRequest( - const GURL& url, - const HttpRequestHeaders& headers, - HttpResponseInfo* response_info, - const CompletionCallback& callback) { - // TODO(ricea): Implement handshake-related functionality. - NOTREACHED(); - return ERR_NOT_IMPLEMENTED; -} - -int WebSocketBasicStream::ReadHandshakeResponse( - const CompletionCallback& callback) { - NOTREACHED(); - return ERR_NOT_IMPLEMENTED; -} - /*static*/ scoped_ptr<WebSocketBasicStream> WebSocketBasicStream::CreateWebSocketBasicStreamForTesting( diff --git a/net/websockets/websocket_basic_stream.h b/net/websockets/websocket_basic_stream.h index a071e61..601a236 100644 --- a/net/websockets/websocket_basic_stream.h +++ b/net/websockets/websocket_basic_stream.h @@ -19,8 +19,6 @@ namespace net { class ClientSocketHandle; class DrainableIOBuffer; class GrowableIOBuffer; -class HttpRequestHeaders; -class HttpResponseInfo; class IOBufferWithSize; struct WebSocketFrame; struct WebSocketFrameChunk; @@ -52,16 +50,6 @@ class NET_EXPORT_PRIVATE WebSocketBasicStream : public WebSocketStream { virtual std::string GetExtensions() const OVERRIDE; - // Writes WebSocket handshake request HTTP-style to the connection. Adds - // "Sec-WebSocket-Key" header; this should not be included in |headers|. - virtual int SendHandshakeRequest(const GURL& url, - const HttpRequestHeaders& headers, - HttpResponseInfo* response_info, - const CompletionCallback& callback) OVERRIDE; - - virtual int ReadHandshakeResponse( - const CompletionCallback& callback) OVERRIDE; - //////////////////////////////////////////////////////////////////////////// // Methods for testing only. diff --git a/net/websockets/websocket_channel_test.cc b/net/websockets/websocket_channel_test.cc index 6bc2a54..77701a5 100644 --- a/net/websockets/websocket_channel_test.cc +++ b/net/websockets/websocket_channel_test.cc @@ -161,19 +161,6 @@ class FakeWebSocketStream : public WebSocketStream { const std::string& extensions) : protocol_(protocol), extensions_(extensions) {} - virtual int SendHandshakeRequest( - const GURL& url, - const HttpRequestHeaders& headers, - HttpResponseInfo* response_info, - const CompletionCallback& callback) OVERRIDE { - return ERR_IO_PENDING; - } - - virtual int ReadHandshakeResponse( - const CompletionCallback& callback) OVERRIDE { - return ERR_IO_PENDING; - } - virtual int ReadFrames(ScopedVector<WebSocketFrame>* frames, const CompletionCallback& callback) OVERRIDE { return ERR_IO_PENDING; @@ -607,12 +594,6 @@ class MockWebSocketStream : public WebSocketStream { MOCK_CONST_METHOD0(GetSubProtocol, std::string()); MOCK_CONST_METHOD0(GetExtensions, std::string()); MOCK_METHOD0(AsWebSocketStream, WebSocketStream*()); - MOCK_METHOD4(SendHandshakeRequest, - int(const GURL& url, - const HttpRequestHeaders& headers, - HttpResponseInfo* response_info, - const CompletionCallback& callback)); - MOCK_METHOD1(ReadHandshakeResponse, int(const CompletionCallback& callback)); }; struct ArgumentCopyingWebSocketStreamFactory { diff --git a/net/websockets/websocket_deflate_stream.cc b/net/websockets/websocket_deflate_stream.cc index d4fe775..fe9fd9e 100644 --- a/net/websockets/websocket_deflate_stream.cc +++ b/net/websockets/websocket_deflate_stream.cc @@ -72,9 +72,7 @@ int WebSocketDeflateStream::WriteFrames(ScopedVector<WebSocketFrame>* frames, return stream_->WriteFrames(frames, callback); } -void WebSocketDeflateStream::Close() { - stream_->Close(); -} +void WebSocketDeflateStream::Close() { stream_->Close(); } std::string WebSocketDeflateStream::GetSubProtocol() const { return stream_->GetSubProtocol(); @@ -84,23 +82,6 @@ std::string WebSocketDeflateStream::GetExtensions() const { return stream_->GetExtensions(); } -int WebSocketDeflateStream::SendHandshakeRequest( - const GURL& url, - const HttpRequestHeaders& headers, - HttpResponseInfo* response_info, - const CompletionCallback& callback) { - // TODO(yhirano) handshake related functions will be moved to somewhere. - NOTIMPLEMENTED(); - return OK; -} - -int WebSocketDeflateStream::ReadHandshakeResponse( - const CompletionCallback& callback) { - // TODO(yhirano) handshake related functions will be moved to somewhere. - NOTIMPLEMENTED(); - return OK; -} - void WebSocketDeflateStream::OnReadComplete( ScopedVector<WebSocketFrame>* frames, const CompletionCallback& callback, @@ -143,9 +124,8 @@ int WebSocketDeflateStream::Deflate(ScopedVector<WebSocketFrame>* frames) { current_writing_opcode_ = WebSocketFrameHeader::kOpCodeContinuation; } else { DCHECK_EQ(WRITING_COMPRESSED_MESSAGE, writing_state_); - if (frame->data && - !deflater_.AddBytes(frame->data->data(), - frame->header.payload_length)) { + if (frame->data && !deflater_.AddBytes(frame->data->data(), + frame->header.payload_length)) { DVLOG(1) << "WebSocket protocol error. " << "deflater_.AddBytes() returns an error."; return ERR_WS_PROTOCOL_ERROR; @@ -217,9 +197,8 @@ int WebSocketDeflateStream::Inflate(ScopedVector<WebSocketFrame>* frames) { frames_to_output.push_back(frame.release()); } else { DCHECK_EQ(reading_state_, READING_COMPRESSED_MESSAGE); - if (frame->data && - !inflater_.AddBytes(frame->data->data(), - frame->header.payload_length)) { + if (frame->data && !inflater_.AddBytes(frame->data->data(), + frame->header.payload_length)) { DVLOG(1) << "WebSocket protocol error. " << "inflater_.AddBytes() returns an error."; return ERR_WS_PROTOCOL_ERROR; diff --git a/net/websockets/websocket_deflate_stream.h b/net/websockets/websocket_deflate_stream.h index 224bfeb..d83696d 100644 --- a/net/websockets/websocket_deflate_stream.h +++ b/net/websockets/websocket_deflate_stream.h @@ -21,9 +21,6 @@ class GURL; namespace net { -class HttpRequestHeaders; -class HttpResponseInfo; - // WebSocketDeflateStream is a WebSocketStream subclass. // WebSocketDeflateStream is for permessage-deflate WebSocket extension[1]. // @@ -41,12 +38,6 @@ class NET_EXPORT_PRIVATE WebSocketDeflateStream : public WebSocketStream { virtual void Close() OVERRIDE; virtual std::string GetSubProtocol() const OVERRIDE; virtual std::string GetExtensions() const OVERRIDE; - virtual int SendHandshakeRequest(const GURL& url, - const HttpRequestHeaders& headers, - HttpResponseInfo* response_info, - const CompletionCallback& callback) OVERRIDE; - virtual int ReadHandshakeResponse(const CompletionCallback& callback) - OVERRIDE; private: enum ReadingState { diff --git a/net/websockets/websocket_deflate_stream_test.cc b/net/websockets/websocket_deflate_stream_test.cc index 63955f1..260991d 100644 --- a/net/websockets/websocket_deflate_stream_test.cc +++ b/net/websockets/websocket_deflate_stream_test.cc @@ -15,7 +15,6 @@ #include "net/base/completion_callback.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" -#include "net/http/http_request_headers.h" #include "net/websockets/websocket_deflater.h" #include "net/websockets/websocket_frame.h" #include "net/websockets/websocket_inflater.h" @@ -23,19 +22,15 @@ #include "net/websockets/websocket_test_util.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" -#include "url/gurl.h" namespace net { - -class HttpResponseInfo; - namespace { -typedef testing::MockFunction<void(int)> MockCallback; // NOLINT -using testing::_; -using testing::InSequence; -using testing::Invoke; -using testing::Return; +typedef ::testing::MockFunction<void(int)> MockCallback; // NOLINT +using ::testing::_; +using ::testing::InSequence; +using ::testing::Invoke; +using ::testing::Return; typedef uint32_t FrameFlag; const FrameFlag kNoFlag = 0; @@ -104,11 +99,6 @@ class MockWebSocketStream : public WebSocketStream { MOCK_METHOD0(Close, void()); MOCK_CONST_METHOD0(GetSubProtocol, std::string()); MOCK_CONST_METHOD0(GetExtensions, std::string()); - MOCK_METHOD4(SendHandshakeRequest, int(const GURL& url, - const HttpRequestHeaders& headers, - HttpResponseInfo* response_info, - const CompletionCallback& callback)); - MOCK_METHOD1(ReadHandshakeResponse, int(const CompletionCallback& callback)); }; class WebSocketDeflateStreamTest : public ::testing::Test { diff --git a/net/websockets/websocket_stream.cc b/net/websockets/websocket_stream.cc index b2d316b..9d1394c 100644 --- a/net/websockets/websocket_stream.cc +++ b/net/websockets/websocket_stream.cc @@ -27,6 +27,4 @@ scoped_ptr<WebSocketStreamRequest> WebSocketStream::CreateAndConnectStream( return make_scoped_ptr(new WebSocketStreamRequest()); } -WebSocketStream* WebSocketStream::AsWebSocketStream() { return this; } - } // namespace net diff --git a/net/websockets/websocket_stream.h b/net/websockets/websocket_stream.h index ca29f57..ce9551d 100644 --- a/net/websockets/websocket_stream.h +++ b/net/websockets/websocket_stream.h @@ -14,15 +14,12 @@ #include "base/memory/scoped_vector.h" #include "net/base/completion_callback.h" #include "net/base/net_export.h" -#include "net/websockets/websocket_stream_base.h" class GURL; namespace net { class BoundNetLog; -class HttpRequestHeaders; -class HttpResponseInfo; class URLRequestContext; struct WebSocketFrame; @@ -49,7 +46,7 @@ class NET_EXPORT_PRIVATE WebSocketStreamRequest { // |callback| will be called when the operation is finished. Non-null |callback| // must be provided to these functions. -class NET_EXPORT_PRIVATE WebSocketStream : public WebSocketStreamBase { +class NET_EXPORT_PRIVATE WebSocketStream { public: // A concrete object derived from ConnectDelegate is supplied by the caller to // CreateAndConnectStream() to receive the result of the connection. @@ -156,40 +153,6 @@ class NET_EXPORT_PRIVATE WebSocketStream : public WebSocketStreamBase { // extensions were negotiated, the empty string is returned. virtual std::string GetExtensions() const = 0; - // TODO(yutak): Add following interfaces: - // - RenewStreamForAuth for authentication (is this necessary?) - // - GetSSLInfo, GetSSLCertRequestInfo for SSL - - // WebSocketStreamBase derived functions - virtual WebSocketStream* AsWebSocketStream() OVERRIDE; - - //////////////////////////////////////////////////////////////////////////// - // Methods used during the stream handshake. These must not be called once a - // WebSocket protocol stream has been established (ie. after the - // SuccessCallback or FailureCallback has been called.) - - // Writes WebSocket handshake request to the underlying socket. Must be called - // before ReadHandshakeResponse(). - // - // |callback| will only be called if this method returns ERR_IO_PENDING. - // - // |response_info| must remain valid until the callback from - // ReadHandshakeResponse has been called. - // - // TODO(ricea): This function is only used during the handshake and is - // probably only applicable to certain subclasses of WebSocketStream. Move it - // somewhere else? Also applies to ReadHandshakeResponse. - virtual int SendHandshakeRequest(const GURL& url, - const HttpRequestHeaders& headers, - HttpResponseInfo* response_info, - const CompletionCallback& callback) = 0; - - // Reads WebSocket handshake response from the underlying socket. Must be - // called after SendHandshakeRequest() completes. - // - // |callback| will only be called if this method returns ERR_IO_PENDING. - virtual int ReadHandshakeResponse(const CompletionCallback& callback) = 0; - protected: WebSocketStream(); diff --git a/net/websockets/websocket_stream_base.h b/net/websockets/websocket_stream_base.h index dc863d2..fbf90ff 100644 --- a/net/websockets/websocket_stream_base.h +++ b/net/websockets/websocket_stream_base.h @@ -9,30 +9,33 @@ // Since net/http can be built without linking net/websockets code, // this file should not depend on net/websockets. -#include <base/basictypes.h> +#include "base/basictypes.h" +#include "base/memory/weak_ptr.h" +#include "net/http/http_stream_base.h" namespace net { class ClientSocketHandle; class SpdySession; -class WebSocketStream; -// WebSocketStreamBase is the base class of WebSocketStream. -// net/http code uses this interface to handle WebSocketStream. -class NET_EXPORT WebSocketStreamBase { +// WebSocketStreamBase is the base class of WebSocketBasicHandshakeStream. +// net/http code uses this interface to handle WebSocketBasicHandshakeStream +// when it needs to be treated differently from HttpStreamBase. +class NET_EXPORT WebSocketStreamBase : public HttpStreamBase { public: class Factory { public: virtual ~Factory() {} - // Create a WebSocketBasicStream. - // This function (or the returned object) takes the ownership - // of |connection|. + // Create a WebSocketBasicHandshakeStream. This function (or the returned + // object) takes the ownership of |connection|. This is called after the + // underlying connection has been established but before any handshake data + // has been transferred. virtual WebSocketStreamBase* CreateBasicStream( ClientSocketHandle* connection, bool using_proxy) = 0; - // Create a WebSocketSpdyStream. + // Create a WebSocketSpdyHandshakeStream (unimplemented as of October 2013) virtual WebSocketStreamBase* CreateSpdyStream( const base::WeakPtr<SpdySession>& session, bool use_relative_url) = 0; @@ -40,9 +43,6 @@ class NET_EXPORT WebSocketStreamBase { virtual ~WebSocketStreamBase() {} - // Return this object as a WebSocketStream. - virtual WebSocketStream* AsWebSocketStream() = 0; - protected: WebSocketStreamBase() {} |