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 f3c4ad3860e506678b34be4e784a8ada27ae72ed..f154555feebe18689406d960c549c12c0362f5a0 100644 |
--- a/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp |
+++ b/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp |
@@ -347,6 +347,8 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document& docum |
, m_audioSourceNode(nullptr) |
#endif |
, m_autoplayHelper(*this) |
+ , m_anyUserGestureEncountered(false) |
+ , m_initialPlaybackRecorded(false) |
{ |
#if ENABLE(OILPAN) |
ThreadState::current()->registerPreFinalizer(this); |
@@ -360,6 +362,7 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document& docum |
setHasCustomStyleCallbacks(); |
addElementToDocumentMap(this, &document); |
+ recordAutoplayMetric(AnyMediaElement); |
philipj_slow
2015/11/25 14:03:42
It's likely that this and the AnyVideoElement will
liberato (no reviews please)
2015/11/25 18:58:54
very good point, thanks.
|
} |
HTMLMediaElement::~HTMLMediaElement() |
@@ -672,17 +675,20 @@ String HTMLMediaElement::canPlayType(const String& mimeType, const String& keySy |
void HTMLMediaElement::recordMetricsIfPausing() |
philipj_slow
2015/11/25 14:03:42
Maybe rename to recordMetricsBeforePause() if that
liberato (no reviews please)
2015/11/25 18:58:54
Done.
|
{ |
// If not playing, then nothing to record. |
- // TODO(liberato): test metrics. this was m_paused. |
if (m_paused) |
return; |
+ // Don't count seeking as a bailout. |
philipj_slow
2015/11/25 14:03:42
Why was this comment added? I see no changes relat
liberato (no reviews please)
2015/11/25 18:58:54
whoops, forgot to delete.
|
const bool bailout = isBailout(); |
+ const bool ended = endedPlayback(); |
philipj_slow
2015/11/25 14:03:42
Have you tested that this is always true when reco
liberato (no reviews please)
2015/11/25 18:58:54
it has worked in all of my tests.
however, i rath
|
// Record that play was paused. We don't care if it was autoplay, |
// play(), or the user manually started it. |
recordAutoplayMetric(AnyPlaybackPaused); |
if (bailout) |
recordAutoplayMetric(AnyPlaybackBailout); |
+ if (ended) |
+ recordAutoplayMetric(AnyPlaybackComplete); |
// If this was a gestureless play, then record that separately. |
// These cover attr and play() gestureless starts. |
@@ -693,6 +699,9 @@ void HTMLMediaElement::recordMetricsIfPausing() |
if (bailout) |
recordAutoplayMetric(AutoplayBailout); |
+ |
+ if (ended) |
+ recordAutoplayMetric(AutoplayComplete); |
} |
} |
@@ -701,8 +710,10 @@ void HTMLMediaElement::load() |
WTF_LOG(Media, "HTMLMediaElement::load(%p)", this); |
recordMetricsIfPausing(); |
+ bool gesture = UserGestureIndicator::processingUserGesture(); |
philipj_slow
2015/11/25 14:03:42
IIUC, this and a bunch of other changes are "will
liberato (no reviews please)
2015/11/25 18:58:54
i had done exactly that, but didn't like it. i'll
|
+ m_anyUserGestureEncountered |= gesture; |
- if (UserGestureIndicator::processingUserGesture() && m_userGestureRequiredForPlay) { |
+ if (gesture && m_userGestureRequiredForPlay) { |
recordAutoplayMetric(AutoplayEnabledThroughLoad); |
m_userGestureRequiredForPlay = false; |
// While usergesture-initiated load()s technically count as autoplayed, |
@@ -1533,29 +1544,40 @@ void HTMLMediaElement::setReadyState(ReadyState state) |
bool isPotentiallyPlaying = potentiallyPlaying(); |
if (m_readyState == HAVE_FUTURE_DATA && oldState <= HAVE_CURRENT_DATA && tracksAreReady) { |
scheduleEvent(EventTypeNames::canplay); |
- if (isPotentiallyPlaying) |
+ if (isPotentiallyPlaying) { |
scheduleEvent(EventTypeNames::playing); |
+ recordAutoplayMetric(AnyPlaybackStarted); |
philipj_slow
2015/11/25 14:03:41
Rather than measuring the playing event, can you p
liberato (no reviews please)
2015/11/25 18:58:54
Done.
|
+ } |
shouldUpdateDisplayState = true; |
} |
if (m_readyState == HAVE_ENOUGH_DATA && oldState < HAVE_ENOUGH_DATA && tracksAreReady) { |
if (oldState <= HAVE_CURRENT_DATA) { |
scheduleEvent(EventTypeNames::canplay); |
- if (isPotentiallyPlaying) |
+ if (isPotentiallyPlaying) { |
scheduleEvent(EventTypeNames::playing); |
+ recordAutoplayMetric(AnyPlaybackStarted); |
+ } |
} |
// Check for autoplay, and record metrics about it if needed. |
- if (shouldAutoplay(RecordMetricsBehavior::DoRecord)) { |
+ if (shouldAutoplay(RecordMetricsBehavior::RecordOnSandboxFailure)) { |
// If the autoplay experiment says that it's okay to play now, |
// then don't require a user gesture. |
m_autoplayHelper.becameReadyToPlay(); |
+ // Record that autoplay media was encountered, but wait until |
philipj_slow
2015/11/25 14:03:41
I don't quite understand this comment. Is it expla
liberato (no reviews please)
2015/11/25 18:58:54
yes. i'll update the comment to make it clearer.
|
+ // after the autoplay experiment helper has had a chance to update |
+ // the user gesture requirement. This is because aME() tries to |
+ // guess whether the play will succeed based on that. |
+ autoplayMediaEncountered(); |
+ |
if (!m_userGestureRequiredForPlay) { |
m_paused = false; |
invalidateCachedTime(); |
scheduleEvent(EventTypeNames::play); |
scheduleEvent(EventTypeNames::playing); |
+ recordAutoplayMetric(AnyPlaybackStarted); |
} |
} |
@@ -1870,12 +1892,13 @@ bool HTMLMediaElement::autoplay() const |
bool HTMLMediaElement::shouldAutoplay(const RecordMetricsBehavior recordMetrics) |
{ |
if (m_autoplaying && m_paused && autoplay()) { |
- if (recordMetrics == RecordMetricsBehavior::DoRecord) |
- autoplayMediaEncountered(); |
- |
if (document().isSandboxed(SandboxAutomaticFeatures)) { |
- if (recordMetrics == RecordMetricsBehavior::DoRecord) |
+ if (recordMetrics == RecordMetricsBehavior::RecordOnSandboxFailure) { |
+ // We record autoplayMediaEncountered here because we know |
+ // that the autoplay attempt will fail. |
+ autoplayMediaEncountered(); |
recordAutoplayMetric(AutoplayDisabledBySandbox); |
+ } |
return false; |
} |
@@ -1952,7 +1975,10 @@ void HTMLMediaElement::play() |
m_autoplayHelper.playMethodCalled(); |
- if (!UserGestureIndicator::processingUserGesture()) { |
+ bool gesture = UserGestureIndicator::processingUserGesture(); |
+ m_anyUserGestureEncountered |= gesture; |
+ |
+ if (!gesture) { |
autoplayMediaEncountered(); |
if (m_userGestureRequiredForPlay) { |
@@ -1989,10 +2015,12 @@ void HTMLMediaElement::playInternal() |
invalidateCachedTime(); |
scheduleEvent(EventTypeNames::play); |
- if (m_readyState <= HAVE_CURRENT_DATA) |
+ if (m_readyState <= HAVE_CURRENT_DATA) { |
scheduleEvent(EventTypeNames::waiting); |
- else if (m_readyState >= HAVE_FUTURE_DATA) |
+ } else if (m_readyState >= HAVE_FUTURE_DATA) { |
scheduleEvent(EventTypeNames::playing); |
+ recordAutoplayMetric(AnyPlaybackStarted); |
philipj_slow
2015/11/25 14:03:42
Can you put this right after the webMediaPlayer()-
liberato (no reviews please)
2015/11/25 18:58:54
Done, and a third case as well.
|
+ } |
} |
m_autoplaying = false; |
@@ -2005,6 +2033,8 @@ void HTMLMediaElement::autoplayMediaEncountered() |
m_autoplayMediaCounted = true; |
recordAutoplayMetric(AutoplayMediaFound); |
+ // If no user gesture was required, then assume that playback will |
philipj_slow
2015/11/25 14:03:42
When you spell it out it's kind of weird. If you k
liberato (no reviews please)
2015/11/25 18:58:54
i'm not sure that it gets any better. wmp->play()
|
+ // actually start. |
if (!m_userGestureRequiredForPlay) |
m_initialPlayWithoutUserGesture = true; |
} |
@@ -2724,6 +2754,7 @@ void HTMLMediaElement::timeChanged() |
// forwards, and paused is false, |
if (!m_paused) { |
// changes paused to true and fires a simple event named pause at the media element. |
+ recordMetricsIfPausing(); |
m_paused = true; |
scheduleEvent(EventTypeNames::pause); |
} |
@@ -2732,7 +2763,6 @@ void HTMLMediaElement::timeChanged() |
m_sentEndEvent = true; |
scheduleEvent(EventTypeNames::ended); |
} |
- recordMetricsIfPausing(); |
} |
} else { |
m_sentEndEvent = false; |
@@ -2939,17 +2969,30 @@ void HTMLMediaElement::updatePlayState() |
webMediaPlayer()->setRate(playbackRate()); |
updateVolume(); |
webMediaPlayer()->play(); |
+ |
+ if (!m_initialPlaybackRecorded) { |
philipj_slow
2015/11/25 14:03:42
I believe this is also to "give us an idea about h
liberato (no reviews please)
2015/11/25 18:58:54
the load call is part of it.
another part of the
|
+ bool gesture = UserGestureIndicator::processingUserGesture(); |
+ recordAutoplayMetric(gesture |
+ ? InitialPlayDuringUserGesture |
+ : InitialPlayNotDuringUserGesture); |
+ |
+ m_anyUserGestureEncountered |= gesture; |
+ recordAutoplayMetric(m_anyUserGestureEncountered |
+ ? InitialPlayWithUserGesture |
+ : InitialPlayWithoutUserGesture); |
+ m_initialPlaybackRecorded = true; |
+ } |
} |
if (mediaControls()) |
mediaControls()->playbackStarted(); |
startPlaybackProgressTimer(); |
m_playing = true; |
- recordAutoplayMetric(AnyPlaybackStarted); |
} else { // Should not be playing right now |
if (isPlaying) |
webMediaPlayer()->pause(); |
+ |
refreshCachedTime(); |
m_playbackProgressTimer.stop(); |
@@ -3580,11 +3623,6 @@ void HTMLMediaElement::removeUserGestureRequirement() |
m_userGestureRequiredForPlay = false; |
} |
-void HTMLMediaElement::setInitialPlayWithoutUserGestures(bool value) |
-{ |
- m_initialPlayWithoutUserGesture = value; |
-} |
- |
void HTMLMediaElement::setNetworkState(NetworkState state) |
{ |
if (m_networkState != state) { |