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