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

Unified Diff: ui/events/platform/platform_event_source.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/platform/platform_event_source.cc
diff --git a/ui/events/platform/platform_event_source.cc b/ui/events/platform/platform_event_source.cc
index 9be6630e268abbcb8ce45c7746f3f34cb119e41c..a33ecb089049809c58693d66cbe7c61ef1128a7a 100644
--- a/ui/events/platform/platform_event_source.cc
+++ b/ui/events/platform/platform_event_source.cc
@@ -6,30 +6,40 @@
#include <algorithm>
+#include "base/lazy_instance.h"
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h"
+#include "base/threading/thread_local.h"
#include "ui/events/platform/platform_event_dispatcher.h"
#include "ui/events/platform/platform_event_observer.h"
#include "ui/events/platform/scoped_event_dispatcher.h"
namespace ui {
+namespace {
-// static
-PlatformEventSource* PlatformEventSource::instance_ = NULL;
+// PlatformEventSource 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<PlatformEventSource>>::Leaky
+ lazy_tls_ptr = LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
PlatformEventSource::PlatformEventSource()
: overridden_dispatcher_(NULL),
overridden_dispatcher_restored_(false) {
- CHECK(!instance_) << "Only one platform event source can be created.";
- instance_ = this;
+ CHECK(!lazy_tls_ptr.Pointer()->Get())
+ << "Only one platform event source can be created per thread.";
+ lazy_tls_ptr.Pointer()->Set(this);
}
PlatformEventSource::~PlatformEventSource() {
- CHECK_EQ(this, instance_);
- instance_ = NULL;
+ CHECK_EQ(this, lazy_tls_ptr.Pointer()->Get());
+ lazy_tls_ptr.Pointer()->Set(nullptr);
}
-PlatformEventSource* PlatformEventSource::GetInstance() { return instance_; }
+PlatformEventSource* PlatformEventSource::GetInstance() {
+ return lazy_tls_ptr.Pointer()->Get();
+}
void PlatformEventSource::AddPlatformEventDispatcher(
PlatformEventDispatcher* dispatcher) {
« services/ui/ws/threaded_image_cursors.cc ('K') | « ui/events/platform/platform_event_source.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698