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

Unified Diff: media/base/pipeline.cc

Issue 423073012: Pipeline: Use WeakPtr for DemuxerHost Calls and Tasks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated unit tests. Created 6 years, 4 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/base/pipeline.cc
diff --git a/media/base/pipeline.cc b/media/base/pipeline.cc
index 91ac2cfa139d4399957659ae9943771ed4d7a7e9..be2323e46314e822aa53ea9da7c7b6960d0382e8 100644
--- a/media/base/pipeline.cc
+++ b/media/base/pipeline.cc
@@ -269,16 +269,10 @@ Pipeline::State Pipeline::GetNextState() const {
return state_;
}
-// The use of base::Unretained(this) in the following 3 functions is safe
-// because these functions are called by the Demuxer directly, before the stop
-// callback is posted by the Demuxer. So the posted tasks will always be
-// executed before the stop callback is executed, and hence before the Pipeline
-// is destructed.
-
void Pipeline::OnDemuxerError(PipelineStatus error) {
task_runner_->PostTask(FROM_HERE,
base::Bind(&Pipeline::ErrorChangedTask,
- base::Unretained(this),
+ weak_this_for_demuxer_,
error));
}
@@ -286,7 +280,7 @@ void Pipeline::AddTextStream(DemuxerStream* text_stream,
const TextTrackConfig& config) {
task_runner_->PostTask(FROM_HERE,
base::Bind(&Pipeline::AddTextStreamTask,
- base::Unretained(this),
+ weak_this_for_demuxer_,
text_stream,
config));
}
@@ -294,7 +288,7 @@ void Pipeline::AddTextStream(DemuxerStream* text_stream,
void Pipeline::RemoveTextStream(DemuxerStream* text_stream) {
task_runner_->PostTask(FROM_HERE,
base::Bind(&Pipeline::RemoveTextStreamTask,
- base::Unretained(this),
+ weak_this_for_demuxer_,
text_stream));
}
@@ -550,6 +544,10 @@ void Pipeline::OnStopCompleted(PipelineStatus status) {
filter_collection_.reset();
demuxer_ = NULL;
+ // Invalid all weak pointers so it's safe to destroy |this| on the render
+ // main thread.
+ weak_factory_.InvalidateWeakPtrs();
+
// If we stop during initialization/seeking we want to run |seek_cb_|
// followed by |stop_cb_| so we don't leave outstanding callbacks around.
if (!seek_cb_.is_null()) {
@@ -779,6 +777,7 @@ void Pipeline::RemoveTextStreamTask(DemuxerStream* text_stream) {
void Pipeline::InitializeDemuxer(const PipelineStatusCB& done_cb) {
DCHECK(task_runner_->BelongsToCurrentThread());
+ weak_this_for_demuxer_ = weak_factory_.GetWeakPtr();
demuxer_ = filter_collection_->GetDemuxer();
demuxer_->Initialize(this, done_cb, text_renderer_);
}

Powered by Google App Engine
This is Rietveld 408576698