Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / devtools / adb / android_usb_socket.h
blob0839c60bdbbd1243ec56b2fe3382945721b30e9a
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_
8 #include <deque>
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"
17 namespace base {
18 class MessageLoop;
21 class AdbMessage;
23 class AndroidUsbSocket : public net::StreamSocket,
24 public base::NonThreadSafe {
25 public:
26 AndroidUsbSocket(scoped_refptr<AndroidUsbDevice> device,
27 uint32 socket_id,
28 const std::string& command,
29 base::Callback<void(uint32)> delete_callback);
30 virtual ~AndroidUsbSocket();
32 void HandleIncoming(scoped_refptr<AdbMessage> message);
34 void Terminated();
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;
58 private:
59 class IORequest {
60 public:
61 IORequest(net::IOBuffer* buffer,
62 int length,
63 const net::CompletionCallback& callback);
64 ~IORequest();
66 scoped_refptr<net::IOBuffer> buffer;
67 int length;
68 net::CompletionCallback callback;
71 void RespondToReaders(bool diconnect);
72 void RespondToWriters();
74 scoped_refptr<AndroidUsbDevice> device_;
75 std::string command_;
76 base::Callback<void(uint32)> delete_callback_;
77 uint32 local_id_;
78 uint32 remote_id_;
79 net::BoundNetLog net_log_;
80 bool is_connected_;
81 bool is_closed_;
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_