Bug 1509446 - part3 : run 'TimeMarchesOn' directly, instead of queuing a task. r=jya
authorAlastor Wu <alwu@mozilla.com>
Fri, 08 Mar 2019 03:12:42 +0000
changeset 520964 d1046aea2e0e
parent 520963 fa26e1068b50
child 520965 ad7bfe5bbc3a
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1509446
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1509446 - part3 : run 'TimeMarchesOn' directly, instead of queuing a task. r=jya According to the spec [1], we should run `TimeMarchesOn` algorithm directly when the specific situations happen, the spec doesn't say that we need to queue a task for it. In addition, all the call sites for `TimeMarchesOn` are on the main thread, so we don't need to worry about race condition. [1] https://html.spec.whatwg.org/multipage/media.html#playing-the-media-resource:time-marches-on-2 https://html.spec.whatwg.org/multipage/media.html#playing-the-media-resource:time-marches-on-3 https://html.spec.whatwg.org/multipage/media.html#playing-the-media-resource:time-marches-on-4 Differential Revision: https://phabricator.services.mozilla.com/D22149
dom/html/TextTrackManager.cpp
--- a/dom/html/TextTrackManager.cpp
+++ b/dom/html/TextTrackManager.cpp
@@ -194,17 +194,17 @@ void TextTrackManager::AddCues(TextTrack
 
   TextTrackCueList* cueList = aTextTrack->GetCues();
   if (cueList) {
     bool dummy;
     WEBVTT_LOGV("AddCues cueList->Length() %d", cueList->Length());
     for (uint32_t i = 0; i < cueList->Length(); ++i) {
       mNewCues->AddCue(*cueList->IndexedGetter(i, dummy));
     }
-    DispatchTimeMarchesOn();
+    TimeMarchesOn();
   }
 }
 
 void TextTrackManager::RemoveTextTrack(TextTrack* aTextTrack,
                                        bool aPendingListOnly) {
   if (!mPendingTextTracks || !mTextTracks) {
     return;
   }
@@ -219,17 +219,17 @@ void TextTrackManager::RemoveTextTrack(T
   // Remove the cues in mNewCues belong to aTextTrack.
   TextTrackCueList* removeCueList = aTextTrack->GetCues();
   if (removeCueList) {
     WEBVTT_LOGV("RemoveTextTrack removeCueList->Length() %d",
                 removeCueList->Length());
     for (uint32_t i = 0; i < removeCueList->Length(); ++i) {
       mNewCues->RemoveCue(*((*removeCueList)[i]));
     }
-    DispatchTimeMarchesOn();
+    TimeMarchesOn();
   }
 }
 
 void TextTrackManager::DidSeek() {
   WEBVTT_LOG("%p DidSeek", this);
   if (mTextTracks) {
     mTextTracks->DidSeek();
   }
@@ -283,26 +283,26 @@ void TextTrackManager::UpdateCueDisplay(
   }
 }
 
 void TextTrackManager::NotifyCueAdded(TextTrackCue& aCue) {
   WEBVTT_LOG("NotifyCueAdded");
   if (mNewCues) {
     mNewCues->AddCue(aCue);
   }
-  DispatchTimeMarchesOn();
+  TimeMarchesOn();
   ReportTelemetryForCue();
 }
 
 void TextTrackManager::NotifyCueRemoved(TextTrackCue& aCue) {
   WEBVTT_LOG("NotifyCueRemoved");
   if (mNewCues) {
     mNewCues->RemoveCue(aCue);
   }
-  DispatchTimeMarchesOn();
+  TimeMarchesOn();
   if (aCue.GetActive()) {
     // We remove an active cue, need to update the display.
     DispatchUpdateCueDisplay();
   }
 }
 
 void TextTrackManager::PopulatePendingList() {
   if (!mTextTracks || !mPendingTextTracks || !mMediaElement) {
@@ -608,29 +608,30 @@ void TextTrackManager::DispatchTimeMarch
       mTimeMarchesOnDispatched = true;
     }
   }
 }
 
 // https://html.spec.whatwg.org/multipage/embedded-content.html#time-marches-on
 void TextTrackManager::TimeMarchesOn() {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
+  mTimeMarchesOnDispatched = false;
+
   CycleCollectedJSContext* context = CycleCollectedJSContext::Get();
   if (context && context->IsInStableOrMetaStableState()) {
     // FireTimeUpdate can be called while at stable state following a
     // current position change which triggered a state watcher in MediaDecoder
     // (see bug 1443429).
     // TimeMarchesOn() will modify JS attributes which is forbidden while in
     // stable state. So we dispatch a task to perform such operation later
     // instead.
     DispatchTimeMarchesOn();
     return;
   }
   WEBVTT_LOG("TimeMarchesOn");
-  mTimeMarchesOnDispatched = false;
 
   // Early return if we don't have any TextTracks or shutting down.
   if (!mTextTracks || mTextTracks->Length() == 0 || IsShutdown()) {
     return;
   }
 
   nsISupports* parentObject = mMediaElement->OwnerDoc()->GetParentObject();
   if (NS_WARN_IF(!parentObject)) {
@@ -820,17 +821,17 @@ void TextTrackManager::TimeMarchesOn() {
 
   // Step 18.
   UpdateCueDisplay();
 }
 
 void TextTrackManager::NotifyCueUpdated(TextTrackCue* aCue) {
   // TODO: Add/Reorder the cue to mNewCues if we have some optimization?
   WEBVTT_LOG("NotifyCueUpdated");
-  DispatchTimeMarchesOn();
+  TimeMarchesOn();
   // For the case "Texttrack.mode = hidden/showing", if the mode
   // changing between showing and hidden, TimeMarchesOn
   // doesn't render the cue. Call DispatchUpdateCueDisplay() explicitly.
   DispatchUpdateCueDisplay();
 }
 
 void TextTrackManager::NotifyReset() {
   WEBVTT_LOG("NotifyReset");