Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLMediaElement.cpp

Issue 2044373002: [Media, Autoplay] Add UMA to record autoplay source (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed Mounir's comments Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 case WebMediaPlayer::PreloadMetaData: 274 case WebMediaPlayer::PreloadMetaData:
275 return "metadata"; 275 return "metadata";
276 case WebMediaPlayer::PreloadAuto: 276 case WebMediaPlayer::PreloadAuto:
277 return "auto"; 277 return "auto";
278 } 278 }
279 279
280 NOTREACHED(); 280 NOTREACHED();
281 return String(); 281 return String();
282 } 282 }
283 283
284 // These values are used for histograms. Do not reorder.
285 enum AutoplaySource {
286 // Autoplay comes from HTMLMediaElement `autoplay` attribute.
287 AutoplaySourceAttribute = 0,
288 // Autoplay comes from `play()` method.
289 AutoplaySourceMethod = 1,
290 // This enum value must be last.
291 NumberOfAutoplaySources = 2,
292 };
293
284 } // anonymous namespace 294 } // anonymous namespace
285 295
286 class HTMLMediaElement::AutoplayHelperClientImpl : 296 class HTMLMediaElement::AutoplayHelperClientImpl :
287 public AutoplayExperimentHelper::Client { 297 public AutoplayExperimentHelper::Client {
288 298
289 public: 299 public:
290 static AutoplayHelperClientImpl* create(HTMLMediaElement* element) 300 static AutoplayHelperClientImpl* create(HTMLMediaElement* element)
291 { 301 {
292 return new AutoplayHelperClientImpl(element); 302 return new AutoplayHelperClientImpl(element);
293 } 303 }
(...skipping 1317 matching lines...) Expand 10 before | Expand all | Expand 10 after
1611 1621
1612 if (m_readyState == HAVE_ENOUGH_DATA && oldState < HAVE_ENOUGH_DATA && track sAreReady) { 1622 if (m_readyState == HAVE_ENOUGH_DATA && oldState < HAVE_ENOUGH_DATA && track sAreReady) {
1613 if (oldState <= HAVE_CURRENT_DATA) { 1623 if (oldState <= HAVE_CURRENT_DATA) {
1614 scheduleEvent(EventTypeNames::canplay); 1624 scheduleEvent(EventTypeNames::canplay);
1615 if (isPotentiallyPlaying) 1625 if (isPotentiallyPlaying)
1616 scheduleNotifyPlaying(); 1626 scheduleNotifyPlaying();
1617 } 1627 }
1618 1628
1619 // Check for autoplay, and record metrics about it if needed. 1629 // Check for autoplay, and record metrics about it if needed.
1620 if (shouldAutoplay(RecordMetricsBehavior::DoRecord)) { 1630 if (shouldAutoplay(RecordMetricsBehavior::DoRecord)) {
1631 recordAutoplaySourceMetric(AutoplaySourceAttribute);
1621 // If the autoplay experiment says that it's okay to play now, 1632 // If the autoplay experiment says that it's okay to play now,
1622 // then don't require a user gesture. 1633 // then don't require a user gesture.
1623 m_autoplayHelper->becameReadyToPlay(); 1634 m_autoplayHelper->becameReadyToPlay();
1624 1635
1625 if (!isGestureNeededForPlayback()) { 1636 if (!isGestureNeededForPlayback()) {
1626 m_paused = false; 1637 m_paused = false;
1627 invalidateCachedTime(); 1638 invalidateCachedTime();
1628 scheduleEvent(EventTypeNames::play); 1639 scheduleEvent(EventTypeNames::play);
1629 scheduleNotifyPlaying(); 1640 scheduleNotifyPlaying();
1630 m_autoplaying = false; 1641 m_autoplaying = false;
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
2044 return promise; 2055 return promise;
2045 } 2056 }
2046 2057
2047 Nullable<ExceptionCode> HTMLMediaElement::play() 2058 Nullable<ExceptionCode> HTMLMediaElement::play()
2048 { 2059 {
2049 DVLOG(MEDIA_LOG_LEVEL) << "play(" << (void*)this << ")"; 2060 DVLOG(MEDIA_LOG_LEVEL) << "play(" << (void*)this << ")";
2050 2061
2051 m_autoplayHelper->playMethodCalled(); 2062 m_autoplayHelper->playMethodCalled();
2052 2063
2053 if (!UserGestureIndicator::processingUserGesture()) { 2064 if (!UserGestureIndicator::processingUserGesture()) {
2065 recordAutoplaySourceMetric(AutoplaySourceMethod);
2054 if (isGestureNeededForPlayback()) { 2066 if (isGestureNeededForPlayback()) {
2055 // If playback is deferred, then don't start playback but don't 2067 // If playback is deferred, then don't start playback but don't
2056 // fail yet either. 2068 // fail yet either.
2057 if (m_autoplayHelper->isPlaybackDeferred()) 2069 if (m_autoplayHelper->isPlaybackDeferred())
2058 return nullptr; 2070 return nullptr;
2059 2071
2060 // If we're already playing, then this play would do nothing anyway. 2072 // If we're already playing, then this play would do nothing anyway.
2061 // Call playInternal to handle scheduling the promise resolution. 2073 // Call playInternal to handle scheduling the promise resolution.
2062 if (!m_paused) { 2074 if (!m_paused) {
2063 playInternal(); 2075 playInternal();
(...skipping 1700 matching lines...) Expand 10 before | Expand all | Expand 10 after
3764 { 3776 {
3765 if (isHTMLVideoElement()) { 3777 if (isHTMLVideoElement()) {
3766 DEFINE_STATIC_LOCAL(EnumerationHistogram, histogram, ("Media.Controls.Sh ow.Video", MediaControlsShowMax)); 3778 DEFINE_STATIC_LOCAL(EnumerationHistogram, histogram, ("Media.Controls.Sh ow.Video", MediaControlsShowMax));
3767 return histogram; 3779 return histogram;
3768 } 3780 }
3769 3781
3770 DEFINE_STATIC_LOCAL(EnumerationHistogram, histogram, ("Media.Controls.Show.A udio", MediaControlsShowMax)); 3782 DEFINE_STATIC_LOCAL(EnumerationHistogram, histogram, ("Media.Controls.Show.A udio", MediaControlsShowMax));
3771 return histogram; 3783 return histogram;
3772 } 3784 }
3773 3785
3786 void HTMLMediaElement::recordAutoplaySourceMetric(int source)
3787 {
3788 DEFINE_STATIC_LOCAL(EnumerationHistogram, videoHistogram, ("Media.Video.Auto play", NumberOfAutoplaySources));
3789 DEFINE_STATIC_LOCAL(EnumerationHistogram, mutedVideoHistogram, ("Media.Video .Autoplay.Muted", NumberOfAutoplaySources));
3790 DEFINE_STATIC_LOCAL(EnumerationHistogram, audioHistogram, ("Media.Audio.Auto play", NumberOfAutoplaySources));
3791
3792 if (isHTMLVideoElement()) {
3793 videoHistogram.count(source);
3794 if (muted())
3795 mutedVideoHistogram.count(source);
3796 } else {
3797 audioHistogram.count(source);
3798 }
3799 }
3800
3774 void HTMLMediaElement::clearWeakMembers(Visitor* visitor) 3801 void HTMLMediaElement::clearWeakMembers(Visitor* visitor)
3775 { 3802 {
3776 if (!ThreadHeap::isHeapObjectAlive(m_audioSourceNode)) { 3803 if (!ThreadHeap::isHeapObjectAlive(m_audioSourceNode)) {
3777 getAudioSourceProvider().setClient(nullptr); 3804 getAudioSourceProvider().setClient(nullptr);
3778 m_audioSourceNode = nullptr; 3805 m_audioSourceNode = nullptr;
3779 } 3806 }
3780 } 3807 }
3781 3808
3782 void HTMLMediaElement::AudioSourceProviderImpl::wrap(WebAudioSourceProvider* pro vider) 3809 void HTMLMediaElement::AudioSourceProviderImpl::wrap(WebAudioSourceProvider* pro vider)
3783 { 3810 {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
3881 3908
3882 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect() co nst 3909 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect() co nst
3883 { 3910 {
3884 IntRect result; 3911 IntRect result;
3885 if (LayoutObject* object = m_element->layoutObject()) 3912 if (LayoutObject* object = m_element->layoutObject())
3886 result = object->absoluteBoundingBoxRect(); 3913 result = object->absoluteBoundingBoxRect();
3887 return result; 3914 return result;
3888 } 3915 }
3889 3916
3890 } // namespace blink 3917 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLMediaElement.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698