Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: media/audio/audio_manager.cc

Issue 1036933003: Update last audio tick time during suspend and resume. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "media/audio/audio_manager.h" 5 #include "media/audio/audio_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/power_monitor/power_monitor.h"
12 #include "build/build_config.h" 13 #include "build/build_config.h"
13 #include "media/audio/fake_audio_log_factory.h" 14 #include "media/audio/fake_audio_log_factory.h"
14 15
15 namespace media { 16 namespace media {
16 namespace { 17 namespace {
17 AudioManager* g_last_created = NULL; 18 AudioManager* g_last_created = NULL;
18 19
19 // Helper class for managing global AudioManager data and hang timers. If the 20 // Helper class for managing global AudioManager data and hang timers. If the
20 // audio thread is unresponsive for more than a minute we want to crash the 21 // audio thread is unresponsive for more than a minute we want to crash the
21 // process so we can catch offenders quickly in the field. 22 // process so we can catch offenders quickly in the field.
22 class AudioManagerHelper { 23 class AudioManagerHelper : public base::PowerObserver {
23 public: 24 public:
24 AudioManagerHelper() : max_hung_task_time_(base::TimeDelta::FromMinutes(1)) {} 25 AudioManagerHelper() : max_hung_task_time_(base::TimeDelta::FromMinutes(1)) {}
25 ~AudioManagerHelper() {} 26 ~AudioManagerHelper() override {}
26 27
27 void StartHangTimer( 28 void StartHangTimer(
28 const scoped_refptr<base::SingleThreadTaskRunner>& monitor_task_runner) { 29 const scoped_refptr<base::SingleThreadTaskRunner>& monitor_task_runner) {
29 CHECK(!monitor_task_runner_); 30 CHECK(!monitor_task_runner_);
30 monitor_task_runner_ = monitor_task_runner; 31 monitor_task_runner_ = monitor_task_runner;
32 base::PowerMonitor::Get()->AddObserver(this);
31 UpdateLastAudioThreadTimeTick(); 33 UpdateLastAudioThreadTimeTick();
32 CrashOnAudioThreadHang(); 34 CrashOnAudioThreadHang();
33 } 35 }
34 36
37 void OnSuspend() override {
38 base::AutoLock lock(hang_lock_);
39 last_audio_thread_timer_tick_ = base::TimeTicks::Now();
40 }
41
42 void OnResume() override {
nasko 2015/03/26 23:10:43 Are we guaranteed that there will be no task execu
DaleCurtis 2015/03/26 23:26:45 Ah, I was going to do this, but thought it wasn't
43 OnSuspend();
nasko 2015/03/26 23:10:44 nit: Why not add a private method that does the wo
DaleCurtis 2015/03/26 23:26:45 No need anymore.
44 }
45
35 // Runs on |monitor_task_runner| typically, but may be started on any thread. 46 // Runs on |monitor_task_runner| typically, but may be started on any thread.
36 void CrashOnAudioThreadHang() { 47 void CrashOnAudioThreadHang() {
37 base::AutoLock lock(hang_lock_); 48 base::AutoLock lock(hang_lock_);
38 CHECK(base::TimeTicks::Now() - last_audio_thread_timer_tick_ <= 49 CHECK(base::TimeTicks::Now() - last_audio_thread_timer_tick_ <=
39 max_hung_task_time_); 50 max_hung_task_time_);
40 monitor_task_runner_->PostDelayedTask( 51 monitor_task_runner_->PostDelayedTask(
41 FROM_HERE, base::Bind(&AudioManagerHelper::CrashOnAudioThreadHang, 52 FROM_HERE, base::Bind(&AudioManagerHelper::CrashOnAudioThreadHang,
42 base::Unretained(this)), 53 base::Unretained(this)),
43 max_hung_task_time_); 54 max_hung_task_time_);
44 } 55 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 AudioManager* AudioManager::CreateForTesting() { 117 AudioManager* AudioManager::CreateForTesting() {
107 return Create(g_helper.Pointer()->fake_log_factory()); 118 return Create(g_helper.Pointer()->fake_log_factory());
108 } 119 }
109 120
110 // static 121 // static
111 AudioManager* AudioManager::Get() { 122 AudioManager* AudioManager::Get() {
112 return g_last_created; 123 return g_last_created;
113 } 124 }
114 125
115 } // namespace media 126 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698