| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/html/AutoplayUmaHelper.h" | 5 #include "core/html/AutoplayUmaHelper.h" |
| 6 | 6 |
| 7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
| 8 #include "core/dom/ElementVisibilityObserver.h" | 8 #include "core/dom/ElementVisibilityObserver.h" |
| 9 #include "core/events/Event.h" | 9 #include "core/events/Event.h" |
| 10 #include "core/frame/Settings.h" | 10 #include "core/frame/Settings.h" |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 | 203 |
| 204 void AutoplayUmaHelper::handlePlayingEvent() { | 204 void AutoplayUmaHelper::handlePlayingEvent() { |
| 205 maybeStartRecordingMutedVideoPlayMethodBecomeVisible(); | 205 maybeStartRecordingMutedVideoPlayMethodBecomeVisible(); |
| 206 maybeStartRecordingMutedVideoOffscreenDuration(); | 206 maybeStartRecordingMutedVideoOffscreenDuration(); |
| 207 | 207 |
| 208 m_element->removeEventListener(EventTypeNames::playing, this, false); | 208 m_element->removeEventListener(EventTypeNames::playing, this, false); |
| 209 } | 209 } |
| 210 | 210 |
| 211 void AutoplayUmaHelper::handlePauseEvent() { | 211 void AutoplayUmaHelper::handlePauseEvent() { |
| 212 maybeStopRecordingMutedVideoOffscreenDuration(); | 212 maybeStopRecordingMutedVideoOffscreenDuration(); |
| 213 maybeRecordUserPausedAutoplayingCrossOriginVideo(); |
| 213 } | 214 } |
| 214 | 215 |
| 215 void AutoplayUmaHelper::contextDestroyed() { | 216 void AutoplayUmaHelper::contextDestroyed() { |
| 216 handleContextDestroyed(); | 217 handleContextDestroyed(); |
| 217 } | 218 } |
| 218 | 219 |
| 219 void AutoplayUmaHelper::handleContextDestroyed() { | 220 void AutoplayUmaHelper::handleContextDestroyed() { |
| 220 maybeStopRecordingMutedVideoPlayMethodBecomeVisible(false); | 221 maybeStopRecordingMutedVideoPlayMethodBecomeVisible(false); |
| 221 maybeStopRecordingMutedVideoOffscreenDuration(); | 222 maybeStopRecordingMutedVideoOffscreenDuration(); |
| 222 } | 223 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 } else { | 293 } else { |
| 293 DEFINE_STATIC_LOCAL( | 294 DEFINE_STATIC_LOCAL( |
| 294 CustomCountHistogram, durationHistogram, | 295 CustomCountHistogram, durationHistogram, |
| 295 ("Media.Video.Autoplay.Muted.PlayMethod.OffscreenDuration", 1, | 296 ("Media.Video.Autoplay.Muted.PlayMethod.OffscreenDuration", 1, |
| 296 maxOffscreenDurationUmaMS, offscreenDurationUmaBucketCount)); | 297 maxOffscreenDurationUmaMS, offscreenDurationUmaBucketCount)); |
| 297 durationHistogram.count(boundedTime); | 298 durationHistogram.count(boundedTime); |
| 298 } | 299 } |
| 299 m_mutedVideoOffscreenDurationVisibilityObserver->stop(); | 300 m_mutedVideoOffscreenDurationVisibilityObserver->stop(); |
| 300 m_mutedVideoOffscreenDurationVisibilityObserver = nullptr; | 301 m_mutedVideoOffscreenDurationVisibilityObserver = nullptr; |
| 301 m_mutedVideoAutoplayOffscreenDurationMS = 0; | 302 m_mutedVideoAutoplayOffscreenDurationMS = 0; |
| 302 m_element->removeEventListener(EventTypeNames::pause, this, false); | 303 maybeUnregisterMediaElementPauseListener(); |
| 303 maybeUnregisterContextDestroyedObserver(); | 304 maybeUnregisterContextDestroyedObserver(); |
| 304 } | 305 } |
| 305 | 306 |
| 307 void AutoplayUmaHelper::maybeRecordUserPausedAutoplayingCrossOriginVideo() { |
| 308 if (!shouldRecordUserPausedAutoplayingCrossOriginVideo()) |
| 309 return; |
| 310 |
| 311 if (m_element->ended() || m_element->seeking()) |
| 312 return; |
| 313 |
| 314 Platform::current()->recordRapporURL( |
| 315 "Media.Autoplay.CrossOrigin.UserPausedAutoplayingVideo.ChildFrame", |
| 316 m_element->document().url()); |
| 317 Platform::current()->recordRapporURL( |
| 318 "Media.Autoplay.CrossOrigin.UserPausedAutoplayingVideo." |
| 319 "TopLevelFrame", |
| 320 m_element->document().topDocument().url()); |
| 321 |
| 322 m_hasRecordedUserPausedAutoplayingCrossOriginVideo = true; |
| 323 maybeUnregisterMediaElementPauseListener(); |
| 324 } |
| 325 |
| 306 void AutoplayUmaHelper::maybeUnregisterContextDestroyedObserver() { | 326 void AutoplayUmaHelper::maybeUnregisterContextDestroyedObserver() { |
| 307 if (!shouldListenToContextDestroyed()) { | 327 if (!shouldListenToContextDestroyed()) { |
| 308 setContext(nullptr); | 328 setContext(nullptr); |
| 309 } | 329 } |
| 310 } | 330 } |
| 311 | 331 |
| 332 void AutoplayUmaHelper::maybeUnregisterMediaElementPauseListener() { |
| 333 if (m_mutedVideoOffscreenDurationVisibilityObserver) |
| 334 return; |
| 335 if (shouldRecordUserPausedAutoplayingCrossOriginVideo()) |
| 336 return; |
| 337 m_element->removeEventListener(EventTypeNames::pause, this, false); |
| 338 } |
| 339 |
| 312 bool AutoplayUmaHelper::shouldListenToContextDestroyed() const { | 340 bool AutoplayUmaHelper::shouldListenToContextDestroyed() const { |
| 313 return m_mutedVideoPlayMethodVisibilityObserver || | 341 return m_mutedVideoPlayMethodVisibilityObserver || |
| 314 m_mutedVideoOffscreenDurationVisibilityObserver; | 342 m_mutedVideoOffscreenDurationVisibilityObserver; |
| 315 } | 343 } |
| 316 | 344 |
| 345 bool AutoplayUmaHelper::shouldRecordUserPausedAutoplayingCrossOriginVideo() |
| 346 const { |
| 347 return m_element->isInCrossOriginFrame() && m_element->isHTMLVideoElement() && |
| 348 m_source != AutoplaySource::NumberOfSources && |
| 349 !m_hasRecordedUserPausedAutoplayingCrossOriginVideo; |
| 350 } |
| 351 |
| 317 DEFINE_TRACE(AutoplayUmaHelper) { | 352 DEFINE_TRACE(AutoplayUmaHelper) { |
| 318 EventListener::trace(visitor); | 353 EventListener::trace(visitor); |
| 319 ContextLifecycleObserver::trace(visitor); | 354 ContextLifecycleObserver::trace(visitor); |
| 320 visitor->trace(m_element); | 355 visitor->trace(m_element); |
| 321 visitor->trace(m_mutedVideoPlayMethodVisibilityObserver); | 356 visitor->trace(m_mutedVideoPlayMethodVisibilityObserver); |
| 322 visitor->trace(m_mutedVideoOffscreenDurationVisibilityObserver); | 357 visitor->trace(m_mutedVideoOffscreenDurationVisibilityObserver); |
| 323 } | 358 } |
| 324 | 359 |
| 325 } // namespace blink | 360 } // namespace blink |
| OLD | NEW |