| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_TEST_CHROMEDRIVER_NET_SYNC_WEBSOCKET_H_ | 5 #ifndef CHROME_TEST_CHROMEDRIVER_NET_SYNC_WEBSOCKET_H_ |
| 6 #define CHROME_TEST_CHROMEDRIVER_NET_SYNC_WEBSOCKET_H_ | 6 #define CHROME_TEST_CHROMEDRIVER_NET_SYNC_WEBSOCKET_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/time/time.h" | |
| 11 | |
| 12 class GURL; | 10 class GURL; |
| 11 class Timeout; |
| 13 | 12 |
| 14 // Proxy for using a WebSocket running on a background thread synchronously. | 13 // Proxy for using a WebSocket running on a background thread synchronously. |
| 15 class SyncWebSocket { | 14 class SyncWebSocket { |
| 16 public: | 15 public: |
| 17 enum StatusCode { | 16 enum StatusCode { |
| 18 kOk = 0, | 17 kOk = 0, |
| 19 kTimeout, | 18 kTimeout, |
| 20 kDisconnected | 19 kDisconnected |
| 21 }; | 20 }; |
| 22 | 21 |
| 23 virtual ~SyncWebSocket() {} | 22 virtual ~SyncWebSocket() {} |
| 24 | 23 |
| 25 // Return true if connected, otherwise return false. | 24 // Return true if connected, otherwise return false. |
| 26 virtual bool IsConnected() = 0; | 25 virtual bool IsConnected() = 0; |
| 27 | 26 |
| 28 // Connects to the WebSocket server. Returns true on success. | 27 // Connects to the WebSocket server. Returns true on success. |
| 29 virtual bool Connect(const GURL& url) = 0; | 28 virtual bool Connect(const GURL& url) = 0; |
| 30 | 29 |
| 31 // Sends message. Returns true on success. | 30 // Sends message. Returns true on success. |
| 32 virtual bool Send(const std::string& message) = 0; | 31 virtual bool Send(const std::string& message) = 0; |
| 33 | 32 |
| 34 // Receives next message and modifies the message on success. Returns | 33 // Receives next message and modifies the message on success. Returns |
| 35 // StatusCode::kTimedout if no message is received within |timeout|. | 34 // StatusCode::kTimedout if no message is received within |timeout|. |
| 36 // Returns StatusCode::kDisconnected if the socket is closed. | 35 // Returns StatusCode::kDisconnected if the socket is closed. |
| 37 virtual StatusCode ReceiveNextMessage( | 36 virtual StatusCode ReceiveNextMessage( |
| 38 std::string* message, | 37 std::string* message, |
| 39 const base::TimeDelta& timeout) = 0; | 38 const Timeout& timeout) = 0; |
| 40 | 39 |
| 41 // Returns whether there are any messages that have been received and not yet | 40 // Returns whether there are any messages that have been received and not yet |
| 42 // handled by ReceiveNextMessage. | 41 // handled by ReceiveNextMessage. |
| 43 virtual bool HasNextMessage() = 0; | 42 virtual bool HasNextMessage() = 0; |
| 44 }; | 43 }; |
| 45 | 44 |
| 46 #endif // CHROME_TEST_CHROMEDRIVER_NET_SYNC_WEBSOCKET_H_ | 45 #endif // CHROME_TEST_CHROMEDRIVER_NET_SYNC_WEBSOCKET_H_ |
| OLD | NEW |