Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / html / AutoplayExperimentHelper.h
blobc9d015f062bce1126923f2ec3613ad7067c92219
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.
5 #ifndef AutoplayExperimentHelper_h
6 #define AutoplayExperimentHelper_h
8 #include "core/html/AutoplayExperimentConfig.h"
9 #include "core/page/Page.h"
10 #include "platform/Timer.h"
11 #include "platform/geometry/IntRect.h"
13 namespace blink {
14 class Document;
15 class HTMLMediaElement;
16 class EventListener;
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,
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).
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,
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,
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,
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,
57 // play() failed to play due to gesture requirement.
58 PlayMethodFailed = 10,
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,
67 // This enum value must be last.
68 NumberOfAutoplayMetrics,
71 class AutoplayExperimentHelper {
72 public:
73 AutoplayExperimentHelper(HTMLMediaElement&);
74 ~AutoplayExperimentHelper();
76 void becameReadyToPlay();
77 void playMethodCalled();
78 void pauseMethodCalled();
79 void mutedChanged();
80 void positionChanged();
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;
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();
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();
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);
101 // Return our media element's document.
102 Document& document() const;
104 inline bool enabled(AutoplayExperimentConfig::Mode mode) const
106 return ((int)m_mode) & ((int)mode);
109 private:
110 HTMLMediaElement& m_element;
112 AutoplayExperimentConfig::Mode m_mode;
114 // Autoplay experiment state.
115 // True if we've received a play() without a pause().
116 bool m_playPending : 1;
118 friend class Internals;
121 } // namespace blink
123 #endif // AutoplayExperimentHelper_h