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

Unified Diff: media/mojo/services/mojo_audio_output_stream_provider.cc

Issue 2869733005: Convert some audio code to OnceCallback. (Closed)
Patch Set: Rebase, comments on unretained. Created 3 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
« no previous file with comments | « media/mojo/services/mojo_audio_output_stream_provider.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/mojo/services/mojo_audio_output_stream_provider.cc
diff --git a/media/mojo/services/mojo_audio_output_stream_provider.cc b/media/mojo/services/mojo_audio_output_stream_provider.cc
index 10f8c89d4d7d797bd5bca401d07f92c73d396112..6141a48062262603c3cca1ed49c2e3bee11aaaed 100644
--- a/media/mojo/services/mojo_audio_output_stream_provider.cc
+++ b/media/mojo/services/mojo_audio_output_stream_provider.cc
@@ -14,9 +14,11 @@ MojoAudioOutputStreamProvider::MojoAudioOutputStreamProvider(
DeleterCallback deleter_callback)
: binding_(this, std::move(request)),
create_delegate_callback_(std::move(create_delegate_callback)),
- deleter_callback_(base::Bind(std::move(deleter_callback), this)) {
+ deleter_callback_(std::move(deleter_callback)) {
DCHECK(thread_checker_.CalledOnValidThread());
- binding_.set_connection_error_handler(deleter_callback_);
+ // Unretained is safe since |this| owns |binding_|.
+ binding_.set_connection_error_handler(base::Bind(
+ &MojoAudioOutputStreamProvider::OnError, base::Unretained(this)));
DCHECK(create_delegate_callback_);
DCHECK(deleter_callback_);
}
@@ -33,14 +35,22 @@ void MojoAudioOutputStreamProvider::Acquire(
if (audio_output_) {
LOG(ERROR) << "Output acquired twice.";
binding_.Unbind();
- deleter_callback_.Run(); // deletes |this|.
+ std::move(deleter_callback_).Run(this); // deletes |this|.
return;
}
+ // Unretained is safe since |this| owns |audio_output_|.
audio_output_.emplace(
std::move(stream_request),
base::BindOnce(std::move(create_delegate_callback_), params),
- std::move(callback), deleter_callback_);
+ std::move(callback),
+ base::BindOnce(&MojoAudioOutputStreamProvider::OnError,
+ base::Unretained(this)));
+}
+
+void MojoAudioOutputStreamProvider::OnError() {
+ // Deletes |this|:
+ std::move(deleter_callback_).Run(this);
}
} // namespace media
« no previous file with comments | « media/mojo/services/mojo_audio_output_stream_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698