From af63c908603f8a2f58f69167129f819d5d30820c Mon Sep 17 00:00:00 2001 From: "ukai@chromium.org" Date: Wed, 17 Mar 2010 05:09:22 +0000 Subject: Refactor WebSocketHandshake out of WebSocket. Make similar code structure with WebKit. Add unittest for WebSocketHandshake. BUG=none TEST=none Review URL: http://codereview.chromium.org/783005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41810 0039d316-1c4b-4281-b951-d872f2087c98 --- net/websockets/websocket.h | 35 +++-------------------------------- 1 file changed, 3 insertions(+), 32 deletions(-) (limited to 'net/websockets/websocket.h') diff --git a/net/websockets/websocket.h b/net/websockets/websocket.h index 0cf95db..5e58391 100644 --- a/net/websockets/websocket.h +++ b/net/websockets/websocket.h @@ -15,6 +15,7 @@ #include #include "base/ref_counted.h" +#include "base/scoped_ptr.h" #include "googleurl/src/gurl.h" #include "net/base/io_buffer.h" #include "net/socket_stream/socket_stream.h" @@ -26,9 +27,9 @@ namespace net { class ClientSocketFactory; class HostResolver; -class HttpResponseHeaders; class WebSocket; +class WebSocketHandshake; // Delegate methods will be called on the same message loop as // WebSocket is constructed. @@ -74,7 +75,6 @@ class WebSocket : public base::RefCountedThreadSafe, ~Request() {} const GURL& url() const { return url_; } - bool is_secure() const; const std::string& protocol() const { return protocol_; } const std::string& origin() const { return origin_; } const std::string& location() const { return location_; } @@ -95,9 +95,6 @@ class WebSocket : public base::RefCountedThreadSafe, return client_socket_factory_; } - // Creates the client handshake message from |this|. - std::string CreateClientHandshakeMessage() const; - private: GURL url_; std::string protocol_; @@ -147,9 +144,6 @@ class WebSocket : public base::RefCountedThreadSafe, virtual void OnError(const SocketStream* socket, int error); private: - enum Mode { - MODE_INCOMPLETE, MODE_NORMAL, MODE_AUTHENTICATE, - }; typedef std::deque< scoped_refptr > PendingDataQueue; friend class WebSocketTest; @@ -157,24 +151,6 @@ class WebSocket : public base::RefCountedThreadSafe, friend class base::RefCountedThreadSafe; virtual ~WebSocket(); - // Checks handshake. - // Prerequisite: Server handshake message is received in |current_read_buf_|. - // Returns number of bytes for server handshake message, - // or negative if server handshake message is not received fully yet. - int CheckHandshake(); - - // Processes server handshake message, parsed as |headers|, and updates - // |ws_origin_|, |ws_location_| and |ws_protocol_|. - // Returns true if it's ok. - // Returns false otherwise (e.g. duplicate WebSocket-Origin: header, etc.) - bool ProcessHeaders(const HttpResponseHeaders& headers); - - // Checks |ws_origin_|, |ws_location_| and |ws_protocol_| are valid - // against |request_|. - // Returns true if it's ok. - // Returns false otherwise (e.g. origin mismatch, etc.) - bool CheckResponseHeaders() const; - // Sends pending data in |current_write_buf_| and/or |pending_write_bufs_|. void SendPending(); @@ -197,16 +173,11 @@ class WebSocket : public base::RefCountedThreadSafe, void DoError(int error); State ready_state_; - Mode mode_; scoped_ptr request_; + scoped_ptr handshake_; WebSocketDelegate* delegate_; MessageLoop* origin_loop_; - // Handshake messages that server sent. - std::string ws_origin_; - std::string ws_location_; - std::string ws_protocol_; - scoped_refptr socket_stream_; int max_pending_send_allowed_; -- cgit v1.1