| 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 11 matching lines...) Expand all Loading... |
| 22 weak_factory_(this) { | 22 weak_factory_(this) { |
| 23 DCHECK(sensor_reader_); | 23 DCHECK(sensor_reader_); |
| 24 sensor_reader_->SetClient(this); | 24 sensor_reader_->SetClient(this); |
| 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 // All Windows sensors, even with high accuracy / sensitivity will not report |
| 33 // reading updates continuously. Therefore, return ON_CHANGE by default. |
| 34 return mojom::ReportingMode::ON_CHANGE; |
| 33 } | 35 } |
| 34 | 36 |
| 35 double PlatformSensorWin::GetMaximumSupportedFrequency() { | 37 double PlatformSensorWin::GetMaximumSupportedFrequency() { |
| 36 double minimal_reporting_interval_ms = | 38 double minimal_reporting_interval_ms = |
| 37 sensor_reader_->GetMinimalReportingIntervalMs(); | 39 sensor_reader_->GetMinimalReportingIntervalMs(); |
| 38 if (!minimal_reporting_interval_ms) | 40 if (!minimal_reporting_interval_ms) |
| 39 return kDefaultSensorReportingFrequency; | 41 return kDefaultSensorReportingFrequency; |
| 40 return base::Time::kMillisecondsPerSecond / minimal_reporting_interval_ms; | 42 return base::Time::kMillisecondsPerSecond / minimal_reporting_interval_ms; |
| 41 } | 43 } |
| 42 | 44 |
| 43 void PlatformSensorWin::OnReadingUpdated(const SensorReading& reading) { | 45 void PlatformSensorWin::OnReadingUpdated(const SensorReading& reading) { |
| 44 UpdateSensorReading(reading, | 46 // Default reporting mode is ON_CHANGE, thus, set notify_clients parameter |
| 45 GetReportingMode() == mojom::ReportingMode::ON_CHANGE); | 47 // to true. |
| 48 UpdateSensorReading(reading, true); |
| 46 } | 49 } |
| 47 | 50 |
| 48 void PlatformSensorWin::OnSensorError() { | 51 void PlatformSensorWin::OnSensorError() { |
| 49 task_runner_->PostTask(FROM_HERE, | 52 task_runner_->PostTask(FROM_HERE, |
| 50 base::Bind(&PlatformSensorWin::NotifySensorError, | 53 base::Bind(&PlatformSensorWin::NotifySensorError, |
| 51 weak_factory_.GetWeakPtr())); | 54 weak_factory_.GetWeakPtr())); |
| 52 } | 55 } |
| 53 | 56 |
| 54 bool PlatformSensorWin::StartSensor( | 57 bool PlatformSensorWin::StartSensor( |
| 55 const PlatformSensorConfiguration& configuration) { | 58 const PlatformSensorConfiguration& configuration) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 73 base::Time::kMillisecondsPerSecond / minimal_reporting_interval_ms; | 76 base::Time::kMillisecondsPerSecond / minimal_reporting_interval_ms; |
| 74 return configuration.frequency() <= max_frequency; | 77 return configuration.frequency() <= max_frequency; |
| 75 } | 78 } |
| 76 | 79 |
| 77 PlatformSensorWin::~PlatformSensorWin() { | 80 PlatformSensorWin::~PlatformSensorWin() { |
| 78 sensor_reader_->SetClient(nullptr); | 81 sensor_reader_->SetClient(nullptr); |
| 79 sensor_thread_runner_->DeleteSoon(FROM_HERE, sensor_reader_); | 82 sensor_thread_runner_->DeleteSoon(FROM_HERE, sensor_reader_); |
| 80 } | 83 } |
| 81 | 84 |
| 82 } // namespace device | 85 } // namespace device |
| OLD | NEW |