| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 | 73 |
| 74 // Handle hotplug events from libusb. | 74 // Handle hotplug events from libusb. |
| 75 static int LIBUSB_CALL HotplugCallback(libusb_context* context, | 75 static int LIBUSB_CALL HotplugCallback(libusb_context* context, |
| 76 PlatformUsbDevice device, | 76 PlatformUsbDevice device, |
| 77 libusb_hotplug_event event, | 77 libusb_hotplug_event event, |
| 78 void* user_data); | 78 void* user_data); |
| 79 // These functions release a reference to the provided platform device. | 79 // These functions release a reference to the provided platform device. |
| 80 void OnPlatformDeviceAdded(PlatformUsbDevice platform_device); | 80 void OnPlatformDeviceAdded(PlatformUsbDevice platform_device); |
| 81 void OnPlatformDeviceRemoved(PlatformUsbDevice platform_device); | 81 void OnPlatformDeviceRemoved(PlatformUsbDevice platform_device); |
| 82 | 82 |
| 83 // Add |platform_device| to the |ignored_devices_| and |
| 84 // run |refresh_complete|. |
| 85 void EnumerationFailed(PlatformUsbDevice platform_device, |
| 86 const base::Closure& refresh_complete); |
| 87 |
| 83 scoped_refptr<UsbContext> context_; | 88 scoped_refptr<UsbContext> context_; |
| 84 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 89 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 85 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 90 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
| 86 | 91 |
| 87 // When available the device list will be updated when new devices are | 92 // When available the device list will be updated when new devices are |
| 88 // connected instead of only when a full enumeration is requested. | 93 // connected instead of only when a full enumeration is requested. |
| 89 // TODO(reillyg): Support this on all platforms. crbug.com/411715 | 94 // TODO(reillyg): Support this on all platforms. crbug.com/411715 |
| 90 bool hotplug_enabled_ = false; | 95 bool hotplug_enabled_ = false; |
| 91 libusb_hotplug_callback_handle hotplug_handle_; | 96 libusb_hotplug_callback_handle hotplug_handle_; |
| 92 | 97 |
| 93 // Enumeration callbacks are queued until an enumeration completes. | 98 // Enumeration callbacks are queued until an enumeration completes. |
| 94 bool enumeration_ready_ = false; | 99 bool enumeration_ready_ = false; |
| 95 bool enumeration_in_progress_ = false; | 100 bool enumeration_in_progress_ = false; |
| 96 std::queue<std::string> pending_path_enumerations_; | 101 std::queue<std::string> pending_path_enumerations_; |
| 97 std::vector<GetDevicesCallback> pending_enumeration_callbacks_; | 102 std::vector<GetDevicesCallback> pending_enumeration_callbacks_; |
| 98 | 103 |
| 99 // The map from unique IDs to UsbDevices. | 104 // The map from unique IDs to UsbDevices. |
| 100 typedef std::map<std::string, scoped_refptr<UsbDeviceImpl>> DeviceMap; | 105 typedef std::map<std::string, scoped_refptr<UsbDeviceImpl>> DeviceMap; |
| 101 DeviceMap devices_; | 106 DeviceMap devices_; |
| 102 | 107 |
| 103 // The map from PlatformUsbDevices to UsbDevices. | 108 // The map from PlatformUsbDevices to UsbDevices. |
| 104 typedef std::map<PlatformUsbDevice, scoped_refptr<UsbDeviceImpl>> | 109 typedef std::map<PlatformUsbDevice, scoped_refptr<UsbDeviceImpl>> |
| 105 PlatformDeviceMap; | 110 PlatformDeviceMap; |
| 106 PlatformDeviceMap platform_devices_; | 111 PlatformDeviceMap platform_devices_; |
| 107 | 112 |
| 113 // The set of devices that only need to be enumerated once and then can be |
| 114 // ignored (for example, hub devices, devices that failed enumeration, etc.). |
| 115 std::set<PlatformUsbDevice> ignored_devices_; |
| 116 |
| 108 // Tracks PlatformUsbDevices that might be removed while they are being | 117 // Tracks PlatformUsbDevices that might be removed while they are being |
| 109 // enumerated. | 118 // enumerated. |
| 110 std::set<PlatformUsbDevice> devices_being_enumerated_; | 119 std::set<PlatformUsbDevice> devices_being_enumerated_; |
| 111 | 120 |
| 112 #if defined(OS_WIN) | 121 #if defined(OS_WIN) |
| 113 ScopedObserver<DeviceMonitorWin, DeviceMonitorWin::Observer> device_observer_; | 122 ScopedObserver<DeviceMonitorWin, DeviceMonitorWin::Observer> device_observer_; |
| 114 #endif // OS_WIN | 123 #endif // OS_WIN |
| 115 | 124 |
| 116 base::WeakPtrFactory<UsbServiceImpl> weak_factory_; | 125 base::WeakPtrFactory<UsbServiceImpl> weak_factory_; |
| 117 | 126 |
| 118 DISALLOW_COPY_AND_ASSIGN(UsbServiceImpl); | 127 DISALLOW_COPY_AND_ASSIGN(UsbServiceImpl); |
| 119 }; | 128 }; |
| 120 | 129 |
| 121 } // namespace device | 130 } // namespace device |
| OLD | NEW |