Index: device/hid/input_service_linux.cc |
diff --git a/device/hid/input_service_linux.cc b/device/hid/input_service_linux.cc |
index b9a1ac040899bd33adcd0719ff3c5c83c95788c3..25d0335377756a49a69cb2aa1d132cbca9a94e95 100644 |
--- a/device/hid/input_service_linux.cc |
+++ b/device/hid/input_service_linux.cc |
@@ -7,7 +7,6 @@ |
#include <memory> |
#include "base/bind.h" |
-#include "base/lazy_instance.h" |
#include "base/logging.h" |
#include "base/macros.h" |
#include "base/scoped_observer.h" |
@@ -36,9 +35,7 @@ const char kIdInputTablet[] = "ID_INPUT_TABLET"; |
const char kIdInputTouchpad[] = "ID_INPUT_TOUCHPAD"; |
const char kIdInputTouchscreen[] = "ID_INPUT_TOUCHSCREEN"; |
-// The instance will be reset when message loop destroys. |
-base::LazyInstance<std::unique_ptr<InputServiceLinux>>::Leaky |
- g_input_service_linux_ptr = LAZY_INSTANCE_INITIALIZER; |
+InputServiceLinux* g_input_service_linux = nullptr; |
bool GetBoolProperty(udev_device* device, const char* key) { |
CHECK(device); |
@@ -91,7 +88,6 @@ 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; |
@@ -114,6 +110,8 @@ InputServiceLinuxImpl::InputServiceLinuxImpl() : observer_(this) { |
} |
InputServiceLinuxImpl::~InputServiceLinuxImpl() { |
+ // Never destroyed. |
+ NOTREACHED(); |
} |
void InputServiceLinuxImpl::OnDeviceAdded(udev_device* device) { |
@@ -163,11 +161,6 @@ 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() |
@@ -195,18 +188,22 @@ InputServiceLinux::~InputServiceLinux() { |
// static |
InputServiceLinux* InputServiceLinux::GetInstance() { |
if (!HasInstance()) |
- g_input_service_linux_ptr.Get().reset(new InputServiceLinuxImpl()); |
- return g_input_service_linux_ptr.Get().get(); |
+ g_input_service_linux = new InputServiceLinuxImpl(); |
+ return g_input_service_linux; |
} |
// static |
bool InputServiceLinux::HasInstance() { |
- return g_input_service_linux_ptr.Get().get(); |
+ return !!g_input_service_linux; |
} |
// static |
-void InputServiceLinux::SetForTesting(InputServiceLinux* service) { |
- g_input_service_linux_ptr.Get().reset(service); |
+void InputServiceLinux::SetForTesting( |
+ std::unique_ptr<InputServiceLinux> service) { |
+ DCHECK(!HasInstance()); |
+ DCHECK(service); |
+ // |service| will never be destroyed. |
+ g_input_service_linux = service.release(); |
} |
void InputServiceLinux::AddObserver(Observer* observer) { |