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

Side by Side Diff: third_party/WebKit/Source/modules/sensor/AmbientLightSensorDispatcher.cpp

Issue 1892083002: Generic Sensor API : Ambient Light Sensor API. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
OLDNEW
(Empty)
1 // Copyright 2016 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 "modules/sensor/AmbientLightSensorDispatcher.h"
6
7 #include "platform/MojoHelper.h"
8 #include "public/platform/Platform.h"
9 #include "public/platform/ServiceRegistry.h"
10 #include "wtf/Assertions.h"
11 #include "wtf/PassOwnPtr.h"
12
13 namespace blink {
14
15 AmbientLightSensorDispatcher& AmbientLightSensorDispatcher::instance()
16 {
17 DEFINE_STATIC_LOCAL(Persistent<AmbientLightSensorDispatcher>, lightSensorDis patcher, (new AmbientLightSensorDispatcher()));
18 return *lightSensorDispatcher;
19 }
20
21 AmbientLightSensorDispatcher::AmbientLightSensorDispatcher()
22 : m_hasLatestData(false)
23 {
24 }
25
26 void AmbientLightSensorDispatcher::queryNextReading()
27 {
28 m_lightSensor->QueryNextReading(
29 sameThreadBindForMojo(&AmbientLightSensorDispatcher::onDidChange, this)) ;
30 }
31
32 void AmbientLightSensorDispatcher::startReading()
33 {
34 m_lightSensor->StartReading();
35 }
36
37 void AmbientLightSensorDispatcher::stopReading()
38 {
39 m_lightSensor->StopReading();
40 }
41
42 void AmbientLightSensorDispatcher::onDidChange(device::AmbientLightSensorReading Ptr alsReading)
43 {
44 queryNextReading();
45
46 ASSERT(alsReading);
47
48 updateSensorReading(AmbientLightSensorReadingProxy(
49 alsReading->timeStamp, alsReading->illuminance));
50 }
51
52 void AmbientLightSensorDispatcher::updateSensorReading(const AmbientLightSensorR eadingProxy& alsReading)
53 {
54 m_alsReading = alsReading;
55 m_hasLatestData = true;
56 notifyControllers();
57 }
58
59 void AmbientLightSensorDispatcher::startListening()
60 {
61 ASSERT(!m_lightSensor.is_bound());
62 Platform::current()->serviceRegistry()->connectToRemoteService(mojo::GetProx y(&m_lightSensor));
timvolodine 2016/05/06 17:05:41 does this mean that for for each blink instance we
riju_ 2016/05/16 16:58:51 Isn't it the case that even for multiple blink ins
timvolodine 2016/05/17 17:46:18 yeah sorry I wasn't clear, I meant there are multi
63 if (!m_hasLatestData)
64 startReading();
65
66 queryNextReading();
67 }
68
69 void AmbientLightSensorDispatcher::stopListening()
70 {
71 stopReading();
72 m_lightSensor.reset();
73 m_hasLatestData = false;
74 }
75
76 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698