| 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
|
|
|