[Session restore] Rename group name Enabled to Restore.
[chromium-blink-merge.git] / content / browser / udev_linux.cc
blobdfcb52b9f2e4b37d646649f2a1df50db4beabb8c
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/udev_linux.h"
7 #include "base/message_loop/message_loop.h"
9 namespace content {
11 UdevLinux::UdevLinux(const std::vector<UdevMonitorFilter>& filters,
12 const UdevNotificationCallback& callback)
13 : udev_(device::udev_new()),
14 monitor_(device::udev_monitor_new_from_netlink(udev_.get(), "udev")),
15 monitor_fd_(-1),
16 callback_(callback) {
17 CHECK(udev_);
18 CHECK(monitor_);
20 for (size_t i = 0; i < filters.size(); ++i) {
21 int ret = device::udev_monitor_filter_add_match_subsystem_devtype(
22 monitor_.get(), filters[i].subsystem, filters[i].devtype);
23 CHECK_EQ(0, ret);
26 int ret = device::udev_monitor_enable_receiving(monitor_.get());
27 CHECK_EQ(0, ret);
28 monitor_fd_ = device::udev_monitor_get_fd(monitor_.get());
29 CHECK_GE(monitor_fd_, 0);
31 bool success = base::MessageLoopForIO::current()->WatchFileDescriptor(
32 monitor_fd_,
33 true,
34 base::MessageLoopForIO::WATCH_READ,
35 &monitor_watcher_,
36 this);
37 CHECK(success);
40 UdevLinux::~UdevLinux() {
41 monitor_watcher_.StopWatchingFileDescriptor();
44 udev* UdevLinux::udev_handle() {
45 return udev_.get();
48 void UdevLinux::OnFileCanReadWithoutBlocking(int fd) {
49 // Events occur when devices attached to the system are added, removed, or
50 // change state. udev_monitor_receive_device() will return a device object
51 // representing the device which changed and what type of change occured.
52 DCHECK_EQ(monitor_fd_, fd);
53 device::ScopedUdevDevicePtr dev(
54 device::udev_monitor_receive_device(monitor_.get()));
55 if (!dev)
56 return;
58 callback_.Run(dev.get());
61 void UdevLinux::OnFileCanWriteWithoutBlocking(int fd) {
64 } // namespace content