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

Unified Diff: device/generic_sensor/platform_sensor_ambient_light_mac.cc

Issue 2332903002: [sensors] [mac] Implement ambient light sensor for macOS (Closed)
Patch Set: More style fixes and build fixes 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_ambient_light_mac.cc
diff --git a/device/generic_sensor/platform_sensor_ambient_light_mac.cc b/device/generic_sensor/platform_sensor_ambient_light_mac.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c46df34372b1e8dc847ad63ed67450c04d41ebb5
--- /dev/null
+++ b/device/generic_sensor/platform_sensor_ambient_light_mac.cc
@@ -0,0 +1,70 @@
+// 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_ambient_light_mac.h"
+
+#include "base/bind.h"
+#include "device/generic_sensor/ambient_light_mac.h"
+#include "device/generic_sensor/platform_sensor_provider_mac.h"
+#include "device/generic_sensor/shared_memory_seqlock_buffer.h"
+
+namespace device {
+
+using DeviceLightHardwareBuffer = SharedMemorySeqLockBuffer<double>;
+
+PlatformSensorAmbientLightMac::PlatformSensorAmbientLightMac(
+ mojom::SensorType type,
+ mojo::ScopedSharedBufferMapping mapping,
+ uint64_t buffer_size,
+ PlatformSensorProvider* provider,
+ scoped_refptr<base::SingleThreadTaskRunner> polling_thread_task_runner)
+ : PlatformSensorMac(type,
+ std::move(mapping),
+ provider,
+ polling_thread_task_runner),
+ current_lux(0) {
+ platformSensor_ = AmbientLightSensor::Create();
+}
+
+PlatformSensorAmbientLightMac::~PlatformSensorAmbientLightMac() = default;
+
+mojom::ReportingMode PlatformSensorAmbientLightMac::GetReportingMode() {
+ return mojom::ReportingMode::ON_CHANGE;
+}
+
+bool PlatformSensorAmbientLightMac::CheckSensorConfiguration(
+ const PlatformSensorConfiguration& configuration) {
+ return configuration.frequency() > 0 &&
+ configuration.frequency() <=
+ PlatformSensorConfiguration::kMaxAllowedFrequency;
+}
+
+PlatformSensorConfiguration
+PlatformSensorAmbientLightMac::GetDefaultConfiguration() {
+ PlatformSensorConfiguration default_configuration;
+ // Default configuration inherited from content/browser/device_sensors.
+ default_configuration.set_frequency(5);
+ return default_configuration;
+}
+
+void PlatformSensorAmbientLightMac::UpdateReading() {
+ uint64_t lux_value[2];
+ platformSensor_->ReadSensorValue(lux_value);
+ uint64_t mean = (lux_value[0] + lux_value[1]) / 2;
+ double lux = AmbientLightSensor::LMUvalueToLux(mean);
+ if (lux == current_lux)
+ return;
+ current_lux = lux;
+ DeviceLightHardwareBuffer* light_buffer =
+ static_cast<DeviceLightHardwareBuffer*>(shared_buffer_mapping_.get());
+ light_buffer->seqlock.WriteBegin();
+ light_buffer->data = lux;
+ light_buffer->seqlock.WriteEnd();
+ ui_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&PlatformSensorAmbientLightMac::NotifySensorReadingChanged,
+ base::Unretained(this)));
Mikhail 2016/09/19 06:25:18 GetWeakPtr() to solve the potential raise conditio
+}
+
+} // namespace device

Powered by Google App Engine
This is Rietveld 408576698