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

Side by Side Diff: third_party/WebKit/Source/core/html/AutoplayExperimentHelper.h

Issue 1470153004: Autoplay experiment metric fixes and additions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cl feedback Created 5 years 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 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef AutoplayExperimentHelper_h 5 #ifndef AutoplayExperimentHelper_h
6 #define AutoplayExperimentHelper_h 6 #define AutoplayExperimentHelper_h
7 7
8 #include "core/page/Page.h" 8 #include "core/page/Page.h"
9 #include "platform/Timer.h" 9 #include "platform/Timer.h"
10 #include "platform/geometry/IntRect.h" 10 #include "platform/geometry/IntRect.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 55
56 // play() failed to play due to gesture requirement. 56 // play() failed to play due to gesture requirement.
57 PlayMethodFailed = 10, 57 PlayMethodFailed = 10,
58 58
59 // Some play, whether user initiated or not, started. 59 // Some play, whether user initiated or not, started.
60 AnyPlaybackStarted = 11, 60 AnyPlaybackStarted = 11,
61 // Some play, whether user initiated or not, paused. 61 // Some play, whether user initiated or not, paused.
62 AnyPlaybackPaused = 12, 62 AnyPlaybackPaused = 12,
63 // Some playback, whether user initiated or not, bailed out early. 63 // Some playback, whether user initiated or not, bailed out early.
64 AnyPlaybackBailout = 13, 64 AnyPlaybackBailout = 13,
65 // Some playback, whether user initiated or not, played to completion.
66 AnyPlaybackComplete = 14,
67
68 // Number of audio elements detected that reach the resource fetch algorithm .
69 AnyAudioElement = 15,
70 // Numer of video elements detected that reach the resource fetch algorithm.
71 AnyVideoElement = 16,
72
73 // User gesture was bypassed, and playback started, and media played to
74 // completion without a user-initiated pause.
75 AutoplayComplete = 17,
76
77 // Autoplay started after the gesture requirement was removed by a
78 // user gesture load().
79 GesturelessPlaybackEnabledByLoad = 18,
80
81 // Gestureless playback started after the gesture requirement was removed
82 // because src is media stream.
83 GesturelessPlaybackEnabledByStream = 19,
84
85 // Gestureless playback was started, but it is unknown why a user gesture
86 // was not required. This includes the case where none is ever required.
87 GesturelessPlaybackUnknownReason = 20,
88
89 // Gestureless playback was enabled by a user gesture play() call.
90 GesturelessPlaybackEnabledByPlayMethod = 21,
65 91
66 // This enum value must be last. 92 // This enum value must be last.
67 NumberOfAutoplayMetrics, 93 NumberOfAutoplayMetrics,
68 }; 94 };
69 95
70 class AutoplayExperimentHelper final { 96 class AutoplayExperimentHelper final {
71 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); 97 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
72 public: 98 public:
73 explicit AutoplayExperimentHelper(HTMLMediaElement&); 99 explicit AutoplayExperimentHelper(HTMLMediaElement&);
74 ~AutoplayExperimentHelper(); 100 ~AutoplayExperimentHelper();
75 101
76 void becameReadyToPlay(); 102 void becameReadyToPlay();
77 void playMethodCalled(); 103 void playMethodCalled();
78 void pauseMethodCalled(); 104 void pauseMethodCalled();
105 void loadMethodCalled();
79 void mutedChanged(); 106 void mutedChanged();
80 void positionChanged(const IntRect&); 107 void positionChanged(const IntRect&);
81 void updatePositionNotificationRegistration(); 108 void updatePositionNotificationRegistration();
109 void recordSandboxFailure();
110 void loadingStarted();
111 void playbackStarted();
112 void playbackEnded();
113 void initialPlayWithUserGesture();
114 void setGestureRemovalReason(AutoplayMetrics);
82 115
83 void triggerAutoplayViewportCheckForTesting(); 116 void triggerAutoplayViewportCheckForTesting();
84 117
85 enum Mode { 118 enum Mode {
86 // Do not enable the autoplay experiment. 119 // Do not enable the autoplay experiment.
87 ExperimentOff = 0, 120 ExperimentOff = 0,
88 // Enable gestureless autoplay for video elements. 121 // Enable gestureless autoplay for video elements.
89 ForVideo = 1 << 0, 122 ForVideo = 1 << 0,
90 // Enable gestureless autoplay for audio elements. 123 // Enable gestureless autoplay for audio elements.
91 ForAudio = 1 << 1, 124 ForAudio = 1 << 1,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 // requires it, else do nothing. 163 // requires it, else do nothing.
131 void muteIfNeeded(); 164 void muteIfNeeded();
132 165
133 // Maybe override the requirement for a user gesture, and start playing 166 // Maybe override the requirement for a user gesture, and start playing
134 // autoplay media. Returns true if only if it starts playback. 167 // autoplay media. Returns true if only if it starts playback.
135 bool maybeStartPlaying(); 168 bool maybeStartPlaying();
136 169
137 // Configure internal state to record that the autoplay experiment is 170 // Configure internal state to record that the autoplay experiment is
138 // going to start playback. This doesn't actually start playback, since 171 // going to start playback. This doesn't actually start playback, since
139 // there are several different cases. 172 // there are several different cases.
140 void prepareToPlay(AutoplayMetrics); 173 void prepareToAutoplay(AutoplayMetrics);
174
175 // Record that an attempt to play without a user gesture has happened.
176 // If there is not a user gesture requirement, then record why there
177 // is no such requirement, with the expectation that playback will start.
178 // This method takes no action after it is called once.
179 void autoplayMediaEncountered();
180
181 // If we are about to enter a paused state, call this to record
182 // autoplay metrics.
183 void recordMetricsBeforePause();
141 184
142 // Process a timer for checking visibility. 185 // Process a timer for checking visibility.
143 void viewportTimerFired(Timer<AutoplayExperimentHelper>*); 186 void viewportTimerFired(Timer<AutoplayExperimentHelper>*);
144 187
145 // Return our media element's document. 188 // Return our media element's document.
146 Document& document() const; 189 Document& document() const;
147 190
148 HTMLMediaElement& element() const; 191 HTMLMediaElement& element() const;
149 192
193 bool isUserGestureRequiredForPlay() const;
194
150 inline bool enabled(Mode mode) const 195 inline bool enabled(Mode mode) const
151 { 196 {
152 return ((int)m_mode) & ((int)mode); 197 return ((int)m_mode) & ((int)mode);
153 } 198 }
154 199
155 Mode fromString(const String& mode); 200 Mode fromString(const String& mode);
156 201
202 void recordAutoplayMetric(AutoplayMetrics);
203
204 // Could stopping at this point be considered a bailout of playback?
205 // (as in, "The user really didn't want to play this").
206 bool isBailout() const;
207
157 RawPtrWillBeMember<HTMLMediaElement> m_element; 208 RawPtrWillBeMember<HTMLMediaElement> m_element;
158 209
159 Mode m_mode; 210 Mode m_mode;
160 211
161 // Autoplay experiment state. 212 // Autoplay experiment state.
162 // True if we've received a play() without a pause(). 213 // True if we've received a play() without a pause().
163 bool m_playPending : 1; 214 bool m_playPending : 1;
164 215
165 // Are we registered with the view for position updates? 216 // Are we registered with the view for position updates?
166 bool m_registeredWithLayoutObject : 1; 217 bool m_registeredWithLayoutObject : 1;
167 218
168 // According to our last position update, are we in the viewport? 219 // According to our last position update, are we in the viewport?
169 bool m_wasInViewport : 1; 220 bool m_wasInViewport : 1;
170 221
222 // Have we counted this autoplay media in the metrics yet?
223 bool m_autoplayMediaCounted : 1;
224
225 // Did the first playback of the media occur without a user gesture?
226 bool m_initialPlayWithoutUserGesture : 1;
227
228 // Did we record that this media element exists in the metrics yet?
229 bool m_recordedElement : 1;
230
171 // According to our last position update, where was our element? 231 // According to our last position update, where was our element?
172 IntRect m_lastLocation; 232 IntRect m_lastLocation;
173 IntRect m_lastVisibleRect; 233 IntRect m_lastVisibleRect;
174 234
175 // When was m_lastLocation set? 235 // When was m_lastLocation set?
176 double m_lastLocationUpdateTime; 236 double m_lastLocationUpdateTime;
177 237
178 Timer<AutoplayExperimentHelper> m_viewportTimer; 238 Timer<AutoplayExperimentHelper> m_viewportTimer;
239
240 // Reason that autoplay would be allowed to proceed without a user gesture.
241 AutoplayMetrics m_autoplayDeferredMetric;
179 }; 242 };
180 243
181 inline AutoplayExperimentHelper::Mode& operator|=(AutoplayExperimentHelper::Mode & a, 244 inline AutoplayExperimentHelper::Mode& operator|=(AutoplayExperimentHelper::Mode & a,
182 const AutoplayExperimentHelper::Mode& b) 245 const AutoplayExperimentHelper::Mode& b)
183 { 246 {
184 a = static_cast<AutoplayExperimentHelper::Mode>(static_cast<int>(a) | static _cast<int>(b)); 247 a = static_cast<AutoplayExperimentHelper::Mode>(static_cast<int>(a) | static _cast<int>(b));
185 return a; 248 return a;
186 } 249 }
187 250
188 251
189 } // namespace blink 252 } // namespace blink
190 253
191 #endif // AutoplayExperimentHelper_h 254 #endif // AutoplayExperimentHelper_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698