| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "device/generic_sensor/platform_sensor_win.h" | 5 #include "device/generic_sensor/platform_sensor_win.h" |
| 6 | 6 |
| 7 namespace device { | 7 namespace device { |
| 8 | 8 |
| 9 namespace { | 9 namespace { |
| 10 constexpr double kDefaultSensorReportingFrequency = 5.0; | 10 constexpr double kDefaultSensorReportingFrequency = 5.0; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 } | 25 } |
| 26 | 26 |
| 27 PlatformSensorConfiguration PlatformSensorWin::GetDefaultConfiguration() { | 27 PlatformSensorConfiguration PlatformSensorWin::GetDefaultConfiguration() { |
| 28 return PlatformSensorConfiguration(kDefaultSensorReportingFrequency); | 28 return PlatformSensorConfiguration(kDefaultSensorReportingFrequency); |
| 29 } | 29 } |
| 30 | 30 |
| 31 mojom::ReportingMode PlatformSensorWin::GetReportingMode() { | 31 mojom::ReportingMode PlatformSensorWin::GetReportingMode() { |
| 32 return sensor_reader_->GetReportingMode(); | 32 return sensor_reader_->GetReportingMode(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 double PlatformSensorWin::GetMaximumSupportedFrequency() { |
| 36 double minimal_reporting_interval_ms = |
| 37 sensor_reader_->GetMinimalReportingIntervalMs(); |
| 38 if (!minimal_reporting_interval_ms) |
| 39 return kDefaultSensorReportingFrequency; |
| 40 return base::Time::kMillisecondsPerSecond / minimal_reporting_interval_ms; |
| 41 } |
| 42 |
| 35 void PlatformSensorWin::OnReadingUpdated(const SensorReading& reading) { | 43 void PlatformSensorWin::OnReadingUpdated(const SensorReading& reading) { |
| 36 UpdateSensorReading(reading, | 44 UpdateSensorReading(reading, |
| 37 GetReportingMode() == mojom::ReportingMode::ON_CHANGE); | 45 GetReportingMode() == mojom::ReportingMode::ON_CHANGE); |
| 38 } | 46 } |
| 39 | 47 |
| 40 void PlatformSensorWin::OnSensorError() { | 48 void PlatformSensorWin::OnSensorError() { |
| 41 task_runner_->PostTask(FROM_HERE, | 49 task_runner_->PostTask(FROM_HERE, |
| 42 base::Bind(&PlatformSensorWin::NotifySensorError, | 50 base::Bind(&PlatformSensorWin::NotifySensorError, |
| 43 weak_factory_.GetWeakPtr())); | 51 weak_factory_.GetWeakPtr())); |
| 44 } | 52 } |
| 45 | 53 |
| 46 bool PlatformSensorWin::StartSensor( | 54 bool PlatformSensorWin::StartSensor( |
| 47 const PlatformSensorConfiguration& configuration) { | 55 const PlatformSensorConfiguration& configuration) { |
| 48 DCHECK(task_runner_->BelongsToCurrentThread()); | 56 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 49 return sensor_reader_->StartSensor(configuration); | 57 return sensor_reader_->StartSensor(configuration); |
| 50 } | 58 } |
| 51 | 59 |
| 52 void PlatformSensorWin::StopSensor() { | 60 void PlatformSensorWin::StopSensor() { |
| 53 DCHECK(task_runner_->BelongsToCurrentThread()); | 61 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 54 sensor_reader_->StopSensor(); | 62 sensor_reader_->StopSensor(); |
| 55 } | 63 } |
| 56 | 64 |
| 57 bool PlatformSensorWin::CheckSensorConfiguration( | 65 bool PlatformSensorWin::CheckSensorConfiguration( |
| 58 const PlatformSensorConfiguration& configuration) { | 66 const PlatformSensorConfiguration& configuration) { |
| 59 DCHECK(task_runner_->BelongsToCurrentThread()); | 67 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 60 double minimal_reporting_interval_ms = | 68 double minimal_reporting_interval_ms = |
| 61 sensor_reader_->GetMinimalReportingIntervalMs(); | 69 sensor_reader_->GetMinimalReportingIntervalMs(); |
| 62 if (minimal_reporting_interval_ms == 0) | 70 if (minimal_reporting_interval_ms == 0) |
| 63 return true; | 71 return true; |
| 64 double min_frequency = | 72 double max_frequency = |
| 65 base::Time::kMillisecondsPerSecond / minimal_reporting_interval_ms; | 73 base::Time::kMillisecondsPerSecond / minimal_reporting_interval_ms; |
| 66 return configuration.frequency() <= min_frequency; | 74 return configuration.frequency() <= max_frequency; |
| 67 } | 75 } |
| 68 | 76 |
| 69 PlatformSensorWin::~PlatformSensorWin() { | 77 PlatformSensorWin::~PlatformSensorWin() { |
| 70 sensor_reader_->SetClient(nullptr); | 78 sensor_reader_->SetClient(nullptr); |
| 71 sensor_thread_runner_->DeleteSoon(FROM_HERE, sensor_reader_); | 79 sensor_thread_runner_->DeleteSoon(FROM_HERE, sensor_reader_); |
| 72 } | 80 } |
| 73 | 81 |
| 74 } // namespace device | 82 } // namespace device |
| OLD | NEW |