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

Unified Diff: media/audio/mac/audio_manager_mac.cc

Issue 14273018: Use the browser UI thread for audio on OSX. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix test failures. Created 7 years, 7 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 side-by-side diff with in-line comments
Download patch
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..60938bb522619d1e1d94eb38600e194457439f87 100644
--- a/media/audio/mac/audio_manager_mac.cc
+++ b/media/audio/mac/audio_manager_mac.cc
@@ -235,17 +235,25 @@ AudioManagerMac::AudioManagerMac()
SetMaxOutputStreamsAllowed(kMaxOutputStreams);
- // Task must be posted last to avoid races from handing out "this" to the
- // audio thread.
- GetMessageLoop()->PostTask(FROM_HERE, base::Bind(
- &AudioManagerMac::CreateDeviceListener, base::Unretained(this)));
+ if (GetMessageLoop()->BelongsToCurrentThread()) {
+ CreateDeviceListener();
+ } else {
+ // Task must be posted last to avoid races from handing out "this" to the
+ // audio thread.
+ 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 +558,8 @@ void AudioManagerMac::CreateDeviceListener() {
if (!GetDefaultOutputDevice(&current_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() {

Powered by Google App Engine
This is Rietveld 408576698