Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "device/usb/usb_service.h" | 5 #include "device/usb/usb_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <queue> | 10 #include <queue> |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 void GetDevices(const GetDevicesCallback& callback) override; | 49 void GetDevices(const GetDevicesCallback& callback) override; |
| 50 | 50 |
| 51 #if defined(OS_WIN) | 51 #if defined(OS_WIN) |
| 52 // device::DeviceMonitorWin::Observer implementation | 52 // device::DeviceMonitorWin::Observer implementation |
| 53 void OnDeviceAdded(const GUID& class_guid, | 53 void OnDeviceAdded(const GUID& class_guid, |
| 54 const std::string& device_path) override; | 54 const std::string& device_path) override; |
| 55 void OnDeviceRemoved(const GUID& class_guid, | 55 void OnDeviceRemoved(const GUID& class_guid, |
| 56 const std::string& device_path) override; | 56 const std::string& device_path) override; |
| 57 #endif // OS_WIN | 57 #endif // OS_WIN |
| 58 | 58 |
| 59 void OnUsbContext(scoped_refptr<UsbContext> context); | |
| 60 | |
| 59 // Enumerate USB devices from OS and update devices_ map. | 61 // Enumerate USB devices from OS and update devices_ map. |
| 60 void RefreshDevices(); | 62 void RefreshDevices(); |
| 61 void OnDeviceList(libusb_device** platform_devices, size_t device_count); | 63 void OnDeviceList(libusb_device** platform_devices, size_t device_count); |
| 62 void RefreshDevicesComplete(); | 64 void RefreshDevicesComplete(); |
| 63 | 65 |
| 64 // Creates a new UsbDevice based on the given libusb device. | 66 // Creates a new UsbDevice based on the given libusb device. |
| 65 void EnumerateDevice(PlatformUsbDevice platform_device, | 67 void EnumerateDevice(PlatformUsbDevice platform_device, |
| 66 const base::Closure& refresh_complete); | 68 const base::Closure& refresh_complete); |
| 67 | 69 |
| 68 void AddDevice(const base::Closure& refresh_complete, | 70 void AddDevice(const base::Closure& refresh_complete, |
| 69 scoped_refptr<UsbDeviceImpl> device); | 71 scoped_refptr<UsbDeviceImpl> device); |
| 70 void RemoveDevice(scoped_refptr<UsbDeviceImpl> device); | 72 void RemoveDevice(scoped_refptr<UsbDeviceImpl> device); |
| 71 | 73 |
| 72 // Handle hotplug events from libusb. | 74 // Handle hotplug events from libusb. |
| 73 static int LIBUSB_CALL HotplugCallback(libusb_context* context, | 75 static int LIBUSB_CALL HotplugCallback(libusb_context* context, |
| 74 PlatformUsbDevice device, | 76 PlatformUsbDevice device, |
| 75 libusb_hotplug_event event, | 77 libusb_hotplug_event event, |
| 76 void* user_data); | 78 void* user_data); |
| 77 // These functions release a reference to the provided platform device. | 79 // These functions release a reference to the provided platform device. |
| 78 void OnPlatformDeviceAdded(PlatformUsbDevice platform_device); | 80 void OnPlatformDeviceAdded(PlatformUsbDevice platform_device); |
| 79 void OnPlatformDeviceRemoved(PlatformUsbDevice platform_device); | 81 void OnPlatformDeviceRemoved(PlatformUsbDevice platform_device); |
| 80 | 82 |
| 81 // Add |platform_device| to the |ignored_devices_| and | 83 // Add |platform_device| to the |ignored_devices_| and |
| 82 // run |refresh_complete|. | 84 // run |refresh_complete|. |
| 83 void EnumerationFailed(PlatformUsbDevice platform_device, | 85 void EnumerationFailed(PlatformUsbDevice platform_device, |
| 84 const base::Closure& refresh_complete); | 86 const base::Closure& refresh_complete); |
| 85 | 87 |
| 86 scoped_refptr<UsbContext> context_; | 88 scoped_refptr<UsbContext> context_; |
| 89 bool usb_unavailable_ = false; | |
|
juncai
2016/12/08 20:00:39
nit: maybe change the variable name to be:
bool us
Reilly Grant (use Gerrit)
2016/12/08 22:44:39
The reason I named this usb_unavailable_ is becaus
juncai
2016/12/08 23:02:10
I see. Thanks for the explanation.
| |
| 87 | 90 |
| 88 // When available the device list will be updated when new devices are | 91 // When available the device list will be updated when new devices are |
| 89 // connected instead of only when a full enumeration is requested. | 92 // connected instead of only when a full enumeration is requested. |
| 90 // TODO(reillyg): Support this on all platforms. crbug.com/411715 | 93 // TODO(reillyg): Support this on all platforms. crbug.com/411715 |
| 91 bool hotplug_enabled_ = false; | 94 bool hotplug_enabled_ = false; |
| 92 libusb_hotplug_callback_handle hotplug_handle_; | 95 libusb_hotplug_callback_handle hotplug_handle_; |
| 93 | 96 |
| 94 // Enumeration callbacks are queued until an enumeration completes. | 97 // Enumeration callbacks are queued until an enumeration completes. |
| 95 bool enumeration_ready_ = false; | 98 bool enumeration_ready_ = false; |
| 96 bool enumeration_in_progress_ = false; | 99 bool enumeration_in_progress_ = false; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 113 #if defined(OS_WIN) | 116 #if defined(OS_WIN) |
| 114 ScopedObserver<DeviceMonitorWin, DeviceMonitorWin::Observer> device_observer_; | 117 ScopedObserver<DeviceMonitorWin, DeviceMonitorWin::Observer> device_observer_; |
| 115 #endif // OS_WIN | 118 #endif // OS_WIN |
| 116 | 119 |
| 117 base::WeakPtrFactory<UsbServiceImpl> weak_factory_; | 120 base::WeakPtrFactory<UsbServiceImpl> weak_factory_; |
| 118 | 121 |
| 119 DISALLOW_COPY_AND_ASSIGN(UsbServiceImpl); | 122 DISALLOW_COPY_AND_ASSIGN(UsbServiceImpl); |
| 120 }; | 123 }; |
| 121 | 124 |
| 122 } // namespace device | 125 } // namespace device |
| OLD | NEW |