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
This commit is contained in:
Alastor Wu
2019-03-08 03:12:42 +00:00
parent a7aae22660
commit fce2ee165c

View File

@@ -199,7 +199,7 @@ void TextTrackManager::AddCues(TextTrack* aTextTrack) {
for (uint32_t i = 0; i < cueList->Length(); ++i) {
mNewCues->AddCue(*cueList->IndexedGetter(i, dummy));
}
DispatchTimeMarchesOn();
TimeMarchesOn();
}
}
@@ -224,7 +224,7 @@ void TextTrackManager::RemoveTextTrack(TextTrack* aTextTrack,
for (uint32_t i = 0; i < removeCueList->Length(); ++i) {
mNewCues->RemoveCue(*((*removeCueList)[i]));
}
DispatchTimeMarchesOn();
TimeMarchesOn();
}
}
@@ -288,7 +288,7 @@ void TextTrackManager::NotifyCueAdded(TextTrackCue& aCue) {
if (mNewCues) {
mNewCues->AddCue(aCue);
}
DispatchTimeMarchesOn();
TimeMarchesOn();
ReportTelemetryForCue();
}
@@ -297,7 +297,7 @@ void TextTrackManager::NotifyCueRemoved(TextTrackCue& aCue) {
if (mNewCues) {
mNewCues->RemoveCue(aCue);
}
DispatchTimeMarchesOn();
TimeMarchesOn();
if (aCue.GetActive()) {
// We remove an active cue, need to update the display.
DispatchUpdateCueDisplay();
@@ -613,6 +613,8 @@ void TextTrackManager::DispatchTimeMarchesOn() {
// 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
@@ -625,7 +627,6 @@ void TextTrackManager::TimeMarchesOn() {
return;
}
WEBVTT_LOG("TimeMarchesOn");
mTimeMarchesOnDispatched = false;
// Early return if we don't have any TextTracks or shutting down.
if (!mTextTracks || mTextTracks->Length() == 0 || IsShutdown()) {
@@ -825,7 +826,7 @@ void TextTrackManager::TimeMarchesOn() {
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.