Home | History | Annotate | Download | only in net
      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_SYNC_WEBSOCKET_H_
      6 #define CHROME_TEST_CHROMEDRIVER_NET_SYNC_WEBSOCKET_H_
      7 
      8 #include <string>
      9 
     10 #include "base/time/time.h"
     11 
     12 class GURL;
     13 
     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
     21   };
     22 
     23   virtual ~SyncWebSocket() {}
     24 
     25   // Return true if connected, otherwise return false.
     26   virtual bool IsConnected() = 0;
     27 
     28   // Connects to the WebSocket server. Returns true on success.
     29   virtual bool Connect(const GURL& url) = 0;
     30 
     31   // Sends message. Returns true on success.
     32   virtual bool Send(const std::string& message) = 0;
     33 
     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;
     40 
     41   // Returns whether there are any messages that have been received and not yet
     42   // handled by ReceiveNextMessage.
     43   virtual bool HasNextMessage() = 0;
     44 };
     45 
     46 #endif  // CHROME_TEST_CHROMEDRIVER_NET_SYNC_WEBSOCKET_H_
     47