| 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 #include "base/single_thread_task_runner.h" |  | 
| 7 |  | 
| 8 namespace device { |  | 
| 9 |  | 
| 10 namespace { |  | 
| 11 constexpr double kDefaultSensorReportingFrequency = 5.0; |  | 
| 12 }  // namespace |  | 
| 13 |  | 
| 14 PlatformSensorWin::PlatformSensorWin( |  | 
| 15     mojom::SensorType type, |  | 
| 16     mojo::ScopedSharedBufferMapping mapping, |  | 
| 17     PlatformSensorProvider* provider, |  | 
| 18     scoped_refptr<base::SingleThreadTaskRunner> sensor_thread_runner, |  | 
| 19     std::unique_ptr<PlatformSensorReaderWin> sensor_reader) |  | 
| 20     : PlatformSensor(type, std::move(mapping), provider), |  | 
| 21       sensor_thread_runner_(sensor_thread_runner), |  | 
| 22       sensor_reader_(sensor_reader.release()), |  | 
| 23       weak_factory_(this) { |  | 
| 24   DCHECK(sensor_reader_); |  | 
| 25   sensor_reader_->SetClient(this); |  | 
| 26 } |  | 
| 27 |  | 
| 28 PlatformSensorConfiguration PlatformSensorWin::GetDefaultConfiguration() { |  | 
| 29   return PlatformSensorConfiguration(kDefaultSensorReportingFrequency); |  | 
| 30 } |  | 
| 31 |  | 
| 32 mojom::ReportingMode PlatformSensorWin::GetReportingMode() { |  | 
| 33   // All Windows sensors, even with high accuracy / sensitivity will not report |  | 
| 34   // reading updates continuously. Therefore, return ON_CHANGE by default. |  | 
| 35   return mojom::ReportingMode::ON_CHANGE; |  | 
| 36 } |  | 
| 37 |  | 
| 38 double PlatformSensorWin::GetMaximumSupportedFrequency() { |  | 
| 39   double minimal_reporting_interval_ms = |  | 
| 40       sensor_reader_->GetMinimalReportingIntervalMs(); |  | 
| 41   if (!minimal_reporting_interval_ms) |  | 
| 42     return kDefaultSensorReportingFrequency; |  | 
| 43   return base::Time::kMillisecondsPerSecond / minimal_reporting_interval_ms; |  | 
| 44 } |  | 
| 45 |  | 
| 46 void PlatformSensorWin::OnReadingUpdated(const SensorReading& reading) { |  | 
| 47   // Default reporting mode is ON_CHANGE, thus, set notify_clients parameter |  | 
| 48   // to true. |  | 
| 49   UpdateSensorReading(reading, true); |  | 
| 50 } |  | 
| 51 |  | 
| 52 void PlatformSensorWin::OnSensorError() { |  | 
| 53   task_runner_->PostTask(FROM_HERE, |  | 
| 54                          base::Bind(&PlatformSensorWin::NotifySensorError, |  | 
| 55                                     weak_factory_.GetWeakPtr())); |  | 
| 56 } |  | 
| 57 |  | 
| 58 bool PlatformSensorWin::StartSensor( |  | 
| 59     const PlatformSensorConfiguration& configuration) { |  | 
| 60   DCHECK(task_runner_->BelongsToCurrentThread()); |  | 
| 61   return sensor_reader_->StartSensor(configuration); |  | 
| 62 } |  | 
| 63 |  | 
| 64 void PlatformSensorWin::StopSensor() { |  | 
| 65   DCHECK(task_runner_->BelongsToCurrentThread()); |  | 
| 66   sensor_reader_->StopSensor(); |  | 
| 67 } |  | 
| 68 |  | 
| 69 bool PlatformSensorWin::CheckSensorConfiguration( |  | 
| 70     const PlatformSensorConfiguration& configuration) { |  | 
| 71   DCHECK(task_runner_->BelongsToCurrentThread()); |  | 
| 72   double minimal_reporting_interval_ms = |  | 
| 73       sensor_reader_->GetMinimalReportingIntervalMs(); |  | 
| 74   if (minimal_reporting_interval_ms == 0) |  | 
| 75     return true; |  | 
| 76   double max_frequency = |  | 
| 77       base::Time::kMillisecondsPerSecond / minimal_reporting_interval_ms; |  | 
| 78   return configuration.frequency() <= max_frequency; |  | 
| 79 } |  | 
| 80 |  | 
| 81 PlatformSensorWin::~PlatformSensorWin() { |  | 
| 82   sensor_reader_->SetClient(nullptr); |  | 
| 83   sensor_thread_runner_->DeleteSoon(FROM_HERE, sensor_reader_); |  | 
| 84 } |  | 
| 85 |  | 
| 86 }  // namespace device |  | 
| OLD | NEW | 
|---|