| 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" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 interface.endpoints.size() != 2) { | 67 interface.endpoints.size() != 2) { |
| 68 return false; | 68 return false; |
| 69 } | 69 } |
| 70 return true; | 70 return true; |
| 71 } | 71 } |
| 72 | 72 |
| 73 void CountAndroidDevices(const base::Callback<void(int)>& callback, | 73 void CountAndroidDevices(const base::Callback<void(int)>& callback, |
| 74 const UsbDevices& devices) { | 74 const UsbDevices& devices) { |
| 75 int device_count = 0; | 75 int device_count = 0; |
| 76 for (const scoped_refptr<UsbDevice>& device : devices) { | 76 for (const scoped_refptr<UsbDevice>& device : devices) { |
| 77 const UsbConfigDescriptor* config = device->GetConfiguration(); | 77 const UsbConfigDescriptor* config = device->GetActiveConfiguration(); |
| 78 if (config) { | 78 if (config) { |
| 79 for (const UsbInterfaceDescriptor& iface : config->interfaces) { | 79 for (const UsbInterfaceDescriptor& iface : config->interfaces) { |
| 80 if (IsAndroidInterface(iface)) { | 80 if (IsAndroidInterface(iface)) { |
| 81 ++device_count; | 81 ++device_count; |
| 82 } | 82 } |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 | 86 |
| 87 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 87 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 crypto::RSAPrivateKey* rsa_key, | 200 crypto::RSAPrivateKey* rsa_key, |
| 201 const base::Closure& barrier, | 201 const base::Closure& barrier, |
| 202 scoped_refptr<UsbDevice> device, | 202 scoped_refptr<UsbDevice> device, |
| 203 int interface_id) { | 203 int interface_id) { |
| 204 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 204 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 205 if (device->serial_number().empty()) { | 205 if (device->serial_number().empty()) { |
| 206 barrier.Run(); | 206 barrier.Run(); |
| 207 return; | 207 return; |
| 208 } | 208 } |
| 209 | 209 |
| 210 const UsbConfigDescriptor* config = device->GetConfiguration(); | 210 const UsbConfigDescriptor* config = device->GetActiveConfiguration(); |
| 211 if (!config) { | 211 if (!config) { |
| 212 barrier.Run(); | 212 barrier.Run(); |
| 213 return; | 213 return; |
| 214 } | 214 } |
| 215 | 215 |
| 216 const UsbInterfaceDescriptor& interface = config->interfaces[interface_id]; | 216 const UsbInterfaceDescriptor& interface = config->interfaces[interface_id]; |
| 217 int inbound_address = 0; | 217 int inbound_address = 0; |
| 218 int outbound_address = 0; | 218 int outbound_address = 0; |
| 219 int zero_mask = 0; | 219 int zero_mask = 0; |
| 220 | 220 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 244 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, | 244 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, |
| 245 const UsbDevices& usb_devices) { | 245 const UsbDevices& usb_devices) { |
| 246 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 246 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 247 // Add new devices. | 247 // Add new devices. |
| 248 AndroidUsbDevices* devices = new AndroidUsbDevices(); | 248 AndroidUsbDevices* devices = new AndroidUsbDevices(); |
| 249 base::Closure barrier = base::BarrierClosure( | 249 base::Closure barrier = base::BarrierClosure( |
| 250 usb_devices.size(), | 250 usb_devices.size(), |
| 251 base::Bind(&RespondOnUIThread, callback, devices, caller_task_runner)); | 251 base::Bind(&RespondOnUIThread, callback, devices, caller_task_runner)); |
| 252 | 252 |
| 253 for (const scoped_refptr<UsbDevice>& device : usb_devices) { | 253 for (const scoped_refptr<UsbDevice>& device : usb_devices) { |
| 254 const UsbConfigDescriptor* config = device->GetConfiguration(); | 254 const UsbConfigDescriptor* config = device->GetActiveConfiguration(); |
| 255 if (!config) { | 255 if (!config) { |
| 256 barrier.Run(); | 256 barrier.Run(); |
| 257 continue; | 257 continue; |
| 258 } | 258 } |
| 259 bool has_android_interface = false; | 259 bool has_android_interface = false; |
| 260 for (size_t j = 0; j < config->interfaces.size(); ++j) { | 260 for (size_t j = 0; j < config->interfaces.size(); ++j) { |
| 261 if (!IsAndroidInterface(config->interfaces[j])) { | 261 if (!IsAndroidInterface(config->interfaces[j])) { |
| 262 continue; | 262 continue; |
| 263 } | 263 } |
| 264 | 264 |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 BrowserThread::PostTask( | 658 BrowserThread::PostTask( |
| 659 BrowserThread::UI, FROM_HERE, | 659 BrowserThread::UI, FROM_HERE, |
| 660 base::Bind(&ReleaseInterface, usb_handle, interface_id_)); | 660 base::Bind(&ReleaseInterface, usb_handle, interface_id_)); |
| 661 } | 661 } |
| 662 | 662 |
| 663 void AndroidUsbDevice::SocketDeleted(uint32 socket_id) { | 663 void AndroidUsbDevice::SocketDeleted(uint32 socket_id) { |
| 664 DCHECK(task_runner_->BelongsToCurrentThread()); | 664 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 665 | 665 |
| 666 sockets_.erase(socket_id); | 666 sockets_.erase(socket_id); |
| 667 } | 667 } |
| OLD | NEW |