| 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/media/AutoplayUmaHelper.h" | 5 #include "core/html/media/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" |
| 11 #include "core/frame/UseCounter.h" |
| 11 #include "core/html/HTMLMediaElement.h" | 12 #include "core/html/HTMLMediaElement.h" |
| 13 #include "core/html/media/AutoplayPolicy.h" |
| 12 #include "platform/Histogram.h" | 14 #include "platform/Histogram.h" |
| 13 #include "platform/wtf/CurrentTime.h" | 15 #include "platform/wtf/CurrentTime.h" |
| 14 #include "public/platform/Platform.h" | 16 #include "public/platform/Platform.h" |
| 15 | 17 |
| 16 namespace blink { | 18 namespace blink { |
| 17 | 19 |
| 18 namespace { | 20 namespace { |
| 19 | 21 |
| 20 const int32_t kMaxOffscreenDurationUmaMS = 60 * 60 * 1000; | 22 const int32_t kMaxOffscreenDurationUmaMS = 60 * 60 * 1000; |
| 21 const int32_t kOffscreenDurationUmaBucketCount = 50; | 23 const int32_t kOffscreenDurationUmaBucketCount = 50; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 element_->GetDocument().Url()); | 105 element_->GetDocument().Url()); |
| 104 } | 106 } |
| 105 } | 107 } |
| 106 | 108 |
| 107 // Record if it will be blocked by Data Saver or Autoplay setting. | 109 // Record if it will be blocked by Data Saver or Autoplay setting. |
| 108 if (element_->IsHTMLVideoElement() && element_->muted() && | 110 if (element_->IsHTMLVideoElement() && element_->muted() && |
| 109 RuntimeEnabledFeatures::autoplayMutedVideosEnabled()) { | 111 RuntimeEnabledFeatures::autoplayMutedVideosEnabled()) { |
| 110 bool data_saver_enabled = | 112 bool data_saver_enabled = |
| 111 element_->GetDocument().GetSettings() && | 113 element_->GetDocument().GetSettings() && |
| 112 element_->GetDocument().GetSettings()->GetDataSaverEnabled(); | 114 element_->GetDocument().GetSettings()->GetDataSaverEnabled(); |
| 113 bool blocked_by_setting = !element_->IsAutoplayAllowedPerSettings(); | 115 bool blocked_by_setting = |
| 116 !element_->GetAutoplayPolicy().IsAutoplayAllowedPerSettings(); |
| 114 | 117 |
| 115 if (data_saver_enabled && blocked_by_setting) { | 118 if (data_saver_enabled && blocked_by_setting) { |
| 116 blocked_muted_video_histogram.Count( | 119 blocked_muted_video_histogram.Count( |
| 117 kAutoplayBlockedReasonDataSaverAndSetting); | 120 kAutoplayBlockedReasonDataSaverAndSetting); |
| 118 } else if (data_saver_enabled) { | 121 } else if (data_saver_enabled) { |
| 119 blocked_muted_video_histogram.Count(kAutoplayBlockedReasonDataSaver); | 122 blocked_muted_video_histogram.Count(kAutoplayBlockedReasonDataSaver); |
| 120 } else if (blocked_by_setting) { | 123 } else if (blocked_by_setting) { |
| 121 blocked_muted_video_histogram.Count(kAutoplayBlockedReasonSetting); | 124 blocked_muted_video_histogram.Count(kAutoplayBlockedReasonSetting); |
| 122 } | 125 } |
| 123 } | 126 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 void AutoplayUmaHelper::RecordAutoplayUnmuteStatus( | 209 void AutoplayUmaHelper::RecordAutoplayUnmuteStatus( |
| 207 AutoplayUnmuteActionStatus status) { | 210 AutoplayUnmuteActionStatus status) { |
| 208 DEFINE_STATIC_LOCAL( | 211 DEFINE_STATIC_LOCAL( |
| 209 EnumerationHistogram, autoplay_unmute_histogram, | 212 EnumerationHistogram, autoplay_unmute_histogram, |
| 210 ("Media.Video.Autoplay.Muted.UnmuteAction", | 213 ("Media.Video.Autoplay.Muted.UnmuteAction", |
| 211 static_cast<int>(AutoplayUnmuteActionStatus::kNumberOfStatus))); | 214 static_cast<int>(AutoplayUnmuteActionStatus::kNumberOfStatus))); |
| 212 | 215 |
| 213 autoplay_unmute_histogram.Count(static_cast<int>(status)); | 216 autoplay_unmute_histogram.Count(static_cast<int>(status)); |
| 214 } | 217 } |
| 215 | 218 |
| 219 void AutoplayUmaHelper::VideoWillBeDrawnToCanvas() { |
| 220 if (HasSource() && !IsVisible()) { |
| 221 UseCounter::Count(element_->GetDocument(), |
| 222 UseCounter::kHiddenAutoplayedVideoInCanvas); |
| 223 } |
| 224 } |
| 225 |
| 216 void AutoplayUmaHelper::DidMoveToNewDocument(Document& old_document) { | 226 void AutoplayUmaHelper::DidMoveToNewDocument(Document& old_document) { |
| 217 if (!ShouldListenToContextDestroyed()) | 227 if (!ShouldListenToContextDestroyed()) |
| 218 return; | 228 return; |
| 219 | 229 |
| 220 SetContext(&element_->GetDocument()); | 230 SetContext(&element_->GetDocument()); |
| 221 } | 231 } |
| 222 | 232 |
| 223 void AutoplayUmaHelper::OnVisibilityChangedForMutedVideoPlayMethodBecomeVisible( | 233 void AutoplayUmaHelper::OnVisibilityChangedForMutedVideoPlayMethodBecomeVisible( |
| 224 bool is_visible) { | 234 bool is_visible) { |
| 225 if (!is_visible || !muted_video_play_method_visibility_observer_) | 235 if (!is_visible || !muted_video_play_method_visibility_observer_) |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 | 399 |
| 390 DEFINE_TRACE(AutoplayUmaHelper) { | 400 DEFINE_TRACE(AutoplayUmaHelper) { |
| 391 EventListener::Trace(visitor); | 401 EventListener::Trace(visitor); |
| 392 ContextLifecycleObserver::Trace(visitor); | 402 ContextLifecycleObserver::Trace(visitor); |
| 393 visitor->Trace(element_); | 403 visitor->Trace(element_); |
| 394 visitor->Trace(muted_video_play_method_visibility_observer_); | 404 visitor->Trace(muted_video_play_method_visibility_observer_); |
| 395 visitor->Trace(muted_video_offscreen_duration_visibility_observer_); | 405 visitor->Trace(muted_video_offscreen_duration_visibility_observer_); |
| 396 } | 406 } |
| 397 | 407 |
| 398 } // namespace blink | 408 } // namespace blink |
| OLD | NEW |