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

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 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 binding_.set_connection_error_handler(base::Bind(
20 &MojoAudioOutputStreamProvider::OnError, base::Unretained(this)));
xhwang 2017/05/15 17:50:55 Can you add a comment why this base::Unretained(th
Max Morin 2017/05/16 07:27:34 Done.
20 DCHECK(create_delegate_callback_); 21 DCHECK(create_delegate_callback_);
21 DCHECK(deleter_callback_); 22 DCHECK(deleter_callback_);
22 } 23 }
23 24
24 MojoAudioOutputStreamProvider::~MojoAudioOutputStreamProvider() { 25 MojoAudioOutputStreamProvider::~MojoAudioOutputStreamProvider() {
25 DCHECK(thread_checker_.CalledOnValidThread()); 26 DCHECK(thread_checker_.CalledOnValidThread());
26 } 27 }
27 28
28 void MojoAudioOutputStreamProvider::Acquire( 29 void MojoAudioOutputStreamProvider::Acquire(
29 mojom::AudioOutputStreamRequest stream_request, 30 mojom::AudioOutputStreamRequest stream_request,
30 const AudioParameters& params, 31 const AudioParameters& params,
31 const AcquireCallback& callback) { 32 const AcquireCallback& callback) {
32 DCHECK(thread_checker_.CalledOnValidThread()); 33 DCHECK(thread_checker_.CalledOnValidThread());
33 if (audio_output_) { 34 if (audio_output_) {
34 LOG(ERROR) << "Output acquired twice."; 35 LOG(ERROR) << "Output acquired twice.";
35 binding_.Unbind(); 36 binding_.Unbind();
36 deleter_callback_.Run(); // deletes |this|. 37 std::move(deleter_callback_).Run(this); // deletes |this|.
37 return; 38 return;
38 } 39 }
39 40
40 audio_output_.emplace( 41 audio_output_.emplace(
41 std::move(stream_request), 42 std::move(stream_request),
42 base::BindOnce(std::move(create_delegate_callback_), params), 43 base::BindOnce(std::move(create_delegate_callback_), params),
43 std::move(callback), deleter_callback_); 44 std::move(callback),
45 base::BindOnce(&MojoAudioOutputStreamProvider::OnError,
46 base::Unretained(this)));
xhwang 2017/05/15 17:50:55 ditto
Max Morin 2017/05/16 07:27:34 Done.
47 }
48
49 void MojoAudioOutputStreamProvider::OnError() {
50 // Deletes |this|:
51 std::move(deleter_callback_).Run(this);
44 } 52 }
45 53
46 } // namespace media 54 } // 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