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

Side by Side Diff: media/mojo/clients/mojo_renderer_impl.cc

Issue 2075193002: Fixes use-after-free in MojoDemuxerStreamImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed comments Created 4 years, 6 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/clients/mojo_renderer_impl.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/clients/mojo_renderer_impl.h" 5 #include "media/mojo/clients/mojo_renderer_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 init_cb_ = init_cb; 49 init_cb_ = init_cb;
50 50
51 // Create audio and video mojom::DemuxerStream and bind its lifetime to 51 // Create audio and video mojom::DemuxerStream and bind its lifetime to
52 // the pipe. 52 // the pipe.
53 DemuxerStream* const audio = 53 DemuxerStream* const audio =
54 demuxer_stream_provider_->GetStream(DemuxerStream::AUDIO); 54 demuxer_stream_provider_->GetStream(DemuxerStream::AUDIO);
55 DemuxerStream* const video = 55 DemuxerStream* const video =
56 demuxer_stream_provider_->GetStream(DemuxerStream::VIDEO); 56 demuxer_stream_provider_->GetStream(DemuxerStream::VIDEO);
57 57
58 mojom::DemuxerStreamPtr audio_stream; 58 mojom::DemuxerStreamPtr audio_stream;
59 if (audio) 59 if (audio) {
60 new MojoDemuxerStreamImpl(audio, GetProxy(&audio_stream)); 60 audio_stream_.reset(
61 new MojoDemuxerStreamImpl(audio, GetProxy(&audio_stream)));
62 audio_stream_->set_connection_error_handler(
63 base::Bind(&MojoRendererImpl::OnDemuxerStreamConnectionError,
64 base::Unretained(this), DemuxerStream::AUDIO));
xhwang 2016/06/18 16:46:16 please add a comment about why Unretained() is saf
alokp 2016/06/19 04:57:45 Done.
65 }
61 66
62 mojom::DemuxerStreamPtr video_stream; 67 mojom::DemuxerStreamPtr video_stream;
63 if (video) 68 if (video) {
64 new MojoDemuxerStreamImpl(video, GetProxy(&video_stream)); 69 video_stream_.reset(
70 new MojoDemuxerStreamImpl(video, GetProxy(&video_stream)));
71 video_stream_->set_connection_error_handler(
72 base::Bind(&MojoRendererImpl::OnDemuxerStreamConnectionError,
73 base::Unretained(this), DemuxerStream::VIDEO));
74 }
65 75
66 BindRemoteRendererIfNeeded(); 76 BindRemoteRendererIfNeeded();
67 77
68 // Using base::Unretained(this) is safe because |this| owns 78 // Using base::Unretained(this) is safe because |this| owns
69 // |remote_renderer_|, and the callback won't be dispatched if 79 // |remote_renderer_|, and the callback won't be dispatched if
70 // |remote_renderer_| is destroyed. 80 // |remote_renderer_| is destroyed.
71 remote_renderer_->Initialize( 81 remote_renderer_->Initialize(
72 binding_.CreateInterfacePtrAndBind(), std::move(audio_stream), 82 binding_.CreateInterfacePtrAndBind(), std::move(audio_stream),
73 std::move(video_stream), 83 std::move(video_stream),
74 base::Bind(&MojoRendererImpl::OnInitialized, base::Unretained(this))); 84 base::Bind(&MojoRendererImpl::OnInitialized, base::Unretained(this)));
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 DCHECK(task_runner_->BelongsToCurrentThread()); 205 DCHECK(task_runner_->BelongsToCurrentThread());
196 206
197 if (!init_cb_.is_null()) { 207 if (!init_cb_.is_null()) {
198 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_INITIALIZATION_FAILED); 208 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_INITIALIZATION_FAILED);
199 return; 209 return;
200 } 210 }
201 211
202 client_->OnError(PIPELINE_ERROR_DECODE); 212 client_->OnError(PIPELINE_ERROR_DECODE);
203 } 213 }
204 214
215 void MojoRendererImpl::OnDemuxerStreamConnectionError(
216 DemuxerStream::Type type) {
217 DVLOG(1) << __FUNCTION__ << ": " << type;
218 DCHECK(task_runner_->BelongsToCurrentThread());
219
220 if (type == DemuxerStream::AUDIO) {
221 audio_stream_.reset();
222 } else {
223 DCHECK(type == DemuxerStream::VIDEO);
224 video_stream_.reset();
225 }
xhwang 2016/06/18 16:46:16 Just to be safe, } else if (type == VIDEO) { .
alokp 2016/06/19 04:57:45 Done.
226 }
227
205 void MojoRendererImpl::BindRemoteRendererIfNeeded() { 228 void MojoRendererImpl::BindRemoteRendererIfNeeded() {
206 DVLOG(2) << __FUNCTION__; 229 DVLOG(2) << __FUNCTION__;
207 DCHECK(task_runner_->BelongsToCurrentThread()); 230 DCHECK(task_runner_->BelongsToCurrentThread());
208 231
209 // If |remote_renderer_| has already been bound, do nothing. 232 // If |remote_renderer_| has already been bound, do nothing.
210 if (remote_renderer_.is_bound()) 233 if (remote_renderer_.is_bound())
211 return; 234 return;
212 235
213 // Bind |remote_renderer_| to the |task_runner_|. 236 // Bind |remote_renderer_| to the |task_runner_|.
214 remote_renderer_.Bind(std::move(remote_renderer_info_)); 237 remote_renderer_.Bind(std::move(remote_renderer_info_));
215 238
216 // Otherwise, set an error handler to catch the connection error. 239 // Otherwise, set an error handler to catch the connection error.
217 // Using base::Unretained(this) is safe because |this| owns 240 // Using base::Unretained(this) is safe because |this| owns
218 // |remote_renderer_|, and the error handler can't be invoked once 241 // |remote_renderer_|, and the error handler can't be invoked once
219 // |remote_renderer_| is destroyed. 242 // |remote_renderer_| is destroyed.
220 remote_renderer_.set_connection_error_handler( 243 remote_renderer_.set_connection_error_handler(
221 base::Bind(&MojoRendererImpl::OnConnectionError, base::Unretained(this))); 244 base::Bind(&MojoRendererImpl::OnConnectionError, base::Unretained(this)));
222 } 245 }
223 246
224 void MojoRendererImpl::OnInitialized(bool success) { 247 void MojoRendererImpl::OnInitialized(bool success) {
225 DVLOG(1) << __FUNCTION__; 248 DVLOG(1) << __FUNCTION__;
226 DCHECK(task_runner_->BelongsToCurrentThread()); 249 DCHECK(task_runner_->BelongsToCurrentThread());
227 DCHECK(!init_cb_.is_null()); 250 DCHECK(!init_cb_.is_null());
228 251
229 base::ResetAndReturn(&init_cb_).Run( 252 base::ResetAndReturn(&init_cb_).Run(
230 success ? PIPELINE_OK : PIPELINE_ERROR_INITIALIZATION_FAILED); 253 success ? PIPELINE_OK : PIPELINE_ERROR_INITIALIZATION_FAILED);
231 } 254 }
232 255
233 } // namespace media 256 } // namespace media
OLDNEW
« no previous file with comments | « media/mojo/clients/mojo_renderer_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698