Home | History | Annotate | Download | only in net
      1 // Copyright (c) 2013 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_ADB_CLIENT_SOCKET_H_
      6 #define CHROME_TEST_CHROMEDRIVER_NET_ADB_CLIENT_SOCKET_H_
      7 
      8 #include "base/callback.h"
      9 #include "net/base/io_buffer.h"
     10 #include "net/socket/stream_socket.h"
     11 
     12 class AdbClientSocket {
     13  public:
     14   typedef base::Callback<void(int, const std::string&)> CommandCallback;
     15   typedef base::Callback<void(int result,
     16                               net::StreamSocket*)> SocketCallback;
     17 
     18   static void AdbQuery(int port,
     19                        const std::string& query,
     20                        const CommandCallback& callback);
     21 
     22   static void TransportQuery(int port,
     23                              const std::string& serial,
     24                              const std::string& socket_name,
     25                              const SocketCallback& callback);
     26 
     27   static void HttpQuery(int port,
     28                         const std::string& serial,
     29                         const std::string& socket_name,
     30                         const std::string& request,
     31                         const CommandCallback& callback);
     32 
     33   static void HttpQuery(int port,
     34                         const std::string& serial,
     35                         const std::string& socket_name,
     36                         const std::string& request,
     37                         const SocketCallback& callback);
     38 
     39   explicit AdbClientSocket(int port);
     40   ~AdbClientSocket();
     41 
     42  protected:
     43   void Connect(const net::CompletionCallback& callback);
     44 
     45   void SendCommand(const std::string& command,
     46                    bool is_void,
     47                    const CommandCallback& callback);
     48 
     49   scoped_ptr<net::StreamSocket> socket_;
     50 
     51  private:
     52   void ReadResponse(const CommandCallback& callback, bool is_void, int result);
     53 
     54   void OnResponseHeader(const CommandCallback& callback,
     55                         bool is_void,
     56                         scoped_refptr<net::IOBuffer> response_buffer,
     57                         int result);
     58 
     59   void OnResponseData(const CommandCallback& callback,
     60                       const std::string& response,
     61                       scoped_refptr<net::IOBuffer> response_buffer,
     62                       int bytes_left,
     63                       int result);
     64 
     65   std::string host_;
     66   int port_;
     67 
     68   DISALLOW_COPY_AND_ASSIGN(AdbClientSocket);
     69 };
     70 
     71 #endif  // CHROME_TEST_CHROMEDRIVER_NET_ADB_CLIENT_SOCKET_H_
     72