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 {
void Start() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
watcher_ = UdevWatcher::StartWatching(this);
watcher_ = UdevWatcher::StartWatching(
this, {UdevWatcher::Filter(kSubsystemHidraw, "")});
watcher_->EnumerateExistingDevices();
task_runner_->PostTask(
FROM_HERE,
......@@ -224,9 +225,11 @@ class HidServiceLinux::BlockingTaskRunnerHelper : public UdevWatcher::Observer {
return;
HidPlatformDeviceId platform_device_id = device_path;
#if DCHECK_IS_ON()
const char* subsystem = udev_device_get_subsystem(device.get());
if (!subsystem || strcmp(subsystem, kSubsystemHidraw) != 0)
return;
DCHECK(subsystem);
DCHECK_EQ(base::StringPiece(subsystem), kSubsystemHidraw);
#endif
const char* str_property = udev_device_get_devnode(device.get());
if (!str_property)
......
......@@ -22,6 +22,8 @@ namespace device {
namespace {
constexpr char kSubsystemTty[] = "tty";
// 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.
struct SerialDriverInfo {
......@@ -84,7 +86,8 @@ std::vector<SerialDriverInfo> ReadSerialDriverInfo() {
SerialDeviceEnumeratorLinux::SerialDeviceEnumeratorLinux() {
DETACH_FROM_SEQUENCE(sequence_checker_);
watcher_ = UdevWatcher::StartWatching(this);
watcher_ = UdevWatcher::StartWatching(
this, {UdevWatcher::Filter(kSubsystemTty, "")});
watcher_->EnumerateExistingDevices();
}
......@@ -97,9 +100,11 @@ void SerialDeviceEnumeratorLinux::OnDeviceAdded(ScopedUdevDevicePtr device) {
base::ScopedBlockingCall scoped_blocking_call(FROM_HERE,
base::BlockingType::MAY_BLOCK);
#if DCHECK_IS_ON()
const char* subsystem = udev_device_get_subsystem(device.get());
if (!subsystem || strcmp(subsystem, "tty") != 0)
return;
DCHECK(subsystem);
DCHECK_EQ(base::StringPiece(subsystem), kSubsystemTty);
#endif
const char* syspath_str = udev_device_get_syspath(device.get());
if (!syspath_str)
......
......@@ -34,6 +34,8 @@ namespace device {
namespace {
constexpr char kSubsystemUsb[] = "usb";
// Standard USB requests and descriptor types:
const uint16_t kUsbVersion2_1 = 0x0210;
......@@ -109,7 +111,8 @@ void UsbServiceLinux::BlockingTaskRunnerHelper::Start() {
// Initializing udev for device enumeration and monitoring may fail. In that
// 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_)
watcher_->EnumerateExistingDevices();
......@@ -123,9 +126,12 @@ void UsbServiceLinux::BlockingTaskRunnerHelper::OnDeviceAdded(
base::ScopedBlockingCall scoped_blocking_call(FROM_HERE,
base::BlockingType::MAY_BLOCK);
#if DCHECK_IS_ON()
const char* subsystem = udev_device_get_subsystem(device.get());
if (!subsystem || strcmp(subsystem, "usb") != 0)
return;
DCHECK(subsystem);
DCHECK_EQ(base::StringPiece(subsystem), kSubsystemUsb);
#endif
const char* value = udev_device_get_devnode(device.get());
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