OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "device/generic_sensor/platform_sensor_win.h" |
| 6 |
| 7 namespace device { |
| 8 |
| 9 namespace { |
| 10 constexpr double kDefaultSensorReportingFrequency = 5.0; |
| 11 } // namespace |
| 12 |
| 13 PlatformSensorWin::PlatformSensorWin( |
| 14 mojom::SensorType type, |
| 15 mojo::ScopedSharedBufferMapping mapping, |
| 16 PlatformSensorProvider* provider, |
| 17 scoped_refptr<base::SingleThreadTaskRunner> sensor_thread_runner, |
| 18 std::unique_ptr<PlatformSensorReaderWin> sensor_reader) |
| 19 : PlatformSensor(type, std::move(mapping), provider), |
| 20 sensor_thread_runner_(sensor_thread_runner), |
| 21 sensor_reader_(sensor_reader.release()), |
| 22 weak_factory_(this) { |
| 23 DCHECK(sensor_reader_); |
| 24 sensor_reader_->SetClient(this); |
| 25 } |
| 26 |
| 27 PlatformSensorConfiguration PlatformSensorWin::GetDefaultConfiguration() { |
| 28 return PlatformSensorConfiguration(kDefaultSensorReportingFrequency); |
| 29 } |
| 30 |
| 31 mojom::ReportingMode PlatformSensorWin::GetReportingMode() { |
| 32 return sensor_reader_->GetReportingMode(); |
| 33 } |
| 34 |
| 35 void PlatformSensorWin::OnReadingUpdated(const SensorReading& reading) { |
| 36 UpdateSensorReading(reading, |
| 37 GetReportingMode() == mojom::ReportingMode::ON_CHANGE); |
| 38 } |
| 39 |
| 40 void PlatformSensorWin::OnSensorError() { |
| 41 task_runner_->PostTask(FROM_HERE, |
| 42 base::Bind(&PlatformSensorWin::NotifySensorError, |
| 43 weak_factory_.GetWeakPtr())); |
| 44 } |
| 45 |
| 46 bool PlatformSensorWin::StartSensor( |
| 47 const PlatformSensorConfiguration& configuration) { |
| 48 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 49 return sensor_reader_->StartSensor(configuration); |
| 50 } |
| 51 |
| 52 void PlatformSensorWin::StopSensor() { |
| 53 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 54 sensor_reader_->StopSensor(); |
| 55 } |
| 56 |
| 57 bool PlatformSensorWin::CheckSensorConfiguration( |
| 58 const PlatformSensorConfiguration& configuration) { |
| 59 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 60 double minimal_reporting_interval_ms = |
| 61 sensor_reader_->GetMinimalReportingIntervalMs(); |
| 62 if (minimal_reporting_interval_ms == 0) |
| 63 return true; |
| 64 double min_frequency = |
| 65 base::Time::kMillisecondsPerSecond / minimal_reporting_interval_ms; |
| 66 return configuration.frequency() <= min_frequency; |
| 67 } |
| 68 |
| 69 PlatformSensorWin::~PlatformSensorWin() { |
| 70 sensor_reader_->SetClient(nullptr); |
| 71 sensor_thread_runner_->DeleteSoon(FROM_HERE, sensor_reader_); |
| 72 } |
| 73 |
| 74 } // namespace device |
OLD | NEW |