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.
5 #ifndef CHROME_BROWSER_DEVTOOLS_ADB_ANDROID_USB_SOCKET_H_
6 #define CHROME_BROWSER_DEVTOOLS_ADB_ANDROID_USB_SOCKET_H_
10 #include "base/memory/ref_counted.h"
11 #include "base/threading/non_thread_safe.h"
12 #include "chrome/browser/devtools/adb/android_usb_device.h"
13 #include "net/base/ip_endpoint.h"
14 #include "net/base/net_errors.h"
15 #include "net/socket/stream_socket.h"
23 class AndroidUsbSocket
: public net::StreamSocket
,
24 public base::NonThreadSafe
{
26 AndroidUsbSocket(scoped_refptr
<AndroidUsbDevice
> device
,
28 const std::string
& command
,
29 base::Callback
<void(uint32
)> delete_callback
);
30 virtual ~AndroidUsbSocket();
32 void HandleIncoming(scoped_refptr
<AdbMessage
> message
);
36 // net::StreamSocket implementation.
37 virtual int Read(net::IOBuffer
* buf
, int buf_len
,
38 const net::CompletionCallback
& callback
) OVERRIDE
;
39 virtual int Write(net::IOBuffer
* buf
, int buf_len
,
40 const net::CompletionCallback
& callback
) OVERRIDE
;
41 virtual bool SetReceiveBufferSize(int32 size
) OVERRIDE
;
42 virtual bool SetSendBufferSize(int32 size
) OVERRIDE
;
43 virtual int Connect(const net::CompletionCallback
& callback
) OVERRIDE
;
44 virtual void Disconnect() OVERRIDE
;
45 virtual bool IsConnected() const OVERRIDE
;
46 virtual bool IsConnectedAndIdle() const OVERRIDE
;
47 virtual int GetPeerAddress(net::IPEndPoint
* address
) const OVERRIDE
;
48 virtual int GetLocalAddress(net::IPEndPoint
* address
) const OVERRIDE
;
49 virtual const net::BoundNetLog
& NetLog() const OVERRIDE
;
50 virtual void SetSubresourceSpeculation() OVERRIDE
;
51 virtual void SetOmniboxSpeculation() OVERRIDE
;
52 virtual bool WasEverUsed() const OVERRIDE
;
53 virtual bool UsingTCPFastOpen() const OVERRIDE
;
54 virtual bool WasNpnNegotiated() const OVERRIDE
;
55 virtual net::NextProto
GetNegotiatedProtocol() const OVERRIDE
;
56 virtual bool GetSSLInfo(net::SSLInfo
* ssl_info
) OVERRIDE
;
61 IORequest(net::IOBuffer
* buffer
,
63 const net::CompletionCallback
& callback
);
66 scoped_refptr
<net::IOBuffer
> buffer
;
68 net::CompletionCallback callback
;
71 void RespondToReaders(bool diconnect
);
72 void RespondToWriters();
74 scoped_refptr
<AndroidUsbDevice
> device_
;
76 base::Callback
<void(uint32
)> delete_callback_
;
79 net::BoundNetLog net_log_
;
82 std::string read_buffer_
;
83 net::CompletionCallback connect_callback_
;
84 std::deque
<IORequest
> read_requests_
;
85 std::deque
<IORequest
> write_requests_
;
87 DISALLOW_COPY_AND_ASSIGN(AndroidUsbSocket
);
90 #endif // CHROME_BROWSER_DEVTOOLS_ADB_ANDROID_USB_SOCKET_H_