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

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

Issue 2978873002: Singletons changes necessary to run the UI Service inside the browser's process. (Closed)
Patch Set: Removing unneeded dependency. Created 3 years, 5 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
« no previous file with comments | « ui/events/devices/input_device_manager.h ('k') | ui/events/platform/platform_event_source.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..1f53855e3f687214c455e485911f621b318fb914 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 singleton is thread-local so that different instances can
+// be used on different threads (eg. UI Service 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
« no previous file with comments | « ui/events/devices/input_device_manager.h ('k') | ui/events/platform/platform_event_source.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698