Chromium Code Reviews| Index: device/generic_sensor/platform_sensor_win.cc |
| diff --git a/device/generic_sensor/platform_sensor_win.cc b/device/generic_sensor/platform_sensor_win.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ee2f137d4c2c550c611f07ae0c8c95fba834e764 |
| --- /dev/null |
| +++ b/device/generic_sensor/platform_sensor_win.cc |
| @@ -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 "device/generic_sensor/platform_sensor_win.h" |
| + |
| +namespace device { |
| + |
| +namespace { |
| +const double kDefaultSensorReportingFrequency = 5.0; |
| +} // anonymous namespace |
|
Reilly Grant (use Gerrit)
2016/10/27 00:59:20
Just, "namespace".
shalamov
2016/10/27 13:51:08
Done.
|
| + |
| +PlatformSensorWin::PlatformSensorWin( |
| + mojom::SensorType type, |
| + mojo::ScopedSharedBufferMapping mapping, |
| + PlatformSensorProvider* provider, |
| + scoped_refptr<base::SingleThreadTaskRunner> sensor_thread_runner, |
| + std::unique_ptr<PlatformSensorReaderWin> sensor_reader) |
| + : PlatformSensor(type, std::move(mapping), provider), |
| + sensor_thread_runner_(sensor_thread_runner), |
| + sensor_reader_(std::move(sensor_reader)), |
| + weak_factory_(this) { |
| + DCHECK(sensor_reader_); |
| + sensor_reader_->SetClient(this); |
| +} |
| + |
| +PlatformSensorConfiguration PlatformSensorWin::GetDefaultConfiguration() { |
| + return PlatformSensorConfiguration(kDefaultSensorReportingFrequency); |
| +} |
| + |
| +mojom::ReportingMode PlatformSensorWin::GetReportingMode() { |
| + DCHECK(sensor_reader_); |
| + return sensor_reader_->GetReportingMode(); |
| +} |
| + |
| +void PlatformSensorWin::OnReadingUpdated(const SensorReading& reading) { |
| + UpdateSensorReading(reading, |
| + GetReportingMode() == mojom::ReportingMode::ON_CHANGE); |
| +} |
| + |
| +void PlatformSensorWin::OnSensorError() { |
| + task_runner_->PostTask(FROM_HERE, |
| + base::Bind(&PlatformSensorWin::NotifySensorError, |
| + weak_factory_.GetWeakPtr())); |
| +} |
| + |
| +bool PlatformSensorWin::StartSensor( |
| + const PlatformSensorConfiguration& configuration) { |
| + DCHECK(task_runner_->BelongsToCurrentThread()); |
| + return sensor_reader_->StartSensor(configuration); |
| +} |
| + |
| +void PlatformSensorWin::StopSensor() { |
| + DCHECK(task_runner_->BelongsToCurrentThread()); |
| + sensor_reader_->StopSensor(); |
| +} |
| + |
| +bool PlatformSensorWin::CheckSensorConfiguration( |
| + const PlatformSensorConfiguration& configuration) { |
| + DCHECK(sensor_reader_); |
| + DCHECK(task_runner_->BelongsToCurrentThread()); |
| + double minimal_reporting_interval_ms = |
| + sensor_reader_->GetMinimalReportingIntervalMs(); |
| + if (minimal_reporting_interval_ms == 0) |
| + return true; |
| + double min_frequency = |
| + 1 / (minimal_reporting_interval_ms / base::Time::kMillisecondsPerSecond); |
| + return configuration.frequency() <= min_frequency; |
| +} |
| + |
| +PlatformSensorWin::~PlatformSensorWin() { |
| + sensor_reader_->SetClient(nullptr); |
| + sensor_thread_runner_->DeleteSoon(FROM_HERE, sensor_reader_.release()); |
| +} |
| + |
| +} // namespace device |