| 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..c51c91e67c168e99c83f6abf01403b0b322d3995
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/modules/sensor/AmbientLightSensorDispatcher.cpp
|
| @@ -0,0 +1,74 @@
|
| +// 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/mojo/MojoHelper.h"
|
| +#include "public/platform/Platform.h"
|
| +#include "public/platform/ServiceRegistry.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(createBaseCallback(bind<device::blink::AmbientLightSensorReadingPtr>(&AmbientLightSensorDispatcher::onDidChange, this)));
|
| +}
|
| +
|
| +void AmbientLightSensorDispatcher::startReading()
|
| +{
|
| + m_lightSensor->StartReading();
|
| +}
|
| +
|
| +void AmbientLightSensorDispatcher::stopReading()
|
| +{
|
| + m_lightSensor->StopReading();
|
| +}
|
| +
|
| +void AmbientLightSensorDispatcher::onDidChange(device::blink::AmbientLightSensorReadingPtr alsReading)
|
| +{
|
| + queryNextReading();
|
| +
|
| + DCHECK(alsReading);
|
| +
|
| + updateSensorReading(AmbientLightSensorReadingProxy(
|
| + alsReading->timeStamp, alsReading->illuminance));
|
| +}
|
| +
|
| +void AmbientLightSensorDispatcher::updateSensorReading(const AmbientLightSensorReadingProxy& alsReading)
|
| +{
|
| + m_alsReading = alsReading;
|
| + m_hasLatestData = true;
|
| + notifyControllers();
|
| +}
|
| +
|
| +void AmbientLightSensorDispatcher::startListening()
|
| +{
|
| + DCHECK(!m_lightSensor.is_bound());
|
| + Platform::current()->serviceRegistry()->connectToRemoteService(mojo::GetProxy(&m_lightSensor));
|
| + if (!m_hasLatestData)
|
| + startReading();
|
| +
|
| + queryNextReading();
|
| +}
|
| +
|
| +void AmbientLightSensorDispatcher::stopListening()
|
| +{
|
| + stopReading();
|
| + m_lightSensor.reset();
|
| + m_hasLatestData = false;
|
| +}
|
| +
|
| +} // namespace blink
|
|
|