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 const double kDefaultSensorReportingFrequency = 5.0; | |
11 } // anonymous namespace | |
Reilly Grant (use Gerrit)
2016/10/27 00:59:20
Just, "namespace".
shalamov
2016/10/27 13:51:08
Done.
| |
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_(std::move(sensor_reader)), | |
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 DCHECK(sensor_reader_); | |
33 return sensor_reader_->GetReportingMode(); | |
34 } | |
35 | |
36 void PlatformSensorWin::OnReadingUpdated(const SensorReading& reading) { | |
37 UpdateSensorReading(reading, | |
38 GetReportingMode() == mojom::ReportingMode::ON_CHANGE); | |
39 } | |
40 | |
41 void PlatformSensorWin::OnSensorError() { | |
42 task_runner_->PostTask(FROM_HERE, | |
43 base::Bind(&PlatformSensorWin::NotifySensorError, | |
44 weak_factory_.GetWeakPtr())); | |
45 } | |
46 | |
47 bool PlatformSensorWin::StartSensor( | |
48 const PlatformSensorConfiguration& configuration) { | |
49 DCHECK(task_runner_->BelongsToCurrentThread()); | |
50 return sensor_reader_->StartSensor(configuration); | |
51 } | |
52 | |
53 void PlatformSensorWin::StopSensor() { | |
54 DCHECK(task_runner_->BelongsToCurrentThread()); | |
55 sensor_reader_->StopSensor(); | |
56 } | |
57 | |
58 bool PlatformSensorWin::CheckSensorConfiguration( | |
59 const PlatformSensorConfiguration& configuration) { | |
60 DCHECK(sensor_reader_); | |
61 DCHECK(task_runner_->BelongsToCurrentThread()); | |
62 double minimal_reporting_interval_ms = | |
63 sensor_reader_->GetMinimalReportingIntervalMs(); | |
64 if (minimal_reporting_interval_ms == 0) | |
65 return true; | |
66 double min_frequency = | |
67 1 / (minimal_reporting_interval_ms / base::Time::kMillisecondsPerSecond); | |
68 return configuration.frequency() <= min_frequency; | |
69 } | |
70 | |
71 PlatformSensorWin::~PlatformSensorWin() { | |
72 sensor_reader_->SetClient(nullptr); | |
73 sensor_thread_runner_->DeleteSoon(FROM_HERE, sensor_reader_.release()); | |
74 } | |
75 | |
76 } // namespace device | |
OLD | NEW |