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

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

Issue 2447973003: [sensors] [win] Implement ambient light sensor for Windows platform (Closed)
Patch Set: Rebased to master Created 4 years, 1 month 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
« no previous file with comments | « device/generic_sensor/platform_sensor_win.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "device/generic_sensor/platform_sensor_win.h"
6
7 namespace device {
8
9 namespace {
10 constexpr double kDefaultSensorReportingFrequency = 5.0;
11 } // namespace
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_(sensor_reader.release()),
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 return sensor_reader_->GetReportingMode();
33 }
34
35 void PlatformSensorWin::OnReadingUpdated(const SensorReading& reading) {
36 UpdateSensorReading(reading,
37 GetReportingMode() == mojom::ReportingMode::ON_CHANGE);
38 }
39
40 void PlatformSensorWin::OnSensorError() {
41 task_runner_->PostTask(FROM_HERE,
42 base::Bind(&PlatformSensorWin::NotifySensorError,
43 weak_factory_.GetWeakPtr()));
44 }
45
46 bool PlatformSensorWin::StartSensor(
47 const PlatformSensorConfiguration& configuration) {
48 DCHECK(task_runner_->BelongsToCurrentThread());
49 return sensor_reader_->StartSensor(configuration);
50 }
51
52 void PlatformSensorWin::StopSensor() {
53 DCHECK(task_runner_->BelongsToCurrentThread());
54 sensor_reader_->StopSensor();
55 }
56
57 bool PlatformSensorWin::CheckSensorConfiguration(
58 const PlatformSensorConfiguration& configuration) {
59 DCHECK(task_runner_->BelongsToCurrentThread());
60 double minimal_reporting_interval_ms =
61 sensor_reader_->GetMinimalReportingIntervalMs();
62 if (minimal_reporting_interval_ms == 0)
63 return true;
64 double min_frequency =
65 base::Time::kMillisecondsPerSecond / minimal_reporting_interval_ms;
66 return configuration.frequency() <= min_frequency;
67 }
68
69 PlatformSensorWin::~PlatformSensorWin() {
70 sensor_reader_->SetClient(nullptr);
71 sensor_thread_runner_->DeleteSoon(FROM_HERE, sensor_reader_);
72 }
73
74 } // namespace device
OLDNEW
« no previous file with comments | « device/generic_sensor/platform_sensor_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698