| Index: device/hid/input_service_linux.cc
|
| diff --git a/device/hid/input_service_linux.cc b/device/hid/input_service_linux.cc
|
| index d8053028fb67d847a0e3fdf8c1193f5fc927315f..4df2cb570ca10942b318e577cab25fd9185d5d41 100644
|
| --- a/device/hid/input_service_linux.cc
|
| +++ b/device/hid/input_service_linux.cc
|
| @@ -10,9 +10,11 @@
|
| #include "base/lazy_instance.h"
|
| #include "base/logging.h"
|
| #include "base/macros.h"
|
| +#include "base/scoped_observer.h"
|
| #include "base/strings/string_number_conversions.h"
|
| #include "base/strings/string_util.h"
|
| #include "base/threading/thread_restrictions.h"
|
| +#include "device/core/device_monitor_linux.h"
|
| #include "device/udev_linux/udev.h"
|
|
|
| namespace device {
|
| @@ -89,6 +91,7 @@ class InputServiceLinuxImpl : public InputServiceLinux,
|
| // Implements DeviceMonitorLinux::Observer:
|
| void OnDeviceAdded(udev_device* device) override;
|
| void OnDeviceRemoved(udev_device* device) override;
|
| + void WillDestroyMonitorMessageLoop() override;
|
|
|
| private:
|
| friend class InputServiceLinux;
|
| @@ -96,22 +99,21 @@ class InputServiceLinuxImpl : public InputServiceLinux,
|
| InputServiceLinuxImpl();
|
| ~InputServiceLinuxImpl() override;
|
|
|
| + ScopedObserver<DeviceMonitorLinux, DeviceMonitorLinux::Observer> observer_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(InputServiceLinuxImpl);
|
| };
|
|
|
| -InputServiceLinuxImpl::InputServiceLinuxImpl() {
|
| +InputServiceLinuxImpl::InputServiceLinuxImpl() : observer_(this) {
|
| base::ThreadRestrictions::AssertIOAllowed();
|
| - base::MessageLoop::current()->AddDestructionObserver(this);
|
|
|
| - DeviceMonitorLinux::GetInstance()->AddObserver(this);
|
| - DeviceMonitorLinux::GetInstance()->Enumerate(base::Bind(
|
| - &InputServiceLinuxImpl::OnDeviceAdded, base::Unretained(this)));
|
| + DeviceMonitorLinux* monitor = DeviceMonitorLinux::GetInstance();
|
| + observer_.Add(monitor);
|
| + monitor->Enumerate(base::Bind(&InputServiceLinuxImpl::OnDeviceAdded,
|
| + base::Unretained(this)));
|
| }
|
|
|
| InputServiceLinuxImpl::~InputServiceLinuxImpl() {
|
| - if (DeviceMonitorLinux::HasInstance())
|
| - DeviceMonitorLinux::GetInstance()->RemoveObserver(this);
|
| - base::MessageLoop::current()->RemoveDestructionObserver(this);
|
| }
|
|
|
| void InputServiceLinuxImpl::OnDeviceAdded(udev_device* device) {
|
| @@ -161,6 +163,11 @@ void InputServiceLinuxImpl::OnDeviceRemoved(udev_device* device) {
|
| RemoveDevice(devnode);
|
| }
|
|
|
| +void InputServiceLinuxImpl::WillDestroyMonitorMessageLoop() {
|
| + DCHECK(CalledOnValidThread());
|
| + g_input_service_linux_ptr.Get().reset(nullptr);
|
| +}
|
| +
|
| } // namespace
|
|
|
| InputServiceLinux::InputDeviceInfo::InputDeviceInfo()
|
| @@ -232,11 +239,6 @@ bool InputServiceLinux::GetDeviceInfo(const std::string& id,
|
| return true;
|
| }
|
|
|
| -void InputServiceLinux::WillDestroyCurrentMessageLoop() {
|
| - DCHECK(CalledOnValidThread());
|
| - g_input_service_linux_ptr.Get().reset(NULL);
|
| -}
|
| -
|
| void InputServiceLinux::AddDevice(const InputDeviceInfo& info) {
|
| devices_[info.id] = info;
|
| FOR_EACH_OBSERVER(Observer, observers_, OnInputDeviceAdded(info));
|
|
|