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" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
14 #include "content/public/browser/browser_thread.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
15 #include "jni/DeviceSensors_jni.h" | 15 #include "jni/DeviceSensors_jni.h" |
16 | 16 |
17 using base::android::AttachCurrentThread; | 17 using base::android::AttachCurrentThread; |
18 using base::android::JavaParamRef; | 18 using base::android::JavaParamRef; |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 void UpdateDeviceOrientationHistogram( | 22 void UpdateDeviceOrientationHistogram( |
23 content::SensorManagerAndroid::OrientationSensorType type) { | 23 content::SensorManagerAndroid::OrientationSensorType type) { |
24 UMA_HISTOGRAM_ENUMERATION("InertialSensor.DeviceOrientationSensorAndroid", | 24 UMA_HISTOGRAM_ENUMERATION("InertialSensor.DeviceOrientationSensorAndroid", |
(...skipping 25 matching lines...) Expand all Loading... |
50 | 50 |
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 ui_task_runner_(nullptr), |
60 is_shutdown_(false) { | 61 is_shutdown_(false) { |
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) { |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 Java_DeviceSensors_getOrientationSensorTypeUsed(AttachCurrentThread(), | 236 Java_DeviceSensors_getOrientationSensorTypeUsed(AttachCurrentThread(), |
236 device_sensors_)); | 237 device_sensors_)); |
237 } | 238 } |
238 | 239 |
239 // ----- Shared memory API methods | 240 // ----- Shared memory API methods |
240 | 241 |
241 // --- Device Light | 242 // --- Device Light |
242 | 243 |
243 void SensorManagerAndroid::StartFetchingDeviceLightData( | 244 void SensorManagerAndroid::StartFetchingDeviceLightData( |
244 DeviceLightHardwareBuffer* buffer) { | 245 DeviceLightHardwareBuffer* buffer) { |
245 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 246 if (ui_task_runner_->RunsTasksOnCurrentThread()) { |
246 StartFetchingLightDataOnUI(buffer); | 247 StartFetchingLightDataOnUI(buffer); |
247 } else { | 248 } else { |
248 BrowserThread::PostTask( | 249 ui_task_runner_->PostTask( |
249 BrowserThread::UI, FROM_HERE, | 250 FROM_HERE, base::Bind(&SensorManagerAndroid::StartFetchingLightDataOnUI, |
250 base::Bind(&SensorManagerAndroid::StartFetchingLightDataOnUI, | 251 base::Unretained(this), buffer)); |
251 base::Unretained(this), | |
252 buffer)); | |
253 } | 252 } |
254 } | 253 } |
255 | 254 |
256 void SensorManagerAndroid::StartFetchingLightDataOnUI( | 255 void SensorManagerAndroid::StartFetchingLightDataOnUI( |
257 DeviceLightHardwareBuffer* buffer) { | 256 DeviceLightHardwareBuffer* buffer) { |
258 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 257 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
259 DCHECK(buffer); | 258 DCHECK(buffer); |
260 if (is_shutdown_) | 259 if (is_shutdown_) |
261 return; | 260 return; |
262 | 261 |
263 { | 262 { |
264 base::AutoLock autolock(light_buffer_lock_); | 263 base::AutoLock autolock(light_buffer_lock_); |
265 device_light_buffer_ = buffer; | 264 device_light_buffer_ = buffer; |
266 SetLightBufferValue(-1); | 265 SetLightBufferValue(-1); |
267 } | 266 } |
268 bool success = Start(CONSUMER_TYPE_LIGHT); | 267 bool success = Start(CONSUMER_TYPE_LIGHT); |
269 if (!success) { | 268 if (!success) { |
270 base::AutoLock autolock(light_buffer_lock_); | 269 base::AutoLock autolock(light_buffer_lock_); |
271 SetLightBufferValue(std::numeric_limits<double>::infinity()); | 270 SetLightBufferValue(std::numeric_limits<double>::infinity()); |
272 } | 271 } |
273 } | 272 } |
274 | 273 |
275 void SensorManagerAndroid::StopFetchingDeviceLightData() { | 274 void SensorManagerAndroid::StopFetchingDeviceLightData() { |
276 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 275 if (ui_task_runner_->RunsTasksOnCurrentThread()) { |
277 StopFetchingLightDataOnUI(); | 276 StopFetchingLightDataOnUI(); |
278 return; | 277 return; |
279 } | 278 } |
280 | 279 |
281 BrowserThread::PostTask( | 280 ui_task_runner_->PostTask( |
282 BrowserThread::UI, FROM_HERE, | 281 FROM_HERE, base::Bind(&SensorManagerAndroid::StopFetchingLightDataOnUI, |
283 base::Bind(&SensorManagerAndroid::StopFetchingLightDataOnUI, | 282 base::Unretained(this))); |
284 base::Unretained(this))); | |
285 } | 283 } |
286 | 284 |
287 void SensorManagerAndroid::StopFetchingLightDataOnUI() { | 285 void SensorManagerAndroid::StopFetchingLightDataOnUI() { |
288 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 286 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
289 if (is_shutdown_) | 287 if (is_shutdown_) |
290 return; | 288 return; |
291 | 289 |
292 Stop(CONSUMER_TYPE_LIGHT); | 290 Stop(CONSUMER_TYPE_LIGHT); |
293 { | 291 { |
294 base::AutoLock autolock(light_buffer_lock_); | 292 base::AutoLock autolock(light_buffer_lock_); |
295 if (device_light_buffer_) { | 293 if (device_light_buffer_) { |
296 SetLightBufferValue(-1); | 294 SetLightBufferValue(-1); |
297 device_light_buffer_ = nullptr; | 295 device_light_buffer_ = nullptr; |
298 } | 296 } |
299 } | 297 } |
300 } | 298 } |
301 | 299 |
302 void SensorManagerAndroid::SetLightBufferValue(double lux) { | 300 void SensorManagerAndroid::SetLightBufferValue(double lux) { |
303 device_light_buffer_->seqlock.WriteBegin(); | 301 device_light_buffer_->seqlock.WriteBegin(); |
304 device_light_buffer_->data.value = lux; | 302 device_light_buffer_->data.value = lux; |
305 device_light_buffer_->seqlock.WriteEnd(); | 303 device_light_buffer_->seqlock.WriteEnd(); |
306 } | 304 } |
307 | 305 |
308 // --- Device Motion | 306 // --- Device Motion |
309 | 307 |
310 void SensorManagerAndroid::StartFetchingDeviceMotionData( | 308 void SensorManagerAndroid::StartFetchingDeviceMotionData( |
311 DeviceMotionHardwareBuffer* buffer) { | 309 DeviceMotionHardwareBuffer* buffer) { |
312 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 310 if (ui_task_runner_->RunsTasksOnCurrentThread()) { |
313 StartFetchingMotionDataOnUI(buffer); | 311 StartFetchingMotionDataOnUI(buffer); |
314 } else { | 312 } else { |
315 BrowserThread::PostTask( | 313 ui_task_runner_->PostTask( |
316 BrowserThread::UI, FROM_HERE, | 314 FROM_HERE, |
317 base::Bind(&SensorManagerAndroid::StartFetchingMotionDataOnUI, | 315 base::Bind(&SensorManagerAndroid::StartFetchingMotionDataOnUI, |
318 base::Unretained(this), | 316 base::Unretained(this), buffer)); |
319 buffer)); | |
320 } | 317 } |
321 } | 318 } |
322 | 319 |
323 void SensorManagerAndroid::StartFetchingMotionDataOnUI( | 320 void SensorManagerAndroid::StartFetchingMotionDataOnUI( |
324 DeviceMotionHardwareBuffer* buffer) { | 321 DeviceMotionHardwareBuffer* buffer) { |
325 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 322 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
326 DCHECK(buffer); | 323 DCHECK(buffer); |
327 if (is_shutdown_) | 324 if (is_shutdown_) |
328 return; | 325 return; |
329 | 326 |
330 { | 327 { |
331 base::AutoLock autolock(motion_buffer_lock_); | 328 base::AutoLock autolock(motion_buffer_lock_); |
332 device_motion_buffer_ = buffer; | 329 device_motion_buffer_ = buffer; |
333 ClearInternalMotionBuffers(); | 330 ClearInternalMotionBuffers(); |
334 } | 331 } |
335 Start(CONSUMER_TYPE_MOTION); | 332 Start(CONSUMER_TYPE_MOTION); |
336 | 333 |
337 // If no motion data can ever be provided, the number of active device motion | 334 // 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 | 335 // sensors will be zero. In that case flag the shared memory buffer |
339 // as ready to read, as it will not change anyway. | 336 // as ready to read, as it will not change anyway. |
340 number_active_device_motion_sensors_ = GetNumberActiveDeviceMotionSensors(); | 337 number_active_device_motion_sensors_ = GetNumberActiveDeviceMotionSensors(); |
341 { | 338 { |
342 base::AutoLock autolock(motion_buffer_lock_); | 339 base::AutoLock autolock(motion_buffer_lock_); |
343 CheckMotionBufferReadyToRead(); | 340 CheckMotionBufferReadyToRead(); |
344 } | 341 } |
345 } | 342 } |
346 | 343 |
347 void SensorManagerAndroid::StopFetchingDeviceMotionData() { | 344 void SensorManagerAndroid::StopFetchingDeviceMotionData() { |
348 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 345 if (ui_task_runner_->RunsTasksOnCurrentThread()) { |
349 StopFetchingMotionDataOnUI(); | 346 StopFetchingMotionDataOnUI(); |
350 return; | 347 return; |
351 } | 348 } |
352 | 349 |
353 BrowserThread::PostTask( | 350 ui_task_runner_->PostTask( |
354 BrowserThread::UI, FROM_HERE, | 351 FROM_HERE, base::Bind(&SensorManagerAndroid::StopFetchingMotionDataOnUI, |
355 base::Bind(&SensorManagerAndroid::StopFetchingMotionDataOnUI, | 352 base::Unretained(this))); |
356 base::Unretained(this))); | |
357 } | 353 } |
358 | 354 |
359 void SensorManagerAndroid::StopFetchingMotionDataOnUI() { | 355 void SensorManagerAndroid::StopFetchingMotionDataOnUI() { |
360 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 356 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
361 if (is_shutdown_) | 357 if (is_shutdown_) |
362 return; | 358 return; |
363 | 359 |
364 Stop(CONSUMER_TYPE_MOTION); | 360 Stop(CONSUMER_TYPE_MOTION); |
365 { | 361 { |
366 base::AutoLock autolock(motion_buffer_lock_); | 362 base::AutoLock autolock(motion_buffer_lock_); |
367 if (device_motion_buffer_) { | 363 if (device_motion_buffer_) { |
368 ClearInternalMotionBuffers(); | 364 ClearInternalMotionBuffers(); |
369 device_motion_buffer_ = nullptr; | 365 device_motion_buffer_ = nullptr; |
370 } | 366 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 void SensorManagerAndroid::ClearInternalMotionBuffers() { | 399 void SensorManagerAndroid::ClearInternalMotionBuffers() { |
404 memset(received_motion_data_, 0, sizeof(received_motion_data_)); | 400 memset(received_motion_data_, 0, sizeof(received_motion_data_)); |
405 number_active_device_motion_sensors_ = 0; | 401 number_active_device_motion_sensors_ = 0; |
406 SetMotionBufferReadyStatus(false); | 402 SetMotionBufferReadyStatus(false); |
407 } | 403 } |
408 | 404 |
409 // --- Device Orientation | 405 // --- Device Orientation |
410 | 406 |
411 void SensorManagerAndroid::StartFetchingDeviceOrientationData( | 407 void SensorManagerAndroid::StartFetchingDeviceOrientationData( |
412 DeviceOrientationHardwareBuffer* buffer) { | 408 DeviceOrientationHardwareBuffer* buffer) { |
413 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 409 if (ui_task_runner_->RunsTasksOnCurrentThread()) { |
414 StartFetchingOrientationDataOnUI(buffer); | 410 StartFetchingOrientationDataOnUI(buffer); |
415 } else { | 411 } else { |
416 BrowserThread::PostTask( | 412 ui_task_runner_->PostTask( |
417 BrowserThread::UI, FROM_HERE, | 413 FROM_HERE, |
418 base::Bind(&SensorManagerAndroid::StartFetchingOrientationDataOnUI, | 414 base::Bind(&SensorManagerAndroid::StartFetchingOrientationDataOnUI, |
419 base::Unretained(this), | 415 base::Unretained(this), buffer)); |
420 buffer)); | |
421 } | 416 } |
422 } | 417 } |
423 | 418 |
424 void SensorManagerAndroid::StartFetchingOrientationDataOnUI( | 419 void SensorManagerAndroid::StartFetchingOrientationDataOnUI( |
425 DeviceOrientationHardwareBuffer* buffer) { | 420 DeviceOrientationHardwareBuffer* buffer) { |
426 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 421 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
427 DCHECK(buffer); | 422 DCHECK(buffer); |
428 if (is_shutdown_) | 423 if (is_shutdown_) |
429 return; | 424 return; |
430 | 425 |
431 { | 426 { |
432 base::AutoLock autolock(orientation_buffer_lock_); | 427 base::AutoLock autolock(orientation_buffer_lock_); |
433 device_orientation_buffer_ = buffer; | 428 device_orientation_buffer_ = buffer; |
434 } | 429 } |
435 bool success = Start(CONSUMER_TYPE_ORIENTATION); | 430 bool success = Start(CONSUMER_TYPE_ORIENTATION); |
436 | 431 |
437 { | 432 { |
438 base::AutoLock autolock(orientation_buffer_lock_); | 433 base::AutoLock autolock(orientation_buffer_lock_); |
439 // If Start() was unsuccessful then set the buffer ready flag to true | 434 // If Start() was unsuccessful then set the buffer ready flag to true |
440 // to start firing all-null events. | 435 // to start firing all-null events. |
441 SetOrientationBufferStatus(buffer, !success /* ready */, | 436 SetOrientationBufferStatus(buffer, !success /* ready */, |
442 false /* absolute */); | 437 false /* absolute */); |
443 orientation_buffer_initialized_ = !success; | 438 orientation_buffer_initialized_ = !success; |
444 } | 439 } |
445 | 440 |
446 if (!success) | 441 if (!success) |
447 UpdateDeviceOrientationHistogram(NOT_AVAILABLE); | 442 UpdateDeviceOrientationHistogram(NOT_AVAILABLE); |
448 } | 443 } |
449 | 444 |
450 void SensorManagerAndroid::StopFetchingDeviceOrientationData() { | 445 void SensorManagerAndroid::StopFetchingDeviceOrientationData() { |
451 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 446 if (ui_task_runner_->RunsTasksOnCurrentThread()) { |
452 StopFetchingOrientationDataOnUI(); | 447 StopFetchingOrientationDataOnUI(); |
453 return; | 448 return; |
454 } | 449 } |
455 | 450 |
456 BrowserThread::PostTask( | 451 ui_task_runner_->PostTask( |
457 BrowserThread::UI, FROM_HERE, | 452 FROM_HERE, |
458 base::Bind(&SensorManagerAndroid::StopFetchingOrientationDataOnUI, | 453 base::Bind(&SensorManagerAndroid::StopFetchingOrientationDataOnUI, |
459 base::Unretained(this))); | 454 base::Unretained(this))); |
460 } | 455 } |
461 | 456 |
462 void SensorManagerAndroid::StopFetchingOrientationDataOnUI() { | 457 void SensorManagerAndroid::StopFetchingOrientationDataOnUI() { |
463 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 458 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
464 if (is_shutdown_) | 459 if (is_shutdown_) |
465 return; | 460 return; |
466 | 461 |
467 Stop(CONSUMER_TYPE_ORIENTATION); | 462 Stop(CONSUMER_TYPE_ORIENTATION); |
468 { | 463 { |
469 base::AutoLock autolock(orientation_buffer_lock_); | 464 base::AutoLock autolock(orientation_buffer_lock_); |
470 if (device_orientation_buffer_) { | 465 if (device_orientation_buffer_) { |
471 SetOrientationBufferStatus(device_orientation_buffer_, false, false); | 466 SetOrientationBufferStatus(device_orientation_buffer_, false, false); |
472 orientation_buffer_initialized_ = false; | 467 orientation_buffer_initialized_ = false; |
473 device_orientation_buffer_ = nullptr; | 468 device_orientation_buffer_ = nullptr; |
474 } | 469 } |
475 } | 470 } |
476 } | 471 } |
477 | 472 |
478 void SensorManagerAndroid::StartFetchingDeviceOrientationAbsoluteData( | 473 void SensorManagerAndroid::StartFetchingDeviceOrientationAbsoluteData( |
479 DeviceOrientationHardwareBuffer* buffer) { | 474 DeviceOrientationHardwareBuffer* buffer) { |
480 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 475 if (ui_task_runner_->RunsTasksOnCurrentThread()) { |
481 StartFetchingOrientationAbsoluteDataOnUI(buffer); | 476 StartFetchingOrientationAbsoluteDataOnUI(buffer); |
482 } else { | 477 } else { |
483 BrowserThread::PostTask( | 478 ui_task_runner_->PostTask( |
484 BrowserThread::UI, FROM_HERE, | 479 FROM_HERE, |
485 base::Bind( | 480 base::Bind( |
486 &SensorManagerAndroid::StartFetchingOrientationAbsoluteDataOnUI, | 481 &SensorManagerAndroid::StartFetchingOrientationAbsoluteDataOnUI, |
487 base::Unretained(this), | 482 base::Unretained(this), buffer)); |
488 buffer)); | |
489 } | 483 } |
490 } | 484 } |
491 | 485 |
492 void SensorManagerAndroid::StopFetchingDeviceOrientationAbsoluteData() { | 486 void SensorManagerAndroid::StopFetchingDeviceOrientationAbsoluteData() { |
493 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 487 if (ui_task_runner_->RunsTasksOnCurrentThread()) { |
494 StopFetchingOrientationAbsoluteDataOnUI(); | 488 StopFetchingOrientationAbsoluteDataOnUI(); |
495 return; | 489 return; |
496 } | 490 } |
497 | 491 |
498 BrowserThread::PostTask( | 492 ui_task_runner_->PostTask( |
499 BrowserThread::UI, FROM_HERE, | 493 FROM_HERE, |
500 base::Bind(&SensorManagerAndroid::StopFetchingOrientationAbsoluteDataOnUI, | 494 base::Bind(&SensorManagerAndroid::StopFetchingOrientationAbsoluteDataOnUI, |
501 base::Unretained(this))); | 495 base::Unretained(this))); |
502 } | 496 } |
503 | 497 |
504 void SensorManagerAndroid::StartFetchingOrientationAbsoluteDataOnUI( | 498 void SensorManagerAndroid::StartFetchingOrientationAbsoluteDataOnUI( |
505 DeviceOrientationHardwareBuffer* buffer) { | 499 DeviceOrientationHardwareBuffer* buffer) { |
506 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 500 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
507 DCHECK(buffer); | 501 DCHECK(buffer); |
508 if (is_shutdown_) | 502 if (is_shutdown_) |
509 return; | 503 return; |
510 | 504 |
511 { | 505 { |
512 base::AutoLock autolock(orientation_absolute_buffer_lock_); | 506 base::AutoLock autolock(orientation_absolute_buffer_lock_); |
513 device_orientation_absolute_buffer_ = buffer; | 507 device_orientation_absolute_buffer_ = buffer; |
514 } | 508 } |
515 bool success = Start(CONSUMER_TYPE_ORIENTATION_ABSOLUTE); | 509 bool success = Start(CONSUMER_TYPE_ORIENTATION_ABSOLUTE); |
516 | 510 |
517 { | 511 { |
518 base::AutoLock autolock(orientation_absolute_buffer_lock_); | 512 base::AutoLock autolock(orientation_absolute_buffer_lock_); |
519 // If Start() was unsuccessful then set the buffer ready flag to true | 513 // If Start() was unsuccessful then set the buffer ready flag to true |
520 // to start firing all-null events. | 514 // to start firing all-null events. |
521 SetOrientationBufferStatus(buffer, !success /* ready */, | 515 SetOrientationBufferStatus(buffer, !success /* ready */, |
522 false /* absolute */); | 516 false /* absolute */); |
523 orientation_absolute_buffer_initialized_ = !success; | 517 orientation_absolute_buffer_initialized_ = !success; |
524 } | 518 } |
525 } | 519 } |
526 | 520 |
527 void SensorManagerAndroid::StopFetchingOrientationAbsoluteDataOnUI() { | 521 void SensorManagerAndroid::StopFetchingOrientationAbsoluteDataOnUI() { |
528 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 522 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
529 if (is_shutdown_) | 523 if (is_shutdown_) |
530 return; | 524 return; |
531 | 525 |
532 Stop(CONSUMER_TYPE_ORIENTATION_ABSOLUTE); | 526 Stop(CONSUMER_TYPE_ORIENTATION_ABSOLUTE); |
533 { | 527 { |
534 base::AutoLock autolock(orientation_absolute_buffer_lock_); | 528 base::AutoLock autolock(orientation_absolute_buffer_lock_); |
535 if (device_orientation_absolute_buffer_) { | 529 if (device_orientation_absolute_buffer_) { |
536 SetOrientationBufferStatus(device_orientation_absolute_buffer_, false, | 530 SetOrientationBufferStatus(device_orientation_absolute_buffer_, false, |
537 false); | 531 false); |
538 orientation_absolute_buffer_initialized_ = false; | 532 orientation_absolute_buffer_initialized_ = false; |
539 device_orientation_absolute_buffer_ = nullptr; | 533 device_orientation_absolute_buffer_ = nullptr; |
540 } | 534 } |
541 } | 535 } |
542 } | 536 } |
543 | 537 |
544 void SensorManagerAndroid::Shutdown() { | 538 void SensorManagerAndroid::InitOnUIThread() { |
545 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 539 DCHECK(!ui_task_runner_); |
| 540 ui_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| 541 DCHECK(ui_task_runner_); |
| 542 } |
| 543 |
| 544 void SensorManagerAndroid::ShutDownOnUIThread() { |
| 545 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
546 is_shutdown_ = true; | 546 is_shutdown_ = true; |
547 } | 547 } |
548 | 548 |
549 } // namespace content | 549 } // namespace content |
OLD | NEW |