Oilpan: fix build after r202625.
[chromium-blink-merge.git] / third_party / WebKit / Source / core / frame / PlatformEventDispatcher.cpp
blob65909711fbfa4e1eddeeb78e780eab4a2acfb375
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.
5 #include "config.h"
6 #include "core/frame/PlatformEventDispatcher.h"
8 #include "core/frame/PlatformEventController.h"
9 #include "wtf/TemporaryChange.h"
11 namespace blink {
13 PlatformEventDispatcher::PlatformEventDispatcher()
14 : m_isDispatching(false)
15 , m_isListening(false)
19 void PlatformEventDispatcher::addController(PlatformEventController* controller)
21 ASSERT(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))
25 return;
27 m_controllers.add(controller);
29 if (!m_isListening) {
30 startListening();
31 m_isListening = true;
35 void PlatformEventDispatcher::removeController(PlatformEventController* controller)
37 ASSERT(m_controllers.contains(controller));
39 m_controllers.remove(controller);
40 if (!m_isDispatching && m_controllers.isEmpty()) {
41 stopListening();
42 m_isListening = false;
46 void PlatformEventDispatcher::notifyControllers()
48 if (m_controllers.isEmpty())
49 return;
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()) {
64 stopListening();
65 m_isListening = false;
69 DEFINE_TRACE(PlatformEventDispatcher)
71 #if ENABLE(OILPAN)
72 visitor->trace(m_controllers);
73 #endif
76 } // namespace blink