OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/hid/device_monitor_linux.h" | 5 #include "device/hid/device_monitor_linux.h" |
6 | 6 |
| 7 #include <memory> |
| 8 |
7 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
8 #include "base/logging.h" | 10 #include "base/logging.h" |
9 #include "base/threading/thread_restrictions.h" | 11 #include "base/threading/thread_restrictions.h" |
10 #include "device/udev_linux/udev.h" | 12 #include "device/udev_linux/udev.h" |
11 | 13 |
12 namespace device { | 14 namespace device { |
13 | 15 |
14 namespace { | 16 namespace { |
15 | 17 |
16 const char kUdevName[] = "udev"; | 18 const char kUdevName[] = "udev"; |
17 const char kUdevActionAdd[] = "add"; | 19 const char kUdevActionAdd[] = "add"; |
18 const char kUdevActionRemove[] = "remove"; | 20 const char kUdevActionRemove[] = "remove"; |
19 | 21 |
20 // The instance will be reset when message loop destroys. | 22 // The instance will be reset when message loop destroys. |
21 base::LazyInstance<scoped_ptr<DeviceMonitorLinux> >::Leaky | 23 base::LazyInstance<std::unique_ptr<DeviceMonitorLinux>>::Leaky |
22 g_device_monitor_linux_ptr = LAZY_INSTANCE_INITIALIZER; | 24 g_device_monitor_linux_ptr = LAZY_INSTANCE_INITIALIZER; |
23 | 25 |
24 } // namespace | 26 } // namespace |
25 | 27 |
26 DeviceMonitorLinux::DeviceMonitorLinux() : monitor_fd_(-1) { | 28 DeviceMonitorLinux::DeviceMonitorLinux() : monitor_fd_(-1) { |
27 base::ThreadRestrictions::AssertIOAllowed(); | 29 base::ThreadRestrictions::AssertIOAllowed(); |
28 base::MessageLoop::current()->AddDestructionObserver(this); | 30 base::MessageLoop::current()->AddDestructionObserver(this); |
29 | 31 |
30 udev_.reset(udev_new()); | 32 udev_.reset(udev_new()); |
31 if (!udev_) { | 33 if (!udev_) { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 void DeviceMonitorLinux::OnFileCanWriteWithoutBlocking(int fd) {} | 142 void DeviceMonitorLinux::OnFileCanWriteWithoutBlocking(int fd) {} |
141 | 143 |
142 DeviceMonitorLinux::~DeviceMonitorLinux() { | 144 DeviceMonitorLinux::~DeviceMonitorLinux() { |
143 DCHECK(thread_checker_.CalledOnValidThread()); | 145 DCHECK(thread_checker_.CalledOnValidThread()); |
144 base::MessageLoop::current()->RemoveDestructionObserver(this); | 146 base::MessageLoop::current()->RemoveDestructionObserver(this); |
145 monitor_watcher_.StopWatchingFileDescriptor(); | 147 monitor_watcher_.StopWatchingFileDescriptor(); |
146 close(monitor_fd_); | 148 close(monitor_fd_); |
147 } | 149 } |
148 | 150 |
149 } // namespace device | 151 } // namespace device |
OLD | NEW |