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

Unified Diff: media/audio/audio_output_dispatcher.cc

Issue 9255017: Add thread safety to AudioManagerBase to protect access to the audio thread member variable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 11 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/audio_output_dispatcher.cc
diff --git a/media/audio/audio_output_dispatcher.cc b/media/audio/audio_output_dispatcher.cc
index 8e402777fc7052004f0e0ab7cc7c1353c1cd7e48..9783c1d027a66946926ad85ba89ee4f674b10b28 100644
--- a/media/audio/audio_output_dispatcher.cc
+++ b/media/audio/audio_output_dispatcher.cc
@@ -14,7 +14,7 @@ AudioOutputDispatcher::AudioOutputDispatcher(
AudioManager* audio_manager, const AudioParameters& params,
base::TimeDelta close_delay)
: audio_manager_(audio_manager),
- message_loop_(audio_manager->GetMessageLoop()),
+ message_loop_(MessageLoop::current()),
params_(params),
pause_delay_(base::TimeDelta::FromMilliseconds(
2 * params.samples_per_packet *
@@ -25,7 +25,9 @@ AudioOutputDispatcher::AudioOutputDispatcher(
close_delay,
weak_this_.GetWeakPtr(),
&AudioOutputDispatcher::ClosePendingStreams) {
- DCHECK_EQ(MessageLoop::current(), message_loop_);
+ // We expect to be instantiated on the audio thread. Otherwise the
+ // message_loop_ member will point to the wrong message loop!
+ DCHECK(audio_manager->GetMessageLoop()->BelongsToCurrentThread());
}
AudioOutputDispatcher::~AudioOutputDispatcher() {
@@ -133,8 +135,9 @@ void AudioOutputDispatcher::Shutdown() {
pausing_streams_.clear();
}
-MessageLoop* AudioOutputDispatcher::message_loop() {
- return message_loop_;
+bool AudioOutputDispatcher::CurrentThreadIsAudioThread() const {
scherkus (not reviewing) 2012/01/18 18:12:31 nit: if this is a single threaded/non-thread safe
+ DCHECK(message_loop_);
+ return MessageLoop::current() == message_loop_;
}
bool AudioOutputDispatcher::CreateAndOpenStream() {

Powered by Google App Engine
This is Rietveld 408576698