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

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

Issue 1179223002: Implement autoplay gesture override experiment. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: fixed !autoplaying behavior + test. Created 5 years, 3 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef AutoplayExperimentHelper_h
6 #define AutoplayExperimentHelper_h
7
8 #include "core/html/AutoplayExperimentConfig.h"
9 #include "core/page/Page.h"
10 #include "platform/Timer.h"
11 #include "platform/geometry/IntRect.h"
12
13 namespace blink {
14 class Document;
15 class HTMLMediaElement;
16 class EventListener;
17
18 // These values are used for a histogram. Do not reorder.
19 enum AutoplayMetrics {
20 // Media element with autoplay seen.
21 AutoplayMediaFound = 0,
22 // Autoplay enabled and user stopped media play at any point.
23 AutoplayPaused = 1,
24 // Autoplay enabled but user bailed out on media play early.
25 AutoplayBailout = 2,
26 // Autoplay disabled but user manually started media.
27 AutoplayManualStart = 3,
28 // Autoplay was (re)enabled through a user-gesture triggered load()
29 AutoplayEnabledThroughLoad = 4,
30 // Autoplay disabled by sandbox flags.
31 AutoplayDisabledBySandbox = 5,
32
33 // These metrics indicate "no gesture detected, but the gesture
34 // requirement was overridden by experiment". They do not include cases
35 // where no user gesture is required (!m_userGestureRequiredForPlay).
36
37 // User gesture requirement was bypassed, and playback started, during
38 // initial load via the autoplay flag. If playback was deferred due to
39 // visibility requirements, then this does not apply.
40 GesturelessPlaybackStartedByAutoplayFlagImmediately = 6,
41
42 // User gesture requirement was bypassed, and playback started, when
43 // the play() method was called. If playback is deferred due to
44 // visibility requirements, then this does not apply.
45 GesturelessPlaybackStartedByPlayMethodImmediately = 7,
46
47 // User gesture requirement was bypassed, and playback started, after
48 // an element with the autoplay flag moved into the viewport. Playback
49 // was deferred earlier due to visibility requirements.
50 GesturelessPlaybackStartedByAutoplayFlagAfterScroll = 8,
51
52 // User gesture requirement was bypassed, and playback started, after
53 // an element on which the play() method was called was moved into the
54 // viewport. Playback had been deferred due to visibility requirements.
55 GesturelessPlaybackStartedByPlayMethodAfterScroll = 9,
56
57 // play() failed to play due to gesture requirement.
58 PlayMethodFailed = 10,
59
60 // Some play, whether user initiated or not, started.
61 AnyPlaybackStarted = 11,
62 // Some play, whether user initiated or not, paused.
63 AnyPlaybackPaused = 12,
64 // Some playback, whether user initiated or not, bailed out early.
65 AnyPlaybackBailout = 13,
66
67 // This enum value must be last.
68 NumberOfAutoplayMetrics,
69 };
70
71 class AutoplayExperimentHelper {
72 public:
73 AutoplayExperimentHelper(HTMLMediaElement&);
74 ~AutoplayExperimentHelper();
75
76 void becameReadyToPlay();
77 void playMethodCalled();
78 void pauseMethodCalled();
79 void mutedChanged();
80 void positionChanged();
81
82 private:
83 // Return true if any only if this player meets (most) of the eligibility
84 // requirements for the experiment to override the need for a user
85 // gesture. This includes everything except the visibility test.
86 bool isEligible() const;
87
88 // Set the muted flag on the media if we're in an experiment mode that
89 // requires it, else do nothing.
90 void muteIfNeeded();
91
92 // Maybe override the requirement for a user gesture, and start playing
93 // autoplay media. Returns true if only if it starts playback.
94 bool maybeStartPlaying();
95
96 // Configure internal state to record that the autoplay experiment is
97 // going to start playback. This doesn't actually start playback, since
98 // there are several different cases.
99 void prepareToPlay(AutoplayMetrics);
100
101 // Return our media element's document.
102 Document& document() const;
103
104 inline bool enabled(AutoplayExperimentConfig::Mode mode) const
105 {
106 return ((int)m_mode) & ((int)mode);
107 }
108
109 private:
110 HTMLMediaElement& m_element;
111
112 AutoplayExperimentConfig::Mode m_mode;
113
114 // Autoplay experiment state.
115 // True if we've received a play() without a pause().
116 bool m_playPending : 1;
117
118 friend class Internals;
119 };
120
121 } // namespace blink
122
123 #endif // AutoplayExperimentHelper_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698