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

Unified Diff: content/browser/device_sensors/data_fetcher_shared_memory_win.cc

Issue 754963006: Windows: Ambient Light API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add dcheck Created 5 years, 10 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
« no previous file with comments | « content/browser/device_sensors/data_fetcher_shared_memory.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 77c962ecd9b97b80fb2c3cc30ca1b6f5d47a75f4..7b29bfd02614f889b4fccb1231acd4281fcb54eb 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,13 @@ namespace {
const double kMeanGravity = 9.80665;
+void SetLightBuffer(content::DeviceLightHardwareBuffer* buffer, double lux) {
+ DCHECK(buffer);
+ buffer->seqlock.WriteBegin();
+ buffer->data.value = lux;
+ buffer->seqlock.WriteEnd();
+}
+
} // namespace
@@ -222,8 +229,41 @@ 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);
+
+ if(!has_lux) {
+ // Could not get lux value.
+ return false;
+ }
+
+ 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 +317,22 @@ bool DataFetcherSharedMemory::Start(ConsumerType consumer_type, void* buffer) {
SetBufferAvailableState(consumer_type, true);
}
break;
+ case CONSUMER_TYPE_LIGHT:
+ {
+ 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) {
+ SetLightBuffer(light_buffer_, -1);
+ return true;
+ }
+
+ // if no sensors are available, fire an Infinity event.
+ SetLightBuffer(light_buffer_, std::numeric_limits<double>::infinity());
+ }
+ break;
default:
NOTREACHED();
}
@@ -293,6 +349,10 @@ bool DataFetcherSharedMemory::Stop(ConsumerType consumer_type) {
case CONSUMER_TYPE_MOTION:
motion_buffer_ = nullptr;
return true;
+ case CONSUMER_TYPE_LIGHT:
+ SetLightBuffer(light_buffer_, -1);
+ light_buffer_ = nullptr;
+ return true;
default:
NOTREACHED();
}
@@ -368,6 +428,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();
}
« no previous file with comments | « content/browser/device_sensors/data_fetcher_shared_memory.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698