Chromium Code Reviews| 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 |