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" |
14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
15 #include "media/audio/fake_audio_log_factory.h" | 16 #include "media/audio/fake_audio_log_factory.h" |
16 | 17 |
17 namespace media { | 18 namespace media { |
18 namespace { | 19 namespace { |
19 AudioManager* g_last_created = NULL; | 20 AudioManager* g_last_created = NULL; |
20 | 21 |
21 // Maximum number of failed pings to the audio thread allowed. A crash will be | 22 // Maximum number of failed pings to the audio thread allowed. A crash will be |
22 // issued once this count is reached. We require at least two pings before | 23 // issued once this count is reached. We require at least two pings before |
23 // crashing to ensure unobservable power events aren't mistakenly caught (e.g., | 24 // 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... |
150 // On OSX the audio thread is the UI thread, for which a hang monitor is not | 151 // On OSX the audio thread is the UI thread, for which a hang monitor is not |
151 // necessary. | 152 // necessary. |
152 #if !defined(OS_MACOSX) | 153 #if !defined(OS_MACOSX) |
153 g_helper.Pointer()->StartHangTimer(monitor_task_runner); | 154 g_helper.Pointer()->StartHangTimer(monitor_task_runner); |
154 #endif | 155 #endif |
155 return manager; | 156 return manager; |
156 } | 157 } |
157 | 158 |
158 // static | 159 // static |
159 AudioManager* AudioManager::CreateForTesting() { | 160 AudioManager* AudioManager::CreateForTesting() { |
160 return Create(g_helper.Pointer()->fake_log_factory()); | 161 AudioManager* manager = 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; |
161 } | 174 } |
162 | 175 |
163 // static | 176 // static |
164 AudioManager* AudioManager::Get() { | 177 AudioManager* AudioManager::Get() { |
165 return g_last_created; | 178 return g_last_created; |
166 } | 179 } |
167 | 180 |
168 } // namespace media | 181 } // namespace media |
OLD | NEW |