Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(585)

Side by Side Diff: Source/core/frame/DeviceEventControllerBase.cpp

Issue 315573002: Generalize and refactor DeviceSensorEvent* architecture to support multi-event type targets. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: add stopUpdating in destructor of BatteryManager. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "config.h"
6 #include "core/frame/DeviceEventControllerBase.h"
7
8 #include "core/page/Page.h"
9
10 namespace WebCore {
11
12 DeviceEventControllerBase::DeviceEventControllerBase(Page* page)
13 : PageLifecycleObserver(page)
14 , m_hasEventListener(false)
15 , m_isActive(false)
16 , m_timer(this, &DeviceEventControllerBase::oneShotCallback)
17 {
18 }
19
20 DeviceEventControllerBase::~DeviceEventControllerBase()
21 {
22 }
23
24 void DeviceEventControllerBase::oneShotCallback(Timer<DeviceEventControllerBase> * timer)
25 {
26 ASSERT_UNUSED(timer, timer == &m_timer);
27 ASSERT(hasLastData());
28 ASSERT(!m_timer.isActive());
29
30 didUpdateData();
31 }
32
33 void DeviceEventControllerBase::startUpdating()
34 {
35 if (m_isActive)
36 return;
37
38 if (hasLastData() && !m_timer.isActive()) {
39 // Make sure to fire the data as soon as possible.
40 m_timer.startOneShot(0, FROM_HERE);
41 }
42
43 registerWithDispatcher();
44 m_isActive = true;
45 }
46
47 void DeviceEventControllerBase::stopUpdating()
48 {
49 if (!m_isActive)
50 return;
51
52 if (m_timer.isActive())
53 m_timer.stop();
54
55 unregisterWithDispatcher();
56 m_isActive = false;
57 }
58
59 void DeviceEventControllerBase::pageVisibilityChanged()
60 {
61 if (!m_hasEventListener)
62 return;
63
64 if (page()->visibilityState() == PageVisibilityStateVisible)
65 startUpdating();
66 else
67 stopUpdating();
68 }
69
70 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/frame/DeviceEventControllerBase.h ('k') | Source/core/frame/DeviceEventDispatcherBase.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698