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

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: re entrancy fix Created 4 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
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/mojo/MojoHelper.h"
8 #include "public/platform/Platform.h"
9 #include "public/platform/ServiceRegistry.h"
10 #include "wtf/PassOwnPtr.h"
11
12 namespace blink {
13
14 AmbientLightSensorDispatcher& AmbientLightSensorDispatcher::instance()
15 {
16 DEFINE_STATIC_LOCAL(Persistent<AmbientLightSensorDispatcher>, lightSensorDis patcher, (new AmbientLightSensorDispatcher()));
17 return *lightSensorDispatcher;
18 }
19
20 AmbientLightSensorDispatcher::AmbientLightSensorDispatcher()
21 : m_hasLatestData(false)
22 {
23 }
24
25 void AmbientLightSensorDispatcher::queryNextReading()
26 {
27 m_lightSensor->QueryNextReading(createBaseCallback(bind<device::blink::Ambie ntLightSensorReadingPtr>(&AmbientLightSensorDispatcher::onDidChange, this)));
28 }
29
30 void AmbientLightSensorDispatcher::startReading()
31 {
32 m_lightSensor->StartReading();
33 }
34
35 void AmbientLightSensorDispatcher::stopReading()
36 {
37 m_lightSensor->StopReading();
38 }
39
40 void AmbientLightSensorDispatcher::onDidChange(device::blink::AmbientLightSensor ReadingPtr alsReading)
41 {
42 queryNextReading();
43
44 DCHECK(alsReading);
45
46 updateSensorReading(AmbientLightSensorReadingProxy(
47 alsReading->timeStamp, alsReading->illuminance));
48 }
49
50 void AmbientLightSensorDispatcher::updateSensorReading(const AmbientLightSensorR eadingProxy& alsReading)
51 {
52 m_alsReading = alsReading;
53 m_hasLatestData = true;
54 notifyControllers();
55 }
56
57 void AmbientLightSensorDispatcher::startListening()
58 {
59 DCHECK(!m_lightSensor.is_bound());
60 Platform::current()->serviceRegistry()->connectToRemoteService(mojo::GetProx y(&m_lightSensor));
61 if (!m_hasLatestData)
62 startReading();
63
64 queryNextReading();
65 }
66
67 void AmbientLightSensorDispatcher::stopListening()
68 {
69 stopReading();
70 m_lightSensor.reset();
71 m_hasLatestData = false;
72 }
73
74 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698