| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/device_sensors/sensor_manager_android.h" | 5 #include "content/browser/device_sensors/sensor_manager_android.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "base/android/context_utils.h" | 9 #include "base/android/context_utils.h" |
| 10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 device_light_buffer_->seqlock.WriteBegin(); | 204 device_light_buffer_->seqlock.WriteBegin(); |
| 205 device_light_buffer_->data.value = value; | 205 device_light_buffer_->data.value = value; |
| 206 device_light_buffer_->seqlock.WriteEnd(); | 206 device_light_buffer_->seqlock.WriteEnd(); |
| 207 } | 207 } |
| 208 | 208 |
| 209 bool SensorManagerAndroid::Start(ConsumerType consumer_type) { | 209 bool SensorManagerAndroid::Start(ConsumerType consumer_type) { |
| 210 DCHECK(!device_sensors_.is_null()); | 210 DCHECK(!device_sensors_.is_null()); |
| 211 int rate_in_microseconds = (consumer_type == CONSUMER_TYPE_LIGHT) | 211 int rate_in_microseconds = (consumer_type == CONSUMER_TYPE_LIGHT) |
| 212 ? kLightSensorIntervalMicroseconds | 212 ? kLightSensorIntervalMicroseconds |
| 213 : kDeviceSensorIntervalMicroseconds; | 213 : kDeviceSensorIntervalMicroseconds; |
| 214 return Java_DeviceSensors_start(AttachCurrentThread(), | 214 return Java_DeviceSensors_start( |
| 215 device_sensors_.obj(), | 215 AttachCurrentThread(), device_sensors_, reinterpret_cast<intptr_t>(this), |
| 216 reinterpret_cast<intptr_t>(this), | 216 static_cast<jint>(consumer_type), rate_in_microseconds); |
| 217 static_cast<jint>(consumer_type), | |
| 218 rate_in_microseconds); | |
| 219 } | 217 } |
| 220 | 218 |
| 221 void SensorManagerAndroid::Stop(ConsumerType consumer_type) { | 219 void SensorManagerAndroid::Stop(ConsumerType consumer_type) { |
| 222 DCHECK(!device_sensors_.is_null()); | 220 DCHECK(!device_sensors_.is_null()); |
| 223 Java_DeviceSensors_stop(AttachCurrentThread(), | 221 Java_DeviceSensors_stop(AttachCurrentThread(), device_sensors_, |
| 224 device_sensors_.obj(), | |
| 225 static_cast<jint>(consumer_type)); | 222 static_cast<jint>(consumer_type)); |
| 226 } | 223 } |
| 227 | 224 |
| 228 int SensorManagerAndroid::GetNumberActiveDeviceMotionSensors() { | 225 int SensorManagerAndroid::GetNumberActiveDeviceMotionSensors() { |
| 229 DCHECK(!device_sensors_.is_null()); | 226 DCHECK(!device_sensors_.is_null()); |
| 230 return Java_DeviceSensors_getNumberActiveDeviceMotionSensors( | 227 return Java_DeviceSensors_getNumberActiveDeviceMotionSensors( |
| 231 AttachCurrentThread(), device_sensors_.obj()); | 228 AttachCurrentThread(), device_sensors_); |
| 232 } | 229 } |
| 233 | 230 |
| 234 SensorManagerAndroid::OrientationSensorType | 231 SensorManagerAndroid::OrientationSensorType |
| 235 SensorManagerAndroid::GetOrientationSensorTypeUsed() { | 232 SensorManagerAndroid::GetOrientationSensorTypeUsed() { |
| 236 DCHECK(!device_sensors_.is_null()); | 233 DCHECK(!device_sensors_.is_null()); |
| 237 return static_cast<SensorManagerAndroid::OrientationSensorType>( | 234 return static_cast<SensorManagerAndroid::OrientationSensorType>( |
| 238 Java_DeviceSensors_getOrientationSensorTypeUsed( | 235 Java_DeviceSensors_getOrientationSensorTypeUsed(AttachCurrentThread(), |
| 239 AttachCurrentThread(), device_sensors_.obj())); | 236 device_sensors_)); |
| 240 } | 237 } |
| 241 | 238 |
| 242 // ----- Shared memory API methods | 239 // ----- Shared memory API methods |
| 243 | 240 |
| 244 // --- Device Light | 241 // --- Device Light |
| 245 | 242 |
| 246 void SensorManagerAndroid::StartFetchingDeviceLightData( | 243 void SensorManagerAndroid::StartFetchingDeviceLightData( |
| 247 DeviceLightHardwareBuffer* buffer) { | 244 DeviceLightHardwareBuffer* buffer) { |
| 248 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 245 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 249 StartFetchingLightDataOnUI(buffer); | 246 StartFetchingLightDataOnUI(buffer); |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 } | 540 } |
| 544 } | 541 } |
| 545 } | 542 } |
| 546 | 543 |
| 547 void SensorManagerAndroid::Shutdown() { | 544 void SensorManagerAndroid::Shutdown() { |
| 548 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 545 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 549 is_shutdown_ = true; | 546 is_shutdown_ = true; |
| 550 } | 547 } |
| 551 | 548 |
| 552 } // namespace content | 549 } // namespace content |
| OLD | NEW |