| Index: third_party/WebKit/Source/core/html/AutoplayUmaHelper.cpp
|
| diff --git a/third_party/WebKit/Source/core/html/AutoplayUmaHelper.cpp b/third_party/WebKit/Source/core/html/AutoplayUmaHelper.cpp
|
| index 72ab6fe5645646c002559684f5da5634e1bf8242..6995e6e5b7beace50f327051dcabca590d00736f 100644
|
| --- a/third_party/WebKit/Source/core/html/AutoplayUmaHelper.cpp
|
| +++ b/third_party/WebKit/Source/core/html/AutoplayUmaHelper.cpp
|
| @@ -5,7 +5,6 @@
|
| #include "core/html/AutoplayUmaHelper.h"
|
|
|
| #include "core/dom/Document.h"
|
| -#include "core/dom/ElementVisibilityObserver.h"
|
| #include "core/events/Event.h"
|
| #include "core/frame/LocalDOMWindow.h"
|
| #include "core/frame/Settings.h"
|
| @@ -30,11 +29,9 @@ AutoplayUmaHelper::AutoplayUmaHelper(HTMLMediaElement* element)
|
| : EventListener(CPPEventListenerType),
|
| m_source(AutoplaySource::NumberOfSources),
|
| m_element(element),
|
| - m_mutedVideoPlayMethodVisibilityObserver(nullptr),
|
| m_mutedVideoAutoplayOffscreenStartTimeMS(0),
|
| m_mutedVideoAutoplayOffscreenDurationMS(0),
|
| - m_isVisible(false),
|
| - m_mutedVideoOffscreenDurationVisibilityObserver(nullptr) {}
|
| + m_isVisible(false) {}
|
|
|
| AutoplayUmaHelper::~AutoplayUmaHelper() = default;
|
|
|
| @@ -116,28 +113,25 @@ void AutoplayUmaHelper::didMoveToNewDocument(Document& oldDocument) {
|
| this, false);
|
| }
|
|
|
| -void AutoplayUmaHelper::onVisibilityChangedForMutedVideoPlayMethodBecomeVisible(
|
| - bool isVisible) {
|
| - if (!isVisible || !m_mutedVideoPlayMethodVisibilityObserver)
|
| - return;
|
| -
|
| - maybeStopRecordingMutedVideoPlayMethodBecomeVisible(true);
|
| -}
|
| -
|
| -void AutoplayUmaHelper::onVisibilityChangedForMutedVideoOffscreenDuration(
|
| - bool isVisible) {
|
| +void AutoplayUmaHelper::visibilityMaybeChangedforMutedVideo(bool isVisible) {
|
| if (isVisible == m_isVisible)
|
| return;
|
|
|
| - if (isVisible)
|
| - m_mutedVideoAutoplayOffscreenDurationMS +=
|
| - static_cast<int64_t>(monotonicallyIncreasingTimeMS()) -
|
| - m_mutedVideoAutoplayOffscreenStartTimeMS;
|
| - else
|
| - m_mutedVideoAutoplayOffscreenStartTimeMS =
|
| - static_cast<int64_t>(monotonicallyIncreasingTimeMS());
|
| -
|
| m_isVisible = isVisible;
|
| +
|
| + if (m_isObservingVisibilityOfMutedVideoOffscreenDuration && isVisible)
|
| + maybeStopRecordingMutedVideoPlayMethodBecomeVisible(true);
|
| +
|
| + if (m_isObservingVisibilityOfMutedVideoOffscreenDuration) {
|
| + if (isVisible) {
|
| + m_mutedVideoAutoplayOffscreenDurationMS +=
|
| + static_cast<int64_t>(monotonicallyIncreasingTimeMS()) -
|
| + m_mutedVideoAutoplayOffscreenStartTimeMS;
|
| + } else {
|
| + m_mutedVideoAutoplayOffscreenStartTimeMS =
|
| + static_cast<int64_t>(monotonicallyIncreasingTimeMS());
|
| + }
|
| + }
|
| }
|
|
|
| void AutoplayUmaHelper::handleEvent(ExecutionContext* executionContext,
|
| @@ -173,12 +167,7 @@ void AutoplayUmaHelper::maybeStartRecordingMutedVideoPlayMethodBecomeVisible() {
|
| !m_element->muted())
|
| return;
|
|
|
| - m_mutedVideoPlayMethodVisibilityObserver = new ElementVisibilityObserver(
|
| - m_element,
|
| - WTF::bind(&AutoplayUmaHelper::
|
| - onVisibilityChangedForMutedVideoPlayMethodBecomeVisible,
|
| - wrapWeakPersistent(this)));
|
| - m_mutedVideoPlayMethodVisibilityObserver->start();
|
| + m_isObservingMutedVideoPlayMethodBecomeVisible = true;
|
| if (m_element->document().domWindow())
|
| m_element->document().domWindow()->addEventListener(EventTypeNames::unload,
|
| this, false);
|
| @@ -186,15 +175,14 @@ void AutoplayUmaHelper::maybeStartRecordingMutedVideoPlayMethodBecomeVisible() {
|
|
|
| void AutoplayUmaHelper::maybeStopRecordingMutedVideoPlayMethodBecomeVisible(
|
| bool visible) {
|
| - if (!m_mutedVideoPlayMethodVisibilityObserver)
|
| + if (!m_isObservingMutedVideoPlayMethodBecomeVisible)
|
| return;
|
|
|
| DEFINE_STATIC_LOCAL(BooleanHistogram, histogram,
|
| ("Media.Video.Autoplay.Muted.PlayMethod.BecomesVisible"));
|
|
|
| histogram.count(visible);
|
| - m_mutedVideoPlayMethodVisibilityObserver->stop();
|
| - m_mutedVideoPlayMethodVisibilityObserver = nullptr;
|
| + m_isObservingMutedVideoPlayMethodBecomeVisible = false;
|
| maybeUnregisterUnloadListener();
|
| }
|
|
|
| @@ -206,13 +194,7 @@ void AutoplayUmaHelper::maybeStartRecordingMutedVideoOffscreenDuration() {
|
| m_mutedVideoAutoplayOffscreenStartTimeMS =
|
| static_cast<int64_t>(monotonicallyIncreasingTimeMS());
|
| m_isVisible = false;
|
| - m_mutedVideoOffscreenDurationVisibilityObserver =
|
| - new ElementVisibilityObserver(
|
| - m_element,
|
| - WTF::bind(&AutoplayUmaHelper::
|
| - onVisibilityChangedForMutedVideoOffscreenDuration,
|
| - wrapWeakPersistent(this)));
|
| - m_mutedVideoOffscreenDurationVisibilityObserver->start();
|
| + m_isObservingVisibilityOfMutedVideoOffscreenDuration = true;
|
| m_element->addEventListener(EventTypeNames::pause, this, false);
|
| if (m_element->document().domWindow())
|
| m_element->document().domWindow()->addEventListener(EventTypeNames::unload,
|
| @@ -220,7 +202,7 @@ void AutoplayUmaHelper::maybeStartRecordingMutedVideoOffscreenDuration() {
|
| }
|
|
|
| void AutoplayUmaHelper::maybeStopRecordingMutedVideoOffscreenDuration() {
|
| - if (!m_mutedVideoOffscreenDurationVisibilityObserver)
|
| + if (!m_isObservingVisibilityOfMutedVideoOffscreenDuration)
|
| return;
|
|
|
| if (!m_isVisible)
|
| @@ -247,8 +229,7 @@ void AutoplayUmaHelper::maybeStopRecordingMutedVideoOffscreenDuration() {
|
| maxOffscreenDurationUmaMS, offscreenDurationUmaBucketCount));
|
| durationHistogram.count(boundedTime);
|
| }
|
| - m_mutedVideoOffscreenDurationVisibilityObserver->stop();
|
| - m_mutedVideoOffscreenDurationVisibilityObserver = nullptr;
|
| + m_isObservingVisibilityOfMutedVideoOffscreenDuration = false;
|
| m_mutedVideoAutoplayOffscreenDurationMS = 0;
|
| m_element->removeEventListener(EventTypeNames::pause, this, false);
|
| maybeUnregisterUnloadListener();
|
| @@ -261,15 +242,13 @@ void AutoplayUmaHelper::maybeUnregisterUnloadListener() {
|
| }
|
|
|
| bool AutoplayUmaHelper::shouldListenToUnloadEvent() const {
|
| - return m_mutedVideoPlayMethodVisibilityObserver ||
|
| - m_mutedVideoOffscreenDurationVisibilityObserver;
|
| + return m_isObservingMutedVideoPlayMethodBecomeVisible ||
|
| + m_isObservingVisibilityOfMutedVideoOffscreenDuration;
|
| }
|
|
|
| DEFINE_TRACE(AutoplayUmaHelper) {
|
| EventListener::trace(visitor);
|
| visitor->trace(m_element);
|
| - visitor->trace(m_mutedVideoPlayMethodVisibilityObserver);
|
| - visitor->trace(m_mutedVideoOffscreenDurationVisibilityObserver);
|
| }
|
|
|
| } // namespace blink
|
|
|