OLD | NEW |
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/debug/alias.h" | 9 #include "base/debug/alias.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/power_monitor/power_monitor.h" | 13 #include "base/power_monitor/power_monitor.h" |
14 #include "base/synchronization/waitable_event.h" | |
15 #include "build/build_config.h" | 14 #include "build/build_config.h" |
16 #include "media/audio/fake_audio_log_factory.h" | 15 #include "media/audio/fake_audio_log_factory.h" |
17 | 16 |
18 namespace media { | 17 namespace media { |
19 namespace { | 18 namespace { |
20 AudioManager* g_last_created = NULL; | 19 AudioManager* g_last_created = NULL; |
21 | 20 |
22 // Maximum number of failed pings to the audio thread allowed. A crash will be | 21 // Maximum number of failed pings to the audio thread allowed. A crash will be |
23 // issued once this count is reached. We require at least two pings before | 22 // issued once this count is reached. We require at least two pings before |
24 // crashing to ensure unobservable power events aren't mistakenly caught (e.g., | 23 // crashing to ensure unobservable power events aren't mistakenly caught (e.g., |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 // On OSX the audio thread is the UI thread, for which a hang monitor is not | 150 // On OSX the audio thread is the UI thread, for which a hang monitor is not |
152 // necessary. | 151 // necessary. |
153 #if !defined(OS_MACOSX) | 152 #if !defined(OS_MACOSX) |
154 g_helper.Pointer()->StartHangTimer(monitor_task_runner); | 153 g_helper.Pointer()->StartHangTimer(monitor_task_runner); |
155 #endif | 154 #endif |
156 return manager; | 155 return manager; |
157 } | 156 } |
158 | 157 |
159 // static | 158 // static |
160 AudioManager* AudioManager::CreateForTesting() { | 159 AudioManager* AudioManager::CreateForTesting() { |
161 AudioManager* manager = Create(g_helper.Pointer()->fake_log_factory()); | 160 return Create(g_helper.Pointer()->fake_log_factory()); |
162 | |
163 // When created for testing, always ensure all methods are ready to run (even | |
164 // if they end up called from other threads. | |
165 if (!manager->GetTaskRunner()->BelongsToCurrentThread()) { | |
166 base::WaitableEvent event(false, false); | |
167 manager->GetTaskRunner()->PostTask( | |
168 FROM_HERE, | |
169 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); | |
170 event.Wait(); | |
171 } | |
172 | |
173 return manager; | |
174 } | 161 } |
175 | 162 |
176 // static | 163 // static |
177 AudioManager* AudioManager::Get() { | 164 AudioManager* AudioManager::Get() { |
178 return g_last_created; | 165 return g_last_created; |
179 } | 166 } |
180 | 167 |
181 } // namespace media | 168 } // namespace media |
OLD | NEW |