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/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.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 "chrome/browser/devtools/device/usb/android_rsa.h" | 17 #include "chrome/browser/devtools/device/usb/android_rsa.h" |
18 #include "chrome/browser/devtools/device/usb/android_usb_socket.h" | 18 #include "chrome/browser/devtools/device/usb/android_usb_socket.h" |
19 #include "components/usb_service/usb_device.h" | 19 #include "components/usb_service/usb_device.h" |
20 #include "components/usb_service/usb_interface.h" | 20 #include "components/usb_service/usb_interface.h" |
21 #include "components/usb_service/usb_service.h" | 21 #include "components/usb_service/usb_service.h" |
22 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
23 #include "crypto/rsa_private_key.h" | 23 #include "crypto/rsa_private_key.h" |
| 24 #include "device/core/device_client.h" |
24 #include "net/base/ip_endpoint.h" | 25 #include "net/base/ip_endpoint.h" |
25 #include "net/base/net_errors.h" | 26 #include "net/base/net_errors.h" |
26 #include "net/socket/stream_socket.h" | 27 #include "net/socket/stream_socket.h" |
27 | 28 |
28 using usb_service::UsbConfigDescriptor; | 29 using usb_service::UsbConfigDescriptor; |
29 using usb_service::UsbDevice; | 30 using usb_service::UsbDevice; |
30 using usb_service::UsbDeviceHandle; | 31 using usb_service::UsbDeviceHandle; |
31 using usb_service::UsbInterfaceAltSettingDescriptor; | 32 using usb_service::UsbInterfaceAltSettingDescriptor; |
32 using usb_service::UsbInterfaceDescriptor; | 33 using usb_service::UsbInterfaceDescriptor; |
33 using usb_service::UsbEndpointDescriptor; | 34 using usb_service::UsbEndpointDescriptor; |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 devices->push_back(android_device.get()); | 218 devices->push_back(android_device.get()); |
218 else | 219 else |
219 usb_handle->Close(); | 220 usb_handle->Close(); |
220 } | 221 } |
221 } | 222 } |
222 barrier.Run(); | 223 barrier.Run(); |
223 } | 224 } |
224 | 225 |
225 static int CountOnFileThread() { | 226 static int CountOnFileThread() { |
226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 227 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
227 UsbService* service = UsbService::GetInstance(); | 228 UsbService* service = device::DeviceClient::Get()->GetUsbService(); |
228 UsbDevices usb_devices; | 229 UsbDevices usb_devices; |
229 if (service != NULL) | 230 if (service != NULL) |
230 service->GetDevices(&usb_devices); | 231 service->GetDevices(&usb_devices); |
231 int device_count = 0; | 232 int device_count = 0; |
232 for (UsbDevices::iterator it = usb_devices.begin(); it != usb_devices.end(); | 233 for (UsbDevices::iterator it = usb_devices.begin(); it != usb_devices.end(); |
233 ++it) { | 234 ++it) { |
234 scoped_refptr<UsbConfigDescriptor> config = (*it)->ListInterfaces(); | 235 scoped_refptr<UsbConfigDescriptor> config = (*it)->ListInterfaces(); |
235 if (!config.get()) | 236 if (!config.get()) |
236 continue; | 237 continue; |
237 | 238 |
238 for (size_t j = 0; j < config->GetNumInterfaces(); ++j) { | 239 for (size_t j = 0; j < config->GetNumInterfaces(); ++j) { |
239 if (IsAndroidInterface(config->GetInterface(j))) | 240 if (IsAndroidInterface(config->GetInterface(j))) |
240 ++device_count; | 241 ++device_count; |
241 } | 242 } |
242 } | 243 } |
243 return device_count; | 244 return device_count; |
244 } | 245 } |
245 | 246 |
246 static void EnumerateOnFileThread( | 247 static void EnumerateOnFileThread( |
247 crypto::RSAPrivateKey* rsa_key, | 248 crypto::RSAPrivateKey* rsa_key, |
248 const AndroidUsbDevicesCallback& callback, | 249 const AndroidUsbDevicesCallback& callback, |
249 scoped_refptr<base::MessageLoopProxy> caller_message_loop_proxy) { | 250 scoped_refptr<base::MessageLoopProxy> caller_message_loop_proxy) { |
250 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 251 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
251 | 252 |
252 UsbService* service = UsbService::GetInstance(); | 253 UsbService* service = device::DeviceClient::Get()->GetUsbService(); |
253 UsbDevices usb_devices; | 254 UsbDevices usb_devices; |
254 if (service != NULL) | 255 if (service != NULL) |
255 service->GetDevices(&usb_devices); | 256 service->GetDevices(&usb_devices); |
256 | 257 |
257 // Add new devices. | 258 // Add new devices. |
258 AndroidUsbDevices* devices = new AndroidUsbDevices(); | 259 AndroidUsbDevices* devices = new AndroidUsbDevices(); |
259 base::Closure barrier = base::BarrierClosure( | 260 base::Closure barrier = base::BarrierClosure( |
260 usb_devices.size(), base::Bind(&RespondOnFileThread, | 261 usb_devices.size(), base::Bind(&RespondOnFileThread, |
261 callback, | 262 callback, |
262 devices, | 263 devices, |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 BrowserThread::PostTask( | 655 BrowserThread::PostTask( |
655 BrowserThread::FILE, FROM_HERE, | 656 BrowserThread::FILE, FROM_HERE, |
656 base::Bind(&ReleaseInterface, usb_handle, interface_id_)); | 657 base::Bind(&ReleaseInterface, usb_handle, interface_id_)); |
657 } | 658 } |
658 | 659 |
659 void AndroidUsbDevice::SocketDeleted(uint32 socket_id) { | 660 void AndroidUsbDevice::SocketDeleted(uint32 socket_id) { |
660 DCHECK(message_loop_ == base::MessageLoop::current()); | 661 DCHECK(message_loop_ == base::MessageLoop::current()); |
661 | 662 |
662 sockets_.erase(socket_id); | 663 sockets_.erase(socket_id); |
663 } | 664 } |
OLD | NEW |