| Index: third_party/WebKit/Source/core/html/HTMLMediaElement.cpp
|
| diff --git a/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp b/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp
|
| index bff62e7bfdb250473405fbd5bc2215a8d99b8bf2..397660f1dade78672e5f00d3dbbaa93ac6f71e34 100644
|
| --- a/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp
|
| +++ b/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp
|
| @@ -293,6 +293,9 @@ enum AutoplaySource {
|
| NumberOfAutoplaySources = 2,
|
| };
|
|
|
| +static const double maxUmaDuration = 10000;
|
| +static const double umaBucketCount = 50;
|
| +
|
| } // anonymous namespace
|
|
|
| class HTMLMediaElement::AutoplayHelperClientImpl :
|
| @@ -448,6 +451,11 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document& docum
|
| , m_playPromiseResolveTask(CancellableTaskFactory::create(this, &HTMLMediaElement::resolveScheduledPlayPromises))
|
| , m_playPromiseRejectTask(CancellableTaskFactory::create(this, &HTMLMediaElement::rejectScheduledPlayPromises))
|
| , m_audioSourceNode(nullptr)
|
| + , m_mutedVideoAutoplayStartTimeMS(0)
|
| + , m_mutedVideoAutoplayOffscreenDurationMS(0)
|
| + , m_isVisible(false)
|
| + , m_isAutoplayFromAttribute(false)
|
| + , m_autoplayOffscreenVisibilityObserver(nullptr)
|
| , m_autoplayHelperClient(AutoplayHelperClientImpl::create(this))
|
| , m_autoplayHelper(AutoplayExperimentHelper::create(m_autoplayHelperClient.get()))
|
| , m_remotePlaybackClient(nullptr)
|
| @@ -472,6 +480,7 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document& docum
|
|
|
| HTMLMediaElement::~HTMLMediaElement()
|
| {
|
| + maybeRecordMutedVideoAutoplayOffscreenDuration();
|
| MEDIA_LOG << "~HTMLMediaElement(" << (void*)this << ")";
|
|
|
| // m_audioSourceNode is explicitly cleared by AudioNode::dispose().
|
| @@ -1640,6 +1649,7 @@ void HTMLMediaElement::setReadyState(ReadyState state)
|
|
|
| // Check for autoplay, and record metrics about it if needed.
|
| if (shouldAutoplay(RecordMetricsBehavior::DoRecord)) {
|
| + m_isAutoplayFromAttribute = true;
|
| recordAutoplaySourceMetric(AutoplaySourceAttribute);
|
|
|
| // If the autoplay experiment says that it's okay to play now,
|
| @@ -2090,6 +2100,7 @@ Nullable<ExceptionCode> HTMLMediaElement::play()
|
| m_autoplayHelper->playMethodCalled();
|
|
|
| if (!UserGestureIndicator::processingUserGesture()) {
|
| + m_isAutoplayFromAttribute = false;
|
| recordAutoplaySourceMetric(AutoplaySourceMethod);
|
| if (isGestureNeededForPlayback()) {
|
| // If playback is deferred, then don't start playback but don't
|
| @@ -2192,6 +2203,7 @@ void HTMLMediaElement::pauseInternal()
|
| scheduleTimeupdateEvent(false);
|
| scheduleEvent(EventTypeNames::pause);
|
| scheduleRejectPlayPromises(AbortError);
|
| + maybeRecordMutedVideoAutoplayOffscreenDuration();
|
| }
|
|
|
| updatePlayState();
|
| @@ -2905,6 +2917,7 @@ void HTMLMediaElement::timeChanged()
|
| // changes paused to true and fires a simple event named pause at the media element.
|
| m_paused = true;
|
| scheduleEvent(EventTypeNames::pause);
|
| + maybeRecordMutedVideoAutoplayOffscreenDuration();
|
| }
|
| // Queue a task to fire a simple event named ended at the media element.
|
| scheduleEvent(EventTypeNames::ended);
|
| @@ -3668,6 +3681,7 @@ DEFINE_TRACE(HTMLMediaElement)
|
| visitor->trace(m_autoplayHelper);
|
| visitor->trace(m_srcObject);
|
| visitor->trace(m_autoplayVisibilityObserver);
|
| + visitor->trace(m_autoplayOffscreenVisibilityObserver);
|
| visitor->template registerWeakMembers<HTMLMediaElement, &HTMLMediaElement::clearWeakMembers>(this);
|
| Supplementable<HTMLMediaElement>::trace(visitor);
|
| HTMLElement::trace(visitor);
|
| @@ -3915,6 +3929,45 @@ void HTMLMediaElement::onVisibilityChangedForAutoplay(bool isVisible)
|
|
|
| m_autoplayVisibilityObserver->stop();
|
| m_autoplayVisibilityObserver = nullptr;
|
| + m_mutedVideoAutoplayStartTimeMS = monotonicallyIncreasingTimeMS();
|
| + m_isVisible = true;
|
| + m_autoplayOffscreenVisibilityObserver = new ElementVisibilityObserver(this, WTF::bind(&HTMLMediaElement::onVisibilityChangedForAutoplayOffscreen, wrapPersistent(this)));
|
| +}
|
| +
|
| +void HTMLMediaElement::onVisibilityChangedForAutoplayOffscreen(bool isVisible)
|
| +{
|
| + if (isVisible == m_isVisible)
|
| + return;
|
| +
|
| + if (isVisible)
|
| + m_mutedVideoAutoplayStartTimeMS = monotonicallyIncreasingTimeMS();
|
| + else
|
| + m_mutedVideoAutoplayOffscreenDurationMS += monotonicallyIncreasingTimeMS() - m_mutedVideoAutoplayStartTimeMS;
|
| +
|
| + m_isVisible = isVisible;
|
| +}
|
| +
|
| +void HTMLMediaElement::maybeRecordMutedVideoAutoplayOffscreenDuration()
|
| +{
|
| + if (!m_autoplayOffscreenVisibilityObserver)
|
| + return;
|
| +
|
| + double timeDeltaMS = m_mutedVideoAutoplayOffscreenDurationMS;
|
| + if (timeDeltaMS < 0)
|
| + timeDeltaMS = 0;
|
| + if (timeDeltaMS > maxUmaDuration)
|
| + timeDeltaMS = maxUmaDuration;
|
| +
|
| + if (m_isAutoplayFromAttribute) {
|
| + DEFINE_STATIC_LOCAL(CustomCountHistogram, durationHistogram, ("Media.Video.Autoplay.Muted.FromAttribute.OffscreenDuration", 0, maxUmaDuration, umaBucketCount));
|
| + durationHistogram.count(timeDeltaMS);
|
| + } else {
|
| + DEFINE_STATIC_LOCAL(CustomCountHistogram, durationHistogram, ("Media.Video.Autoplay.Muted.FromMethod.OffscreenDuration", 0, maxUmaDuration, umaBucketCount));
|
| + durationHistogram.count(timeDeltaMS);
|
| + }
|
| + m_autoplayOffscreenVisibilityObserver->stop();
|
| + m_autoplayOffscreenVisibilityObserver = nullptr;
|
| + m_mutedVideoAutoplayOffscreenDurationMS = 0;
|
| }
|
|
|
| void HTMLMediaElement::clearWeakMembers(Visitor* visitor)
|
|
|