Chromium Code Reviews| 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 3983e1b82f1f7f8ba5754617a52b40633a1c087c..b9cd265bab6ddf6b7a4522b53dde5a244c7cbe5f 100644 |
| --- a/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp |
| +++ b/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp |
| @@ -44,6 +44,7 @@ |
| #include "core/frame/Settings.h" |
| #include "core/frame/UseCounter.h" |
| #include "core/frame/csp/ContentSecurityPolicy.h" |
| +#include "core/html/AutoplayUmaHelper.h" |
| #include "core/html/HTMLMediaSource.h" |
| #include "core/html/HTMLSourceElement.h" |
| #include "core/html/HTMLTrackElement.h" |
| @@ -280,16 +281,6 @@ String preloadTypeToString(WebMediaPlayer::Preload preloadType) |
| return String(); |
| } |
| -// These values are used for histograms. Do not reorder. |
| -enum AutoplaySource { |
| - // Autoplay comes from HTMLMediaElement `autoplay` attribute. |
| - AutoplaySourceAttribute = 0, |
| - // Autoplay comes from `play()` method. |
| - AutoplaySourceMethod = 1, |
| - // This enum value must be last. |
| - NumberOfAutoplaySources = 2, |
| -}; |
| - |
| } // anonymous namespace |
| class HTMLMediaElement::AutoplayHelperClientImpl : |
| @@ -447,6 +438,7 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document& docum |
| , m_audioSourceNode(nullptr) |
| , m_autoplayHelperClient(AutoplayHelperClientImpl::create(this)) |
| , m_autoplayHelper(AutoplayExperimentHelper::create(m_autoplayHelperClient.get())) |
| + , m_autoplayUmaHelper(AutoplayUmaHelper::create(this)) |
| , m_remotePlaybackClient(nullptr) |
| , m_autoplayVisibilityObserver(nullptr) |
| { |
| @@ -490,6 +482,8 @@ void HTMLMediaElement::dispose() |
| // See Document::isDelayingLoadEvent(). |
| // Also see http://crbug.com/275223 for more details. |
| clearMediaPlayerAndAudioSourceProviderClientWithoutLocking(); |
| + |
| + m_autoplayUmaHelper->onElementDestroyed(); |
| } |
| void HTMLMediaElement::didMoveToNewDocument(Document& oldDocument) |
| @@ -1626,7 +1620,7 @@ void HTMLMediaElement::setReadyState(ReadyState state) |
| // Check for autoplay, and record metrics about it if needed. |
| if (shouldAutoplay(RecordMetricsBehavior::DoRecord)) { |
| - recordAutoplaySourceMetric(AutoplaySourceAttribute); |
| + m_autoplayUmaHelper->onAutoplayInitiated(AutoplaySource::Attribute); |
|
mlamouri (slow - plz ping)
2016/07/04 15:18:19
I wonder if we shouldn't move this check to the pr
Zhiqiang Zhang (Slow)
2016/07/06 13:55:51
Acknowledged.
|
| // If the autoplay experiment says that it's okay to play now, |
| // then don't require a user gesture. |
| @@ -2076,7 +2070,7 @@ Nullable<ExceptionCode> HTMLMediaElement::play() |
| m_autoplayHelper->playMethodCalled(); |
| if (!UserGestureIndicator::processingUserGesture()) { |
| - recordAutoplaySourceMetric(AutoplaySourceMethod); |
| + m_autoplayUmaHelper->onAutoplayInitiated(AutoplaySource::Method); |
| if (isGestureNeededForPlayback()) { |
| // If playback is deferred, then don't start playback but don't |
| // fail yet either. |
| @@ -2132,6 +2126,7 @@ void HTMLMediaElement::playInternal() |
| seek(0); |
| if (m_paused) { |
| + m_autoplayUmaHelper->onAutoplayStarted(); |
|
mlamouri (slow - plz ping)
2016/07/04 15:18:19
Maybe this should be called onPlaybackStart{,ed,in
Zhiqiang Zhang (Slow)
2016/07/06 13:55:51
Using EventListener now :)
|
| m_paused = false; |
| invalidateCachedTime(); |
| scheduleEvent(EventTypeNames::play); |
| @@ -2301,9 +2296,9 @@ void HTMLMediaElement::setMuted(bool muted) |
| if (wasAutoplayingMuted) { |
| if (isGestureNeededForPlayback()) { |
| pause(); |
| - recordAutoplayUnmuteStatus(AutoplayUnmuteActionFailure); |
| + m_autoplayUmaHelper->recordAutoplayUnmuteStatus(AutoplayUnmuteActionStatus::Failure); |
| } else { |
| - recordAutoplayUnmuteStatus(AutoplayUnmuteActionSuccess); |
| + m_autoplayUmaHelper->recordAutoplayUnmuteStatus(AutoplayUnmuteActionStatus::Success); |
| } |
| } |
| } |
| @@ -3661,6 +3656,7 @@ DEFINE_TRACE(HTMLMediaElement) |
| visitor->trace(m_audioSourceProvider); |
| visitor->trace(m_autoplayHelperClient); |
| visitor->trace(m_autoplayHelper); |
| + visitor->trace(m_autoplayUmaHelper); |
| visitor->trace(m_srcObject); |
| visitor->trace(m_autoplayVisibilityObserver); |
| visitor->template registerWeakMembers<HTMLMediaElement, &HTMLMediaElement::clearWeakMembers>(this); |
| @@ -3881,28 +3877,6 @@ EnumerationHistogram& HTMLMediaElement::showControlsHistogram() const |
| return histogram; |
| } |
| -void HTMLMediaElement::recordAutoplaySourceMetric(int source) |
| -{ |
| - DEFINE_STATIC_LOCAL(EnumerationHistogram, videoHistogram, ("Media.Video.Autoplay", NumberOfAutoplaySources)); |
| - DEFINE_STATIC_LOCAL(EnumerationHistogram, mutedVideoHistogram, ("Media.Video.Autoplay.Muted", NumberOfAutoplaySources)); |
| - DEFINE_STATIC_LOCAL(EnumerationHistogram, audioHistogram, ("Media.Audio.Autoplay", NumberOfAutoplaySources)); |
| - |
| - if (isHTMLVideoElement()) { |
| - videoHistogram.count(source); |
| - if (muted()) |
| - mutedVideoHistogram.count(source); |
| - } else { |
| - audioHistogram.count(source); |
| - } |
| -} |
| - |
| -void HTMLMediaElement::recordAutoplayUnmuteStatus(AutoplayUnmuteActionStatus status) |
| -{ |
| - DEFINE_STATIC_LOCAL(EnumerationHistogram, autoplayUnmuteHistogram, ("Media.Video.Autoplay.Muted.UnmuteAction", AutoplayUnmuteActionMax)); |
| - |
| - autoplayUnmuteHistogram.count(status); |
| -} |
| - |
| void HTMLMediaElement::onVisibilityChangedForAutoplay(bool isVisible) |
| { |
| if (!isVisible) |
| @@ -3916,6 +3890,7 @@ void HTMLMediaElement::onVisibilityChangedForAutoplay(bool isVisible) |
| m_autoplaying = false; |
| updatePlayState(); |
| + m_autoplayUmaHelper->onAutoplayStarted(); |
| } |
|
mlamouri (slow - plz ping)
2016/07/04 15:18:19
If we are here, the source is unlikely play() so i
Zhiqiang Zhang (Slow)
2016/07/06 13:55:51
Since we are using EventListener, there's no probl
|
| m_autoplayVisibilityObserver->stop(); |