Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(465)

Side by Side Diff: chrome/test/chromedriver/net/websocket.h

Issue 11316115: [chromedriver] Write websocket client and sync websocket client. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
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_WEBSOCKET_H_
6 #define CHROME_TEST_CHROMEDRIVER_NET_WEBSOCKET_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/base/completion_callback.h"
17 #include "net/base/net_errors.h"
18 #include "net/socket_stream/socket_stream.h"
19 #include "net/websockets/websocket_frame_parser.h"
20
21 namespace net {
22 class URLRequestContextGetter;
23 class WebSocketJob;
24 } // namespace net
25
26 class WebSocketListener;
27
28 // A text-only, non-thread safe WebSocket. Must be created and used on a single
29 // thread. Intended particularly for use with net::HttpServer.
30 class WebSocket : public net::SocketStream::Delegate {
31 public:
32 WebSocket(net::URLRequestContextGetter* context_getter,
33 const GURL& url,
34 WebSocketListener* listener);
35 virtual ~WebSocket();
36
37 // Initializes the WebSocket connection. Invokes the given callback with
38 // a net::Error. May only be called once.
39 void Connect(const net::CompletionCallback& callback);
40
41 // Sends the given message and returns true on success.
42 bool Send(const std::string& message);
43
44 // Overridden from net::SocketStream::Delegate:
45 virtual void OnConnected(net::SocketStream* socket,
46 int max_pending_send_allowed) OVERRIDE;
47 virtual void OnSentData(net::SocketStream* socket,
48 int amount_sent) OVERRIDE;
49 virtual void OnReceivedData(net::SocketStream* socket,
50 const char* data,
51 int len) OVERRIDE;
52 virtual void OnClose(net::SocketStream* socket) OVERRIDE;
53
54 private:
55 void OnConnectFinished(net::Error error);
56
57 base::ThreadChecker thread_checker_;
58 scoped_refptr<net::URLRequestContextGetter> context_getter_;
59 GURL url_;
60 scoped_refptr<net::WebSocketJob> web_socket_;
61 WebSocketListener* listener_;
62 net::CompletionCallback connect_callback_;
63 std::string sec_key_;
64 net::WebSocketFrameParser parser_;
65 std::string next_message_;
66 bool connected_;
67
68 DISALLOW_COPY_AND_ASSIGN(WebSocket);
69 };
70
71 // Listens for WebSocket messages and disconnects on the same thread as the
72 // WebSocket.
73 class WebSocketListener {
74 public:
75 virtual ~WebSocketListener() {}
76
77 // Called when a WebSocket message is received.
78 virtual void OnMessageReceived(const std::string& message) = 0;
79
80 // Called when the WebSocket connection closes. Will be called at most once.
81 // Will not be called if the connection was never established or if the close
82 // was initiated by the client.
83 virtual void OnClose() = 0;
84 };
85
86 #endif // CHROME_TEST_CHROMEDRIVER_NET_WEBSOCKET_H_
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/net/url_request_context_getter.cc ('k') | chrome/test/chromedriver/net/websocket.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698