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

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

Issue 1329853004: Include viewport visibility checks for autoplay experiment. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@autoplay_step1
Patch Set: rebased. 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
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/html/AutoplayExperimentConfig.h" 8 #include "core/html/AutoplayExperimentConfig.h"
9 #include "core/page/Page.h" 9 #include "core/page/Page.h"
10 #include "platform/Timer.h" 10 #include "platform/Timer.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 public: 72 public:
73 AutoplayExperimentHelper(HTMLMediaElement&); 73 AutoplayExperimentHelper(HTMLMediaElement&);
74 ~AutoplayExperimentHelper(); 74 ~AutoplayExperimentHelper();
75 75
76 void becameReadyToPlay(); 76 void becameReadyToPlay();
77 void playMethodCalled(); 77 void playMethodCalled();
78 void pauseMethodCalled(); 78 void pauseMethodCalled();
79 void mutedChanged(); 79 void mutedChanged();
80 void positionChanged(); 80 void positionChanged();
81 81
82 // For testing.
83 void triggerAutoplayViewportCheck();
84
82 private: 85 private:
86 // The location and size of our element, and the viewport. Also supports
87 // "not valid", in case some of the information isn't available.
philipj_slow 2015/09/21 15:02:05 I looks like PageVisibilityState is doesn't have a
liberato (no reviews please) 2015/09/23 06:14:57 i don't see a way to make it work automatically.
philipj_slow 2015/09/25 15:32:27 OK, looks like it was successfully removed.
88 class LocationState {
89 public:
90 LocationState() : m_valid(false) {}
91 LocationState(Element&);
92
93 bool valid() const { return m_valid; }
94 PageVisibilityState visibilityState() const { return m_visibilityState; }
95 const IntRect& element() const { return m_element; }
96 const IntRect& screen() const { return m_screen; }
97
98 bool operator==(const LocationState&) const;
99 bool operator!=(const LocationState&) const;
100
101 // Return true if and only if the player is visible.
philipj_slow 2015/09/21 15:02:05 s/player/element/ and maybe rename to isElementVis
liberato (no reviews please) 2015/09/23 06:14:57 Done.
102 bool isInViewport() const;
103
104 // Return true if and only if the element's page is visible.
105 bool isPageVisible() const;
106
107 private:
108 bool m_valid;
109 PageVisibilityState m_visibilityState;
110 IntRect m_element;
111 IntRect m_screen;
112 };
113
114 // Register to receive position updates, if we haven't already. If we
115 // have, then this does nothing.
116 void registerForPositionUpdatesIfNeeded();
117
118 // Un-register for position updates, if we are currently registered.
119 void unregisterForPositionUpdatesIfNeeded();
120
83 // Return true if any only if this player meets (most) of the eligibility 121 // Return true if any only if this player meets (most) of the eligibility
philipj_slow 2015/09/25 15:32:27 Another "player" here if you want to fix it.
84 // requirements for the experiment to override the need for a user 122 // requirements for the experiment to override the need for a user
85 // gesture. This includes everything except the visibility test. 123 // gesture. This includes everything except the visibility test.
86 bool isEligible() const; 124 bool isEligible() const;
87 125
126 // Return false if and only if the element described by LocationState is
127 // not visible, and we care that it must be visible.
philipj_slow 2015/09/21 15:02:05 It's pretty hard to tell from this header when you
liberato (no reviews please) 2015/09/23 06:14:57 if yuo have LocationState, pass it in. if not, th
philipj_slow 2015/09/25 15:32:27 Acknowledged.
128 bool meetsVisibilityRequirements(const LocationState&) const;
129
130 // Return false if and only if the player is not visible, and we care
philipj_slow 2015/09/21 15:02:05 s/player/element/?
liberato (no reviews please) 2015/09/23 06:14:57 Done.
131 // that it must be visible.
132 bool meetsVisibilityRequirements() const;
133
88 // Set the muted flag on the media if we're in an experiment mode that 134 // Set the muted flag on the media if we're in an experiment mode that
89 // requires it, else do nothing. 135 // requires it, else do nothing.
90 void muteIfNeeded(); 136 void muteIfNeeded();
91 137
92 // Maybe override the requirement for a user gesture, and start playing 138 // Maybe override the requirement for a user gesture, and start playing
93 // autoplay media. Returns true if only if it starts playback. 139 // autoplay media. Returns true if only if it starts playback.
94 bool maybeStartPlaying(); 140 bool maybeStartPlaying();
95 141
96 // Configure internal state to record that the autoplay experiment is 142 // Configure internal state to record that the autoplay experiment is
97 // going to start playback. This doesn't actually start playback, since 143 // going to start playback. This doesn't actually start playback, since
98 // there are several different cases. 144 // there are several different cases.
99 void prepareToPlay(AutoplayMetrics); 145 void prepareToPlay(AutoplayMetrics);
100 146
147 // Process a timer for checking visibility.
148 void viewportTimerFired(Timer<AutoplayExperimentHelper>*);
149
101 // Return our media element's document. 150 // Return our media element's document.
102 Document& document() const; 151 Document& document() const;
103 152
104 inline bool enabled(AutoplayExperimentConfig::Mode mode) const 153 inline bool enabled(AutoplayExperimentConfig::Mode mode) const
105 { 154 {
106 return ((int)m_mode) & ((int)mode); 155 return ((int)m_mode) & ((int)mode);
107 } 156 }
108 157
109 private: 158 private:
110 HTMLMediaElement& m_element; 159 HTMLMediaElement& m_element;
111 160
112 AutoplayExperimentConfig::Mode m_mode; 161 AutoplayExperimentConfig::Mode m_mode;
113 162
114 // Autoplay experiment state. 163 // Autoplay experiment state.
115 // True if we've received a play() without a pause(). 164 // True if we've received a play() without a pause().
116 bool m_playPending : 1; 165 bool m_playPending : 1;
117 166
167 // Are we registered with the view for position updates?
168 bool m_registeredWithView : 1;
169
170 // According to our last position update, are we in the viewport?
171 bool m_wasInViewport : 1;
172
173 // According to our last position update, where was our element?
174 LocationState m_lastLocation;
175
176 // When was m_lastLocation set?
177 double m_lastLocationUpdateTime;
178
179 Timer<AutoplayExperimentHelper> m_viewportTimer;
180
118 friend class Internals; 181 friend class Internals;
119 }; 182 };
120 183
121 } // namespace blink 184 } // namespace blink
122 185
123 #endif // AutoplayExperimentHelper_h 186 #endif // AutoplayExperimentHelper_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698