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

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

Issue 1949633002: Don't remove the gesture requirement in the autoplay experiment. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed test expectations. Created 4 years, 7 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 // 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 101
102 public: 102 public:
103 // For easier testing, collect all the things we care about here. 103 // For easier testing, collect all the things we care about here.
104 class Client : public GarbageCollectedFinalized<Client> { 104 class Client : public GarbageCollectedFinalized<Client> {
105 public: 105 public:
106 virtual ~Client() {} 106 virtual ~Client() {}
107 107
108 // HTMLMediaElement 108 // HTMLMediaElement
109 virtual double currentTime() const = 0; 109 virtual double currentTime() const = 0;
110 virtual double duration() const = 0; 110 virtual double duration() const = 0;
111 virtual bool paused() const = 0;
111 virtual bool ended() const = 0; 112 virtual bool ended() const = 0;
112 virtual bool muted() const = 0; 113 virtual bool muted() const = 0;
113 virtual void setMuted(bool) = 0; 114 virtual void setMuted(bool) = 0;
114 virtual void playInternal() = 0; 115 virtual void playInternal() = 0;
115 virtual bool isUserGestureRequiredForPlay() const = 0; 116 virtual bool isLockedPendingUserGesture() const = 0;
116 virtual void removeUserGestureRequirement() = 0; 117 virtual void unlockUserGesture() = 0;
117 virtual void recordAutoplayMetric(AutoplayMetrics) = 0; 118 virtual void recordAutoplayMetric(AutoplayMetrics) = 0;
118 virtual bool shouldAutoplay() = 0; 119 virtual bool shouldAutoplay() = 0;
119 virtual bool isHTMLVideoElement() const = 0; 120 virtual bool isHTMLVideoElement() const = 0;
120 virtual bool isHTMLAudioElement() const = 0; 121 virtual bool isHTMLAudioElement() const = 0;
121 122
122 // Document 123 // Document
123 virtual bool isLegacyViewportType() = 0; 124 virtual bool isLegacyViewportType() = 0;
124 virtual PageVisibilityState pageVisibilityState() const = 0; 125 virtual PageVisibilityState pageVisibilityState() const = 0;
125 virtual String autoplayExperimentMode() const = 0; 126 virtual String autoplayExperimentMode() const = 0;
126 127
(...skipping 12 matching lines...) Expand all
139 { 140 {
140 return new AutoplayExperimentHelper(client); 141 return new AutoplayExperimentHelper(client);
141 } 142 }
142 143
143 ~AutoplayExperimentHelper(); 144 ~AutoplayExperimentHelper();
144 145
145 void becameReadyToPlay(); 146 void becameReadyToPlay();
146 void playMethodCalled(); 147 void playMethodCalled();
147 void pauseMethodCalled(); 148 void pauseMethodCalled();
148 void loadMethodCalled(); 149 void loadMethodCalled();
149 void mutedChanged();
150 void positionChanged(const IntRect&); 150 void positionChanged(const IntRect&);
151 void updatePositionNotificationRegistration(); 151 void updatePositionNotificationRegistration();
152 void recordSandboxFailure(); 152 void recordSandboxFailure();
153 void loadingStarted(); 153 void loadingStarted();
154 void playbackStarted(); 154 void playbackStarted();
155 void playbackStopped(); 155 void playbackStopped();
156 void initialPlayWithUserGesture(); 156 void initialPlayWithUserGesture();
157 157
158 // Returns true if and only if any experiment is enabled (i.e., |m_mode| 158 // Returns true if and only if any experiment is enabled (i.e., |m_mode|
159 // is not ExperimentOff). 159 // is not ExperimentOff).
160 bool isExperimentEnabled(); 160 bool isExperimentEnabled();
161 161
162 // Clean up. For Oilpan, this means "early in HTMLMediaElement's dispose". 162 // Clean up. For Oilpan, this means "early in HTMLMediaElement's dispose".
163 // For non-Oilpan, just delete the object. 163 // For non-Oilpan, just delete the object.
164 void dispose(); 164 void dispose();
165 165
166 // Remove the user gesture requirement, and record why. If there is no 166 // Remove the user gesture requirement, and record why. If there is no
167 // gesture requirement, then this does nothing. 167 // gesture requirement, then this does nothing.
168 void removeUserGestureRequirement(AutoplayMetrics); 168 void unlockUserGesture(AutoplayMetrics);
169
170 // Set the reason that we're overridding the user gesture. If there is no
171 // gesture requirement, then this does nothing.
172 void setDeferredOverrideReason(AutoplayMetrics);
173
174 // Return true if and only if the user gesture requirement is currently
175 // overridden by the experiment, permitting playback.
176 bool isGestureRequirementOverridden() const;
177
178 // Return true if and only if playback is queued but hasn't started yet,
179 // such as if the element doesn't meet visibility requirements.
180 bool isPlaybackDeferred() const;
169 181
170 // Set the position to the current view's position, and 182 // Set the position to the current view's position, and
171 void triggerAutoplayViewportCheckForTesting(); 183 void triggerAutoplayViewportCheckForTesting();
172 184
173 enum Mode { 185 enum Mode {
174 // Do not enable the autoplay experiment. 186 // Do not enable the autoplay experiment.
175 ExperimentOff = 0, 187 ExperimentOff = 0,
176 // Enable gestureless autoplay for video elements. 188 // Enable gestureless autoplay for video elements.
177 ForVideo = 1 << 0, 189 ForVideo = 1 << 0,
178 // Enable gestureless autoplay for audio elements. 190 // Enable gestureless autoplay for audio elements.
(...skipping 24 matching lines...) Expand all
203 private: 215 private:
204 explicit AutoplayExperimentHelper(Client*); 216 explicit AutoplayExperimentHelper(Client*);
205 217
206 // Register to receive position updates, if we haven't already. If we 218 // Register to receive position updates, if we haven't already. If we
207 // have, then this does nothing. 219 // have, then this does nothing.
208 void registerForPositionUpdatesIfNeeded(); 220 void registerForPositionUpdatesIfNeeded();
209 221
210 // Un-register for position updates, if we are currently registered. 222 // Un-register for position updates, if we are currently registered.
211 void unregisterForPositionUpdatesIfNeeded(); 223 void unregisterForPositionUpdatesIfNeeded();
212 224
225 // Modifiers for checking isEligible().
226 enum EligibilityMode {
227 // Perform all normal eligibility checks.
228 Normal = 0,
229
230 // Perform normal eligibility checks, but skip checking if autoplay has
231 // actually been requested. In other words, don't fail just becase
232 // nobody has called play() and/or set the autoplay attribute.
233 IgnorePendingPlayback = 1
234 };
235
213 // Return true if any only if this player meets (most) of the eligibility 236 // Return true if any only if this player meets (most) of the eligibility
214 // requirements for the experiment to override the need for a user 237 // requirements for the experiment to override the need for a user
215 // gesture. This includes everything except the visibility test. 238 // gesture. This includes everything except the visibility test.
216 bool isEligible() const; 239 // |mode| modifies the eligibility check, as described above.
240 bool isEligible(EligibilityMode = Normal) const;
217 241
218 // Return false if and only if m_element is not visible, and we care 242 // Return false if and only if m_element is not visible, and we care
219 // that it must be visible. 243 // that it must be visible.
220 bool meetsVisibilityRequirements() const; 244 bool meetsVisibilityRequirements() const;
221 245
222 // Set the muted flag on the media if we're in an experiment mode that 246 // Set the muted flag on the media if we're in an experiment mode that
223 // requires it, else do nothing. 247 // requires it, else do nothing.
224 void muteIfNeeded(); 248 void muteIfNeeded();
225 249
226 // Maybe override the requirement for a user gesture, and start playing 250 // Maybe override the requirement for a user gesture, and start playing
(...skipping 15 matching lines...) Expand all
242 void recordMetricsBeforePause(); 266 void recordMetricsBeforePause();
243 267
244 // Process a timer for checking visibility. 268 // Process a timer for checking visibility.
245 void viewportTimerFired(Timer<AutoplayExperimentHelper>*); 269 void viewportTimerFired(Timer<AutoplayExperimentHelper>*);
246 270
247 // Return our media element's document. 271 // Return our media element's document.
248 Document& document() const; 272 Document& document() const;
249 273
250 Client& client() const; 274 Client& client() const;
251 275
252 bool isUserGestureRequiredForPlay() const; 276 bool isLockedPendingUserGesture() const;
253 277
254 inline bool enabled(Mode mode) const 278 inline bool enabled(Mode mode) const
255 { 279 {
256 return ((int)m_mode) & ((int)mode); 280 return ((int)m_mode) & ((int)mode);
257 } 281 }
258 282
259 Mode fromString(const String& mode); 283 Mode fromString(const String& mode);
260 284
261 void recordAutoplayMetric(AutoplayMetrics); 285 void recordAutoplayMetric(AutoplayMetrics);
262 286
(...skipping 23 matching lines...) Expand all
286 // a media element tries to autoplay, and we record that via the 310 // a media element tries to autoplay, and we record that via the
287 // AutoplayMediaFound metric. 311 // AutoplayMediaFound metric.
288 bool m_autoplayMediaEncountered : 1; 312 bool m_autoplayMediaEncountered : 1;
289 313
290 // Have we recorded a metric about the cause of the initial playback of 314 // Have we recorded a metric about the cause of the initial playback of
291 // this media yet? 315 // this media yet?
292 bool m_playbackStartedMetricRecorded : 1; 316 bool m_playbackStartedMetricRecorded : 1;
293 317
294 // Is the current playback the result of autoplay? If so, then this flag 318 // Is the current playback the result of autoplay? If so, then this flag
295 // records that the pause / stop should be counted in the autoplay metrics. 319 // records that the pause / stop should be counted in the autoplay metrics.
296 bool m_waitingForAutoplayPlaybackEnd : 1; 320 bool m_waitingForAutoplayPlaybackStop : 1;
297 321
298 // Did we record that this media element exists in the metrics yet? This is 322 // Did we record that this media element exists in the metrics yet? This is
299 // independent of whether it autoplays; we just want to know how many 323 // independent of whether it autoplays; we just want to know how many
300 // elements exist for the Any{Audio|Video}Element metrics. 324 // elements exist for the Any{Audio|Video}Element metrics.
301 bool m_recordedElement : 1; 325 bool m_recordedElement : 1;
302 326
303 // According to our last position update, where was our element? 327 // According to our last position update, where was our element?
304 IntRect m_lastLocation; 328 IntRect m_lastLocation;
305 IntRect m_lastVisibleRect; 329 IntRect m_lastVisibleRect;
306 330
307 // When was m_lastLocation set? 331 // When was m_lastLocation set?
308 double m_lastLocationUpdateTime; 332 double m_lastLocationUpdateTime;
309 333
310 Timer<AutoplayExperimentHelper> m_viewportTimer; 334 Timer<AutoplayExperimentHelper> m_viewportTimer;
311 335
312 // Reason that autoplay would be allowed to proceed without a user gesture. 336 // Reason that autoplay would be allowed to proceed without a user gesture.
313 AutoplayMetrics m_autoplayDeferredMetric; 337 AutoplayMetrics m_autoplayDeferredMetric;
314 }; 338 };
315 339
316 inline AutoplayExperimentHelper::Mode& operator|=(AutoplayExperimentHelper::Mode & a, 340 inline AutoplayExperimentHelper::Mode& operator|=(AutoplayExperimentHelper::Mode & a,
317 const AutoplayExperimentHelper::Mode& b) 341 const AutoplayExperimentHelper::Mode& b)
318 { 342 {
319 a = static_cast<AutoplayExperimentHelper::Mode>(static_cast<int>(a) | static _cast<int>(b)); 343 a = static_cast<AutoplayExperimentHelper::Mode>(static_cast<int>(a) | static _cast<int>(b));
320 return a; 344 return a;
321 } 345 }
322 346
323 } // namespace blink 347 } // namespace blink
324 348
325 #endif // AutoplayExperimentHelper_h 349 #endif // AutoplayExperimentHelper_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698