Chromium Code Reviews| 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..3c46d660c30bd6bb5589598a8d9c085d6851d019 100644 |
| --- a/ui/events/platform/platform_event_source.cc |
| +++ b/ui/events/platform/platform_event_source.cc |
| @@ -6,30 +6,41 @@ |
| #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 singleton 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 |
|
sky
2017/06/27 19:58:57
Same comment here. What code in chrome/ash is maki
mfomitchev
2017/06/27 22:14:55
Aura does it: https://cs.chromium.org/chromium/src
sky
2017/06/28 00:22:02
That's only for the LOCAL case. How are we trigger
mfomitchev
2017/06/28 15:56:32
Oops, you are right, this isn't needed. I misread
mfomitchev
2017/07/12 20:37:13
I remember now there was another reason I made thi
|
| + 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) { |