Index: chrome/test/chromedriver/net/web_socket.h |
diff --git a/chrome/test/chromedriver/net/web_socket.h b/chrome/test/chromedriver/net/web_socket.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..75e9f25df39c8628dc36cb20fbd9bad0efe9cd6a |
--- /dev/null |
+++ b/chrome/test/chromedriver/net/web_socket.h |
@@ -0,0 +1,81 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
Takashi Toyoshima
2012/11/27 07:57:37
Other WebSocket* classes have a filename websocket
kkania
2012/11/27 19:58:23
Done.
|
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_TEST_CHROMEDRIVER_NET_WEB_SOCKET_H_ |
+#define CHROME_TEST_CHROMEDRIVER_NET_WEB_SOCKET_H_ |
+ |
+#include <string> |
+ |
+#include "base/basictypes.h" |
+#include "base/callback.h" |
+#include "base/compiler_specific.h" |
+#include "base/memory/ref_counted.h" |
+#include "base/threading/thread_checker.h" |
+#include "googleurl/src/gurl.h" |
+#include "net/socket_stream/socket_stream.h" |
+ |
+namespace net { |
+class URLRequestContextGetter; |
+class WebSocketJob; |
+} |
Takashi Toyoshima
2012/11/27 07:57:37
} // namespace net
kkania
2012/11/27 19:58:23
Done.
|
+ |
+class WebSocketListener; |
+ |
+// A text-only, non-thread safe WebSocket. Must be created and used on a single |
+// thread. |
+class WebSocket : public net::SocketStream::Delegate { |
Takashi Toyoshima
2012/11/27 07:57:37
Memo:
SocketStream will be obsolete and replaced w
kkania
2012/11/27 19:58:23
Done.
|
+ public: |
+ WebSocket(net::URLRequestContextGetter* context_getter, |
+ const GURL& url, |
+ WebSocketListener* listener); |
+ virtual ~WebSocket(); |
+ |
+ // Initializes the WebSocket connection. Invokes the given callback with |
+ // a boolean success parameter. May only be called once. |
+ void Connect(const base::Callback<void(bool)>& callback); |
Takashi Toyoshima
2012/11/27 07:57:37
Using net::CompletionCallback is usual style for n
kkania
2012/11/27 19:58:23
Done.
|
+ |
+ // Writes the given message and returns true on success. |
+ bool Write(const std::string& message); |
Takashi Toyoshima
2012/11/27 07:57:37
Send() looks consistent.
kkania
2012/11/27 19:58:23
Done.
|
+ |
+ // Overridden from net::SocketStream::Delegate: |
+ virtual void OnConnected(net::SocketStream* socket, |
+ int max_pending_send_allowed) OVERRIDE; |
+ virtual void OnSentData(net::SocketStream* socket, |
+ int amount_sent) OVERRIDE; |
+ virtual void OnReceivedData(net::SocketStream* socket, |
+ const char* data, |
+ int len) OVERRIDE; |
+ virtual void OnClose(net::SocketStream* socket) OVERRIDE; |
+ |
+ private: |
+ void OnConnectFinished(bool success); |
+ |
+ base::ThreadChecker thread_checker_; |
+ scoped_refptr<net::URLRequestContextGetter> context_getter_; |
+ GURL url_; |
+ scoped_refptr<net::WebSocketJob> web_socket_; |
+ WebSocketListener* listener_; |
+ base::Callback<void(bool)> connect_callback_; |
Takashi Toyoshima
2012/11/27 07:57:37
net::CompletionCallback
kkania
2012/11/27 19:58:23
Done.
|
+ std::string incoming_msg_buf_; |
+ bool connected_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(WebSocket); |
+}; |
+ |
+// Listens for WebSocket messages and disconnects on the same thread as the |
+// WebSocket. |
+class WebSocketListener { |
+ public: |
+ virtual ~WebSocketListener() {} |
+ |
+ // Called when a WebSocket message is received. |
+ virtual void OnMessageReceived(const std::string& message) = 0; |
+ |
+ // Called when the WebSocket connection closes. Will be called at most once. |
+ // Will not be called if the connection was never established or if the close |
+ // was initiated by the client. |
+ virtual void OnClose() = 0; |
+}; |
+ |
+#endif // CHROME_TEST_CHROMEDRIVER_NET_WEB_SOCKET_H_ |