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

Unified Diff: media/audio/audio_output_proxy.cc

Issue 2621993002: Makes AudioOutputProxy -> AudioOutputDispatcher reference weak. (Closed)
Patch Set: adds CreateStreamProxy Created 3 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_proxy.cc
diff --git a/media/audio/audio_output_proxy.cc b/media/audio/audio_output_proxy.cc
index a69cbc9522e8cd207bf8d002023e8f3e61a0f17c..fdbb8bcda0846d4c28197e5e4755aeb9b9868006 100644
--- a/media/audio/audio_output_proxy.cc
+++ b/media/audio/audio_output_proxy.cc
@@ -11,10 +11,10 @@
namespace media {
-AudioOutputProxy::AudioOutputProxy(AudioOutputDispatcher* dispatcher)
- : dispatcher_(dispatcher),
- state_(kCreated),
- volume_(1.0) {
+AudioOutputProxy::AudioOutputProxy(
+ base::WeakPtr<AudioOutputDispatcher> dispatcher)
+ : dispatcher_(std::move(dispatcher)), state_(kCreated), volume_(1.0) {
+ DCHECK(dispatcher_);
}
AudioOutputProxy::~AudioOutputProxy() {
@@ -26,7 +26,7 @@ bool AudioOutputProxy::Open() {
DCHECK(CalledOnValidThread());
DCHECK_EQ(state_, kCreated);
- if (!dispatcher_->OpenStream()) {
+ if (!dispatcher_ || !dispatcher_->OpenStream()) {
state_ = kOpenError;
return false;
}
@@ -43,7 +43,7 @@ void AudioOutputProxy::Start(AudioSourceCallback* callback) {
// calls to succeed after failing, so we allow it to be called again.
DCHECK(state_ == kOpened || state_ == kStartError);
- if (!dispatcher_->StartStream(callback, this)) {
+ if (!dispatcher_ || !dispatcher_->StartStream(callback, this)) {
state_ = kStartError;
callback->OnError(this);
return;
@@ -56,14 +56,17 @@ void AudioOutputProxy::Stop() {
if (state_ != kPlaying)
return;
- dispatcher_->StopStream(this);
+ if (dispatcher_)
+ dispatcher_->StopStream(this);
state_ = kOpened;
}
void AudioOutputProxy::SetVolume(double volume) {
DCHECK(CalledOnValidThread());
volume_ = volume;
- dispatcher_->StreamVolumeSet(this, volume);
+
+ if (dispatcher_)
+ dispatcher_->StreamVolumeSet(this, volume);
}
void AudioOutputProxy::GetVolume(double* volume) {
@@ -78,7 +81,7 @@ void AudioOutputProxy::Close() {
// kStartError means OpenStream() succeeded and the stream must be closed
// before destruction.
- if (state_ != kCreated && state_ != kOpenError)
+ if (state_ != kCreated && state_ != kOpenError && dispatcher_)
dispatcher_->CloseStream(this);
state_ = kClosed;

Powered by Google App Engine
This is Rietveld 408576698