Home | History | Annotate | Download | only in devtools
      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_BROWSER_DEVTOOLS_ADB_CLIENT_SOCKET_H_
      6 #define CHROME_BROWSER_DEVTOOLS_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 
     23   static void HttpQuery(net::StreamSocket* socket,
     24                         const std::string& request,
     25                         const CommandCallback& callback);
     26 
     27   static void HttpQuery(net::StreamSocket* socket,
     28                         const std::string& request,
     29                         const SocketCallback& callback);
     30 
     31   static void TransportQuery(int port,
     32                              const std::string& serial,
     33                              const std::string& socket_name,
     34                              const SocketCallback& callback);
     35 
     36   explicit AdbClientSocket(int port);
     37   ~AdbClientSocket();
     38 
     39  protected:
     40   void Connect(const net::CompletionCallback& callback);
     41 
     42   void SendCommand(const std::string& command,
     43                    bool is_void,
     44                    const CommandCallback& callback);
     45 
     46   scoped_ptr<net::StreamSocket> socket_;
     47 
     48  private:
     49   void ReadResponse(const CommandCallback& callback, bool is_void, int result);
     50 
     51   void OnResponseHeader(const CommandCallback& callback,
     52                         bool is_void,
     53                         scoped_refptr<net::IOBuffer> response_buffer,
     54                         int result);
     55 
     56   void OnResponseData(const CommandCallback& callback,
     57                       const std::string& response,
     58                       scoped_refptr<net::IOBuffer> response_buffer,
     59                       int bytes_left,
     60                       int result);
     61 
     62   std::string host_;
     63   int port_;
     64 
     65   DISALLOW_COPY_AND_ASSIGN(AdbClientSocket);
     66 };
     67 
     68 #endif  // CHROME_BROWSER_DEVTOOLS_ADB_CLIENT_SOCKET_H_
     69