Bug 1525156 - part2 : Add Telemetry to know how many autoplay media, which has been resumed from blocked, played exactly 7 secocnds or more, or less than 7 seconds. r=cpearce,janerik

By adding the Telemetry to measure the number of video/audio which played exactly 7 seconds or more, or less than 7 seconds, after those media has been resumed from blocked state, we can know how many media would meet the Chrome's MEI condition, which could help us to know more about the whole landscape of autoplay media.

In addition, it could help us know how many media are played 'by users intention' because we assume that users are more likely to stop the media if autoplay media is unblocked by accident.

Differential Revision: https://phabricator.services.mozilla.com/D18628

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Alastor Wu 2019-02-26 04:44:19 +00:00
Родитель 2607aaaa8d
Коммит 1caaa8a882
3 изменённых файлов: 95 добавлений и 1 удалений

Просмотреть файл

@ -1717,6 +1717,53 @@ void HTMLMediaElement::ShutdownDecoder() {
ReportAudioTrackSilenceProportionTelemetry();
}
void HTMLMediaElement::ReportPlayedTimeAfterBlockedTelemetry() {
if (!mHasPlayEverBeenBlocked) {
return;
}
mHasPlayEverBeenBlocked = false;
const double playTimeThreshold = 7.0;
const double playTimeAfterBlocked = mCurrentLoadPlayTime.Total();
if (playTimeAfterBlocked <= 0.0) {
return;
}
const bool isDurationLessThanTimeThresholdAndMediaPlayedToTheEnd =
Duration() < playTimeThreshold && Ended();
LOG(LogLevel::Debug, ("%p PLAYED_TIME_AFTER_AUTOPLAY_BLOCKED=%f, isVideo=%d",
this, playTimeAfterBlocked, IsVideo()));
if (IsVideo() && playTimeAfterBlocked >= playTimeThreshold) {
AccumulateCategorical(
mozilla::Telemetry::LABELS_MEDIA_PLAYED_TIME_AFTER_AUTOPLAY_BLOCKED::
VPlayedMoreThan7s);
} else if (IsVideo() && playTimeAfterBlocked < playTimeThreshold) {
if (isDurationLessThanTimeThresholdAndMediaPlayedToTheEnd) {
AccumulateCategorical(
mozilla::Telemetry::LABELS_MEDIA_PLAYED_TIME_AFTER_AUTOPLAY_BLOCKED::
VPlayedToTheEnd);
} else {
AccumulateCategorical(
mozilla::Telemetry::LABELS_MEDIA_PLAYED_TIME_AFTER_AUTOPLAY_BLOCKED::
VPlayedLessThan7s);
}
} else if (!IsVideo() && playTimeAfterBlocked >= playTimeThreshold) {
AccumulateCategorical(
mozilla::Telemetry::LABELS_MEDIA_PLAYED_TIME_AFTER_AUTOPLAY_BLOCKED::
APlayedMoreThan7s);
} else if (!IsVideo() && playTimeAfterBlocked < playTimeThreshold) {
if (isDurationLessThanTimeThresholdAndMediaPlayedToTheEnd) {
AccumulateCategorical(
mozilla::Telemetry::LABELS_MEDIA_PLAYED_TIME_AFTER_AUTOPLAY_BLOCKED::
APlayedToTheEnd);
} else {
AccumulateCategorical(
mozilla::Telemetry::LABELS_MEDIA_PLAYED_TIME_AFTER_AUTOPLAY_BLOCKED::
APlayedLessThan7s);
}
}
}
void HTMLMediaElement::AbortExistingLoads() {
// Abort any already-running instance of the resource selection algorithm.
mLoadWaitStatus = NOT_WAITING;
@ -1838,6 +1885,7 @@ void HTMLMediaElement::AbortExistingLoads() {
mEventDeliveryPaused = false;
mPendingEvents.Clear();
mCurrentLoadPlayTime.Reset();
AssertReadyStateIsNothing();
}
@ -3529,6 +3577,7 @@ HTMLMediaElement::~HTMLMediaElement() {
}
WakeLockRelease();
ReportPlayedTimeAfterBlockedTelemetry();
DecoderDoctorLogger::LogDestruction(this);
}
@ -3670,6 +3719,7 @@ void HTMLMediaElement::DispatchEventsWhenPlayWasNotAllowed() {
#endif
OwnerDoc()->MaybeNotifyAutoplayBlocked();
ReportToConsole(nsIScriptError::warningFlag, "BlockAutoplayError");
mHasPlayEverBeenBlocked = true;
}
void HTMLMediaElement::PlayInternal(bool aHandlingUserInput) {
@ -5727,16 +5777,25 @@ void HTMLMediaElement::DispatchAsyncEvent(const nsAString& aName) {
if ((aName.EqualsLiteral("play") || aName.EqualsLiteral("playing"))) {
mPlayTime.Start();
mCurrentLoadPlayTime.Start();
if (IsHidden()) {
HiddenVideoStart();
}
} else if (aName.EqualsLiteral("waiting")) {
mPlayTime.Pause();
mCurrentLoadPlayTime.Pause();
HiddenVideoStop();
} else if (aName.EqualsLiteral("pause")) {
mPlayTime.Pause();
mCurrentLoadPlayTime.Pause();
HiddenVideoStop();
}
// It would happen when (1) media aborts current load (2) media pauses (3)
// media end (4) media unbind from tree (because we would pause it)
if (aName.EqualsLiteral("pause")) {
ReportPlayedTimeAfterBlockedTelemetry();
}
}
nsresult HTMLMediaElement::DispatchPendingMediaEvents() {
@ -5871,6 +5930,7 @@ void HTMLMediaElement::SuspendOrResumeElement(bool aPauseElement,
UpdateSrcMediaStreamPlaying();
UpdateAudioChannelPlayingState();
if (aPauseElement) {
mCurrentLoadPlayTime.Pause();
ReportTelemetry();
// For EME content, we may force destruction of the CDM client (and CDM
@ -5888,6 +5948,9 @@ void HTMLMediaElement::SuspendOrResumeElement(bool aPauseElement,
}
mEventDeliveryPaused = aSuspendEvents;
} else {
if (!mPaused) {
mCurrentLoadPlayTime.Start();
}
if (mDecoder) {
mDecoder->Resume();
if (!mPaused && !mDecoder->IsEnded()) {

Просмотреть файл

@ -1669,7 +1669,7 @@ class HTMLMediaElement : public nsGenericHTMLElement,
MozPromiseHolder<GenericNonExclusivePromise> mAllowedToPlayPromise;
public:
// Helper class to measure times for MSE telemetry stats
// Helper class to measure times for playback telemetry stats
class TimeDurationAccumulator {
public:
TimeDurationAccumulator() : mCount(0) {}
@ -1702,6 +1702,11 @@ class HTMLMediaElement : public nsGenericHTMLElement,
// Count current run in this report, without increasing the stored count.
return mCount + 1;
}
void Reset() {
mStartTime = TimeStamp();
mSum = TimeDuration();
mCount = 0;
}
private:
TimeStamp mStartTime;
@ -1733,6 +1738,18 @@ class HTMLMediaElement : public nsGenericHTMLElement,
// Total time a video has (or would have) spent in video-decode-suspend mode.
TimeDurationAccumulator mVideoDecodeSuspendTime;
// Total time a video has spent playing on the current load, it would be reset
// when media aborts the current load; be paused when the docuemt enters the
// bf-cache and be resumed when the docuemt leaves the bf-cache.
TimeDurationAccumulator mCurrentLoadPlayTime;
// True if media has ever been blocked by autoplay policy before.
bool mHasPlayEverBeenBlocked = false;
// Report the Telemetry about whether media played over the specific time
// threshold.
void ReportPlayedTimeAfterBlockedTelemetry();
// True if user has called load(), seek() or element has started playing
// before. It's *only* use for checking autoplay policy
bool mIsBlessed = false;

Просмотреть файл

@ -14387,6 +14387,20 @@
"description": "The number of times the user adds a site to the allow list, removes a site from the allow list, adds a site to the block list and removes a site from the block list.",
"releaseChannelCollection": "opt-out"
},
"MEDIA_PLAYED_TIME_AFTER_AUTOPLAY_BLOCKED": {
"record_in_processes": ["main", "content"],
"alert_emails": [
"alwu@mozilla.com",
"cpearce@mozilla.com",
"nohlmeier@mozilla.com"
],
"expires_in_version": "72",
"kind": "categorical",
"labels": ["VPlayedMoreThan7s", "VPlayedLessThan7s", "VPlayedToTheEnd", "APlayedMoreThan7s", "APlayedLessThan7s", "APlayedToTheEnd"],
"bug_numbers": [1525156],
"description": "The number of times autoplay media (audio and video), which has been blocked by autoplay policy, played exactly 7 seconds or more, or less than 7 seconds after it has been resumed from the blocked state. If media's duration is less than 7 seconds and it played to the end before user pauses it, it would be in another category which is different from 'play >= 7 seconds' and 'play < 7 seconds'.",
"releaseChannelCollection": "opt-out"
},
"QM_REPOSITORIES_INITIALIZATION_TIME": {
"record_in_processes": ["main"],
"expires_in_version": "72",