| 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..77b9ddb0250eeeb1da264c552db00f6b625cd21f 100644
|
| --- a/third_party/WebKit/Source/core/html/AutoplayUmaHelper.cpp
|
| +++ b/third_party/WebKit/Source/core/html/AutoplayUmaHelper.cpp
|
| @@ -30,11 +30,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 +114,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 +168,7 @@ void AutoplayUmaHelper::maybeStartRecordingMutedVideoPlayMethodBecomeVisible() {
|
| !m_element->muted())
|
| return;
|
|
|
| - m_mutedVideoPlayMethodVisibilityObserver = new ElementVisibilityObserver(
|
| - m_element,
|
| - WTF::bind(&AutoplayUmaHelper::
|
| - onVisibilityChangedForMutedVideoPlayMethodBecomeVisible,
|
| - wrapWeakPersistent(this)));
|
| - m_mutedVideoPlayMethodVisibilityObserver->start();
|
| + m_isObservingVisibilityOfMutedAutoplayVideo = true;
|
| if (m_element->document().domWindow())
|
| m_element->document().domWindow()->addEventListener(EventTypeNames::unload,
|
| this, false);
|
| @@ -186,15 +176,14 @@ void AutoplayUmaHelper::maybeStartRecordingMutedVideoPlayMethodBecomeVisible() {
|
|
|
| void AutoplayUmaHelper::maybeStopRecordingMutedVideoPlayMethodBecomeVisible(
|
| bool visible) {
|
| - if (!m_mutedVideoPlayMethodVisibilityObserver)
|
| + if (!m_isObservingVisibilityOfMutedAutoplayVideo)
|
| return;
|
|
|
| DEFINE_STATIC_LOCAL(BooleanHistogram, histogram,
|
| ("Media.Video.Autoplay.Muted.PlayMethod.BecomesVisible"));
|
|
|
| histogram.count(visible);
|
| - m_mutedVideoPlayMethodVisibilityObserver->stop();
|
| - m_mutedVideoPlayMethodVisibilityObserver = nullptr;
|
| + m_isObservingVisibilityOfMutedAutoplayVideo = false;
|
| maybeUnregisterUnloadListener();
|
| }
|
|
|
| @@ -206,13 +195,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 +203,7 @@ void AutoplayUmaHelper::maybeStartRecordingMutedVideoOffscreenDuration() {
|
| }
|
|
|
| void AutoplayUmaHelper::maybeStopRecordingMutedVideoOffscreenDuration() {
|
| - if (!m_mutedVideoOffscreenDurationVisibilityObserver)
|
| + if (!m_isObservingVisibilityOfMutedVideoOffscreenDuration)
|
| return;
|
|
|
| if (!m_isVisible)
|
| @@ -247,8 +230,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 +243,13 @@ void AutoplayUmaHelper::maybeUnregisterUnloadListener() {
|
| }
|
|
|
| bool AutoplayUmaHelper::shouldListenToUnloadEvent() const {
|
| - return m_mutedVideoPlayMethodVisibilityObserver ||
|
| - m_mutedVideoOffscreenDurationVisibilityObserver;
|
| + return m_isObservingVisibilityOfMutedAutoplayVideo ||
|
| + m_isObservingVisibilityOfMutedVideoOffscreenDuration;
|
| }
|
|
|
| DEFINE_TRACE(AutoplayUmaHelper) {
|
| EventListener::trace(visitor);
|
| visitor->trace(m_element);
|
| - visitor->trace(m_mutedVideoPlayMethodVisibilityObserver);
|
| - visitor->trace(m_mutedVideoOffscreenDurationVisibilityObserver);
|
| }
|
|
|
| } // namespace blink
|
|
|