Commit 35f83455 authored by Reilly Grant's avatar Reilly Grant Committed by Commit Bot

Use UdevWatcher to filter USB, HID and serial devices

UsbServiceLinux, HidServiceLinux and SerialDeviceEnumeratorLinux each
only care about devices from a particular subsystem. This change avoids
processing other devices which should decrease the time it takes to
perform the initial enumeration.

Change-Id: I3535b5e6ecbb8c013957197cff151011a19a6097
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2227094
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Commit-Queue: Matt Reynolds <mattreynolds@chromium.org>
Reviewed-by: default avatarMatt Reynolds <mattreynolds@chromium.org>
Auto-Submit: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#774416}
parent dbc0e087
...@@ -205,7 +205,8 @@ class HidServiceLinux::BlockingTaskRunnerHelper : public UdevWatcher::Observer { ...@@ -205,7 +205,8 @@ class HidServiceLinux::BlockingTaskRunnerHelper : public UdevWatcher::Observer {
void Start() { void Start() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
watcher_ = UdevWatcher::StartWatching(this); watcher_ = UdevWatcher::StartWatching(
this, {UdevWatcher::Filter(kSubsystemHidraw, "")});
watcher_->EnumerateExistingDevices(); watcher_->EnumerateExistingDevices();
task_runner_->PostTask( task_runner_->PostTask(
FROM_HERE, FROM_HERE,
...@@ -224,9 +225,11 @@ class HidServiceLinux::BlockingTaskRunnerHelper : public UdevWatcher::Observer { ...@@ -224,9 +225,11 @@ class HidServiceLinux::BlockingTaskRunnerHelper : public UdevWatcher::Observer {
return; return;
HidPlatformDeviceId platform_device_id = device_path; HidPlatformDeviceId platform_device_id = device_path;
#if DCHECK_IS_ON()
const char* subsystem = udev_device_get_subsystem(device.get()); const char* subsystem = udev_device_get_subsystem(device.get());
if (!subsystem || strcmp(subsystem, kSubsystemHidraw) != 0) DCHECK(subsystem);
return; DCHECK_EQ(base::StringPiece(subsystem), kSubsystemHidraw);
#endif
const char* str_property = udev_device_get_devnode(device.get()); const char* str_property = udev_device_get_devnode(device.get());
if (!str_property) if (!str_property)
......
...@@ -22,6 +22,8 @@ namespace device { ...@@ -22,6 +22,8 @@ namespace device {
namespace { namespace {
constexpr char kSubsystemTty[] = "tty";
// Holds information about a TTY driver for serial devices. Each driver creates // Holds information about a TTY driver for serial devices. Each driver creates
// device nodes with a given major number and in a range of minor numbers. // device nodes with a given major number and in a range of minor numbers.
struct SerialDriverInfo { struct SerialDriverInfo {
...@@ -84,7 +86,8 @@ std::vector<SerialDriverInfo> ReadSerialDriverInfo() { ...@@ -84,7 +86,8 @@ std::vector<SerialDriverInfo> ReadSerialDriverInfo() {
SerialDeviceEnumeratorLinux::SerialDeviceEnumeratorLinux() { SerialDeviceEnumeratorLinux::SerialDeviceEnumeratorLinux() {
DETACH_FROM_SEQUENCE(sequence_checker_); DETACH_FROM_SEQUENCE(sequence_checker_);
watcher_ = UdevWatcher::StartWatching(this); watcher_ = UdevWatcher::StartWatching(
this, {UdevWatcher::Filter(kSubsystemTty, "")});
watcher_->EnumerateExistingDevices(); watcher_->EnumerateExistingDevices();
} }
...@@ -97,9 +100,11 @@ void SerialDeviceEnumeratorLinux::OnDeviceAdded(ScopedUdevDevicePtr device) { ...@@ -97,9 +100,11 @@ void SerialDeviceEnumeratorLinux::OnDeviceAdded(ScopedUdevDevicePtr device) {
base::ScopedBlockingCall scoped_blocking_call(FROM_HERE, base::ScopedBlockingCall scoped_blocking_call(FROM_HERE,
base::BlockingType::MAY_BLOCK); base::BlockingType::MAY_BLOCK);
#if DCHECK_IS_ON()
const char* subsystem = udev_device_get_subsystem(device.get()); const char* subsystem = udev_device_get_subsystem(device.get());
if (!subsystem || strcmp(subsystem, "tty") != 0) DCHECK(subsystem);
return; DCHECK_EQ(base::StringPiece(subsystem), kSubsystemTty);
#endif
const char* syspath_str = udev_device_get_syspath(device.get()); const char* syspath_str = udev_device_get_syspath(device.get());
if (!syspath_str) if (!syspath_str)
......
...@@ -34,6 +34,8 @@ namespace device { ...@@ -34,6 +34,8 @@ namespace device {
namespace { namespace {
constexpr char kSubsystemUsb[] = "usb";
// Standard USB requests and descriptor types: // Standard USB requests and descriptor types:
const uint16_t kUsbVersion2_1 = 0x0210; const uint16_t kUsbVersion2_1 = 0x0210;
...@@ -109,7 +111,8 @@ void UsbServiceLinux::BlockingTaskRunnerHelper::Start() { ...@@ -109,7 +111,8 @@ void UsbServiceLinux::BlockingTaskRunnerHelper::Start() {
// Initializing udev for device enumeration and monitoring may fail. In that // Initializing udev for device enumeration and monitoring may fail. In that
// case this service will continue to exist but no devices will be found. // case this service will continue to exist but no devices will be found.
watcher_ = UdevWatcher::StartWatching(this); watcher_ = UdevWatcher::StartWatching(
this, {UdevWatcher::Filter(kSubsystemUsb, "")});
if (watcher_) if (watcher_)
watcher_->EnumerateExistingDevices(); watcher_->EnumerateExistingDevices();
...@@ -123,9 +126,12 @@ void UsbServiceLinux::BlockingTaskRunnerHelper::OnDeviceAdded( ...@@ -123,9 +126,12 @@ void UsbServiceLinux::BlockingTaskRunnerHelper::OnDeviceAdded(
base::ScopedBlockingCall scoped_blocking_call(FROM_HERE, base::ScopedBlockingCall scoped_blocking_call(FROM_HERE,
base::BlockingType::MAY_BLOCK); base::BlockingType::MAY_BLOCK);
#if DCHECK_IS_ON()
const char* subsystem = udev_device_get_subsystem(device.get()); const char* subsystem = udev_device_get_subsystem(device.get());
if (!subsystem || strcmp(subsystem, "usb") != 0) DCHECK(subsystem);
return; DCHECK_EQ(base::StringPiece(subsystem), kSubsystemUsb);
#endif
const char* value = udev_device_get_devnode(device.get()); const char* value = udev_device_get_devnode(device.get());
if (!value) if (!value)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment