Index: media/base/pipeline.cc |
diff --git a/media/base/pipeline.cc b/media/base/pipeline.cc |
index c1446828394c60a725fc2c33700d2270e7a5e05f..bc55981f6cfbdbaf96e29f2d1c50da616d6b624a 100644 |
--- a/media/base/pipeline.cc |
+++ b/media/base/pipeline.cc |
@@ -200,6 +200,11 @@ void Pipeline::SetErrorForTesting(PipelineStatus status) { |
OnError(status); |
} |
+bool Pipeline::HasWeakPtrsForTesting() const { |
+ DCHECK(task_runner_->BelongsToCurrentThread()); |
+ return weak_factory_.HasWeakPtrs(); |
+} |
+ |
void Pipeline::SetState(State next_state) { |
DVLOG(1) << GetStateString(state_) << " -> " << GetStateString(next_state); |
@@ -602,7 +607,14 @@ void Pipeline::StopTask(const base::Closure& stop_cb) { |
DCHECK(stop_cb_.is_null()); |
if (state_ == kStopped) { |
+ // Invalid all weak pointers so it's safe to destroy |this| on the render |
+ // main thread. |
+ weak_factory_.InvalidateWeakPtrs(); |
+ |
+ // NOTE: pipeline may be deleted at this point in time as a result of |
+ // executing |stop_cb|. |
stop_cb.Run(); |
+ |
return; |
} |