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

Unified Diff: device/udev_linux/udev_linux.cc

Issue 2392583002: Use FileDescriptorWatcher in UdevLinux (Closed)
Patch Set: fix build error Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/udev_linux/udev_linux.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/udev_linux/udev_linux.cc
diff --git a/device/udev_linux/udev_linux.cc b/device/udev_linux/udev_linux.cc
index 7fbd3b35ec8f0deeb974ee3f155ca13b52991167..bce88a1115719c75c858aaf1cdf23bbc52da56ce 100644
--- a/device/udev_linux/udev_linux.cc
+++ b/device/udev_linux/udev_linux.cc
@@ -6,7 +6,7 @@
#include <stddef.h>
-#include "base/message_loop/message_loop.h"
+#include "base/bind.h"
namespace device {
@@ -18,7 +18,6 @@ UdevLinux::UdevLinux(const std::vector<UdevMonitorFilter>& filters,
callback_(callback) {
CHECK(udev_);
CHECK(monitor_);
- CHECK_EQ(base::MessageLoop::TYPE_IO, base::MessageLoop::current()->type());
for (const UdevMonitorFilter& filter : filters) {
const int ret = udev_monitor_filter_add_match_subsystem_devtype(
@@ -31,25 +30,21 @@ UdevLinux::UdevLinux(const std::vector<UdevMonitorFilter>& filters,
monitor_fd_ = udev_monitor_get_fd(monitor_.get());
CHECK_GE(monitor_fd_, 0);
- bool success = base::MessageLoopForIO::current()->WatchFileDescriptor(
- monitor_fd_, true, base::MessageLoopForIO::WATCH_READ, &monitor_watcher_,
- this);
- CHECK(success);
+ monitor_watch_controller_ = base::FileDescriptorWatcher::WatchReadable(
+ monitor_fd_, base::Bind(&UdevLinux::OnMonitorCanReadWithoutBlocking,
+ base::Unretained(this)));
}
-UdevLinux::~UdevLinux() {
- monitor_watcher_.StopWatchingFileDescriptor();
-}
+UdevLinux::~UdevLinux() = default;
udev* UdevLinux::udev_handle() {
return udev_.get();
}
-void UdevLinux::OnFileCanReadWithoutBlocking(int fd) {
+void UdevLinux::OnMonitorCanReadWithoutBlocking() {
// Events occur when devices attached to the system are added, removed, or
// change state. udev_monitor_receive_device() will return a device object
// representing the device which changed and what type of change occured.
- DCHECK_EQ(monitor_fd_, fd);
ScopedUdevDevicePtr dev(udev_monitor_receive_device(monitor_.get()));
if (!dev)
return;
@@ -57,6 +52,4 @@ void UdevLinux::OnFileCanReadWithoutBlocking(int fd) {
callback_.Run(dev.get());
}
-void UdevLinux::OnFileCanWriteWithoutBlocking(int fd) {}
-
} // namespace device
« no previous file with comments | « device/udev_linux/udev_linux.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698