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/PlatformEventController.h"
8 #include "core/page/Page.h"
12 PlatformEventController::PlatformEventController(Page
* page
)
13 : PageLifecycleObserver(page
)
14 , m_hasEventListener(false)
16 , m_timer(this, &PlatformEventController::oneShotCallback
)
20 PlatformEventController::~PlatformEventController()
24 void PlatformEventController::oneShotCallback(Timer
<PlatformEventController
>* timer
)
26 ASSERT_UNUSED(timer
, timer
== &m_timer
);
27 ASSERT(hasLastData());
28 ASSERT(!m_timer
.isActive());
33 void PlatformEventController::startUpdating()
38 if (hasLastData() && !m_timer
.isActive()) {
39 // Make sure to fire the data as soon as possible.
40 m_timer
.startOneShot(0, FROM_HERE
);
43 registerWithDispatcher();
47 void PlatformEventController::stopUpdating()
52 if (m_timer
.isActive())
55 unregisterWithDispatcher();
59 void PlatformEventController::pageVisibilityChanged()
61 if (!m_hasEventListener
)
64 if (page()->visibilityState() == PageVisibilityStateVisible
)