| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_DEVTOOLS_DEVICE_USB_ANDROID_USB_DEVICE_H_ | 5 #ifndef CHROME_BROWSER_DEVTOOLS_DEVICE_USB_ANDROID_USB_DEVICE_H_ |
| 6 #define CHROME_BROWSER_DEVTOOLS_DEVICE_USB_ANDROID_USB_DEVICE_H_ | 6 #define CHROME_BROWSER_DEVTOOLS_DEVICE_USB_ANDROID_USB_DEVICE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "device/usb/usb_device_handle.h" | 15 #include "device/usb/usb_device_handle.h" |
| 16 | 16 |
| 17 namespace base { | 17 namespace base { |
| 18 class MessageLoop; | 18 class SingleThreadTaskRunner; |
| 19 } | 19 } |
| 20 | 20 |
| 21 namespace crypto { | 21 namespace crypto { |
| 22 class RSAPrivateKey; | 22 class RSAPrivateKey; |
| 23 } | 23 } |
| 24 | 24 |
| 25 namespace net { | 25 namespace net { |
| 26 class StreamSocket; | 26 class StreamSocket; |
| 27 } | 27 } |
| 28 | 28 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 DISALLOW_COPY_AND_ASSIGN(AdbMessage); | 61 DISALLOW_COPY_AND_ASSIGN(AdbMessage); |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 class AndroidUsbDevice; | 64 class AndroidUsbDevice; |
| 65 typedef std::vector<scoped_refptr<AndroidUsbDevice> > AndroidUsbDevices; | 65 typedef std::vector<scoped_refptr<AndroidUsbDevice> > AndroidUsbDevices; |
| 66 typedef base::Callback<void(const AndroidUsbDevices&)> | 66 typedef base::Callback<void(const AndroidUsbDevices&)> |
| 67 AndroidUsbDevicesCallback; | 67 AndroidUsbDevicesCallback; |
| 68 | 68 |
| 69 class AndroidUsbDevice : public base::RefCountedThreadSafe<AndroidUsbDevice> { | 69 class AndroidUsbDevice : public base::RefCountedThreadSafe<AndroidUsbDevice> { |
| 70 public: | 70 public: |
| 71 static void CountDevices(const base::Callback<void(int)>& callback); |
| 71 static void Enumerate(crypto::RSAPrivateKey* rsa_key, | 72 static void Enumerate(crypto::RSAPrivateKey* rsa_key, |
| 72 const AndroidUsbDevicesCallback& callback); | 73 const AndroidUsbDevicesCallback& callback); |
| 73 | 74 |
| 74 static void CountDevices(const base::Callback<void(int)>& callback); | |
| 75 | |
| 76 AndroidUsbDevice(crypto::RSAPrivateKey* rsa_key, | 75 AndroidUsbDevice(crypto::RSAPrivateKey* rsa_key, |
| 77 scoped_refptr<device::UsbDeviceHandle> device, | 76 scoped_refptr<device::UsbDeviceHandle> device, |
| 78 const std::string& serial, | 77 const std::string& serial, |
| 79 int inbound_address, | 78 int inbound_address, |
| 80 int outbound_address, | 79 int outbound_address, |
| 81 int zero_mask, | 80 int zero_mask, |
| 82 int interface_id); | 81 int interface_id); |
| 83 | 82 |
| 84 void InitOnCallerThread(); | 83 void InitOnCallerThread(); |
| 85 | 84 |
| 86 net::StreamSocket* CreateSocket(const std::string& command); | 85 net::StreamSocket* CreateSocket(const std::string& command); |
| 87 | 86 |
| 88 void Send(uint32 command, | 87 void Send(uint32 command, |
| 89 uint32 arg0, | 88 uint32 arg0, |
| 90 uint32 arg1, | 89 uint32 arg1, |
| 91 const std::string& body); | 90 const std::string& body); |
| 92 | 91 |
| 93 scoped_refptr<device::UsbDeviceHandle> usb_device() { return usb_handle_; } | 92 scoped_refptr<device::UsbDeviceHandle> usb_device() { return usb_handle_; } |
| 94 | 93 |
| 95 std::string serial() { return serial_; } | 94 std::string serial() { return serial_; } |
| 96 | 95 |
| 97 bool is_connected() { return is_connected_; } | 96 bool is_connected() { return is_connected_; } |
| 98 | 97 |
| 99 private: | 98 private: |
| 100 friend class base::RefCountedThreadSafe<AndroidUsbDevice>; | 99 friend class base::RefCountedThreadSafe<AndroidUsbDevice>; |
| 101 virtual ~AndroidUsbDevice(); | 100 virtual ~AndroidUsbDevice(); |
| 102 | 101 |
| 103 void Queue(scoped_ptr<AdbMessage> message); | 102 void Queue(scoped_ptr<AdbMessage> message); |
| 104 void ProcessOutgoing(); | 103 void ProcessOutgoing(); |
| 105 void OutgoingMessageSent(device::UsbTransferStatus status, | 104 static void OutgoingMessageSent( |
| 106 scoped_refptr<net::IOBuffer> buffer, | 105 base::WeakPtr<AndroidUsbDevice> device, |
| 107 size_t result); | 106 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 107 device::UsbTransferStatus status, |
| 108 scoped_refptr<net::IOBuffer> buffer, |
| 109 size_t result); |
| 108 | 110 |
| 109 void ReadHeader(); | 111 void ReadHeader(); |
| 112 static void ReceivedHeader( |
| 113 base::WeakPtr<AndroidUsbDevice> device, |
| 114 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 115 device::UsbTransferStatus status, |
| 116 scoped_refptr<net::IOBuffer> buffer, |
| 117 size_t result); |
| 110 void ParseHeader(device::UsbTransferStatus status, | 118 void ParseHeader(device::UsbTransferStatus status, |
| 111 scoped_refptr<net::IOBuffer> buffer, | 119 scoped_refptr<net::IOBuffer> buffer, |
| 112 size_t result); | 120 size_t result); |
| 113 | 121 |
| 114 void ReadBody(scoped_ptr<AdbMessage> message, | 122 void ReadBody(scoped_ptr<AdbMessage> message, |
| 115 uint32 data_length, | 123 uint32 data_length, |
| 116 uint32 data_check); | 124 uint32 data_check); |
| 125 static void ReceivedBody( |
| 126 base::WeakPtr<AndroidUsbDevice> device, |
| 127 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 128 scoped_ptr<AdbMessage> message, |
| 129 uint32 data_length, |
| 130 uint32 data_check, |
| 131 device::UsbTransferStatus status, |
| 132 scoped_refptr<net::IOBuffer> buffer, |
| 133 size_t result); |
| 117 void ParseBody(scoped_ptr<AdbMessage> message, | 134 void ParseBody(scoped_ptr<AdbMessage> message, |
| 118 uint32 data_length, | 135 uint32 data_length, |
| 119 uint32 data_check, | 136 uint32 data_check, |
| 120 device::UsbTransferStatus status, | 137 device::UsbTransferStatus status, |
| 121 scoped_refptr<net::IOBuffer> buffer, | 138 scoped_refptr<net::IOBuffer> buffer, |
| 122 size_t result); | 139 size_t result); |
| 123 | 140 |
| 124 void HandleIncoming(scoped_ptr<AdbMessage> message); | 141 void HandleIncoming(scoped_ptr<AdbMessage> message); |
| 125 | 142 |
| 126 void TransferError(device::UsbTransferStatus status); | 143 void TransferError(device::UsbTransferStatus status); |
| 127 | 144 |
| 128 void TerminateIfReleased(scoped_refptr<device::UsbDeviceHandle> usb_handle); | 145 void TerminateIfReleased(scoped_refptr<device::UsbDeviceHandle> usb_handle); |
| 129 void Terminate(); | 146 void Terminate(); |
| 130 | 147 |
| 131 void SocketDeleted(uint32 socket_id); | 148 void SocketDeleted(uint32 socket_id); |
| 132 | 149 |
| 133 base::MessageLoop* message_loop_; | 150 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 134 | 151 |
| 135 scoped_ptr<crypto::RSAPrivateKey> rsa_key_; | 152 scoped_ptr<crypto::RSAPrivateKey> rsa_key_; |
| 136 | 153 |
| 137 // Device info | 154 // Device info |
| 138 scoped_refptr<device::UsbDeviceHandle> usb_handle_; | 155 scoped_refptr<device::UsbDeviceHandle> usb_handle_; |
| 139 std::string serial_; | 156 std::string serial_; |
| 140 int inbound_address_; | 157 int inbound_address_; |
| 141 int outbound_address_; | 158 int outbound_address_; |
| 142 int zero_mask_; | 159 int zero_mask_; |
| 143 int interface_id_; | 160 int interface_id_; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 157 // Outgoing messages pending connect | 174 // Outgoing messages pending connect |
| 158 typedef ScopedVector<AdbMessage> PendingMessages; | 175 typedef ScopedVector<AdbMessage> PendingMessages; |
| 159 PendingMessages pending_messages_; | 176 PendingMessages pending_messages_; |
| 160 | 177 |
| 161 base::WeakPtrFactory<AndroidUsbDevice> weak_factory_; | 178 base::WeakPtrFactory<AndroidUsbDevice> weak_factory_; |
| 162 | 179 |
| 163 DISALLOW_COPY_AND_ASSIGN(AndroidUsbDevice); | 180 DISALLOW_COPY_AND_ASSIGN(AndroidUsbDevice); |
| 164 }; | 181 }; |
| 165 | 182 |
| 166 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_USB_ANDROID_USB_DEVICE_H_ | 183 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_USB_ANDROID_USB_DEVICE_H_ |
| OLD | NEW |