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

Unified Diff: ui/events/devices/input_device_manager.cc

Issue 2916823002: Move Mus into chrome's process when running with --mus.
Patch Set: Addressing most feedback, making this work on device. Created 3 years, 6 months 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
Index: ui/events/devices/input_device_manager.cc
diff --git a/ui/events/devices/input_device_manager.cc b/ui/events/devices/input_device_manager.cc
index b6ca664e25a4f42bf7f4dcd015cf7583e73560b8..0c1f75a34c4a0841d3b6cc15fa0a47c8550a600a 100644
--- a/ui/events/devices/input_device_manager.cc
+++ b/ui/events/devices/input_device_manager.cc
@@ -3,31 +3,41 @@
// found in the LICENSE file.
#include "ui/events/devices/input_device_manager.h"
+#include "base/lazy_instance.h"
+#include "base/threading/thread_local.h"
namespace ui {
+namespace {
-InputDeviceManager* InputDeviceManager::instance_ = nullptr;
+// InputDeviceManager is thread local so that different instances can be used on
+// different threads (e.g. WindowServer thread vs. Browser UI thread).
+base::LazyInstance<base::ThreadLocalPointer<InputDeviceManager>>::Leaky
+ lazy_tls_ptr = LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
// static
InputDeviceManager* InputDeviceManager::GetInstance() {
- DCHECK(instance_);
- return instance_;
+ InputDeviceManager* instance = lazy_tls_ptr.Pointer()->Get();
+ DCHECK(instance) << "InputDeviceManager::SetInstance must be called before "
+ "getting the instance of InputDeviceManager.";
+ return instance;
}
// static
bool InputDeviceManager::HasInstance() {
- return instance_ != nullptr;
+ return lazy_tls_ptr.Pointer()->Get() != nullptr;
}
// static
void InputDeviceManager::SetInstance(InputDeviceManager* instance) {
- DCHECK(!instance_);
- instance_ = instance;
+ DCHECK(!lazy_tls_ptr.Pointer()->Get());
+ lazy_tls_ptr.Pointer()->Set(instance);
}
// static
void InputDeviceManager::ClearInstance() {
- instance_ = nullptr;
+ lazy_tls_ptr.Pointer()->Set(nullptr);
}
} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698