Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(315)

Unified Diff: device/hid/input_service_linux.cc

Issue 2482463002: Remove DeviceMonitorLinux::WillDestroyCurrentMessageLoop(). (Closed)
Patch Set: CR achuithb #24 Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/hid/input_service_linux.h ('k') | device/hid/mock_hid_service.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
« no previous file with comments | « device/hid/input_service_linux.h ('k') | device/hid/mock_hid_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698