Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chrome / test / chromedriver / net / sync_websocket.h
blob5dd59da54446fd72fbb336f17924f190fbd88458
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.
5 #ifndef CHROME_TEST_CHROMEDRIVER_NET_SYNC_WEBSOCKET_H_
6 #define CHROME_TEST_CHROMEDRIVER_NET_SYNC_WEBSOCKET_H_
8 #include <string>
10 #include "base/time/time.h"
12 class GURL;
14 // Proxy for using a WebSocket running on a background thread synchronously.
15 class SyncWebSocket {
16 public:
17 enum StatusCode {
18 kOk = 0,
19 kTimeout,
20 kDisconnected
23 virtual ~SyncWebSocket() {}
25 // Return true if connected, otherwise return false.
26 virtual bool IsConnected() = 0;
28 // Connects to the WebSocket server. Returns true on success.
29 virtual bool Connect(const GURL& url) = 0;
31 // Sends message. Returns true on success.
32 virtual bool Send(const std::string& message) = 0;
34 // Receives next message and modifies the message on success. Returns
35 // StatusCode::kTimedout if no message is received within |timeout|.
36 // Returns StatusCode::kDisconnected if the socket is closed.
37 virtual StatusCode ReceiveNextMessage(
38 std::string* message,
39 const base::TimeDelta& timeout) = 0;
41 // Returns whether there are any messages that have been received and not yet
42 // handled by ReceiveNextMessage.
43 virtual bool HasNextMessage() = 0;
46 #endif // CHROME_TEST_CHROMEDRIVER_NET_SYNC_WEBSOCKET_H_