| Index: media/audio/audio_manager.cc
|
| diff --git a/media/audio/audio_manager.cc b/media/audio/audio_manager.cc
|
| index 70e09512af0962d6604b4700ecc80aa2307e5dfc..8a09415a50a5a4d79c8e9b864081a65b37e4c041 100644
|
| --- a/media/audio/audio_manager.cc
|
| +++ b/media/audio/audio_manager.cc
|
| @@ -9,6 +9,7 @@
|
| #include "base/lazy_instance.h"
|
| #include "base/logging.h"
|
| #include "base/message_loop/message_loop.h"
|
| +#include "base/power_monitor/power_monitor.h"
|
| #include "build/build_config.h"
|
| #include "media/audio/fake_audio_log_factory.h"
|
|
|
| @@ -19,24 +20,46 @@ AudioManager* g_last_created = NULL;
|
| // Helper class for managing global AudioManager data and hang timers. If the
|
| // audio thread is unresponsive for more than a minute we want to crash the
|
| // process so we can catch offenders quickly in the field.
|
| -class AudioManagerHelper {
|
| +class AudioManagerHelper : public base::PowerObserver {
|
| public:
|
| - AudioManagerHelper() : max_hung_task_time_(base::TimeDelta::FromMinutes(1)) {}
|
| - ~AudioManagerHelper() {}
|
| + AudioManagerHelper()
|
| + : max_hung_task_time_(base::TimeDelta::FromMinutes(1)),
|
| + hang_detection_enabled_(true) {}
|
| + ~AudioManagerHelper() override {}
|
|
|
| void StartHangTimer(
|
| const scoped_refptr<base::SingleThreadTaskRunner>& monitor_task_runner) {
|
| CHECK(!monitor_task_runner_);
|
| monitor_task_runner_ = monitor_task_runner;
|
| + base::PowerMonitor::Get()->AddObserver(this);
|
| UpdateLastAudioThreadTimeTick();
|
| CrashOnAudioThreadHang();
|
| }
|
|
|
| + // Disable hang detection when the system goes into the suspend state.
|
| + void OnSuspend() override {
|
| + base::AutoLock lock(hang_lock_);
|
| + hang_detection_enabled_ = false;
|
| + }
|
| +
|
| + // Reenable hang detection once the system comes out of the suspend state.
|
| + void OnResume() override {
|
| + base::AutoLock lock(hang_lock_);
|
| + hang_detection_enabled_ = true;
|
| + last_audio_thread_timer_tick_ = base::TimeTicks::Now();
|
| + }
|
| +
|
| // Runs on |monitor_task_runner| typically, but may be started on any thread.
|
| void CrashOnAudioThreadHang() {
|
| base::AutoLock lock(hang_lock_);
|
| - CHECK(base::TimeTicks::Now() - last_audio_thread_timer_tick_ <=
|
| - max_hung_task_time_);
|
| +
|
| + // Don't attempt to verify the tick time if the system is in the process of
|
| + // suspending or resuming.
|
| + if (hang_detection_enabled_) {
|
| + CHECK(base::TimeTicks::Now() - last_audio_thread_timer_tick_ <=
|
| + max_hung_task_time_);
|
| + }
|
| +
|
| monitor_task_runner_->PostDelayedTask(
|
| FROM_HERE, base::Bind(&AudioManagerHelper::CrashOnAudioThreadHang,
|
| base::Unretained(this)),
|
| @@ -63,6 +86,7 @@ class AudioManagerHelper {
|
| scoped_refptr<base::SingleThreadTaskRunner> monitor_task_runner_;
|
|
|
| base::Lock hang_lock_;
|
| + bool hang_detection_enabled_;
|
| base::TimeTicks last_audio_thread_timer_tick_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(AudioManagerHelper);
|
|
|