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

Unified Diff: device/generic_sensor/platform_sensor_polling_mac.cc

Issue 2332903002: [sensors] [mac] Implement ambient light sensor for macOS (Closed)
Patch Set: Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: device/generic_sensor/platform_sensor_polling_mac.cc
diff --git a/device/generic_sensor/platform_sensor_polling_mac.cc b/device/generic_sensor/platform_sensor_polling_mac.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e3199347e30338061cfe9b1d87bd6193c44bb1df
--- /dev/null
+++ b/device/generic_sensor/platform_sensor_polling_mac.cc
@@ -0,0 +1,40 @@
+// 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_polling_mac.h"
+
+#include "device/generic_sensor/platform_sensor_mac.h"
+
+namespace device {
+
+SensorsPollingThreadMac::SensorsPollingThreadMac(const char* name)
+ : base::Thread(name) {}
+
+SensorsPollingThreadMac::~SensorsPollingThreadMac() = default;
+
+void SensorsPollingThreadMac::BeginPollingSensor(
+ PlatformSensorMac* sensor,
+ const PlatformSensorConfiguration& configuration) {
+ auto it = sensors_.find(sensor);
+ if (it != sensors_.end())
+ return;
+
+ std::unique_ptr<base::RepeatingTimer> timer(new base::RepeatingTimer);
+ timer->Start(FROM_HERE, base::TimeDelta::FromMicroseconds(
+ base::Time::kMicrosecondsPerSecond /
+ configuration.frequency()),
+ sensor, &PlatformSensorMac::UpdateReading);
+ sensors_.insert({sensor, std::move(timer)});
+}
+
+void SensorsPollingThreadMac::StopPollingSensor(PlatformSensorMac* sensor) {
+ auto it = sensors_.find(sensor);
+ if (it == sensors_.end())
+ return;
+
+ it->second.reset();
+ sensors_.erase(it);
+}
+
+} // namespace device

Powered by Google App Engine
This is Rietveld 408576698