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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/mojo/services/mojo_audio_output_stream_provider.h" 5 #include "media/mojo/services/mojo_audio_output_stream_provider.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 namespace media { 9 namespace media {
10 10
11 MojoAudioOutputStreamProvider::MojoAudioOutputStreamProvider( 11 MojoAudioOutputStreamProvider::MojoAudioOutputStreamProvider(
12 mojom::AudioOutputStreamProviderRequest request, 12 mojom::AudioOutputStreamProviderRequest request,
13 CreateDelegateCallback create_delegate_callback, 13 CreateDelegateCallback create_delegate_callback,
14 DeleterCallback deleter_callback) 14 DeleterCallback deleter_callback)
15 : binding_(this, std::move(request)), 15 : binding_(this, std::move(request)),
16 create_delegate_callback_(std::move(create_delegate_callback)), 16 create_delegate_callback_(std::move(create_delegate_callback)),
17 deleter_callback_(base::Bind(std::move(deleter_callback), this)) { 17 deleter_callback_(std::move(deleter_callback)) {
18 DCHECK(thread_checker_.CalledOnValidThread()); 18 DCHECK(thread_checker_.CalledOnValidThread());
19 binding_.set_connection_error_handler(deleter_callback_); 19 // Unretained is safe since |this| owns |binding_|.
20 binding_.set_connection_error_handler(base::Bind(
21 &MojoAudioOutputStreamProvider::OnError, base::Unretained(this)));
20 DCHECK(create_delegate_callback_); 22 DCHECK(create_delegate_callback_);
21 DCHECK(deleter_callback_); 23 DCHECK(deleter_callback_);
22 } 24 }
23 25
24 MojoAudioOutputStreamProvider::~MojoAudioOutputStreamProvider() { 26 MojoAudioOutputStreamProvider::~MojoAudioOutputStreamProvider() {
25 DCHECK(thread_checker_.CalledOnValidThread()); 27 DCHECK(thread_checker_.CalledOnValidThread());
26 } 28 }
27 29
28 void MojoAudioOutputStreamProvider::Acquire( 30 void MojoAudioOutputStreamProvider::Acquire(
29 mojom::AudioOutputStreamRequest stream_request, 31 mojom::AudioOutputStreamRequest stream_request,
30 const AudioParameters& params, 32 const AudioParameters& params,
31 const AcquireCallback& callback) { 33 const AcquireCallback& callback) {
32 DCHECK(thread_checker_.CalledOnValidThread()); 34 DCHECK(thread_checker_.CalledOnValidThread());
33 if (audio_output_) { 35 if (audio_output_) {
34 LOG(ERROR) << "Output acquired twice."; 36 LOG(ERROR) << "Output acquired twice.";
35 binding_.Unbind(); 37 binding_.Unbind();
36 deleter_callback_.Run(); // deletes |this|. 38 std::move(deleter_callback_).Run(this); // deletes |this|.
37 return; 39 return;
38 } 40 }
39 41
42 // Unretained is safe since |this| owns |audio_output_|.
40 audio_output_.emplace( 43 audio_output_.emplace(
41 std::move(stream_request), 44 std::move(stream_request),
42 base::BindOnce(std::move(create_delegate_callback_), params), 45 base::BindOnce(std::move(create_delegate_callback_), params),
43 std::move(callback), deleter_callback_); 46 std::move(callback),
47 base::BindOnce(&MojoAudioOutputStreamProvider::OnError,
48 base::Unretained(this)));
49 }
50
51 void MojoAudioOutputStreamProvider::OnError() {
52 // Deletes |this|:
53 std::move(deleter_callback_).Run(this);
44 } 54 }
45 55
46 } // namespace media 56 } // namespace media
OLDNEW
« 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