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 "config.h" | 5 #include "config.h" |
| 6 #include "core/frame/PlatformEventDispatcher.h" | 6 #include "core/frame/PlatformEventDispatcher.h" |
| 7 | 7 |
| 8 #include "core/frame/PlatformEventController.h" | 8 #include "core/frame/PlatformEventController.h" |
| 9 #include "wtf/TemporaryChange.h" | 9 #include "wtf/TemporaryChange.h" |
| 10 | 10 |
| 11 namespace blink { | 11 namespace blink { |
| 12 | 12 |
| 13 PlatformEventDispatcher::PlatformEventDispatcher() | 13 PlatformEventDispatcher::PlatformEventDispatcher() |
| 14 : m_needsPurge(false) | 14 : m_needsPurge(false) |
| 15 , m_isDispatching(false) | 15 , m_isDispatching(false) |
| 16 { | 16 { |
| 17 } | 17 } |
| 18 | 18 |
| 19 PlatformEventDispatcher::~PlatformEventDispatcher() | |
| 20 { | |
| 21 } | |
| 22 | |
| 23 void PlatformEventDispatcher::addController(PlatformEventController* controller) | 19 void PlatformEventDispatcher::addController(PlatformEventController* controller) |
| 24 { | 20 { |
| 25 bool wasEmpty = m_controllers.isEmpty(); | 21 bool wasEmpty = m_controllers.isEmpty(); |
| 26 if (!m_controllers.contains(controller)) | 22 if (!m_controllers.contains(controller)) |
| 27 m_controllers.append(controller); | 23 m_controllers.append(controller); |
| 28 if (wasEmpty) | 24 if (wasEmpty) |
| 29 startListening(); | 25 startListening(); |
| 30 } | 26 } |
| 31 | 27 |
| 32 void PlatformEventDispatcher::removeController(PlatformEventController* controll er) | 28 void PlatformEventDispatcher::removeController(PlatformEventController* controll er) |
|
haraken
2014/10/03 01:55:33
We need to make sure that removeController() is ne
sof
2014/10/03 06:34:04
The singleton dispatcher instances are held by per
haraken
2014/10/03 10:10:56
ah, you're right.
However, it looks a bit inconsi
sof
2014/10/03 10:27:11
With Oilpan enabled, it is redundant, but not with
sof
2014/10/03 12:21:16
Went ahead and added such.
The Oilpan-specific ca
| |
| 33 { | 29 { |
| 34 // Do not actually remove the controller from the vector, instead zero them out. | 30 // Do not actually remove the controller from the vector, instead zero them out. |
| 35 // The zeros are removed in these two cases: | 31 // The zeros are removed in these two cases: |
| 36 // 1. either immediately if we are not dispatching any events, | 32 // 1. either immediately if we are not dispatching any events, |
| 37 // 2. or after events to all controllers have dispatched (see notifyControll ers()). | 33 // 2. or after events to all controllers have dispatched (see notifyControll ers()). |
| 38 // This is to correctly handle the re-entrancy case when a controller is des troyed | 34 // This is to correctly handle the re-entrancy case when a controller is des troyed |
| 39 // while the events are still being dispatched. | 35 // while the events are still being dispatched. |
| 40 size_t index = m_controllers.find(controller); | 36 size_t index = m_controllers.find(controller); |
| 41 if (index == kNotFound) | 37 if (index == kNotFound) |
| 42 return; | 38 return; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 for (size_t i = 0; i < size; ++i) { | 73 for (size_t i = 0; i < size; ++i) { |
| 78 if (m_controllers[i]) | 74 if (m_controllers[i]) |
| 79 m_controllers[i]->didUpdateData(); | 75 m_controllers[i]->didUpdateData(); |
| 80 } | 76 } |
| 81 } | 77 } |
| 82 | 78 |
| 83 if (m_needsPurge) | 79 if (m_needsPurge) |
| 84 purgeControllers(); | 80 purgeControllers(); |
| 85 } | 81 } |
| 86 | 82 |
| 83 void PlatformEventDispatcher::trace(Visitor* visitor) | |
| 84 { | |
| 85 visitor->trace(m_controllers); | |
|
haraken
2014/10/03 01:55:33
Why do you trace m_controllers? If we trace m_cont
sof
2014/10/03 05:05:29
It's a HeapVector<> of PlatformEventController* -
haraken
2014/10/03 05:36:01
Makes sense. Shall we add a comment?
sof
2014/10/03 06:34:04
Done.
I incorrectly assumed that PlatformEventCo
haraken
2014/10/03 10:10:56
Can we move DeviceSingleWindowEventController, Nav
sof
2014/10/03 10:27:11
NavigatorGamepad is a navigator supplement, so we
| |
| 86 visitor->registerWeakMembers<PlatformEventDispatcher, &PlatformEventDispatch er::clearWeakMembers>(this); | |
| 87 } | |
| 88 | |
| 89 void PlatformEventDispatcher::clearWeakMembers(Visitor* visitor) | |
| 90 { | |
| 91 for (size_t i = 0; i < m_controllers.size(); ++i) { | |
| 92 if (!visitor->isAlive(m_controllers[i])) { | |
| 93 m_controllers[i] = nullptr; | |
| 94 m_needsPurge = true; | |
| 95 } | |
| 96 } | |
| 97 // Next notification will purge the empty slots. | |
| 98 } | |
| 99 | |
| 87 } // namespace blink | 100 } // namespace blink |
| OLD | NEW |