| 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 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "chrome/browser/usb/usb_device_handle.h" | 13 #include "components/usb_service/usb_device_handle.h" |
| 14 | 14 |
| 15 namespace base { | 15 namespace base { |
| 16 class MessageLoop; | 16 class MessageLoop; |
| 17 } | 17 } |
| 18 | 18 |
| 19 namespace crypto { | 19 namespace crypto { |
| 20 class RSAPrivateKey; | 20 class RSAPrivateKey; |
| 21 } | 21 } |
| 22 | 22 |
| 23 namespace net { | 23 namespace net { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 AndroidUsbDevicesCallback; | 66 AndroidUsbDevicesCallback; |
| 67 | 67 |
| 68 class AndroidUsbDevice : public base::RefCountedThreadSafe<AndroidUsbDevice> { | 68 class AndroidUsbDevice : public base::RefCountedThreadSafe<AndroidUsbDevice> { |
| 69 public: | 69 public: |
| 70 static void Enumerate(crypto::RSAPrivateKey* rsa_key, | 70 static void Enumerate(crypto::RSAPrivateKey* rsa_key, |
| 71 const AndroidUsbDevicesCallback& callback); | 71 const AndroidUsbDevicesCallback& callback); |
| 72 | 72 |
| 73 static void CountDevices(const base::Callback<void(int)>& callback); | 73 static void CountDevices(const base::Callback<void(int)>& callback); |
| 74 | 74 |
| 75 AndroidUsbDevice(crypto::RSAPrivateKey* rsa_key, | 75 AndroidUsbDevice(crypto::RSAPrivateKey* rsa_key, |
| 76 scoped_refptr<UsbDeviceHandle> device, | 76 scoped_refptr<usb_service::UsbDeviceHandle> device, |
| 77 const std::string& serial, | 77 const std::string& serial, |
| 78 int inbound_address, | 78 int inbound_address, |
| 79 int outbound_address, | 79 int outbound_address, |
| 80 int zero_mask, | 80 int zero_mask, |
| 81 int interface_id); | 81 int interface_id); |
| 82 | 82 |
| 83 void InitOnCallerThread(); | 83 void InitOnCallerThread(); |
| 84 | 84 |
| 85 net::StreamSocket* CreateSocket(const std::string& command); | 85 net::StreamSocket* CreateSocket(const std::string& command); |
| 86 | 86 |
| 87 void Send(uint32 command, | 87 void Send(uint32 command, |
| 88 uint32 arg0, | 88 uint32 arg0, |
| 89 uint32 arg1, | 89 uint32 arg1, |
| 90 const std::string& body); | 90 const std::string& body); |
| 91 | 91 |
| 92 scoped_refptr<UsbDeviceHandle> usb_device() { return usb_handle_; } | 92 scoped_refptr<usb_service::UsbDeviceHandle> usb_device() { |
| 93 return usb_handle_; |
| 94 } |
| 93 | 95 |
| 94 std::string serial() { return serial_; } | 96 std::string serial() { return serial_; } |
| 95 | 97 |
| 96 bool is_connected() { return is_connected_; } | 98 bool is_connected() { return is_connected_; } |
| 97 | 99 |
| 98 private: | 100 private: |
| 99 friend class base::RefCountedThreadSafe<AndroidUsbDevice>; | 101 friend class base::RefCountedThreadSafe<AndroidUsbDevice>; |
| 100 virtual ~AndroidUsbDevice(); | 102 virtual ~AndroidUsbDevice(); |
| 101 | 103 |
| 102 void Queue(scoped_refptr<AdbMessage> message); | 104 void Queue(scoped_refptr<AdbMessage> message); |
| 103 void ProcessOutgoing(); | 105 void ProcessOutgoing(); |
| 104 void OutgoingMessageSent(UsbTransferStatus status, | 106 void OutgoingMessageSent(usb_service::UsbTransferStatus status, |
| 105 scoped_refptr<net::IOBuffer> buffer, | 107 scoped_refptr<net::IOBuffer> buffer, |
| 106 size_t result); | 108 size_t result); |
| 107 | 109 |
| 108 void ReadHeader(); | 110 void ReadHeader(); |
| 109 void ParseHeader(UsbTransferStatus status, | 111 void ParseHeader(usb_service::UsbTransferStatus status, |
| 110 scoped_refptr<net::IOBuffer> buffer, | 112 scoped_refptr<net::IOBuffer> buffer, |
| 111 size_t result); | 113 size_t result); |
| 112 | 114 |
| 113 void ReadBody(scoped_refptr<AdbMessage> message, | 115 void ReadBody(scoped_refptr<AdbMessage> message, |
| 114 uint32 data_length, | 116 uint32 data_length, |
| 115 uint32 data_check); | 117 uint32 data_check); |
| 116 void ParseBody(scoped_refptr<AdbMessage> message, | 118 void ParseBody(scoped_refptr<AdbMessage> message, |
| 117 uint32 data_length, | 119 uint32 data_length, |
| 118 uint32 data_check, | 120 uint32 data_check, |
| 119 UsbTransferStatus status, | 121 usb_service::UsbTransferStatus status, |
| 120 scoped_refptr<net::IOBuffer> buffer, | 122 scoped_refptr<net::IOBuffer> buffer, |
| 121 size_t result); | 123 size_t result); |
| 122 | 124 |
| 123 void HandleIncoming(scoped_refptr<AdbMessage> message); | 125 void HandleIncoming(scoped_refptr<AdbMessage> message); |
| 124 | 126 |
| 125 void TransferError(UsbTransferStatus status); | 127 void TransferError(usb_service::UsbTransferStatus status); |
| 126 | 128 |
| 127 void TerminateIfReleased(scoped_refptr<UsbDeviceHandle> usb_handle); | 129 void TerminateIfReleased( |
| 130 scoped_refptr<usb_service::UsbDeviceHandle> usb_handle); |
| 128 void Terminate(); | 131 void Terminate(); |
| 129 | 132 |
| 130 void SocketDeleted(uint32 socket_id); | 133 void SocketDeleted(uint32 socket_id); |
| 131 | 134 |
| 132 base::MessageLoop* message_loop_; | 135 base::MessageLoop* message_loop_; |
| 133 | 136 |
| 134 scoped_ptr<crypto::RSAPrivateKey> rsa_key_; | 137 scoped_ptr<crypto::RSAPrivateKey> rsa_key_; |
| 135 | 138 |
| 136 // Device info | 139 // Device info |
| 137 scoped_refptr<UsbDeviceHandle> usb_handle_; | 140 scoped_refptr<usb_service::UsbDeviceHandle> usb_handle_; |
| 138 std::string serial_; | 141 std::string serial_; |
| 139 int inbound_address_; | 142 int inbound_address_; |
| 140 int outbound_address_; | 143 int outbound_address_; |
| 141 int zero_mask_; | 144 int zero_mask_; |
| 142 int interface_id_; | 145 int interface_id_; |
| 143 | 146 |
| 144 bool is_connected_; | 147 bool is_connected_; |
| 145 bool signature_sent_; | 148 bool signature_sent_; |
| 146 | 149 |
| 147 // Created sockets info | 150 // Created sockets info |
| 148 uint32 last_socket_id_; | 151 uint32 last_socket_id_; |
| 149 typedef std::map<uint32, AndroidUsbSocket*> AndroidUsbSockets; | 152 typedef std::map<uint32, AndroidUsbSocket*> AndroidUsbSockets; |
| 150 AndroidUsbSockets sockets_; | 153 AndroidUsbSockets sockets_; |
| 151 | 154 |
| 152 // Outgoing bulk queue | 155 // Outgoing bulk queue |
| 153 typedef std::pair<scoped_refptr<net::IOBuffer>, size_t> BulkMessage; | 156 typedef std::pair<scoped_refptr<net::IOBuffer>, size_t> BulkMessage; |
| 154 std::queue<BulkMessage> outgoing_queue_; | 157 std::queue<BulkMessage> outgoing_queue_; |
| 155 | 158 |
| 156 // Outgoing messages pending connect | 159 // Outgoing messages pending connect |
| 157 typedef std::vector<scoped_refptr<AdbMessage> > PendingMessages; | 160 typedef std::vector<scoped_refptr<AdbMessage> > PendingMessages; |
| 158 PendingMessages pending_messages_; | 161 PendingMessages pending_messages_; |
| 159 | 162 |
| 160 base::WeakPtrFactory<AndroidUsbDevice> weak_factory_; | 163 base::WeakPtrFactory<AndroidUsbDevice> weak_factory_; |
| 161 | 164 |
| 162 DISALLOW_COPY_AND_ASSIGN(AndroidUsbDevice); | 165 DISALLOW_COPY_AND_ASSIGN(AndroidUsbDevice); |
| 163 }; | 166 }; |
| 164 | 167 |
| 165 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_USB_ANDROID_USB_DEVICE_H_ | 168 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_USB_ANDROID_USB_DEVICE_H_ |
| OLD | NEW |