Skip to content

Commit

Permalink
Adds CHECKs to ensure that AudioManager is valid.
Browse files Browse the repository at this point in the history
During the construction of AudioOutputController, AudioManager must
still be valid. AudioOutputController instances are created on the
IO thread, which is stopped before AudioManager is destroyed.

BUG=606234

Review-Url: https://codereview.chromium.org/1991483002
Cr-Commit-Position: refs/heads/master@{#394296}
  • Loading branch information
alokp-chromium authored and Commit bot committed May 18, 2016
1 parent 97550c8 commit 6cdc7bb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions content/browser/renderer_host/media/audio_renderer_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ void AudioRendererHost::GetOutputControllers(
}

void AudioRendererHost::OnChannelClosing() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
// Since the IPC sender is gone, close all requested audio streams.
while (!audio_entries_.empty()) {
// Note: OnCloseStream() removes the entries from audio_entries_.
Expand Down
11 changes: 9 additions & 2 deletions media/audio/audio_output_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ scoped_refptr<AudioOutputController> AudioOutputController::Create(
const AudioParameters& params,
const std::string& output_device_id,
SyncReader* sync_reader) {
DCHECK(audio_manager);
CHECK(audio_manager);
CHECK_EQ(AudioManager::Get(), audio_manager);
DCHECK(sync_reader);

if (!params.IsValid() || !audio_manager)
if (!params.IsValid())
return NULL;

scoped_refptr<AudioOutputController> controller(new AudioOutputController(
Expand All @@ -73,28 +74,33 @@ scoped_refptr<AudioOutputController> AudioOutputController::Create(
}

void AudioOutputController::Play() {
CHECK_EQ(AudioManager::Get(), audio_manager_);
message_loop_->PostTask(FROM_HERE, base::Bind(
&AudioOutputController::DoPlay, this));
}

void AudioOutputController::Pause() {
CHECK_EQ(AudioManager::Get(), audio_manager_);
message_loop_->PostTask(FROM_HERE, base::Bind(
&AudioOutputController::DoPause, this));
}

void AudioOutputController::Close(const base::Closure& closed_task) {
CHECK_EQ(AudioManager::Get(), audio_manager_);
DCHECK(!closed_task.is_null());
message_loop_->PostTaskAndReply(FROM_HERE, base::Bind(
&AudioOutputController::DoClose, this), closed_task);
}

void AudioOutputController::SetVolume(double volume) {
CHECK_EQ(AudioManager::Get(), audio_manager_);
message_loop_->PostTask(FROM_HERE, base::Bind(
&AudioOutputController::DoSetVolume, this, volume));
}

void AudioOutputController::GetOutputDeviceId(
base::Callback<void(const std::string&)> callback) const {
CHECK_EQ(AudioManager::Get(), audio_manager_);
base::PostTaskAndReplyWithResult(
message_loop_.get(),
FROM_HERE,
Expand All @@ -104,6 +110,7 @@ void AudioOutputController::GetOutputDeviceId(

void AudioOutputController::SwitchOutputDevice(
const std::string& output_device_id, const base::Closure& callback) {
CHECK_EQ(AudioManager::Get(), audio_manager_);
message_loop_->PostTaskAndReply(
FROM_HERE,
base::Bind(&AudioOutputController::DoSwitchOutputDevice, this,
Expand Down

0 comments on commit 6cdc7bb

Please sign in to comment.