| 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 #ifndef DEVICE_BASE_DEVICE_MONITOR_LINUX_H_ | 5 #ifndef DEVICE_BASE_DEVICE_MONITOR_LINUX_H_ |
| 6 #define DEVICE_BASE_DEVICE_MONITOR_LINUX_H_ | 6 #define DEVICE_BASE_DEVICE_MONITOR_LINUX_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/files/file_descriptor_watcher_posix.h" | 11 #include "base/files/file_descriptor_watcher_posix.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/message_loop/message_loop.h" | |
| 14 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 15 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
| 16 #include "device/base/device_base_export.h" | 15 #include "device/base/device_base_export.h" |
| 17 #include "device/udev_linux/scoped_udev.h" | 16 #include "device/udev_linux/scoped_udev.h" |
| 18 | 17 |
| 19 struct udev_device; | 18 struct udev_device; |
| 20 | 19 |
| 21 namespace device { | 20 namespace device { |
| 22 | 21 |
| 23 // This class listends for notifications from libudev about | 22 // This class listends for notifications from libudev about |
| 24 // connected/disconnected devices. This class is *NOT* thread-safe. | 23 // connected/disconnected devices. This class is *NOT* thread-safe. |
| 25 class DEVICE_BASE_EXPORT DeviceMonitorLinux | 24 class DEVICE_BASE_EXPORT DeviceMonitorLinux { |
| 26 : public base::MessageLoop::DestructionObserver { | |
| 27 public: | 25 public: |
| 28 typedef base::Callback<void(udev_device* device)> EnumerateCallback; | 26 typedef base::Callback<void(udev_device* device)> EnumerateCallback; |
| 29 | 27 |
| 30 class Observer { | 28 class Observer { |
| 31 public: | 29 public: |
| 32 virtual ~Observer() {} | 30 virtual ~Observer() {} |
| 33 virtual void OnDeviceAdded(udev_device* device) = 0; | 31 virtual void OnDeviceAdded(udev_device* device) = 0; |
| 34 virtual void OnDeviceRemoved(udev_device* device) = 0; | 32 virtual void OnDeviceRemoved(udev_device* device) = 0; |
| 35 virtual void WillDestroyMonitorMessageLoop() = 0; | |
| 36 }; | 33 }; |
| 37 | 34 |
| 38 DeviceMonitorLinux(); | 35 DeviceMonitorLinux(); |
| 39 | 36 |
| 40 static DeviceMonitorLinux* GetInstance(); | 37 static DeviceMonitorLinux* GetInstance(); |
| 41 | 38 |
| 42 void AddObserver(Observer* observer); | 39 void AddObserver(Observer* observer); |
| 43 void RemoveObserver(Observer* observer); | 40 void RemoveObserver(Observer* observer); |
| 44 | 41 |
| 45 void Enumerate(const EnumerateCallback& callback); | 42 void Enumerate(const EnumerateCallback& callback); |
| 46 | 43 |
| 47 // Implements base::MessageLoop::DestructionObserver | |
| 48 void WillDestroyCurrentMessageLoop() override; | |
| 49 | |
| 50 private: | 44 private: |
| 51 friend std::default_delete<DeviceMonitorLinux>; | 45 friend std::default_delete<DeviceMonitorLinux>; |
| 52 | 46 |
| 53 ~DeviceMonitorLinux() override; | 47 ~DeviceMonitorLinux(); |
| 54 | 48 |
| 55 void OnMonitorCanReadWithoutBlocking(); | 49 void OnMonitorCanReadWithoutBlocking(); |
| 56 | 50 |
| 57 ScopedUdevPtr udev_; | 51 ScopedUdevPtr udev_; |
| 58 ScopedUdevMonitorPtr monitor_; | 52 ScopedUdevMonitorPtr monitor_; |
| 59 int monitor_fd_; | 53 int monitor_fd_; |
| 60 std::unique_ptr<base::FileDescriptorWatcher::Controller> | 54 std::unique_ptr<base::FileDescriptorWatcher::Controller> |
| 61 monitor_watch_controller_; | 55 monitor_watch_controller_; |
| 62 | 56 |
| 63 base::ObserverList<Observer, true> observers_; | 57 base::ObserverList<Observer, true> observers_; |
| 64 | 58 |
| 65 base::ThreadChecker thread_checker_; | 59 base::ThreadChecker thread_checker_; |
| 66 | 60 |
| 67 DISALLOW_COPY_AND_ASSIGN(DeviceMonitorLinux); | 61 DISALLOW_COPY_AND_ASSIGN(DeviceMonitorLinux); |
| 68 }; | 62 }; |
| 69 | 63 |
| 70 } // namespace device | 64 } // namespace device |
| 71 | 65 |
| 72 #endif // DEVICE_BASE_DEVICE_MONITOR_LINUX_H_ | 66 #endif // DEVICE_BASE_DEVICE_MONITOR_LINUX_H_ |
| OLD | NEW |