summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorqinmin@chromium.org <qinmin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-25 17:45:12 +0000
committerqinmin@chromium.org <qinmin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-25 17:45:12 +0000
commit36368dc4699d2fc15a782275848a9a232a34cf23 (patch)
tree26437b086df3fc3e17f9848c9182acd7ed7564b0
parent6fb3256c5140724b690e298dbd1aaea5ae72db4a (diff)
downloadchromium_src-36368dc4699d2fc15a782275848a9a232a34cf23.zip
chromium_src-36368dc4699d2fc15a782275848a9a232a34cf23.tar.gz
chromium_src-36368dc4699d2fc15a782275848a9a232a34cf23.tar.bz2
Merge 213462 "Merge 210444 "MediaSourceDelegate::Destroy() inval..."
> Merge 210444 "MediaSourceDelegate::Destroy() invalidates all wea..." > > > MediaSourceDelegate::Destroy() invalidates all weak pointers. > > > > This guarantees outstanding callback won't be fired after Destroy() is called. > > Therefore we don't need to check |demuxer_| in those callbacks, which makes the > > code much cleaner. > > > > BUG=233420 > > TEST=none > > > > Review URL: https://chromiumcodereview.appspot.com/18325022 > > BUG=261561 > TBR=qinmin@chromium.org > > Review URL: https://codereview.chromium.org/19514007 TBR=xhwang@chromium.org Review URL: https://codereview.chromium.org/20375002 git-svn-id: svn://svn.chromium.org/chrome/branches/1547/src@213650 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/renderer/media/android/media_source_delegate.cc25
1 files changed, 17 insertions, 8 deletions
diff --git a/content/renderer/media/android/media_source_delegate.cc b/content/renderer/media/android/media_source_delegate.cc
index 71cefaf..e2af874 100644
--- a/content/renderer/media/android/media_source_delegate.cc
+++ b/content/renderer/media/android/media_source_delegate.cc
@@ -93,11 +93,17 @@ void MediaSourceDelegate::Destroy() {
update_network_state_cb_.Reset();
media_source_.reset();
proxy_ = NULL;
-
demuxer_ = NULL;
- if (chunk_demuxer_)
- chunk_demuxer_->Stop(
- BIND_TO_RENDER_LOOP(&MediaSourceDelegate::OnDemuxerStopDone));
+
+ weak_this_.InvalidateWeakPtrs();
+ DCHECK(!weak_this_.HasWeakPtrs());
+
+ if (chunk_demuxer_) {
+ // The callback OnDemuxerStopDone() owns |this| and will delete it when
+ // called. Hence using base::Unretained(this) is safe here.
+ chunk_demuxer_->Stop(base::Bind(&MediaSourceDelegate::OnDemuxerStopDone,
+ base::Unretained(this)));
+ }
}
void MediaSourceDelegate::InitializeMediaSource(
@@ -114,8 +120,8 @@ void MediaSourceDelegate::InitializeMediaSource(
chunk_demuxer_.reset(new media::ChunkDemuxer(
BIND_TO_RENDER_LOOP(&MediaSourceDelegate::OnDemuxerOpened),
BIND_TO_RENDER_LOOP_1(&MediaSourceDelegate::OnNeedKey, ""),
- base::Bind(&MediaSourceDelegate::OnAddTextTrack,
- base::Unretained(this)),
+ // WeakPtrs can only bind to methods without return values.
+ base::Bind(&MediaSourceDelegate::OnAddTextTrack, base::Unretained(this)),
base::Bind(&LogMediaSourceError, media_log_)));
chunk_demuxer_->Initialize(this,
BIND_TO_RENDER_LOOP(&MediaSourceDelegate::OnDemuxerInitDone));
@@ -237,6 +243,8 @@ void MediaSourceDelegate::OnBufferReady(
DCHECK(status == DemuxerStream::kAborted ||
index < params->access_units.size());
bool is_audio = stream->type() == DemuxerStream::AUDIO;
+ DCHECK(demuxer_);
+
if (status != DemuxerStream::kAborted &&
index >= params->access_units.size()) {
LOG(ERROR) << "The internal state inconsistency onBufferReady: "
@@ -327,10 +335,11 @@ void MediaSourceDelegate::OnDemuxerError(
update_network_state_cb_.Run(PipelineErrorToNetworkState(status));
}
-void MediaSourceDelegate::OnDemuxerInitDone(
- media::PipelineStatus status) {
+void MediaSourceDelegate::OnDemuxerInitDone(media::PipelineStatus status) {
DVLOG(1) << "MediaSourceDelegate::OnDemuxerInitDone(" << status << ") : "
<< player_id_;
+ DCHECK(demuxer_);
+
if (status != media::PIPELINE_OK) {
OnDemuxerError(status);
return;