OLD | NEW |
---|---|
(Empty) | |
1 // 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.
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_TEST_CHROMEDRIVER_NET_WEB_SOCKET_H_ | |
6 #define CHROME_TEST_CHROMEDRIVER_NET_WEB_SOCKET_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/callback.h" | |
12 #include "base/compiler_specific.h" | |
13 #include "base/memory/ref_counted.h" | |
14 #include "base/threading/thread_checker.h" | |
15 #include "googleurl/src/gurl.h" | |
16 #include "net/socket_stream/socket_stream.h" | |
17 | |
18 namespace net { | |
19 class URLRequestContextGetter; | |
20 class WebSocketJob; | |
21 } | |
Takashi Toyoshima
2012/11/27 07:57:37
} // namespace net
kkania
2012/11/27 19:58:23
Done.
| |
22 | |
23 class WebSocketListener; | |
24 | |
25 // A text-only, non-thread safe WebSocket. Must be created and used on a single | |
26 // thread. | |
27 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.
| |
28 public: | |
29 WebSocket(net::URLRequestContextGetter* context_getter, | |
30 const GURL& url, | |
31 WebSocketListener* listener); | |
32 virtual ~WebSocket(); | |
33 | |
34 // Initializes the WebSocket connection. Invokes the given callback with | |
35 // a boolean success parameter. May only be called once. | |
36 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.
| |
37 | |
38 // Writes the given message and returns true on success. | |
39 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.
| |
40 | |
41 // Overridden from net::SocketStream::Delegate: | |
42 virtual void OnConnected(net::SocketStream* socket, | |
43 int max_pending_send_allowed) OVERRIDE; | |
44 virtual void OnSentData(net::SocketStream* socket, | |
45 int amount_sent) OVERRIDE; | |
46 virtual void OnReceivedData(net::SocketStream* socket, | |
47 const char* data, | |
48 int len) OVERRIDE; | |
49 virtual void OnClose(net::SocketStream* socket) OVERRIDE; | |
50 | |
51 private: | |
52 void OnConnectFinished(bool success); | |
53 | |
54 base::ThreadChecker thread_checker_; | |
55 scoped_refptr<net::URLRequestContextGetter> context_getter_; | |
56 GURL url_; | |
57 scoped_refptr<net::WebSocketJob> web_socket_; | |
58 WebSocketListener* listener_; | |
59 base::Callback<void(bool)> connect_callback_; | |
Takashi Toyoshima
2012/11/27 07:57:37
net::CompletionCallback
kkania
2012/11/27 19:58:23
Done.
| |
60 std::string incoming_msg_buf_; | |
61 bool connected_; | |
62 | |
63 DISALLOW_COPY_AND_ASSIGN(WebSocket); | |
64 }; | |
65 | |
66 // Listens for WebSocket messages and disconnects on the same thread as the | |
67 // WebSocket. | |
68 class WebSocketListener { | |
69 public: | |
70 virtual ~WebSocketListener() {} | |
71 | |
72 // Called when a WebSocket message is received. | |
73 virtual void OnMessageReceived(const std::string& message) = 0; | |
74 | |
75 // Called when the WebSocket connection closes. Will be called at most once. | |
76 // Will not be called if the connection was never established or if the close | |
77 // was initiated by the client. | |
78 virtual void OnClose() = 0; | |
79 }; | |
80 | |
81 #endif // CHROME_TEST_CHROMEDRIVER_NET_WEB_SOCKET_H_ | |
OLD | NEW |