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

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

Issue 1470153004: Autoplay experiment metric fixes and additions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added histograms.xml . 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 #include "config.h" 5 #include "config.h"
6 #include "core/html/AutoplayExperimentHelper.h" 6 #include "core/html/AutoplayExperimentHelper.h"
7 7
8 #include "core/dom/Document.h" 8 #include "core/dom/Document.h"
9 #include "core/frame/FrameView.h" 9 #include "core/frame/FrameView.h"
10 #include "core/frame/Settings.h" 10 #include "core/frame/Settings.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 AutoplayExperimentHelper::~AutoplayExperimentHelper() 47 AutoplayExperimentHelper::~AutoplayExperimentHelper()
48 { 48 {
49 unregisterForPositionUpdatesIfNeeded(); 49 unregisterForPositionUpdatesIfNeeded();
50 } 50 }
51 51
52 void AutoplayExperimentHelper::becameReadyToPlay() 52 void AutoplayExperimentHelper::becameReadyToPlay()
53 { 53 {
54 // Assuming that we're eligible to override the user gesture requirement, 54 // Assuming that we're eligible to override the user gesture requirement,
55 // either play if we meet the visibility checks, or install a listener 55 // either play if we meet the visibility checks, or install a listener
56 // to wait for them to pass. 56 // to wait for them to pass. We do not actually start playback; our
57 // caller must do that.
57 if (isEligible()) { 58 if (isEligible()) {
58 if (meetsVisibilityRequirements()) 59 if (meetsVisibilityRequirements())
59 prepareToPlay(GesturelessPlaybackStartedByAutoplayFlagImmediately); 60 prepareToAutoplay(GesturelessPlaybackStartedByAutoplayFlagImmediatel y);
60 else 61 else
61 registerForPositionUpdatesIfNeeded(); 62 registerForPositionUpdatesIfNeeded();
62 } 63 }
63 } 64 }
64 65
65 void AutoplayExperimentHelper::playMethodCalled() 66 void AutoplayExperimentHelper::playMethodCalled()
66 { 67 {
67 // Set the pending state, even if the play isn't going to be pending. 68 // Set the pending state, even if the play isn't going to be pending.
68 // Eligibility can change if, for example, the mute status changes. 69 // Eligibility can change if, for example, the mute status changes.
69 // Having this set is okay. 70 // Having this set is okay.
70 m_playPending = true; 71 m_playPending = true;
71 72
72 if (!UserGestureIndicator::processingUserGesture()) { 73 if (!UserGestureIndicator::processingUserGesture()) {
73 74
74 if (isEligible()) { 75 if (isEligible()) {
75 // Remember that userGestureRequiredForPlay is required for 76 // Remember that userGestureRequiredForPlay is required for
76 // us to be eligible for the experiment. 77 // us to be eligible for the experiment.
77 // If we are able to override the gesture requirement now, then 78 // If we are able to override the gesture requirement now, then
78 // do so. Otherwise, install an event listener if we need one. 79 // do so. Otherwise, install an event listener if we need one.
79 if (meetsVisibilityRequirements()) { 80 if (meetsVisibilityRequirements()) {
80 // Override the gesture and play. 81 // Override the gesture and play.
81 prepareToPlay(GesturelessPlaybackStartedByPlayMethodImmediately) ; 82 prepareToAutoplay(GesturelessPlaybackStartedByPlayMethodImmediat ely);
82 } else { 83 } else {
83 // Wait for viewport visibility. 84 // Wait for viewport visibility.
84 registerForPositionUpdatesIfNeeded(); 85 registerForPositionUpdatesIfNeeded();
85 } 86 }
86 } 87 }
87 88
88 } else if (element().isUserGestureRequiredForPlay()) { 89 } else if (element().isUserGestureRequiredForPlay()) {
89 unregisterForPositionUpdatesIfNeeded(); 90 unregisterForPositionUpdatesIfNeeded();
90 } 91 }
91 } 92 }
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 } 249 }
249 250
250 bool AutoplayExperimentHelper::maybeStartPlaying() 251 bool AutoplayExperimentHelper::maybeStartPlaying()
251 { 252 {
252 // See if we're allowed to autoplay now. 253 // See if we're allowed to autoplay now.
253 if (!isEligible() || !meetsVisibilityRequirements()) { 254 if (!isEligible() || !meetsVisibilityRequirements()) {
254 return false; 255 return false;
255 } 256 }
256 257
257 // Start playing! 258 // Start playing!
258 prepareToPlay(element().shouldAutoplay() 259 prepareToAutoplay(element().shouldAutoplay()
259 ? GesturelessPlaybackStartedByAutoplayFlagAfterScroll 260 ? GesturelessPlaybackStartedByAutoplayFlagAfterScroll
260 : GesturelessPlaybackStartedByPlayMethodAfterScroll); 261 : GesturelessPlaybackStartedByPlayMethodAfterScroll);
262
263 // Record that this played without a user gesture.
264 element().autoplayMediaEncountered();
265
261 element().playInternal(); 266 element().playInternal();
262 267
263 return true; 268 return true;
264 } 269 }
265 270
266 bool AutoplayExperimentHelper::isEligible() const 271 bool AutoplayExperimentHelper::isEligible() const
267 { 272 {
268 if (m_mode == Mode::ExperimentOff) 273 if (m_mode == Mode::ExperimentOff)
269 return false; 274 return false;
270 275
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 { 311 {
307 if (enabled(PlayMuted)) { 312 if (enabled(PlayMuted)) {
308 ASSERT(!isEligible()); 313 ASSERT(!isEligible());
309 // If we are actually changing the muted state, then this will call 314 // If we are actually changing the muted state, then this will call
310 // mutedChanged(). If isEligible(), then mutedChanged() will try 315 // mutedChanged(). If isEligible(), then mutedChanged() will try
311 // to start playback, which we should not do here. 316 // to start playback, which we should not do here.
312 element().setMuted(true); 317 element().setMuted(true);
313 } 318 }
314 } 319 }
315 320
316 void AutoplayExperimentHelper::prepareToPlay(AutoplayMetrics metric) 321 void AutoplayExperimentHelper::prepareToAutoplay(AutoplayMetrics metric)
317 { 322 {
323 // Record why we're allowing autoplay.
318 element().recordAutoplayMetric(metric); 324 element().recordAutoplayMetric(metric);
319 325
320 // This also causes !isEligible, so that we don't allow autoplay more than 326 // This also causes !isEligible, so that we don't allow autoplay more than
321 // once. Be sure to do this before muteIfNeeded(). 327 // once. Be sure to do this before muteIfNeeded().
322 element().removeUserGestureRequirement(); 328 element().removeUserGestureRequirement();
323 329
330 // Don't bother to call autoplayMediaEncountered, since whoever initiates
331 // playback has do it anyway, in case we don't allow autoplay.
332
324 unregisterForPositionUpdatesIfNeeded(); 333 unregisterForPositionUpdatesIfNeeded();
325 muteIfNeeded(); 334 muteIfNeeded();
326 335
327 // Record that this autoplayed without a user gesture. This is normally
328 // set when we discover an autoplay attribute, but we include all cases
329 // where playback started without a user gesture, e.g., play().
330 element().setInitialPlayWithoutUserGestures(true);
331
332 // Do not actually start playback here. 336 // Do not actually start playback here.
333 } 337 }
334 338
335 Document& AutoplayExperimentHelper::document() const 339 Document& AutoplayExperimentHelper::document() const
336 { 340 {
337 return element().document(); 341 return element().document();
338 } 342 }
339 343
340 HTMLMediaElement& AutoplayExperimentHelper::element() const 344 HTMLMediaElement& AutoplayExperimentHelper::element() const
341 { 345 {
(...skipping 16 matching lines...) Expand all
358 value |= IfMuted; 362 value |= IfMuted;
359 if (mode.contains("-ifmobile")) 363 if (mode.contains("-ifmobile"))
360 value |= IfMobile; 364 value |= IfMobile;
361 if (mode.contains("-playmuted")) 365 if (mode.contains("-playmuted"))
362 value |= PlayMuted; 366 value |= PlayMuted;
363 367
364 return value; 368 return value;
365 } 369 }
366 370
367 } 371 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698