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 #include "chrome/browser/devtools/device/usb/android_usb_device.h" | 5 #include "chrome/browser/devtools/device/usb/android_usb_device.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/barrier_closure.h" | 9 #include "base/barrier_closure.h" |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
18 #include "chrome/browser/devtools/device/usb/android_rsa.h" | 18 #include "chrome/browser/devtools/device/usb/android_rsa.h" |
19 #include "chrome/browser/devtools/device/usb/android_usb_socket.h" | 19 #include "chrome/browser/devtools/device/usb/android_usb_socket.h" |
20 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
21 #include "crypto/rsa_private_key.h" | 21 #include "crypto/rsa_private_key.h" |
22 #include "device/core/device_client.h" | 22 #include "device/core/device_client.h" |
23 #include "device/usb/usb_descriptors.h" | |
24 #include "device/usb/usb_device.h" | 23 #include "device/usb/usb_device.h" |
25 #include "device/usb/usb_service.h" | 24 #include "device/usb/usb_service.h" |
26 #include "net/base/ip_endpoint.h" | 25 #include "net/base/ip_endpoint.h" |
27 #include "net/base/net_errors.h" | 26 #include "net/base/net_errors.h" |
28 #include "net/socket/stream_socket.h" | 27 #include "net/socket/stream_socket.h" |
29 | 28 |
30 using device::UsbConfigDescriptor; | 29 using device::UsbConfigDescriptor; |
31 using device::UsbDevice; | 30 using device::UsbDevice; |
32 using device::UsbDeviceHandle; | 31 using device::UsbDeviceHandle; |
33 using device::UsbInterfaceDescriptor; | 32 using device::UsbInterfaceDescriptor; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 interface.endpoints.size() != 2) { | 66 interface.endpoints.size() != 2) { |
68 return false; | 67 return false; |
69 } | 68 } |
70 return true; | 69 return true; |
71 } | 70 } |
72 | 71 |
73 void CountAndroidDevices(const base::Callback<void(int)>& callback, | 72 void CountAndroidDevices(const base::Callback<void(int)>& callback, |
74 const UsbDevices& devices) { | 73 const UsbDevices& devices) { |
75 int device_count = 0; | 74 int device_count = 0; |
76 for (const scoped_refptr<UsbDevice>& device : devices) { | 75 for (const scoped_refptr<UsbDevice>& device : devices) { |
77 const UsbConfigDescriptor* config = device->GetConfiguration(); | 76 const UsbConfigDescriptor* config = device->GetActiveConfiguration(); |
78 if (config) { | 77 if (config) { |
79 for (const UsbInterfaceDescriptor& iface : config->interfaces) { | 78 for (const UsbInterfaceDescriptor& iface : config->interfaces) { |
80 if (IsAndroidInterface(iface)) { | 79 if (IsAndroidInterface(iface)) { |
81 ++device_count; | 80 ++device_count; |
82 } | 81 } |
83 } | 82 } |
84 } | 83 } |
85 } | 84 } |
86 | 85 |
87 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 86 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 crypto::RSAPrivateKey* rsa_key, | 199 crypto::RSAPrivateKey* rsa_key, |
201 const base::Closure& barrier, | 200 const base::Closure& barrier, |
202 scoped_refptr<UsbDevice> device, | 201 scoped_refptr<UsbDevice> device, |
203 int interface_id) { | 202 int interface_id) { |
204 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 203 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
205 if (device->serial_number().empty()) { | 204 if (device->serial_number().empty()) { |
206 barrier.Run(); | 205 barrier.Run(); |
207 return; | 206 return; |
208 } | 207 } |
209 | 208 |
210 const UsbConfigDescriptor* config = device->GetConfiguration(); | 209 const UsbConfigDescriptor* config = device->GetActiveConfiguration(); |
211 if (!config) { | 210 if (!config) { |
212 barrier.Run(); | 211 barrier.Run(); |
213 return; | 212 return; |
214 } | 213 } |
215 | 214 |
216 const UsbInterfaceDescriptor& interface = config->interfaces[interface_id]; | 215 const UsbInterfaceDescriptor& interface = config->interfaces[interface_id]; |
217 int inbound_address = 0; | 216 int inbound_address = 0; |
218 int outbound_address = 0; | 217 int outbound_address = 0; |
219 int zero_mask = 0; | 218 int zero_mask = 0; |
220 | 219 |
(...skipping 23 matching lines...) Expand all Loading... |
244 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, | 243 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, |
245 const UsbDevices& usb_devices) { | 244 const UsbDevices& usb_devices) { |
246 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 245 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
247 // Add new devices. | 246 // Add new devices. |
248 AndroidUsbDevices* devices = new AndroidUsbDevices(); | 247 AndroidUsbDevices* devices = new AndroidUsbDevices(); |
249 base::Closure barrier = base::BarrierClosure( | 248 base::Closure barrier = base::BarrierClosure( |
250 usb_devices.size(), | 249 usb_devices.size(), |
251 base::Bind(&RespondOnUIThread, callback, devices, caller_task_runner)); | 250 base::Bind(&RespondOnUIThread, callback, devices, caller_task_runner)); |
252 | 251 |
253 for (const scoped_refptr<UsbDevice>& device : usb_devices) { | 252 for (const scoped_refptr<UsbDevice>& device : usb_devices) { |
254 const UsbConfigDescriptor* config = device->GetConfiguration(); | 253 const UsbConfigDescriptor* config = device->GetActiveConfiguration(); |
255 if (!config) { | 254 if (!config) { |
256 barrier.Run(); | 255 barrier.Run(); |
257 continue; | 256 continue; |
258 } | 257 } |
259 bool has_android_interface = false; | 258 bool has_android_interface = false; |
260 for (size_t j = 0; j < config->interfaces.size(); ++j) { | 259 for (size_t j = 0; j < config->interfaces.size(); ++j) { |
261 if (!IsAndroidInterface(config->interfaces[j])) { | 260 if (!IsAndroidInterface(config->interfaces[j])) { |
262 continue; | 261 continue; |
263 } | 262 } |
264 | 263 |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 BrowserThread::PostTask( | 657 BrowserThread::PostTask( |
659 BrowserThread::UI, FROM_HERE, | 658 BrowserThread::UI, FROM_HERE, |
660 base::Bind(&ReleaseInterface, usb_handle, interface_id_)); | 659 base::Bind(&ReleaseInterface, usb_handle, interface_id_)); |
661 } | 660 } |
662 | 661 |
663 void AndroidUsbDevice::SocketDeleted(uint32 socket_id) { | 662 void AndroidUsbDevice::SocketDeleted(uint32 socket_id) { |
664 DCHECK(task_runner_->BelongsToCurrentThread()); | 663 DCHECK(task_runner_->BelongsToCurrentThread()); |
665 | 664 |
666 sockets_.erase(socket_id); | 665 sockets_.erase(socket_id); |
667 } | 666 } |
OLD | NEW |