Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: device/usb/usb_service_impl.h

Issue 1903933002: Store devices that only need to be enumerated once (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address reillyg@'s comment Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | device/usb/usb_service_impl.cc » ('j') | device/usb/usb_service_impl.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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_|.
84 void AddIgnoredDevice(PlatformUsbDevice platform_device);
85
83 scoped_refptr<UsbContext> context_; 86 scoped_refptr<UsbContext> context_;
84 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 87 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
85 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; 88 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
86 89
87 // When available the device list will be updated when new devices are 90 // When available the device list will be updated when new devices are
88 // connected instead of only when a full enumeration is requested. 91 // connected instead of only when a full enumeration is requested.
89 // TODO(reillyg): Support this on all platforms. crbug.com/411715 92 // TODO(reillyg): Support this on all platforms. crbug.com/411715
90 bool hotplug_enabled_ = false; 93 bool hotplug_enabled_ = false;
91 libusb_hotplug_callback_handle hotplug_handle_; 94 libusb_hotplug_callback_handle hotplug_handle_;
92 95
93 // Enumeration callbacks are queued until an enumeration completes. 96 // Enumeration callbacks are queued until an enumeration completes.
94 bool enumeration_ready_ = false; 97 bool enumeration_ready_ = false;
95 bool enumeration_in_progress_ = false; 98 bool enumeration_in_progress_ = false;
96 std::queue<std::string> pending_path_enumerations_; 99 std::queue<std::string> pending_path_enumerations_;
97 std::vector<GetDevicesCallback> pending_enumeration_callbacks_; 100 std::vector<GetDevicesCallback> pending_enumeration_callbacks_;
98 101
99 // The map from unique IDs to UsbDevices. 102 // The map from unique IDs to UsbDevices.
100 typedef std::map<std::string, scoped_refptr<UsbDeviceImpl>> DeviceMap; 103 typedef std::map<std::string, scoped_refptr<UsbDeviceImpl>> DeviceMap;
101 DeviceMap devices_; 104 DeviceMap devices_;
102 105
103 // The map from PlatformUsbDevices to UsbDevices. 106 // The map from PlatformUsbDevices to UsbDevices.
104 typedef std::map<PlatformUsbDevice, scoped_refptr<UsbDeviceImpl>> 107 typedef std::map<PlatformUsbDevice, scoped_refptr<UsbDeviceImpl>>
105 PlatformDeviceMap; 108 PlatformDeviceMap;
106 PlatformDeviceMap platform_devices_; 109 PlatformDeviceMap platform_devices_;
107 110
111 // The set of devices that only need to be enumerated once and then can be
112 // ignored (for example, hub devices, devices that failed enumeration, etc.).
113 std::set<PlatformUsbDevice> ignored_devices_;
114
108 // Tracks PlatformUsbDevices that might be removed while they are being 115 // Tracks PlatformUsbDevices that might be removed while they are being
109 // enumerated. 116 // enumerated.
110 std::set<PlatformUsbDevice> devices_being_enumerated_; 117 std::set<PlatformUsbDevice> devices_being_enumerated_;
111 118
112 #if defined(OS_WIN) 119 #if defined(OS_WIN)
113 ScopedObserver<DeviceMonitorWin, DeviceMonitorWin::Observer> device_observer_; 120 ScopedObserver<DeviceMonitorWin, DeviceMonitorWin::Observer> device_observer_;
114 #endif // OS_WIN 121 #endif // OS_WIN
115 122
116 base::WeakPtrFactory<UsbServiceImpl> weak_factory_; 123 base::WeakPtrFactory<UsbServiceImpl> weak_factory_;
117 124
118 DISALLOW_COPY_AND_ASSIGN(UsbServiceImpl); 125 DISALLOW_COPY_AND_ASSIGN(UsbServiceImpl);
119 }; 126 };
120 127
121 } // namespace device 128 } // namespace device
OLDNEW
« no previous file with comments | « no previous file | device/usb/usb_service_impl.cc » ('j') | device/usb/usb_service_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698