Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/events/platform/platform_event_source.h" | 5 #include "ui/events/platform/platform_event_source.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | |
| 9 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 10 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/threading/thread_local.h" | |
| 11 #include "ui/events/platform/platform_event_dispatcher.h" | 13 #include "ui/events/platform/platform_event_dispatcher.h" |
| 12 #include "ui/events/platform/platform_event_observer.h" | 14 #include "ui/events/platform/platform_event_observer.h" |
| 13 #include "ui/events/platform/scoped_event_dispatcher.h" | 15 #include "ui/events/platform/scoped_event_dispatcher.h" |
| 14 | 16 |
| 15 namespace ui { | 17 namespace ui { |
| 18 namespace { | |
| 16 | 19 |
| 17 // static | 20 // PlatformEventSource singleton is thread local so that different instances |
| 18 PlatformEventSource* PlatformEventSource::instance_ = NULL; | 21 // can be used on different threads (e.g. WindowServer thread vs. browser UI |
| 22 // thread). | |
| 23 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
| |
| 24 lazy_tls_ptr = LAZY_INSTANCE_INITIALIZER; | |
| 25 | |
| 26 } // namespace | |
| 19 | 27 |
| 20 PlatformEventSource::PlatformEventSource() | 28 PlatformEventSource::PlatformEventSource() |
| 21 : overridden_dispatcher_(NULL), | 29 : overridden_dispatcher_(NULL), |
| 22 overridden_dispatcher_restored_(false) { | 30 overridden_dispatcher_restored_(false) { |
| 23 CHECK(!instance_) << "Only one platform event source can be created."; | 31 CHECK(!lazy_tls_ptr.Pointer()->Get()) |
| 24 instance_ = this; | 32 << "Only one platform event source can be created per thread."; |
| 33 lazy_tls_ptr.Pointer()->Set(this); | |
| 25 } | 34 } |
| 26 | 35 |
| 27 PlatformEventSource::~PlatformEventSource() { | 36 PlatformEventSource::~PlatformEventSource() { |
| 28 CHECK_EQ(this, instance_); | 37 CHECK_EQ(this, lazy_tls_ptr.Pointer()->Get()); |
| 29 instance_ = NULL; | 38 lazy_tls_ptr.Pointer()->Set(nullptr); |
| 30 } | 39 } |
| 31 | 40 |
| 32 PlatformEventSource* PlatformEventSource::GetInstance() { return instance_; } | 41 PlatformEventSource* PlatformEventSource::GetInstance() { |
| 42 return lazy_tls_ptr.Pointer()->Get(); | |
| 43 } | |
| 33 | 44 |
| 34 void PlatformEventSource::AddPlatformEventDispatcher( | 45 void PlatformEventSource::AddPlatformEventDispatcher( |
| 35 PlatformEventDispatcher* dispatcher) { | 46 PlatformEventDispatcher* dispatcher) { |
| 36 CHECK(dispatcher); | 47 CHECK(dispatcher); |
| 37 dispatchers_.AddObserver(dispatcher); | 48 dispatchers_.AddObserver(dispatcher); |
| 38 OnDispatcherListChanged(); | 49 OnDispatcherListChanged(); |
| 39 } | 50 } |
| 40 | 51 |
| 41 void PlatformEventSource::RemovePlatformEventDispatcher( | 52 void PlatformEventSource::RemovePlatformEventDispatcher( |
| 42 PlatformEventDispatcher* dispatcher) { | 53 PlatformEventDispatcher* dispatcher) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 | 112 |
| 102 void PlatformEventSource::OnDispatcherListChanged() { | 113 void PlatformEventSource::OnDispatcherListChanged() { |
| 103 } | 114 } |
| 104 | 115 |
| 105 void PlatformEventSource::OnOverriddenDispatcherRestored() { | 116 void PlatformEventSource::OnOverriddenDispatcherRestored() { |
| 106 CHECK(overridden_dispatcher_); | 117 CHECK(overridden_dispatcher_); |
| 107 overridden_dispatcher_restored_ = true; | 118 overridden_dispatcher_restored_ = true; |
| 108 } | 119 } |
| 109 | 120 |
| 110 } // namespace ui | 121 } // namespace ui |
| OLD | NEW |