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(WebMediaPlayer::LoadType load_type) { | |
51 if (load_type == WebMediaPlayer::kLoadTypeURL) | |
52 load_start_time_ms_ = MonotonicallyIncreasingTimeMS(); | |
53 } | |
mlamouri (slow - plz ping)
2017/05/16 12:59:40
Instead of adding a "OnLoadStarted", I think it wo
hubbe
2017/05/16 20:57:13
Much better, done.
(I just had to make GetLoadType
| |
54 | |
47 void AutoplayUmaHelper::OnAutoplayInitiated(AutoplaySource source) { | 55 void AutoplayUmaHelper::OnAutoplayInitiated(AutoplaySource source) { |
56 int32_t autoplay_wait_time_ms = -1; | |
57 if (load_start_time_ms_ != 0.0) { | |
58 autoplay_wait_time_ms = static_cast<int32_t>( | |
59 std::min<int64_t>(MonotonicallyIncreasingTimeMS() - load_start_time_ms_, | |
60 std::numeric_limits<int32_t>::max())); | |
61 } | |
48 DEFINE_STATIC_LOCAL(EnumerationHistogram, video_histogram, | 62 DEFINE_STATIC_LOCAL(EnumerationHistogram, video_histogram, |
49 ("Media.Video.Autoplay", | 63 ("Media.Video.Autoplay", |
50 static_cast<int>(AutoplaySource::kNumberOfUmaSources))); | 64 static_cast<int>(AutoplaySource::kNumberOfUmaSources))); |
51 DEFINE_STATIC_LOCAL(EnumerationHistogram, muted_video_histogram, | 65 DEFINE_STATIC_LOCAL(EnumerationHistogram, muted_video_histogram, |
52 ("Media.Video.Autoplay.Muted", | 66 ("Media.Video.Autoplay.Muted", |
53 static_cast<int>(AutoplaySource::kNumberOfUmaSources))); | 67 static_cast<int>(AutoplaySource::kNumberOfUmaSources))); |
54 DEFINE_STATIC_LOCAL(EnumerationHistogram, audio_histogram, | 68 DEFINE_STATIC_LOCAL(EnumerationHistogram, audio_histogram, |
55 ("Media.Audio.Autoplay", | 69 ("Media.Audio.Autoplay", |
56 static_cast<int>(AutoplaySource::kNumberOfUmaSources))); | 70 static_cast<int>(AutoplaySource::kNumberOfUmaSources))); |
57 DEFINE_STATIC_LOCAL( | 71 DEFINE_STATIC_LOCAL( |
58 EnumerationHistogram, blocked_muted_video_histogram, | 72 EnumerationHistogram, blocked_muted_video_histogram, |
59 ("Media.Video.Autoplay.Muted.Blocked", kAutoplayBlockedReasonMax)); | 73 ("Media.Video.Autoplay.Muted.Blocked", kAutoplayBlockedReasonMax)); |
60 | 74 |
75 DEFINE_STATIC_LOCAL(CustomCountHistogram, wait_time_video_attrib_histogram, | |
76 ("Media.Video.Autoplay.Attribute.WaitTime", 1, | |
77 kMaxWaitTimeUmaMS, kWaitTimeBucketCount)); | |
78 DEFINE_STATIC_LOCAL(CustomCountHistogram, wait_time_audio_attrib_histogram, | |
79 ("Media.Audio.Autoplay.Attribute.WaitTime", 1, | |
80 kMaxWaitTimeUmaMS, kWaitTimeBucketCount)); | |
81 DEFINE_STATIC_LOCAL(CustomCountHistogram, wait_time_video_play_histogram, | |
82 ("Media.Video.Autoplay.PlayMethod.WaitTime", 1, | |
83 kMaxWaitTimeUmaMS, kWaitTimeBucketCount)); | |
84 DEFINE_STATIC_LOCAL(CustomCountHistogram, wait_time_audio_play_histogram, | |
85 ("Media.Audio.Autoplay.PlayMethod.WaitTime", 1, | |
86 kMaxWaitTimeUmaMS, kWaitTimeBucketCount)); | |
87 | |
61 // Autoplay already initiated | 88 // Autoplay already initiated |
62 if (sources_.count(source)) | 89 if (sources_.count(source)) |
63 return; | 90 return; |
64 | 91 |
65 sources_.insert(source); | 92 sources_.insert(source); |
66 | 93 |
67 // Record the source. | 94 // Record the source. |
68 if (element_->IsHTMLVideoElement()) { | 95 if (element_->IsHTMLVideoElement()) { |
69 video_histogram.Count(static_cast<int>(source)); | 96 video_histogram.Count(static_cast<int>(source)); |
70 if (element_->muted()) | 97 if (element_->muted()) |
71 muted_video_histogram.Count(static_cast<int>(source)); | 98 muted_video_histogram.Count(static_cast<int>(source)); |
99 if (autoplay_wait_time_ms >= 0) { | |
100 if (source == AutoplaySource::kAttribute) { | |
101 wait_time_video_attrib_histogram.Count(autoplay_wait_time_ms); | |
102 } else if (source == AutoplaySource::kMethod) { | |
103 wait_time_video_play_histogram.Count(autoplay_wait_time_ms); | |
104 } | |
105 } | |
72 } else { | 106 } else { |
73 audio_histogram.Count(static_cast<int>(source)); | 107 audio_histogram.Count(static_cast<int>(source)); |
108 if (autoplay_wait_time_ms >= 0) { | |
109 if (source == AutoplaySource::kAttribute) { | |
110 wait_time_audio_attrib_histogram.Count(autoplay_wait_time_ms); | |
111 } else if (source == AutoplaySource::kMethod) { | |
112 wait_time_audio_play_histogram.Count(autoplay_wait_time_ms); | |
113 } | |
114 } | |
74 } | 115 } |
75 | 116 |
76 // Record dual source. | 117 // Record dual source. |
77 if (sources_.size() == | 118 if (sources_.size() == |
78 static_cast<size_t>(AutoplaySource::kNumberOfSources)) { | 119 static_cast<size_t>(AutoplaySource::kNumberOfSources)) { |
79 if (element_->IsHTMLVideoElement()) { | 120 if (element_->IsHTMLVideoElement()) { |
80 video_histogram.Count(static_cast<int>(AutoplaySource::kDualSource)); | 121 video_histogram.Count(static_cast<int>(AutoplaySource::kDualSource)); |
81 if (element_->muted()) | 122 if (element_->muted()) |
82 muted_video_histogram.Count( | 123 muted_video_histogram.Count( |
83 static_cast<int>(AutoplaySource::kDualSource)); | 124 static_cast<int>(AutoplaySource::kDualSource)); |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
399 | 440 |
400 DEFINE_TRACE(AutoplayUmaHelper) { | 441 DEFINE_TRACE(AutoplayUmaHelper) { |
401 EventListener::Trace(visitor); | 442 EventListener::Trace(visitor); |
402 ContextLifecycleObserver::Trace(visitor); | 443 ContextLifecycleObserver::Trace(visitor); |
403 visitor->Trace(element_); | 444 visitor->Trace(element_); |
404 visitor->Trace(muted_video_play_method_visibility_observer_); | 445 visitor->Trace(muted_video_play_method_visibility_observer_); |
405 visitor->Trace(muted_video_offscreen_duration_visibility_observer_); | 446 visitor->Trace(muted_video_offscreen_duration_visibility_observer_); |
406 } | 447 } |
407 | 448 |
408 } // namespace blink | 449 } // namespace blink |
OLD | NEW |