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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/sensor/AmbientLightSensorDispatcher.cpp
diff --git a/third_party/WebKit/Source/modules/sensor/AmbientLightSensorDispatcher.cpp b/third_party/WebKit/Source/modules/sensor/AmbientLightSensorDispatcher.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..6d7996062759ca8b9d9f0ae5badd02b5822188cc
--- /dev/null
+++ b/third_party/WebKit/Source/modules/sensor/AmbientLightSensorDispatcher.cpp
@@ -0,0 +1,76 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "modules/sensor/AmbientLightSensorDispatcher.h"
+
+#include "platform/MojoHelper.h"
+#include "public/platform/Platform.h"
+#include "public/platform/ServiceRegistry.h"
+#include "wtf/Assertions.h"
+#include "wtf/PassOwnPtr.h"
+
+namespace blink {
+
+AmbientLightSensorDispatcher& AmbientLightSensorDispatcher::instance()
+{
+ DEFINE_STATIC_LOCAL(Persistent<AmbientLightSensorDispatcher>, lightSensorDispatcher, (new AmbientLightSensorDispatcher()));
+ return *lightSensorDispatcher;
+}
+
+AmbientLightSensorDispatcher::AmbientLightSensorDispatcher()
+ : m_hasLatestData(false)
+{
+}
+
+void AmbientLightSensorDispatcher::queryNextReading()
+{
+ m_lightSensor->QueryNextReading(
+ sameThreadBindForMojo(&AmbientLightSensorDispatcher::onDidChange, this));
+}
+
+void AmbientLightSensorDispatcher::startReading()
+{
+ m_lightSensor->StartReading();
+}
+
+void AmbientLightSensorDispatcher::stopReading()
+{
+ m_lightSensor->StopReading();
+}
+
+void AmbientLightSensorDispatcher::onDidChange(device::AmbientLightSensorReadingPtr alsReading)
+{
+ queryNextReading();
+
+ ASSERT(alsReading);
+
+ updateSensorReading(AmbientLightSensorReadingProxy(
+ alsReading->timeStamp, alsReading->illuminance));
+}
+
+void AmbientLightSensorDispatcher::updateSensorReading(const AmbientLightSensorReadingProxy& alsReading)
+{
+ m_alsReading = alsReading;
+ m_hasLatestData = true;
+ notifyControllers();
+}
+
+void AmbientLightSensorDispatcher::startListening()
+{
+ ASSERT(!m_lightSensor.is_bound());
+ Platform::current()->serviceRegistry()->connectToRemoteService(mojo::GetProxy(&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
+ if (!m_hasLatestData)
+ startReading();
+
+ queryNextReading();
+}
+
+void AmbientLightSensorDispatcher::stopListening()
+{
+ stopReading();
+ m_lightSensor.reset();
+ m_hasLatestData = false;
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698