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
3 // found in the LICENSE file.
6 #include "core/frame/PlatformEventDispatcher.h"
8 #include "core/frame/PlatformEventController.h"
9 #include "wtf/TemporaryChange.h"
13 PlatformEventDispatcher::PlatformEventDispatcher()
14 : m_isDispatching(false)
15 , m_isListening(false)
19 void PlatformEventDispatcher::addController(PlatformEventController
* controller
)
22 // TODO: If we can avoid to register a same controller twice, we can change
23 // this 'if' to ASSERT.
24 if (m_controllers
.contains(controller
))
27 m_controllers
.add(controller
);
35 void PlatformEventDispatcher::removeController(PlatformEventController
* controller
)
37 ASSERT(m_controllers
.contains(controller
));
39 m_controllers
.remove(controller
);
40 if (!m_isDispatching
&& m_controllers
.isEmpty()) {
42 m_isListening
= false;
46 void PlatformEventDispatcher::notifyControllers()
48 if (m_controllers
.isEmpty())
52 TemporaryChange
<bool> changeIsDispatching(m_isDispatching
, true);
53 // HashSet m_controllers can be updated during an iteration, and it stops the iteration.
54 // Thus we store it into a Vector to access all elements.
55 WillBeHeapVector
<RawPtrWillBeMember
<PlatformEventController
>> snapshotVector
;
56 copyToVector(m_controllers
, snapshotVector
);
57 for (PlatformEventController
* controller
: snapshotVector
) {
58 if (m_controllers
.contains(controller
))
59 controller
->didUpdateData();
63 if (m_controllers
.isEmpty()) {
65 m_isListening
= false;
69 DEFINE_TRACE(PlatformEventDispatcher
)
72 visitor
->trace(m_controllers
);