Chromium Code Reviews| 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/frame/UseCounter.h" |
| 12 #include "core/html/HTMLMediaElement.h" | 12 #include "core/html/HTMLMediaElement.h" |
| 13 #include "core/html/media/AutoplayPolicy.h" | 13 #include "core/html/media/AutoplayPolicy.h" |
| 14 #include "platform/Histogram.h" | 14 #include "platform/Histogram.h" |
| 15 #include "platform/wtf/CurrentTime.h" | 15 #include "platform/wtf/CurrentTime.h" |
| 16 #include "public/platform/Platform.h" | 16 #include "public/platform/Platform.h" |
| 17 | 17 |
| 18 namespace blink { | 18 namespace blink { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 const int32_t kMaxOffscreenDurationUmaMS = 60 * 60 * 1000; | 22 const int32_t kMaxOffscreenDurationUmaMS = 60 * 60 * 1000; |
| 23 const int32_t kOffscreenDurationUmaBucketCount = 50; | 23 const int32_t kOffscreenDurationUmaBucketCount = 50; |
| 24 const int32_t kMaxWaitTimeUmaMS = 30 * 1000; | |
| 25 const int32_t kWaitTimeBucketCount = 50; | |
| 24 | 26 |
| 25 } // namespace | 27 } // namespace |
| 26 | 28 |
| 27 AutoplayUmaHelper* AutoplayUmaHelper::Create(HTMLMediaElement* element) { | 29 AutoplayUmaHelper* AutoplayUmaHelper::Create(HTMLMediaElement* element) { |
| 28 return new AutoplayUmaHelper(element); | 30 return new AutoplayUmaHelper(element); |
| 29 } | 31 } |
| 30 | 32 |
| 31 AutoplayUmaHelper::AutoplayUmaHelper(HTMLMediaElement* element) | 33 AutoplayUmaHelper::AutoplayUmaHelper(HTMLMediaElement* element) |
| 32 : EventListener(kCPPEventListenerType), | 34 : EventListener(kCPPEventListenerType), |
| 33 ContextLifecycleObserver(nullptr), | 35 ContextLifecycleObserver(nullptr), |
| 34 element_(element), | 36 element_(element), |
| 35 muted_video_play_method_visibility_observer_(nullptr), | 37 muted_video_play_method_visibility_observer_(nullptr), |
| 36 muted_video_autoplay_offscreen_start_time_ms_(0), | 38 muted_video_autoplay_offscreen_start_time_ms_(0), |
| 37 muted_video_autoplay_offscreen_duration_ms_(0), | 39 muted_video_autoplay_offscreen_duration_ms_(0), |
| 38 is_visible_(false), | 40 is_visible_(false), |
| 39 muted_video_offscreen_duration_visibility_observer_(nullptr) {} | 41 muted_video_offscreen_duration_visibility_observer_(nullptr), |
| 42 load_start_time_ms_(0.0) {} | |
| 40 | 43 |
| 41 AutoplayUmaHelper::~AutoplayUmaHelper() = default; | 44 AutoplayUmaHelper::~AutoplayUmaHelper() = default; |
| 42 | 45 |
| 43 bool AutoplayUmaHelper::operator==(const EventListener& other) const { | 46 bool AutoplayUmaHelper::operator==(const EventListener& other) const { |
| 44 return this == &other; | 47 return this == &other; |
| 45 } | 48 } |
| 46 | 49 |
| 50 void AutoplayUmaHelper::OnLoadStarted() { | |
|
DaleCurtis
2017/05/02 21:05:28
Probably should take the type. We only care about
hubbe
2017/05/02 22:33:26
Done.
| |
| 51 load_start_time_ms_ = MonotonicallyIncreasingTimeMS(); | |
| 52 } | |
| 53 | |
| 47 void AutoplayUmaHelper::OnAutoplayInitiated(AutoplaySource source) { | 54 void AutoplayUmaHelper::OnAutoplayInitiated(AutoplaySource source) { |
| 55 int32_t autoplay_wait_time_ms = -1; | |
| 56 if (load_start_time_ms_ != 0.0) { | |
| 57 autoplay_wait_time_ms = static_cast<int32_t>( | |
| 58 std::min<int64_t>(MonotonicallyIncreasingTimeMS() - load_start_time_ms_, | |
|
DaleCurtis
2017/05/02 21:05:28
Clamp to kMaxWaitTimeUmaMS?
hubbe
2017/05/02 22:33:26
Doesn't the histogram already do that?
hubbe
2017/05/03 20:37:24
Checked, it does, here: https://cs.chromium.org/ch
| |
| 59 std::numeric_limits<int32_t>::max())); | |
| 60 } | |
| 48 DEFINE_STATIC_LOCAL(EnumerationHistogram, video_histogram, | 61 DEFINE_STATIC_LOCAL(EnumerationHistogram, video_histogram, |
| 49 ("Media.Video.Autoplay", | 62 ("Media.Video.Autoplay", |
| 50 static_cast<int>(AutoplaySource::kNumberOfUmaSources))); | 63 static_cast<int>(AutoplaySource::kNumberOfUmaSources))); |
| 51 DEFINE_STATIC_LOCAL(EnumerationHistogram, muted_video_histogram, | 64 DEFINE_STATIC_LOCAL(EnumerationHistogram, muted_video_histogram, |
| 52 ("Media.Video.Autoplay.Muted", | 65 ("Media.Video.Autoplay.Muted", |
| 53 static_cast<int>(AutoplaySource::kNumberOfUmaSources))); | 66 static_cast<int>(AutoplaySource::kNumberOfUmaSources))); |
| 54 DEFINE_STATIC_LOCAL(EnumerationHistogram, audio_histogram, | 67 DEFINE_STATIC_LOCAL(EnumerationHistogram, audio_histogram, |
| 55 ("Media.Audio.Autoplay", | 68 ("Media.Audio.Autoplay", |
| 56 static_cast<int>(AutoplaySource::kNumberOfUmaSources))); | 69 static_cast<int>(AutoplaySource::kNumberOfUmaSources))); |
| 57 DEFINE_STATIC_LOCAL( | 70 DEFINE_STATIC_LOCAL( |
| 58 EnumerationHistogram, blocked_muted_video_histogram, | 71 EnumerationHistogram, blocked_muted_video_histogram, |
| 59 ("Media.Video.Autoplay.Muted.Blocked", kAutoplayBlockedReasonMax)); | 72 ("Media.Video.Autoplay.Muted.Blocked", kAutoplayBlockedReasonMax)); |
| 60 | 73 |
| 74 DEFINE_STATIC_LOCAL(CustomCountHistogram, wait_time_video_attrib_histogram, | |
|
DaleCurtis
2017/05/02 21:05:28
I don't think we really care about the difference
Zhiqiang Zhang (Slow)
2017/05/02 21:21:22
I think the experiment would only affect autoplay
DaleCurtis
2017/05/02 21:36:38
Ah, I didn't realize the behavior was different. H
hubbe
2017/05/02 22:33:26
The thing we're changing actually changes the read
| |
| 75 ("Media.Video.Autoplay.Video.Attribute.WaitTimeMS", 1, | |
| 76 kMaxWaitTimeUmaMS, kWaitTimeBucketCount)); | |
| 77 DEFINE_STATIC_LOCAL(CustomCountHistogram, wait_time_audio_attrib_histogram, | |
| 78 ("Media.Video.Autoplay.Audio.Attribute.WaitTimeMS", 1, | |
| 79 kMaxWaitTimeUmaMS, kWaitTimeBucketCount)); | |
| 80 DEFINE_STATIC_LOCAL(CustomCountHistogram, wait_time_video_play_histogram, | |
| 81 ("Media.Video.Autoplay.Video.PlayMethod.WaitTimeMS", 1, | |
| 82 kMaxWaitTimeUmaMS, kWaitTimeBucketCount)); | |
| 83 DEFINE_STATIC_LOCAL(CustomCountHistogram, wait_time_audio_play_histogram, | |
| 84 ("Media.Video.Autoplay.Audio.PlayMethod.WaitTimeMS", 1, | |
| 85 kMaxWaitTimeUmaMS, kWaitTimeBucketCount)); | |
| 86 | |
| 61 // Autoplay already initiated | 87 // Autoplay already initiated |
| 62 if (sources_.count(source)) | 88 if (sources_.count(source)) |
| 63 return; | 89 return; |
| 64 | 90 |
| 65 sources_.insert(source); | 91 sources_.insert(source); |
| 66 | 92 |
| 67 // Record the source. | 93 // Record the source. |
| 68 if (element_->IsHTMLVideoElement()) { | 94 if (element_->IsHTMLVideoElement()) { |
| 69 video_histogram.Count(static_cast<int>(source)); | 95 video_histogram.Count(static_cast<int>(source)); |
| 70 if (element_->muted()) | 96 if (element_->muted()) |
| 71 muted_video_histogram.Count(static_cast<int>(source)); | 97 muted_video_histogram.Count(static_cast<int>(source)); |
| 98 if (autoplay_wait_time_ms >= 0) { | |
| 99 if (source == AutoplaySource::kAttribute) { | |
| 100 wait_time_video_attrib_histogram.Count(autoplay_wait_time_ms); | |
| 101 } else if (source == AutoplaySource::kMethod) { | |
| 102 wait_time_video_play_histogram.Count(autoplay_wait_time_ms); | |
| 103 } | |
| 104 } | |
| 72 } else { | 105 } else { |
| 73 audio_histogram.Count(static_cast<int>(source)); | 106 audio_histogram.Count(static_cast<int>(source)); |
| 107 if (autoplay_wait_time_ms >= 0) { | |
| 108 if (source == AutoplaySource::kAttribute) { | |
| 109 wait_time_audio_attrib_histogram.Count(autoplay_wait_time_ms); | |
| 110 } else if (source == AutoplaySource::kMethod) { | |
| 111 wait_time_audio_play_histogram.Count(autoplay_wait_time_ms); | |
| 112 } | |
| 113 } | |
| 74 } | 114 } |
| 75 | 115 |
| 76 // Record dual source. | 116 // Record dual source. |
| 77 if (sources_.size() == | 117 if (sources_.size() == |
| 78 static_cast<size_t>(AutoplaySource::kNumberOfSources)) { | 118 static_cast<size_t>(AutoplaySource::kNumberOfSources)) { |
| 79 if (element_->IsHTMLVideoElement()) { | 119 if (element_->IsHTMLVideoElement()) { |
| 80 video_histogram.Count(static_cast<int>(AutoplaySource::kDualSource)); | 120 video_histogram.Count(static_cast<int>(AutoplaySource::kDualSource)); |
| 81 if (element_->muted()) | 121 if (element_->muted()) |
| 82 muted_video_histogram.Count( | 122 muted_video_histogram.Count( |
| 83 static_cast<int>(AutoplaySource::kDualSource)); | 123 static_cast<int>(AutoplaySource::kDualSource)); |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 399 | 439 |
| 400 DEFINE_TRACE(AutoplayUmaHelper) { | 440 DEFINE_TRACE(AutoplayUmaHelper) { |
| 401 EventListener::Trace(visitor); | 441 EventListener::Trace(visitor); |
| 402 ContextLifecycleObserver::Trace(visitor); | 442 ContextLifecycleObserver::Trace(visitor); |
| 403 visitor->Trace(element_); | 443 visitor->Trace(element_); |
| 404 visitor->Trace(muted_video_play_method_visibility_observer_); | 444 visitor->Trace(muted_video_play_method_visibility_observer_); |
| 405 visitor->Trace(muted_video_offscreen_duration_visibility_observer_); | 445 visitor->Trace(muted_video_offscreen_duration_visibility_observer_); |
| 406 } | 446 } |
| 407 | 447 |
| 408 } // namespace blink | 448 } // namespace blink |
| OLD | NEW |