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 |