Bug 1332544 - replace use of mOwner with GetOwner() which provides more checks. r=gerald a=gchang
authorJW Wang <jwwang@mozilla.com>
Fri, 20 Jan 2017 11:47:53 +0800
changeset 375665 f78767560dc26c97d0e35c3ab6c36fec078d875a
parent 375664 9b49981936b607d4d6f02b098ecf7191c86f19be
child 375666 7261f391ff4fb2287a7a8530d9319eccb378e510
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald, gchang
bugs1332544
milestone53.0a2
Bug 1332544 - replace use of mOwner with GetOwner() which provides more checks. r=gerald a=gchang MozReview-Commit-ID: DUTO4vR2kjU
dom/media/MediaDecoder.cpp
dom/media/MediaDecoder.h
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -164,17 +164,17 @@ MediaDecoder::ResourceCallback::Disconne
     mTimer = nullptr;
   }
 }
 
 MediaDecoderOwner*
 MediaDecoder::ResourceCallback::GetMediaOwner() const
 {
   MOZ_ASSERT(NS_IsMainThread());
-  return mDecoder ? mDecoder->mOwner : nullptr;
+  return mDecoder ? mDecoder->GetOwner() : nullptr;
 }
 
 void
 MediaDecoder::ResourceCallback::SetInfinite(bool aInfinite)
 {
   MOZ_ASSERT(NS_IsMainThread());
   if (mDecoder) {
     mDecoder->SetInfinite(aInfinite);
@@ -543,37 +543,37 @@ MediaDecoder::OnPlaybackEvent(MediaEvent
       break;
     case MediaEventType::SeekStarted:
       SeekingStarted();
       break;
     case MediaEventType::Invalidate:
       Invalidate();
       break;
     case MediaEventType::EnterVideoSuspend:
-      mOwner->DispatchAsyncEvent(NS_LITERAL_STRING("mozentervideosuspend"));
+      GetOwner()->DispatchAsyncEvent(NS_LITERAL_STRING("mozentervideosuspend"));
       break;
     case MediaEventType::ExitVideoSuspend:
-      mOwner->DispatchAsyncEvent(NS_LITERAL_STRING("mozexitvideosuspend"));
+      GetOwner()->DispatchAsyncEvent(NS_LITERAL_STRING("mozexitvideosuspend"));
       break;
   }
 }
 
 void
 MediaDecoder::OnPlaybackErrorEvent(const MediaResult& aError)
 {
   DecodeError(aError);
 }
 
 void
 MediaDecoder::OnDecoderDoctorEvent(DecoderDoctorEvent aEvent)
 {
   MOZ_ASSERT(NS_IsMainThread());
   // OnDecoderDoctorEvent is disconnected at shutdown time.
   MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
-  HTMLMediaElement* element = mOwner->GetMediaElement();
+  HTMLMediaElement* element = GetOwner()->GetMediaElement();
   if (!element) {
     return;
   }
   nsIDocument* doc = element->OwnerDoc();
   if (!doc) {
     return;
   }
   DecoderDoctorDiagnostics diags;
@@ -707,17 +707,17 @@ MediaDecoder::Seek(double aTime, SeekTar
   mLogicalPosition = aTime;
 
   mLogicallySeeking = true;
   SeekTarget target = SeekTarget(timeUsecs, aSeekType);
   CallSeek(target, aPromise);
 
   if (mPlayState == PLAY_STATE_ENDED) {
     PinForSeek();
-    ChangeState(mOwner->GetPaused() ? PLAY_STATE_PAUSED : PLAY_STATE_PLAYING);
+    ChangeState(GetOwner()->GetPaused() ? PLAY_STATE_PAUSED : PLAY_STATE_PLAYING);
   }
   return NS_OK;
 }
 
 void
 MediaDecoder::AsyncResolveSeekDOMPromiseIfExists()
 {
   MOZ_ASSERT(NS_IsMainThread());
@@ -808,22 +808,22 @@ MediaDecoder::MetadataLoaded(nsAutoPtr<M
   mMediaSeekableOnlyInBufferedRanges = aInfo->mMediaSeekableOnlyInBufferedRanges;
   mInfo = aInfo.forget();
   ConstructMediaTracks();
 
   // Make sure the element and the frame (if any) are told about
   // our new size.
   if (aEventVisibility != MediaDecoderEventVisibility::Suppressed) {
     mFiredMetadataLoaded = true;
-    mOwner->MetadataLoaded(mInfo, nsAutoPtr<const MetadataTags>(aTags.forget()));
+    GetOwner()->MetadataLoaded(mInfo, nsAutoPtr<const MetadataTags>(aTags.forget()));
   }
-  // Invalidate() will end up calling mOwner->UpdateMediaSize with the last
+  // Invalidate() will end up calling GetOwner()->UpdateMediaSize with the last
   // dimensions retrieved from the video frame container. The video frame
   // container contains more up to date dimensions than aInfo.
-  // So we call Invalidate() after calling mOwner->MetadataLoaded to ensure
+  // So we call Invalidate() after calling GetOwner()->MetadataLoaded to ensure
   // the media element has the latest dimensions.
   Invalidate();
 
   EnsureTelemetryReported();
 }
 
 void
 MediaDecoder::EnsureTelemetryReported()
@@ -888,37 +888,37 @@ MediaDecoder::FirstFrameLoaded(nsAutoPtr
   if (mPlayState == PLAY_STATE_LOADING) {
     ChangeState(mNextState);
   }
 
   // Run NotifySuspendedStatusChanged now to give us a chance to notice
   // that autoplay should run.
   NotifySuspendedStatusChanged();
 
-  // mOwner->FirstFrameLoaded() might call us back. Put it at the bottom of
+  // GetOwner()->FirstFrameLoaded() might call us back. Put it at the bottom of
   // this function to avoid unexpected shutdown from reentrant calls.
   if (aEventVisibility != MediaDecoderEventVisibility::Suppressed) {
-    mOwner->FirstFrameLoaded();
+    GetOwner()->FirstFrameLoaded();
   }
 }
 
 void
 MediaDecoder::NetworkError()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
-  mOwner->NetworkError();
+  GetOwner()->NetworkError();
 }
 
 void
 MediaDecoder::DecodeError(const MediaResult& aError)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
-  mOwner->DecodeError(aError);
+  GetOwner()->DecodeError(aError);
 }
 
 void
 MediaDecoder::UpdateSameOriginStatus(bool aSameOrigin)
 {
   MOZ_ASSERT(NS_IsMainThread());
   mSameOriginMedia = aSameOrigin;
 }
@@ -930,17 +930,17 @@ MediaDecoder::IsSeeking() const
   return mLogicallySeeking;
 }
 
 bool
 MediaDecoder::OwnerHasError() const
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
-  return mOwner->HasError();
+  return GetOwner()->HasError();
 }
 
 class MediaElementGMPCrashHelper : public GMPCrashHelper
 {
 public:
   explicit MediaElementGMPCrashHelper(HTMLMediaElement* aElement)
     : mElement(aElement)
   {
@@ -957,18 +957,18 @@ public:
 private:
   WeakPtr<HTMLMediaElement> mElement;
 };
 
 already_AddRefed<GMPCrashHelper>
 MediaDecoder::GetCrashHelper()
 {
   MOZ_ASSERT(NS_IsMainThread());
-  return mOwner->GetMediaElement() ?
-    MakeAndAddRef<MediaElementGMPCrashHelper>(mOwner->GetMediaElement()) : nullptr;
+  return GetOwner()->GetMediaElement() ?
+    MakeAndAddRef<MediaElementGMPCrashHelper>(GetOwner()->GetMediaElement()) : nullptr;
 }
 
 bool
 MediaDecoder::IsEnded() const
 {
   MOZ_ASSERT(NS_IsMainThread());
   return mPlayState == PLAY_STATE_ENDED;
 }
@@ -992,19 +992,19 @@ MediaDecoder::PlaybackEnded()
                 mLogicallySeeking.Ref(), ToPlayStateStr(mPlayState));
     return;
   }
 
   DECODER_LOG("MediaDecoder::PlaybackEnded");
 
   ChangeState(PLAY_STATE_ENDED);
   InvalidateWithFlags(VideoFrameContainer::INVALIDATE_FORCE);
-  mOwner->PlaybackEnded();
+  GetOwner()->PlaybackEnded();
 
-  // This must be called after |mOwner->PlaybackEnded()| call above, in order
+  // This must be called after |GetOwner()->PlaybackEnded()| call above, in order
   // to fire the required durationchange.
   if (IsInfinite()) {
     SetInfinite(false);
   }
 }
 
 MediaStatistics
 MediaDecoder::GetStatistics()
@@ -1064,40 +1064,40 @@ MediaDecoder::UpdatePlaybackRate()
 
 void
 MediaDecoder::NotifySuspendedStatusChanged()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
   if (mResource) {
     bool suspended = mResource->IsSuspendedByCache();
-    mOwner->NotifySuspendedByCache(suspended);
+    GetOwner()->NotifySuspendedByCache(suspended);
   }
 }
 
 void
 MediaDecoder::NotifyBytesDownloaded()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
   UpdatePlaybackRate();
-  mOwner->DownloadProgressed();
+  GetOwner()->DownloadProgressed();
 }
 
 void
 MediaDecoder::NotifyDownloadEnded(nsresult aStatus)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
 
   DECODER_LOG("NotifyDownloadEnded, status=%x", aStatus);
 
   if (aStatus == NS_BINDING_ABORTED) {
     // Download has been cancelled by user.
-    mOwner->LoadAborted();
+    GetOwner()->LoadAborted();
     return;
   }
 
   UpdatePlaybackRate();
 
   if (NS_SUCCEEDED(aStatus)) {
     // A final progress event will be fired by the MediaResource calling
     // DownloadSuspended on the element.
@@ -1110,17 +1110,17 @@ MediaDecoder::NotifyDownloadEnded(nsresu
 
 void
 MediaDecoder::NotifyPrincipalChanged()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
   nsCOMPtr<nsIPrincipal> newPrincipal = GetCurrentPrincipal();
   mMediaPrincipalHandle = MakePrincipalHandle(newPrincipal);
-  mOwner->NotifyDecoderPrincipalChanged();
+  GetOwner()->NotifyDecoderPrincipalChanged();
 }
 
 void
 MediaDecoder::NotifyBytesConsumed(int64_t aBytes, int64_t aOffset)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
 
@@ -1147,17 +1147,17 @@ MediaDecoder::OnSeekResolved()
     // in operation.
     UnpinForSeek();
     mLogicallySeeking = false;
   }
 
   // Ensure logical position is updated after seek.
   UpdateLogicalPositionInternal();
 
-  mOwner->SeekCompleted();
+  GetOwner()->SeekCompleted();
   AsyncResolveSeekDOMPromiseIfExists();
 }
 
 void
 MediaDecoder::OnSeekRejected()
 {
   MOZ_ASSERT(NS_IsMainThread());
   mSeekRequest.Complete();
@@ -1165,17 +1165,17 @@ MediaDecoder::OnSeekRejected()
   AsyncRejectSeekDOMPromiseIfExists();
 }
 
 void
 MediaDecoder::SeekingStarted()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
-  mOwner->SeekStarted();
+  GetOwner()->SeekStarted();
 }
 
 void
 MediaDecoder::ChangeState(PlayState aState)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(!IsShutdown(), "SHUTDOWN is the final state.");
 
@@ -1240,17 +1240,17 @@ MediaDecoder::DurationChanged()
 
   // Duration has changed so we should recompute playback rate
   UpdatePlaybackRate();
 
   // See https://www.w3.org/Bugs/Public/show_bug.cgi?id=28822 for a discussion
   // of whether we should fire durationchange on explicit infinity.
   if (mFiredMetadataLoaded &&
       (!mozilla::IsInfinite<double>(mDuration) || mExplicitDuration.Ref().isSome())) {
-    mOwner->DispatchAsyncEvent(NS_LITERAL_STRING("durationchange"));
+    GetOwner()->DispatchAsyncEvent(NS_LITERAL_STRING("durationchange"));
   }
 
   if (CurrentPosition() > TimeUnit::FromSeconds(mDuration).ToMicroseconds()) {
     Seek(mDuration, SeekTarget::Accurate);
   }
 }
 
 void
@@ -1377,17 +1377,17 @@ MediaDecoder::SetPlaybackRate(double aPl
   double oldRate = mPlaybackRate;
   mPlaybackRate = aPlaybackRate;
   if (aPlaybackRate == 0) {
     Pause();
     return;
   }
 
 
-  if (oldRate == 0 && !mOwner->GetPaused()) {
+  if (oldRate == 0 && !GetOwner()->GetPaused()) {
     // PlaybackRate is no longer null.
     // Restart the playback if the media was playing.
     Play();
   }
 
   if (mDecoderStateMachine) {
     mDecoderStateMachine->DispatchSetPlaybackRate(aPlaybackRate);
   }
@@ -1509,17 +1509,17 @@ MediaDecoder::GetStateMachine() const {
   return mDecoderStateMachine;
 }
 
 void
 MediaDecoder::FireTimeUpdate()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
-  mOwner->FireTimeUpdate(true);
+  GetOwner()->FireTimeUpdate(true);
 }
 
 void
 MediaDecoder::PinForSeek()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MediaResource* resource = GetResource();
   if (!resource || mPinnedForSeek) {
@@ -1667,17 +1667,17 @@ MediaDecoder::ConstructMediaTracks()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
 
   if (mMediaTracksConstructed || !mInfo) {
     return;
   }
 
-  HTMLMediaElement* element = mOwner->GetMediaElement();
+  HTMLMediaElement* element = GetOwner()->GetMediaElement();
   if (!element) {
     return;
   }
 
   mMediaTracksConstructed = true;
 
   AudioTrackList* audioList = element->AudioTracks();
   if (audioList && mInfo->HasAudio()) {
@@ -1700,17 +1700,17 @@ MediaDecoder::ConstructMediaTracks()
 }
 
 void
 MediaDecoder::RemoveMediaTracks()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
 
-  HTMLMediaElement* element = mOwner->GetMediaElement();
+  HTMLMediaElement* element = GetOwner()->GetMediaElement();
   if (!element) {
     return;
   }
 
   AudioTrackList* audioList = element->AudioTracks();
   if (audioList) {
     audioList->RemoveTracks();
   }
@@ -1758,17 +1758,17 @@ MediaDecoder::DumpDebugInfo()
     GetStateMachine()->DumpDebugInfo();
   }
 }
 
 void
 MediaDecoder::NotifyAudibleStateChanged()
 {
   MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
-  mOwner->SetAudibleState(mIsAudioDataAudible);
+  GetOwner()->SetAudibleState(mIsAudioDataAudible);
 }
 
 MediaMemoryTracker::MediaMemoryTracker()
 {
 }
 
 void
 MediaMemoryTracker::InitMemoryReporter()
--- a/dom/media/MediaDecoder.h
+++ b/dom/media/MediaDecoder.h
@@ -468,17 +468,17 @@ private:
   {
     GetFrameStatistics().NotifyDecodedFrames(aStats);
   }
 
   void UpdateReadyState()
   {
     MOZ_ASSERT(NS_IsMainThread());
     MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
-    mOwner->UpdateReadyState();
+    GetOwner()->UpdateReadyState();
   }
 
   virtual MediaDecoderOwner::NextFrameStatus NextFrameStatus() { return mNextFrameStatus; }
   virtual MediaDecoderOwner::NextFrameStatus NextFrameBufferedStatus();
 
   // Returns a string describing the state of the media player internal
   // data. Used for debugging purposes.
   virtual void GetMozDebugReaderData(nsACString& aString) {}