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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/generic_sensor/platform_sensor_win.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/generic_sensor/platform_sensor_win.cc
diff --git a/device/generic_sensor/platform_sensor_win.cc b/device/generic_sensor/platform_sensor_win.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cb4cecff851822c760c6a7c2bd66b83e93e0d801
--- /dev/null
+++ b/device/generic_sensor/platform_sensor_win.cc
@@ -0,0 +1,74 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "device/generic_sensor/platform_sensor_win.h"
+
+namespace device {
+
+namespace {
+constexpr double kDefaultSensorReportingFrequency = 5.0;
+} // namespace
+
+PlatformSensorWin::PlatformSensorWin(
+ mojom::SensorType type,
+ mojo::ScopedSharedBufferMapping mapping,
+ PlatformSensorProvider* provider,
+ scoped_refptr<base::SingleThreadTaskRunner> sensor_thread_runner,
+ std::unique_ptr<PlatformSensorReaderWin> sensor_reader)
+ : PlatformSensor(type, std::move(mapping), provider),
+ sensor_thread_runner_(sensor_thread_runner),
+ sensor_reader_(sensor_reader.release()),
+ weak_factory_(this) {
+ DCHECK(sensor_reader_);
+ sensor_reader_->SetClient(this);
+}
+
+PlatformSensorConfiguration PlatformSensorWin::GetDefaultConfiguration() {
+ return PlatformSensorConfiguration(kDefaultSensorReportingFrequency);
+}
+
+mojom::ReportingMode PlatformSensorWin::GetReportingMode() {
+ return sensor_reader_->GetReportingMode();
+}
+
+void PlatformSensorWin::OnReadingUpdated(const SensorReading& reading) {
+ UpdateSensorReading(reading,
+ GetReportingMode() == mojom::ReportingMode::ON_CHANGE);
+}
+
+void PlatformSensorWin::OnSensorError() {
+ task_runner_->PostTask(FROM_HERE,
+ base::Bind(&PlatformSensorWin::NotifySensorError,
+ weak_factory_.GetWeakPtr()));
+}
+
+bool PlatformSensorWin::StartSensor(
+ const PlatformSensorConfiguration& configuration) {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+ return sensor_reader_->StartSensor(configuration);
+}
+
+void PlatformSensorWin::StopSensor() {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+ sensor_reader_->StopSensor();
+}
+
+bool PlatformSensorWin::CheckSensorConfiguration(
+ const PlatformSensorConfiguration& configuration) {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+ double minimal_reporting_interval_ms =
+ sensor_reader_->GetMinimalReportingIntervalMs();
+ if (minimal_reporting_interval_ms == 0)
+ return true;
+ double min_frequency =
+ base::Time::kMillisecondsPerSecond / minimal_reporting_interval_ms;
+ return configuration.frequency() <= min_frequency;
+}
+
+PlatformSensorWin::~PlatformSensorWin() {
+ sensor_reader_->SetClient(nullptr);
+ sensor_thread_runner_->DeleteSoon(FROM_HERE, sensor_reader_);
+}
+
+} // namespace device
« 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