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..96098eeebfd1bda92d9deabadaad50f3db6a65d6 | 
| --- /dev/null | 
| +++ b/device/generic_sensor/platform_sensor_ambient_light_mac.cc | 
| @@ -0,0 +1,73 @@ | 
| +// 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/platform_sensor_util_mac.h" | 
| +#include "device/generic_sensor/shared_memory_seqlock_buffer.h" | 
| + | 
| +namespace device { | 
| + | 
| +struct DeviceLightData { | 
| 
 
Mikhail
2016/09/16 16:23:54
why is that needed?
 
 | 
| + DeviceLightData() : illuminance(0) {} | 
| + double illuminance; | 
| +}; | 
| + | 
| +typedef SharedMemorySeqLockBuffer<DeviceLightData> DeviceLightHardwareBuffer; | 
| 
 
Mikhail
2016/09/16 16:23:54
nit: using DeviceLightHardwareBuffer = ..
 
 | 
| + | 
| +PlatformSensorAmbientLightMac::PlatformSensorAmbientLightMac( | 
| + mojom::SensorType type, | 
| + mojo::ScopedSharedBufferMapping mapping, | 
| + uint64_t buffer_size, | 
| + PlatformSensorProvider* provider, | 
| + const scoped_refptr<base::SingleThreadTaskRunner>& | 
| + polling_thread_task_runner) | 
| + : PlatformSensorMac(type, | 
| + std::move(mapping), | 
| + provider, | 
| + polling_thread_task_runner), | 
| + current_lux(0) { | 
| + platformSensor_ = AmbientLightSensor::Create(); | 
| +} | 
| + | 
| +mojom::ReportingMode PlatformSensorAmbientLightMac::GetReportingMode() { | 
| + return mojom::ReportingMode::ON_CHANGE; | 
| +} | 
| + | 
| +bool PlatformSensorAmbientLightMac::CheckSensorConfiguration( | 
| + const PlatformSensorConfiguration& configuration) { | 
| + return configuration.frequency() > 0 && configuration.frequency() <= 60; | 
| 
 
Mikhail
2016/09/16 16:23:54
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 = device::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.illuminance = lux; | 
| + light_buffer->seqlock.WriteEnd(); | 
| + ui_task_runner_->PostTask( | 
| + FROM_HERE, | 
| + base::Bind(&PlatformSensorAmbientLightMac::NotifySensorReadingChanged, | 
| + base::Unretained(this))); | 
| +} | 
| + | 
| +} // namespace device |