Chromium Code Reviews| Index: content/browser/device_sensors/data_fetcher_shared_memory_win.cc |
| diff --git a/content/browser/device_sensors/data_fetcher_shared_memory_win.cc b/content/browser/device_sensors/data_fetcher_shared_memory_win.cc |
| index c5d24fc75198cd743fbd9ca54070ab9dfcb4c3e4..28582eae8c3fd17904100b013a3b95b33cf0fea4 100644 |
| --- a/content/browser/device_sensors/data_fetcher_shared_memory_win.cc |
| +++ b/content/browser/device_sensors/data_fetcher_shared_memory_win.cc |
| @@ -18,6 +18,16 @@ namespace { |
| const double kMeanGravity = 9.80665; |
| +static bool SetLightBuffer(content::DeviceLightHardwareBuffer* buffer, |
|
timvolodine
2015/03/02 17:39:58
no need for static
riju_
2015/03/03 09:53:55
Done.
|
| + double lux) { |
| + if (!buffer) |
| + return false; |
| + buffer->seqlock.WriteBegin(); |
| + buffer->data.value = lux; |
| + buffer->seqlock.WriteEnd(); |
| + return true; |
|
timvolodine
2015/03/02 17:39:58
do you need to return anything at all? the result
riju_
2015/03/03 09:53:55
Done.
|
| +} |
| + |
| } // namespace |
| @@ -222,8 +232,36 @@ class DataFetcherSharedMemory::SensorEventSinkMotion |
| DISALLOW_COPY_AND_ASSIGN(SensorEventSinkMotion); |
| }; |
| +class DataFetcherSharedMemory::SensorEventSinkLight |
| + : public DataFetcherSharedMemory::SensorEventSink { |
| + public: |
| + explicit SensorEventSinkLight(DeviceLightHardwareBuffer* const buffer) |
| + : buffer_(buffer) {} |
| + virtual ~SensorEventSinkLight() {} |
| + |
| + protected: |
| + virtual bool UpdateSharedMemoryBuffer(ISensor* sensor, |
| + ISensorDataReport* new_data) override { |
| + double lux; |
| + bool has_lux; |
| + |
| + GetSensorValue(SENSOR_DATA_TYPE_LIGHT_LEVEL_LUX, new_data, &lux, &has_lux); |
|
timvolodine
2015/03/02 17:39:58
has_lux does not seem be used after the call. shou
riju_
2015/03/03 09:53:55
Done. returning early if valid no lux value is fou
|
| + |
| + SetLightBuffer(buffer_, lux); |
| + |
| + return true; |
| + } |
| + |
| + private: |
| + DeviceLightHardwareBuffer* const buffer_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SensorEventSinkLight); |
| +}; |
| + |
| DataFetcherSharedMemory::DataFetcherSharedMemory() |
| - : motion_buffer_(nullptr), orientation_buffer_(nullptr) { |
| + : motion_buffer_(nullptr), |
| + orientation_buffer_(nullptr), |
| + light_buffer_(nullptr) { |
| } |
| DataFetcherSharedMemory::~DataFetcherSharedMemory() { |
| @@ -277,6 +315,20 @@ bool DataFetcherSharedMemory::Start(ConsumerType consumer_type, void* buffer) { |
| SetBufferAvailableState(consumer_type, true); |
| } |
| break; |
| + case CONSUMER_TYPE_LIGHT: |
|
timvolodine
2015/03/02 17:39:58
alignment as with above cases
riju_
2015/03/03 09:53:55
Done.
|
| + { |
| + light_buffer_ = static_cast<DeviceLightHardwareBuffer*>(buffer); |
| + scoped_refptr<SensorEventSink> sink( |
| + new SensorEventSinkLight(light_buffer_)); |
| + bool sensor_light_available = RegisterForSensor( |
| + SENSOR_TYPE_AMBIENT_LIGHT, sensor_light_.Receive(), sink); |
| + if (sensor_light_available) |
|
timvolodine
2015/03/02 17:39:58
what's the value of the buffer? should it be initi
riju_
2015/03/03 09:53:55
Done.
|
| + return true; |
| + |
| + // if no sensors are available, fire an Infinity event. |
| + SetLightBuffer(light_buffer_, std::numeric_limits<double>::infinity()); |
| + } |
| + break; |
| default: |
| NOTREACHED(); |
| } |
| @@ -293,6 +345,9 @@ bool DataFetcherSharedMemory::Stop(ConsumerType consumer_type) { |
| case CONSUMER_TYPE_MOTION: |
| motion_buffer_ = nullptr; |
| return true; |
| + case CONSUMER_TYPE_LIGHT: |
| + SetLightBuffer(light_buffer_, -1); |
|
timvolodine
2015/03/02 17:39:58
also light_buffer = nullptr?
riju_
2015/03/03 09:53:55
Done.
|
| + return true; |
| default: |
| NOTREACHED(); |
| } |
| @@ -368,6 +423,12 @@ void DataFetcherSharedMemory::DisableSensors(ConsumerType consumer_type) { |
| sensor_gyrometer_.Release(); |
| } |
| break; |
| + case CONSUMER_TYPE_LIGHT: |
| + if (sensor_light_.get()) { |
| + sensor_light_->SetEventSink(nullptr); |
| + sensor_light_.Release(); |
| + } |
| + break; |
| default: |
| NOTREACHED(); |
| } |