| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 namespace content { | 51 namespace content { |
| 52 | 52 |
| 53 SensorManagerAndroid::SensorManagerAndroid() | 53 SensorManagerAndroid::SensorManagerAndroid() |
| 54 : number_active_device_motion_sensors_(0), | 54 : number_active_device_motion_sensors_(0), |
| 55 device_light_buffer_(nullptr), | 55 device_light_buffer_(nullptr), |
| 56 device_motion_buffer_(nullptr), | 56 device_motion_buffer_(nullptr), |
| 57 device_orientation_buffer_(nullptr), | 57 device_orientation_buffer_(nullptr), |
| 58 motion_buffer_initialized_(false), | 58 motion_buffer_initialized_(false), |
| 59 orientation_buffer_initialized_(false), | 59 orientation_buffer_initialized_(false), |
| 60 is_shutdown_(false) { | 60 is_shutdown_(false) { |
| 61 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 61 memset(received_motion_data_, 0, sizeof(received_motion_data_)); | 62 memset(received_motion_data_, 0, sizeof(received_motion_data_)); |
| 62 device_sensors_.Reset(Java_DeviceSensors_getInstance( | 63 device_sensors_.Reset(Java_DeviceSensors_getInstance( |
| 63 AttachCurrentThread(), base::android::GetApplicationContext())); | 64 AttachCurrentThread(), base::android::GetApplicationContext())); |
| 64 } | 65 } |
| 65 | 66 |
| 66 SensorManagerAndroid::~SensorManagerAndroid() { | 67 SensorManagerAndroid::~SensorManagerAndroid() { |
| 67 } | 68 } |
| 68 | 69 |
| 69 bool SensorManagerAndroid::Register(JNIEnv* env) { | 70 bool SensorManagerAndroid::Register(JNIEnv* env) { |
| 70 return RegisterNativesImpl(env); | 71 return RegisterNativesImpl(env); |
| 71 } | 72 } |
| 72 | 73 |
| 73 SensorManagerAndroid* SensorManagerAndroid::GetInstance() { | 74 SensorManagerAndroid* SensorManagerAndroid::GetInstance() { |
| 75 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 74 return base::Singleton< | 76 return base::Singleton< |
| 75 SensorManagerAndroid, | 77 SensorManagerAndroid, |
| 76 base::LeakySingletonTraits<SensorManagerAndroid>>::get(); | 78 base::LeakySingletonTraits<SensorManagerAndroid>>::get(); |
| 77 } | 79 } |
| 78 | 80 |
| 79 void SensorManagerAndroid::GotOrientation(JNIEnv*, | 81 void SensorManagerAndroid::GotOrientation(JNIEnv*, |
| 80 const JavaParamRef<jobject>&, | 82 const JavaParamRef<jobject>&, |
| 81 double alpha, | 83 double alpha, |
| 82 double beta, | 84 double beta, |
| 83 double gamma) { | 85 double gamma) { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 | 202 |
| 201 if (!device_light_buffer_) | 203 if (!device_light_buffer_) |
| 202 return; | 204 return; |
| 203 | 205 |
| 204 device_light_buffer_->seqlock.WriteBegin(); | 206 device_light_buffer_->seqlock.WriteBegin(); |
| 205 device_light_buffer_->data.value = value; | 207 device_light_buffer_->data.value = value; |
| 206 device_light_buffer_->seqlock.WriteEnd(); | 208 device_light_buffer_->seqlock.WriteEnd(); |
| 207 } | 209 } |
| 208 | 210 |
| 209 bool SensorManagerAndroid::Start(ConsumerType consumer_type) { | 211 bool SensorManagerAndroid::Start(ConsumerType consumer_type) { |
| 212 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 210 DCHECK(!device_sensors_.is_null()); | 213 DCHECK(!device_sensors_.is_null()); |
| 211 int rate_in_microseconds = (consumer_type == CONSUMER_TYPE_LIGHT) | 214 int rate_in_microseconds = (consumer_type == CONSUMER_TYPE_LIGHT) |
| 212 ? kLightSensorIntervalMicroseconds | 215 ? kLightSensorIntervalMicroseconds |
| 213 : kDeviceSensorIntervalMicroseconds; | 216 : kDeviceSensorIntervalMicroseconds; |
| 214 return Java_DeviceSensors_start( | 217 return Java_DeviceSensors_start( |
| 215 AttachCurrentThread(), device_sensors_, reinterpret_cast<intptr_t>(this), | 218 AttachCurrentThread(), device_sensors_, reinterpret_cast<intptr_t>(this), |
| 216 static_cast<jint>(consumer_type), rate_in_microseconds); | 219 static_cast<jint>(consumer_type), rate_in_microseconds); |
| 217 } | 220 } |
| 218 | 221 |
| 219 void SensorManagerAndroid::Stop(ConsumerType consumer_type) { | 222 void SensorManagerAndroid::Stop(ConsumerType consumer_type) { |
| 223 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 220 DCHECK(!device_sensors_.is_null()); | 224 DCHECK(!device_sensors_.is_null()); |
| 221 Java_DeviceSensors_stop(AttachCurrentThread(), device_sensors_, | 225 Java_DeviceSensors_stop(AttachCurrentThread(), device_sensors_, |
| 222 static_cast<jint>(consumer_type)); | 226 static_cast<jint>(consumer_type)); |
| 223 } | 227 } |
| 224 | 228 |
| 225 int SensorManagerAndroid::GetNumberActiveDeviceMotionSensors() { | 229 int SensorManagerAndroid::GetNumberActiveDeviceMotionSensors() { |
| 230 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 226 DCHECK(!device_sensors_.is_null()); | 231 DCHECK(!device_sensors_.is_null()); |
| 227 return Java_DeviceSensors_getNumberActiveDeviceMotionSensors( | 232 return Java_DeviceSensors_getNumberActiveDeviceMotionSensors( |
| 228 AttachCurrentThread(), device_sensors_); | 233 AttachCurrentThread(), device_sensors_); |
| 229 } | 234 } |
| 230 | 235 |
| 231 SensorManagerAndroid::OrientationSensorType | 236 SensorManagerAndroid::OrientationSensorType |
| 232 SensorManagerAndroid::GetOrientationSensorTypeUsed() { | 237 SensorManagerAndroid::GetOrientationSensorTypeUsed() { |
| 238 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 233 DCHECK(!device_sensors_.is_null()); | 239 DCHECK(!device_sensors_.is_null()); |
| 234 return static_cast<SensorManagerAndroid::OrientationSensorType>( | 240 return static_cast<SensorManagerAndroid::OrientationSensorType>( |
| 235 Java_DeviceSensors_getOrientationSensorTypeUsed(AttachCurrentThread(), | 241 Java_DeviceSensors_getOrientationSensorTypeUsed(AttachCurrentThread(), |
| 236 device_sensors_)); | 242 device_sensors_)); |
| 237 } | 243 } |
| 238 | 244 |
| 239 // ----- Shared memory API methods | 245 // ----- Shared memory API methods |
| 240 | 246 |
| 241 // --- Device Light | 247 // --- Device Light |
| 242 | 248 |
| 243 void SensorManagerAndroid::StartFetchingDeviceLightData( | 249 void SensorManagerAndroid::StartFetchingDeviceLightData( |
| 244 DeviceLightHardwareBuffer* buffer) { | 250 DeviceLightHardwareBuffer* buffer) { |
| 245 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { | |
| 246 StartFetchingLightDataOnUI(buffer); | |
| 247 } else { | |
| 248 BrowserThread::PostTask( | |
| 249 BrowserThread::UI, FROM_HERE, | |
| 250 base::Bind(&SensorManagerAndroid::StartFetchingLightDataOnUI, | |
| 251 base::Unretained(this), | |
| 252 buffer)); | |
| 253 } | |
| 254 } | |
| 255 | |
| 256 void SensorManagerAndroid::StartFetchingLightDataOnUI( | |
| 257 DeviceLightHardwareBuffer* buffer) { | |
| 258 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 251 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 259 DCHECK(buffer); | 252 DCHECK(buffer); |
| 260 if (is_shutdown_) | 253 if (is_shutdown_) |
| 261 return; | 254 return; |
| 262 | 255 |
| 263 { | 256 { |
| 264 base::AutoLock autolock(light_buffer_lock_); | 257 base::AutoLock autolock(light_buffer_lock_); |
| 265 device_light_buffer_ = buffer; | 258 device_light_buffer_ = buffer; |
| 266 SetLightBufferValue(-1); | 259 SetLightBufferValue(-1); |
| 267 } | 260 } |
| 268 bool success = Start(CONSUMER_TYPE_LIGHT); | 261 bool success = Start(CONSUMER_TYPE_LIGHT); |
| 269 if (!success) { | 262 if (!success) { |
| 270 base::AutoLock autolock(light_buffer_lock_); | 263 base::AutoLock autolock(light_buffer_lock_); |
| 271 SetLightBufferValue(std::numeric_limits<double>::infinity()); | 264 SetLightBufferValue(std::numeric_limits<double>::infinity()); |
| 272 } | 265 } |
| 273 } | 266 } |
| 274 | 267 |
| 275 void SensorManagerAndroid::StopFetchingDeviceLightData() { | 268 void SensorManagerAndroid::StopFetchingDeviceLightData() { |
| 276 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { | |
| 277 StopFetchingLightDataOnUI(); | |
| 278 return; | |
| 279 } | |
| 280 | |
| 281 BrowserThread::PostTask( | |
| 282 BrowserThread::UI, FROM_HERE, | |
| 283 base::Bind(&SensorManagerAndroid::StopFetchingLightDataOnUI, | |
| 284 base::Unretained(this))); | |
| 285 } | |
| 286 | |
| 287 void SensorManagerAndroid::StopFetchingLightDataOnUI() { | |
| 288 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 269 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 289 if (is_shutdown_) | 270 if (is_shutdown_) |
| 290 return; | 271 return; |
| 291 | 272 |
| 292 Stop(CONSUMER_TYPE_LIGHT); | 273 Stop(CONSUMER_TYPE_LIGHT); |
| 293 { | 274 { |
| 294 base::AutoLock autolock(light_buffer_lock_); | 275 base::AutoLock autolock(light_buffer_lock_); |
| 295 if (device_light_buffer_) { | 276 if (device_light_buffer_) { |
| 296 SetLightBufferValue(-1); | 277 SetLightBufferValue(-1); |
| 297 device_light_buffer_ = nullptr; | 278 device_light_buffer_ = nullptr; |
| 298 } | 279 } |
| 299 } | 280 } |
| 300 } | 281 } |
| 301 | 282 |
| 302 void SensorManagerAndroid::SetLightBufferValue(double lux) { | 283 void SensorManagerAndroid::SetLightBufferValue(double lux) { |
| 303 device_light_buffer_->seqlock.WriteBegin(); | 284 device_light_buffer_->seqlock.WriteBegin(); |
| 304 device_light_buffer_->data.value = lux; | 285 device_light_buffer_->data.value = lux; |
| 305 device_light_buffer_->seqlock.WriteEnd(); | 286 device_light_buffer_->seqlock.WriteEnd(); |
| 306 } | 287 } |
| 307 | 288 |
| 308 // --- Device Motion | 289 // --- Device Motion |
| 309 | 290 |
| 310 void SensorManagerAndroid::StartFetchingDeviceMotionData( | 291 void SensorManagerAndroid::StartFetchingDeviceMotionData( |
| 311 DeviceMotionHardwareBuffer* buffer) { | 292 DeviceMotionHardwareBuffer* buffer) { |
| 312 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { | |
| 313 StartFetchingMotionDataOnUI(buffer); | |
| 314 } else { | |
| 315 BrowserThread::PostTask( | |
| 316 BrowserThread::UI, FROM_HERE, | |
| 317 base::Bind(&SensorManagerAndroid::StartFetchingMotionDataOnUI, | |
| 318 base::Unretained(this), | |
| 319 buffer)); | |
| 320 } | |
| 321 } | |
| 322 | |
| 323 void SensorManagerAndroid::StartFetchingMotionDataOnUI( | |
| 324 DeviceMotionHardwareBuffer* buffer) { | |
| 325 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 293 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 326 DCHECK(buffer); | 294 DCHECK(buffer); |
| 327 if (is_shutdown_) | 295 if (is_shutdown_) |
| 328 return; | 296 return; |
| 329 | 297 |
| 330 { | 298 { |
| 331 base::AutoLock autolock(motion_buffer_lock_); | 299 base::AutoLock autolock(motion_buffer_lock_); |
| 332 device_motion_buffer_ = buffer; | 300 device_motion_buffer_ = buffer; |
| 333 ClearInternalMotionBuffers(); | 301 ClearInternalMotionBuffers(); |
| 334 } | 302 } |
| 335 Start(CONSUMER_TYPE_MOTION); | 303 Start(CONSUMER_TYPE_MOTION); |
| 336 | 304 |
| 337 // If no motion data can ever be provided, the number of active device motion | 305 // If no motion data can ever be provided, the number of active device motion |
| 338 // sensors will be zero. In that case flag the shared memory buffer | 306 // sensors will be zero. In that case flag the shared memory buffer |
| 339 // as ready to read, as it will not change anyway. | 307 // as ready to read, as it will not change anyway. |
| 340 number_active_device_motion_sensors_ = GetNumberActiveDeviceMotionSensors(); | 308 number_active_device_motion_sensors_ = GetNumberActiveDeviceMotionSensors(); |
| 341 { | 309 { |
| 342 base::AutoLock autolock(motion_buffer_lock_); | 310 base::AutoLock autolock(motion_buffer_lock_); |
| 343 CheckMotionBufferReadyToRead(); | 311 CheckMotionBufferReadyToRead(); |
| 344 } | 312 } |
| 345 } | 313 } |
| 346 | 314 |
| 347 void SensorManagerAndroid::StopFetchingDeviceMotionData() { | 315 void SensorManagerAndroid::StopFetchingDeviceMotionData() { |
| 348 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { | |
| 349 StopFetchingMotionDataOnUI(); | |
| 350 return; | |
| 351 } | |
| 352 | |
| 353 BrowserThread::PostTask( | |
| 354 BrowserThread::UI, FROM_HERE, | |
| 355 base::Bind(&SensorManagerAndroid::StopFetchingMotionDataOnUI, | |
| 356 base::Unretained(this))); | |
| 357 } | |
| 358 | |
| 359 void SensorManagerAndroid::StopFetchingMotionDataOnUI() { | |
| 360 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 316 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 361 if (is_shutdown_) | 317 if (is_shutdown_) |
| 362 return; | 318 return; |
| 363 | 319 |
| 364 Stop(CONSUMER_TYPE_MOTION); | 320 Stop(CONSUMER_TYPE_MOTION); |
| 365 { | 321 { |
| 366 base::AutoLock autolock(motion_buffer_lock_); | 322 base::AutoLock autolock(motion_buffer_lock_); |
| 367 if (device_motion_buffer_) { | 323 if (device_motion_buffer_) { |
| 368 ClearInternalMotionBuffers(); | 324 ClearInternalMotionBuffers(); |
| 369 device_motion_buffer_ = nullptr; | 325 device_motion_buffer_ = nullptr; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 void SensorManagerAndroid::ClearInternalMotionBuffers() { | 359 void SensorManagerAndroid::ClearInternalMotionBuffers() { |
| 404 memset(received_motion_data_, 0, sizeof(received_motion_data_)); | 360 memset(received_motion_data_, 0, sizeof(received_motion_data_)); |
| 405 number_active_device_motion_sensors_ = 0; | 361 number_active_device_motion_sensors_ = 0; |
| 406 SetMotionBufferReadyStatus(false); | 362 SetMotionBufferReadyStatus(false); |
| 407 } | 363 } |
| 408 | 364 |
| 409 // --- Device Orientation | 365 // --- Device Orientation |
| 410 | 366 |
| 411 void SensorManagerAndroid::StartFetchingDeviceOrientationData( | 367 void SensorManagerAndroid::StartFetchingDeviceOrientationData( |
| 412 DeviceOrientationHardwareBuffer* buffer) { | 368 DeviceOrientationHardwareBuffer* buffer) { |
| 413 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { | |
| 414 StartFetchingOrientationDataOnUI(buffer); | |
| 415 } else { | |
| 416 BrowserThread::PostTask( | |
| 417 BrowserThread::UI, FROM_HERE, | |
| 418 base::Bind(&SensorManagerAndroid::StartFetchingOrientationDataOnUI, | |
| 419 base::Unretained(this), | |
| 420 buffer)); | |
| 421 } | |
| 422 } | |
| 423 | |
| 424 void SensorManagerAndroid::StartFetchingOrientationDataOnUI( | |
| 425 DeviceOrientationHardwareBuffer* buffer) { | |
| 426 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 369 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 427 DCHECK(buffer); | 370 DCHECK(buffer); |
| 428 if (is_shutdown_) | 371 if (is_shutdown_) |
| 429 return; | 372 return; |
| 430 | 373 |
| 431 { | 374 { |
| 432 base::AutoLock autolock(orientation_buffer_lock_); | 375 base::AutoLock autolock(orientation_buffer_lock_); |
| 433 device_orientation_buffer_ = buffer; | 376 device_orientation_buffer_ = buffer; |
| 434 } | 377 } |
| 435 bool success = Start(CONSUMER_TYPE_ORIENTATION); | 378 bool success = Start(CONSUMER_TYPE_ORIENTATION); |
| 436 | 379 |
| 437 { | 380 { |
| 438 base::AutoLock autolock(orientation_buffer_lock_); | 381 base::AutoLock autolock(orientation_buffer_lock_); |
| 439 // If Start() was unsuccessful then set the buffer ready flag to true | 382 // If Start() was unsuccessful then set the buffer ready flag to true |
| 440 // to start firing all-null events. | 383 // to start firing all-null events. |
| 441 SetOrientationBufferStatus(buffer, !success /* ready */, | 384 SetOrientationBufferStatus(buffer, !success /* ready */, |
| 442 false /* absolute */); | 385 false /* absolute */); |
| 443 orientation_buffer_initialized_ = !success; | 386 orientation_buffer_initialized_ = !success; |
| 444 } | 387 } |
| 445 | 388 |
| 446 if (!success) | 389 if (!success) |
| 447 UpdateDeviceOrientationHistogram(NOT_AVAILABLE); | 390 UpdateDeviceOrientationHistogram(NOT_AVAILABLE); |
| 448 } | 391 } |
| 449 | 392 |
| 450 void SensorManagerAndroid::StopFetchingDeviceOrientationData() { | 393 void SensorManagerAndroid::StopFetchingDeviceOrientationData() { |
| 451 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { | |
| 452 StopFetchingOrientationDataOnUI(); | |
| 453 return; | |
| 454 } | |
| 455 | |
| 456 BrowserThread::PostTask( | |
| 457 BrowserThread::UI, FROM_HERE, | |
| 458 base::Bind(&SensorManagerAndroid::StopFetchingOrientationDataOnUI, | |
| 459 base::Unretained(this))); | |
| 460 } | |
| 461 | |
| 462 void SensorManagerAndroid::StopFetchingOrientationDataOnUI() { | |
| 463 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 394 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 464 if (is_shutdown_) | 395 if (is_shutdown_) |
| 465 return; | 396 return; |
| 466 | 397 |
| 467 Stop(CONSUMER_TYPE_ORIENTATION); | 398 Stop(CONSUMER_TYPE_ORIENTATION); |
| 468 { | 399 { |
| 469 base::AutoLock autolock(orientation_buffer_lock_); | 400 base::AutoLock autolock(orientation_buffer_lock_); |
| 470 if (device_orientation_buffer_) { | 401 if (device_orientation_buffer_) { |
| 471 SetOrientationBufferStatus(device_orientation_buffer_, false, false); | 402 SetOrientationBufferStatus(device_orientation_buffer_, false, false); |
| 472 orientation_buffer_initialized_ = false; | 403 orientation_buffer_initialized_ = false; |
| 473 device_orientation_buffer_ = nullptr; | 404 device_orientation_buffer_ = nullptr; |
| 474 } | 405 } |
| 475 } | 406 } |
| 476 } | 407 } |
| 477 | 408 |
| 478 void SensorManagerAndroid::StartFetchingDeviceOrientationAbsoluteData( | 409 void SensorManagerAndroid::StartFetchingDeviceOrientationAbsoluteData( |
| 479 DeviceOrientationHardwareBuffer* buffer) { | 410 DeviceOrientationHardwareBuffer* buffer) { |
| 480 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { | |
| 481 StartFetchingOrientationAbsoluteDataOnUI(buffer); | |
| 482 } else { | |
| 483 BrowserThread::PostTask( | |
| 484 BrowserThread::UI, FROM_HERE, | |
| 485 base::Bind( | |
| 486 &SensorManagerAndroid::StartFetchingOrientationAbsoluteDataOnUI, | |
| 487 base::Unretained(this), | |
| 488 buffer)); | |
| 489 } | |
| 490 } | |
| 491 | |
| 492 void SensorManagerAndroid::StopFetchingDeviceOrientationAbsoluteData() { | |
| 493 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { | |
| 494 StopFetchingOrientationAbsoluteDataOnUI(); | |
| 495 return; | |
| 496 } | |
| 497 | |
| 498 BrowserThread::PostTask( | |
| 499 BrowserThread::UI, FROM_HERE, | |
| 500 base::Bind(&SensorManagerAndroid::StopFetchingOrientationAbsoluteDataOnUI, | |
| 501 base::Unretained(this))); | |
| 502 } | |
| 503 | |
| 504 void SensorManagerAndroid::StartFetchingOrientationAbsoluteDataOnUI( | |
| 505 DeviceOrientationHardwareBuffer* buffer) { | |
| 506 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 411 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 507 DCHECK(buffer); | 412 DCHECK(buffer); |
| 508 if (is_shutdown_) | 413 if (is_shutdown_) |
| 509 return; | 414 return; |
| 510 | 415 |
| 511 { | 416 { |
| 512 base::AutoLock autolock(orientation_absolute_buffer_lock_); | 417 base::AutoLock autolock(orientation_absolute_buffer_lock_); |
| 513 device_orientation_absolute_buffer_ = buffer; | 418 device_orientation_absolute_buffer_ = buffer; |
| 514 } | 419 } |
| 515 bool success = Start(CONSUMER_TYPE_ORIENTATION_ABSOLUTE); | 420 bool success = Start(CONSUMER_TYPE_ORIENTATION_ABSOLUTE); |
| 516 | 421 |
| 517 { | 422 { |
| 518 base::AutoLock autolock(orientation_absolute_buffer_lock_); | 423 base::AutoLock autolock(orientation_absolute_buffer_lock_); |
| 519 // If Start() was unsuccessful then set the buffer ready flag to true | 424 // If Start() was unsuccessful then set the buffer ready flag to true |
| 520 // to start firing all-null events. | 425 // to start firing all-null events. |
| 521 SetOrientationBufferStatus(buffer, !success /* ready */, | 426 SetOrientationBufferStatus(buffer, !success /* ready */, |
| 522 false /* absolute */); | 427 false /* absolute */); |
| 523 orientation_absolute_buffer_initialized_ = !success; | 428 orientation_absolute_buffer_initialized_ = !success; |
| 524 } | 429 } |
| 525 } | 430 } |
| 526 | 431 |
| 527 void SensorManagerAndroid::StopFetchingOrientationAbsoluteDataOnUI() { | 432 void SensorManagerAndroid::StopFetchingDeviceOrientationAbsoluteData() { |
| 528 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 433 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 529 if (is_shutdown_) | 434 if (is_shutdown_) |
| 530 return; | 435 return; |
| 531 | 436 |
| 532 Stop(CONSUMER_TYPE_ORIENTATION_ABSOLUTE); | 437 Stop(CONSUMER_TYPE_ORIENTATION_ABSOLUTE); |
| 533 { | 438 { |
| 534 base::AutoLock autolock(orientation_absolute_buffer_lock_); | 439 base::AutoLock autolock(orientation_absolute_buffer_lock_); |
| 535 if (device_orientation_absolute_buffer_) { | 440 if (device_orientation_absolute_buffer_) { |
| 536 SetOrientationBufferStatus(device_orientation_absolute_buffer_, false, | 441 SetOrientationBufferStatus(device_orientation_absolute_buffer_, false, |
| 537 false); | 442 false); |
| 538 orientation_absolute_buffer_initialized_ = false; | 443 orientation_absolute_buffer_initialized_ = false; |
| 539 device_orientation_absolute_buffer_ = nullptr; | 444 device_orientation_absolute_buffer_ = nullptr; |
| 540 } | 445 } |
| 541 } | 446 } |
| 542 } | 447 } |
| 543 | 448 |
| 544 void SensorManagerAndroid::Shutdown() { | 449 void SensorManagerAndroid::Shutdown() { |
| 545 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 450 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 546 is_shutdown_ = true; | 451 is_shutdown_ = true; |
| 547 } | 452 } |
| 548 | 453 |
| 549 } // namespace content | 454 } // namespace content |
| OLD | NEW |