| Index: device/sensor/sensor_impl.cc
|
| diff --git a/device/sensor/sensor_impl.cc b/device/sensor/sensor_impl.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f8d9dfd5ca46a1f5419feba5d9aad3b4b003ad4e
|
| --- /dev/null
|
| +++ b/device/sensor/sensor_impl.cc
|
| @@ -0,0 +1,63 @@
|
| +// 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 "device/sensor/sensor_impl.h"
|
| +
|
| +#include <utility>
|
| +
|
| +#include "base/bind.h"
|
| +
|
| +namespace device {
|
| +
|
| +// static
|
| +void SensorImpl::Create(mojo::InterfaceRequest<AmbientLightSensor> request) {
|
| + new SensorImpl(std::move(request));
|
| +}
|
| +
|
| +SensorImpl::SensorImpl(mojo::InterfaceRequest<AmbientLightSensor> request)
|
| + : binding_(this, std::move(request)), reading_to_report_(false) {
|
| + // NOTE: DidChange may be called before AddCallback returns. This is done to
|
| + // report current reading.
|
| + subscription_ = SensorService::GetInstance()->AddCallback(
|
| + base::Bind(&SensorImpl::DidChange, base::Unretained(this)));
|
| +}
|
| +
|
| +SensorImpl::~SensorImpl() {}
|
| +
|
| +void SensorImpl::QueryNextReading(const SensorReadingCallback& callback) {
|
| + if (!callback_.is_null()) {
|
| + DVLOG(1) << "Overlapped call to QueryNextReading!";
|
| + delete this;
|
| + return;
|
| + }
|
| + callback_ = callback;
|
| +
|
| + if (reading_to_report_)
|
| + ReportReading();
|
| +}
|
| +
|
| +void SensorImpl::StartReading() {
|
| + // TODO(riju): To be implemented.
|
| +}
|
| +
|
| +void SensorImpl::StopReading() {
|
| + // TODO(riju): To be implemented.
|
| +}
|
| +
|
| +void SensorImpl::DidChange(const AmbientLightSensorReading& sensor_reading) {
|
| + reading_ = sensor_reading;
|
| + reading_to_report_ = true;
|
| +
|
| + if (!callback_.is_null())
|
| + ReportReading();
|
| +}
|
| +
|
| +void SensorImpl::ReportReading() {
|
| + callback_.Run(reading_.Clone());
|
| + callback_.reset();
|
| +
|
| + reading_to_report_ = false;
|
| +}
|
| +
|
| +} // namespace device
|
|
|