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..cb4cecff851822c760c6a7c2bd66b83e93e0d801 |
--- /dev/null |
+++ b/device/generic_sensor/platform_sensor_win.cc |
@@ -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 "device/generic_sensor/platform_sensor_win.h" |
+ |
+namespace device { |
+ |
+namespace { |
+constexpr double kDefaultSensorReportingFrequency = 5.0; |
+} // namespace |
+ |
+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_(sensor_reader.release()), |
+ weak_factory_(this) { |
+ DCHECK(sensor_reader_); |
+ sensor_reader_->SetClient(this); |
+} |
+ |
+PlatformSensorConfiguration PlatformSensorWin::GetDefaultConfiguration() { |
+ return PlatformSensorConfiguration(kDefaultSensorReportingFrequency); |
+} |
+ |
+mojom::ReportingMode PlatformSensorWin::GetReportingMode() { |
+ 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(task_runner_->BelongsToCurrentThread()); |
+ double minimal_reporting_interval_ms = |
+ sensor_reader_->GetMinimalReportingIntervalMs(); |
+ if (minimal_reporting_interval_ms == 0) |
+ return true; |
+ double min_frequency = |
+ base::Time::kMillisecondsPerSecond / minimal_reporting_interval_ms; |
+ return configuration.frequency() <= min_frequency; |
+} |
+ |
+PlatformSensorWin::~PlatformSensorWin() { |
+ sensor_reader_->SetClient(nullptr); |
+ sensor_thread_runner_->DeleteSoon(FROM_HERE, sensor_reader_); |
+} |
+ |
+} // namespace device |