Index: media/audio/mac/audio_manager_mac.cc |
diff --git a/media/audio/mac/audio_manager_mac.cc b/media/audio/mac/audio_manager_mac.cc |
index 33dcff08d129dc163a87da2d8a0adf99a5868f3e..5cbdd5fefd66ba6bee7af3ce9f2182f529e18bb4 100644 |
--- a/media/audio/mac/audio_manager_mac.cc |
+++ b/media/audio/mac/audio_manager_mac.cc |
@@ -236,16 +236,21 @@ AudioManagerMac::AudioManagerMac() |
SetMaxOutputStreamsAllowed(kMaxOutputStreams); |
// Task must be posted last to avoid races from handing out "this" to the |
- // audio thread. |
+ // audio thread. Always PostTask even if we're on the right thread since |
+ // AudioManager creation is on the startup path and this may be slow. |
GetMessageLoop()->PostTask(FROM_HERE, base::Bind( |
&AudioManagerMac::CreateDeviceListener, base::Unretained(this))); |
} |
AudioManagerMac::~AudioManagerMac() { |
- // It's safe to post a task here since Shutdown() will wait for all tasks to |
- // complete before returning. |
- GetMessageLoop()->PostTask(FROM_HERE, base::Bind( |
- &AudioManagerMac::DestroyDeviceListener, base::Unretained(this))); |
+ if (GetMessageLoop()->BelongsToCurrentThread()) { |
+ DestroyDeviceListener(); |
+ } else { |
+ // It's safe to post a task here since Shutdown() will wait for all tasks to |
+ // complete before returning. |
+ GetMessageLoop()->PostTask(FROM_HERE, base::Bind( |
+ &AudioManagerMac::DestroyDeviceListener, base::Unretained(this))); |
+ } |
Shutdown(); |
} |
@@ -550,10 +555,8 @@ void AudioManagerMac::CreateDeviceListener() { |
if (!GetDefaultOutputDevice(¤t_output_device_)) |
current_output_device_ = kAudioDeviceUnknown; |
- output_device_listener_.reset(new AudioDeviceListenerMac(BindToLoop( |
- GetMessageLoop(), base::Bind( |
- &AudioManagerMac::HandleDeviceChanges, |
- base::Unretained(this))))); |
+ output_device_listener_.reset(new AudioDeviceListenerMac(base::Bind( |
+ &AudioManagerMac::HandleDeviceChanges, base::Unretained(this)))); |
} |
void AudioManagerMac::DestroyDeviceListener() { |