1 // Copyright 2014 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_BROWSER_DEVTOOLS_DEVICE_USB_ANDROID_USB_SOCKET_H_
6 #define CHROME_BROWSER_DEVTOOLS_DEVICE_USB_ANDROID_USB_SOCKET_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/threading/non_thread_safe.h"
11 #include "chrome/browser/devtools/device/usb/android_usb_device.h"
12 #include "net/base/ip_endpoint.h"
13 #include "net/socket/stream_socket.h"
19 class AndroidUsbSocket
: public net::StreamSocket
,
20 public base::NonThreadSafe
{
22 AndroidUsbSocket(scoped_refptr
<AndroidUsbDevice
> device
,
24 const std::string
& command
,
25 base::Closure delete_callback
);
26 ~AndroidUsbSocket() override
;
28 void HandleIncoming(scoped_ptr
<AdbMessage
> message
);
30 void Terminated(bool closed_by_device
);
32 // net::StreamSocket implementation.
33 int Read(net::IOBuffer
* buf
,
35 const net::CompletionCallback
& callback
) override
;
36 int Write(net::IOBuffer
* buf
,
38 const net::CompletionCallback
& callback
) override
;
39 int SetReceiveBufferSize(int32 size
) override
;
40 int SetSendBufferSize(int32 size
) override
;
41 int Connect(const net::CompletionCallback
& callback
) override
;
42 void Disconnect() override
;
43 bool IsConnected() const override
;
44 bool IsConnectedAndIdle() const override
;
45 int GetPeerAddress(net::IPEndPoint
* address
) const override
;
46 int GetLocalAddress(net::IPEndPoint
* address
) const override
;
47 const net::BoundNetLog
& NetLog() const override
;
48 void SetSubresourceSpeculation() override
;
49 void SetOmniboxSpeculation() override
;
50 bool WasEverUsed() const override
;
51 bool UsingTCPFastOpen() const override
;
52 bool WasNpnNegotiated() const override
;
53 net::NextProto
GetNegotiatedProtocol() const override
;
54 bool GetSSLInfo(net::SSLInfo
* ssl_info
) override
;
55 void GetConnectionAttempts(net::ConnectionAttempts
* out
) const override
;
56 void ClearConnectionAttempts() override
{}
57 void AddConnectionAttempts(const net::ConnectionAttempts
& attempts
) override
{
61 void RespondToReader(bool disconnect
);
62 void RespondToWriter(int result
);
64 scoped_refptr
<AndroidUsbDevice
> device_
;
68 net::BoundNetLog net_log_
;
70 std::string read_buffer_
;
71 scoped_refptr
<net::IOBuffer
> read_io_buffer_
;
74 net::CompletionCallback connect_callback_
;
75 net::CompletionCallback read_callback_
;
76 net::CompletionCallback write_callback_
;
77 base::Closure delete_callback_
;
78 base::WeakPtrFactory
<AndroidUsbSocket
> weak_factory_
;
80 DISALLOW_COPY_AND_ASSIGN(AndroidUsbSocket
);
83 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_USB_ANDROID_USB_SOCKET_H_