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

Unified Diff: content/browser/device_orientation/sensor_manager_android.cc

Issue 152893002: [DeviceLight API] Content Side Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix in Java file, stop() Created 6 years, 9 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: content/browser/device_orientation/sensor_manager_android.cc
diff --git a/content/browser/device_orientation/sensor_manager_android.cc b/content/browser/device_orientation/sensor_manager_android.cc
index cec2c5e6a5eaba9bc30fc4d99fc09ac0b74fde53..77afb71abc3119b927c2fef8261c6832c2ed4c13 100644
--- a/content/browser/device_orientation/sensor_manager_android.cc
+++ b/content/browser/device_orientation/sensor_manager_android.cc
@@ -26,8 +26,10 @@ namespace content {
SensorManagerAndroid::SensorManagerAndroid()
: number_active_device_motion_sensors_(0),
+ device_light_buffer_(NULL),
device_motion_buffer_(NULL),
device_orientation_buffer_(NULL),
+ is_light_buffer_ready_(false),
is_motion_buffer_ready_(false),
is_orientation_buffer_ready_(false) {
memset(received_motion_data_, 0, sizeof(received_motion_data_));
@@ -137,6 +139,23 @@ void SensorManagerAndroid::GotRotationRate(
}
}
+void SensorManagerAndroid::GotLight(
+ JNIEnv*, jobject, double value) {
+ base::AutoLock autolock(light_buffer_lock_);
+
+ if (!device_light_buffer_)
+ return;
+
+ device_light_buffer_->seqlock.WriteBegin();
+ device_light_buffer_->data = value;
+
+ device_light_buffer_->seqlock.WriteEnd();
+
+ if (!is_light_buffer_ready_) {
+ SetLightBufferReadyStatus(true);
+ }
+}
+
bool SensorManagerAndroid::Start(EventType event_type) {
DCHECK(!device_orientation_.is_null());
return Java_DeviceMotionAndOrientation_start(
@@ -161,6 +180,45 @@ int SensorManagerAndroid::GetNumberActiveDeviceMotionSensors() {
// ----- Shared memory API methods
+// --- Device Light
+
+bool SensorManagerAndroid::StartFetchingDeviceLightData(
+ DeviceLightHardwareBuffer* buffer) {
+ DCHECK(buffer);
+ {
+ base::AutoLock autolock(light_buffer_lock_);
+ device_light_buffer_ = buffer;
+ ClearInternalLightBuffers();
+ }
+ bool success = Start(kTypeLight);
+ {
+ base::AutoLock autolock(light_buffer_lock_);
+ // If Start() was unsuccessful then set the buffer ready flag to true
+ // to start firing all-null events.
+ SetLightBufferReadyStatus(!success);
+ }
+ return success;
+}
+
+void SensorManagerAndroid::StopFetchingDeviceLightData() {
+ Stop(kTypeLight);
+ {
+ base::AutoLock autolock(light_buffer_lock_);
+ if (device_light_buffer_) {
+ ClearInternalLightBuffers();
+ device_light_buffer_ = NULL;
+ }
+ }
+}
+
+void SensorManagerAndroid::SetLightBufferReadyStatus(bool ready) {
+ is_light_buffer_ready_ = ready;
+}
+
+void SensorManagerAndroid::ClearInternalLightBuffers() {
+ SetLightBufferReadyStatus(false);
+}
+
// --- Device Motion
bool SensorManagerAndroid::StartFetchingDeviceMotionData(
« no previous file with comments | « content/browser/device_orientation/sensor_manager_android.h ('k') | content/browser/renderer_host/render_process_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698