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

Side by Side Diff: Source/modules/device_light/DeviceLightDispatcher.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
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 "modules/device_light/DeviceLightDispatcher.h" 6 #include "modules/device_light/DeviceLightDispatcher.h"
7 7
8 #include "core/frame/DeviceSensorEventDispatcher.h" 8 #include "core/frame/DeviceSensorEventDispatcher.h"
9 #include "modules/device_light/DeviceLightController.h" 9 #include "modules/device_light/DeviceLightController.h"
10 #include "public/platform/Platform.h" 10 #include "public/platform/Platform.h"
11 #include "wtf/TemporaryChange.h"
12 11
13 namespace WebCore { 12 namespace WebCore {
14 13
15 DeviceLightDispatcher& DeviceLightDispatcher::instance() 14 DeviceLightDispatcher& DeviceLightDispatcher::instance()
16 { 15 {
17 DEFINE_STATIC_LOCAL(DeviceLightDispatcher, deviceLightDispatcher, ()); 16 DEFINE_STATIC_LOCAL(DeviceLightDispatcher, deviceLightDispatcher, ());
18 return deviceLightDispatcher; 17 return deviceLightDispatcher;
19 } 18 }
20 19
21 DeviceLightDispatcher::DeviceLightDispatcher() 20 DeviceLightDispatcher::DeviceLightDispatcher()
22 : m_lastDeviceLightData(-1) 21 : m_lastDeviceLightData(-1)
23 { 22 {
24 } 23 }
25 24
26 DeviceLightDispatcher::~DeviceLightDispatcher() 25 DeviceLightDispatcher::~DeviceLightDispatcher()
27 { 26 {
28 } 27 }
29 28
30
31 void DeviceLightDispatcher::addDeviceLightController(DeviceLightController* cont roller)
32 {
33 addController(controller);
34 }
35
36 void DeviceLightDispatcher::removeDeviceLightController(DeviceLightController* c ontroller)
37 {
38 removeController(controller);
39 }
40
41 void DeviceLightDispatcher::startListening() 29 void DeviceLightDispatcher::startListening()
42 { 30 {
43 blink::Platform::current()->setDeviceLightListener(this); 31 blink::Platform::current()->setDeviceLightListener(this);
44 } 32 }
45 33
46 void DeviceLightDispatcher::stopListening() 34 void DeviceLightDispatcher::stopListening()
47 { 35 {
48 blink::Platform::current()->setDeviceLightListener(0); 36 blink::Platform::current()->setDeviceLightListener(0);
49 m_lastDeviceLightData = -1; 37 m_lastDeviceLightData = -1;
50 } 38 }
51 39
52 void DeviceLightDispatcher::didChangeDeviceLight(double value) 40 void DeviceLightDispatcher::didChangeDeviceLight(double value)
53 { 41 {
54 m_lastDeviceLightData = value; 42 m_lastDeviceLightData = value;
55 43 notifyControllers();
56 {
57 TemporaryChange<bool> changeIsDispatching(m_isDispatching, true);
58 // Don't fire controllers removed or added during event dispatch.
59 size_t size = m_controllers.size();
60 for (size_t i = 0; i < size; ++i) {
61 if (m_controllers[i])
62 static_cast<DeviceLightController*>(m_controllers[i])->didChange DeviceLight(m_lastDeviceLightData);
63 }
64 }
65
66 if (m_needsPurge)
67 purgeControllers();
68 } 44 }
69 45
70 double DeviceLightDispatcher::latestDeviceLightData() const 46 double DeviceLightDispatcher::latestDeviceLightData() const
71 { 47 {
72 return m_lastDeviceLightData; 48 return m_lastDeviceLightData;
73 } 49 }
74 50
75 } // namespace WebCore 51 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/device_light/DeviceLightDispatcher.h ('k') | Source/modules/device_orientation/DeviceMotionController.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698