Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(220)

Side by Side Diff: services/device/generic_sensor/platform_sensor_win.cc

Issue 2898433002: Revert of Move //device/generic_sensor to be part of the internal implementation of the Device Service. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "services/device/generic_sensor/platform_sensor_win.h"
6
7 #include "base/single_thread_task_runner.h"
8
9 namespace device {
10
11 namespace {
12 constexpr double kDefaultSensorReportingFrequency = 5.0;
13 } // namespace
14
15 PlatformSensorWin::PlatformSensorWin(
16 mojom::SensorType type,
17 mojo::ScopedSharedBufferMapping mapping,
18 PlatformSensorProvider* provider,
19 scoped_refptr<base::SingleThreadTaskRunner> sensor_thread_runner,
20 std::unique_ptr<PlatformSensorReaderWin> sensor_reader)
21 : PlatformSensor(type, std::move(mapping), provider),
22 sensor_thread_runner_(sensor_thread_runner),
23 sensor_reader_(sensor_reader.release()),
24 weak_factory_(this) {
25 DCHECK(sensor_reader_);
26 sensor_reader_->SetClient(this);
27 }
28
29 PlatformSensorConfiguration PlatformSensorWin::GetDefaultConfiguration() {
30 return PlatformSensorConfiguration(kDefaultSensorReportingFrequency);
31 }
32
33 mojom::ReportingMode PlatformSensorWin::GetReportingMode() {
34 // All Windows sensors, even with high accuracy / sensitivity will not report
35 // reading updates continuously. Therefore, return ON_CHANGE by default.
36 return mojom::ReportingMode::ON_CHANGE;
37 }
38
39 double PlatformSensorWin::GetMaximumSupportedFrequency() {
40 double minimal_reporting_interval_ms =
41 sensor_reader_->GetMinimalReportingIntervalMs();
42 if (!minimal_reporting_interval_ms)
43 return kDefaultSensorReportingFrequency;
44 return base::Time::kMillisecondsPerSecond / minimal_reporting_interval_ms;
45 }
46
47 void PlatformSensorWin::OnReadingUpdated(const SensorReading& reading) {
48 // Default reporting mode is ON_CHANGE, thus, set notify_clients parameter
49 // to true.
50 UpdateSensorReading(reading, true);
51 }
52
53 void PlatformSensorWin::OnSensorError() {
54 task_runner_->PostTask(FROM_HERE,
55 base::Bind(&PlatformSensorWin::NotifySensorError,
56 weak_factory_.GetWeakPtr()));
57 }
58
59 bool PlatformSensorWin::StartSensor(
60 const PlatformSensorConfiguration& configuration) {
61 DCHECK(task_runner_->BelongsToCurrentThread());
62 return sensor_reader_->StartSensor(configuration);
63 }
64
65 void PlatformSensorWin::StopSensor() {
66 DCHECK(task_runner_->BelongsToCurrentThread());
67 sensor_reader_->StopSensor();
68 }
69
70 bool PlatformSensorWin::CheckSensorConfiguration(
71 const PlatformSensorConfiguration& configuration) {
72 DCHECK(task_runner_->BelongsToCurrentThread());
73 double minimal_reporting_interval_ms =
74 sensor_reader_->GetMinimalReportingIntervalMs();
75 if (minimal_reporting_interval_ms == 0)
76 return true;
77 double max_frequency =
78 base::Time::kMillisecondsPerSecond / minimal_reporting_interval_ms;
79 return configuration.frequency() <= max_frequency;
80 }
81
82 PlatformSensorWin::~PlatformSensorWin() {
83 sensor_reader_->SetClient(nullptr);
84 sensor_thread_runner_->DeleteSoon(FROM_HERE, sensor_reader_);
85 }
86
87 } // namespace device
OLDNEW
« no previous file with comments | « services/device/generic_sensor/platform_sensor_win.h ('k') | services/device/generic_sensor/sensor_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698