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 created_time_ms_(MonotonicallyIncreasingTimeMS()) {} | |
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 |
47 void AutoplayUmaHelper::OnAutoplayInitiated(AutoplaySource source) { | 50 void AutoplayUmaHelper::OnAutoplayInitiated(AutoplaySource source) { |
51 int32_t autoplay_wait_time_ms = static_cast<int32_t>( | |
52 std::min<int64_t>(MonotonicallyIncreasingTimeMS() - created_time_ms_, | |
53 std::numeric_limits<int32_t>::max())); | |
54 | |
48 DEFINE_STATIC_LOCAL(EnumerationHistogram, video_histogram, | 55 DEFINE_STATIC_LOCAL(EnumerationHistogram, video_histogram, |
49 ("Media.Video.Autoplay", | 56 ("Media.Video.Autoplay", |
50 static_cast<int>(AutoplaySource::kNumberOfUmaSources))); | 57 static_cast<int>(AutoplaySource::kNumberOfUmaSources))); |
51 DEFINE_STATIC_LOCAL(EnumerationHistogram, muted_video_histogram, | 58 DEFINE_STATIC_LOCAL(EnumerationHistogram, muted_video_histogram, |
52 ("Media.Video.Autoplay.Muted", | 59 ("Media.Video.Autoplay.Muted", |
53 static_cast<int>(AutoplaySource::kNumberOfUmaSources))); | 60 static_cast<int>(AutoplaySource::kNumberOfUmaSources))); |
54 DEFINE_STATIC_LOCAL(EnumerationHistogram, audio_histogram, | 61 DEFINE_STATIC_LOCAL(EnumerationHistogram, audio_histogram, |
55 ("Media.Audio.Autoplay", | 62 ("Media.Audio.Autoplay", |
56 static_cast<int>(AutoplaySource::kNumberOfUmaSources))); | 63 static_cast<int>(AutoplaySource::kNumberOfUmaSources))); |
57 DEFINE_STATIC_LOCAL( | 64 DEFINE_STATIC_LOCAL( |
58 EnumerationHistogram, blocked_muted_video_histogram, | 65 EnumerationHistogram, blocked_muted_video_histogram, |
59 ("Media.Video.Autoplay.Muted.Blocked", kAutoplayBlockedReasonMax)); | 66 ("Media.Video.Autoplay.Muted.Blocked", kAutoplayBlockedReasonMax)); |
60 | 67 |
68 DEFINE_STATIC_LOCAL(CustomCountHistogram, wait_time_video_attrib_histogram, | |
69 ("Media.Video.Autoplay.Video.Attribute.WaitTimeMS", 1, | |
70 kMaxWaitTimeUmaMS, kWaitTimeBucketCount)); | |
71 DEFINE_STATIC_LOCAL(CustomCountHistogram, wait_time_audio_attrib_histogram, | |
72 ("Media.Video.Autoplay.Audio.Attribute.WaitTimeMS", 1, | |
73 kMaxWaitTimeUmaMS, kWaitTimeBucketCount)); | |
74 DEFINE_STATIC_LOCAL(CustomCountHistogram, wait_time_video_play_histogram, | |
75 ("Media.Video.Autoplay.Video.PlayMethod.WaitTimeMS", 1, | |
76 kMaxWaitTimeUmaMS, kWaitTimeBucketCount)); | |
77 DEFINE_STATIC_LOCAL(CustomCountHistogram, wait_time_audio_play_histogram, | |
78 ("Media.Video.Autoplay.Audio.PlayMethod.WaitTimeMS", 1, | |
79 kMaxWaitTimeUmaMS, kWaitTimeBucketCount)); | |
80 | |
61 // Autoplay already initiated | 81 // Autoplay already initiated |
62 if (sources_.count(source)) | 82 if (sources_.count(source)) |
63 return; | 83 return; |
64 | 84 |
65 sources_.insert(source); | 85 sources_.insert(source); |
66 | 86 |
67 // Record the source. | 87 // Record the source. |
68 if (element_->IsHTMLVideoElement()) { | 88 if (element_->IsHTMLVideoElement()) { |
69 video_histogram.Count(static_cast<int>(source)); | 89 video_histogram.Count(static_cast<int>(source)); |
70 if (element_->muted()) | 90 if (element_->muted()) |
71 muted_video_histogram.Count(static_cast<int>(source)); | 91 muted_video_histogram.Count(static_cast<int>(source)); |
92 if (source == AutoplaySource::kAttribute) { | |
Zhiqiang Zhang (Slow)
2017/05/02 00:12:05
Not sure autoplay by attribute will be affected by
| |
93 wait_time_video_attrib_histogram.Count(autoplay_wait_time_ms); | |
94 } else if (source == AutoplaySource::kMethod) { | |
95 wait_time_video_play_histogram.Count(autoplay_wait_time_ms); | |
96 } | |
72 } else { | 97 } else { |
73 audio_histogram.Count(static_cast<int>(source)); | 98 audio_histogram.Count(static_cast<int>(source)); |
99 if (source == AutoplaySource::kAttribute) { | |
Zhiqiang Zhang (Slow)
2017/05/02 00:12:05
Ditto.
| |
100 wait_time_audio_attrib_histogram.Count(autoplay_wait_time_ms); | |
101 } else if (source == AutoplaySource::kMethod) { | |
102 wait_time_audio_play_histogram.Count(autoplay_wait_time_ms); | |
103 } | |
74 } | 104 } |
75 | 105 |
76 // Record dual source. | 106 // Record dual source. |
77 if (sources_.size() == | 107 if (sources_.size() == |
78 static_cast<size_t>(AutoplaySource::kNumberOfSources)) { | 108 static_cast<size_t>(AutoplaySource::kNumberOfSources)) { |
79 if (element_->IsHTMLVideoElement()) { | 109 if (element_->IsHTMLVideoElement()) { |
80 video_histogram.Count(static_cast<int>(AutoplaySource::kDualSource)); | 110 video_histogram.Count(static_cast<int>(AutoplaySource::kDualSource)); |
81 if (element_->muted()) | 111 if (element_->muted()) |
82 muted_video_histogram.Count( | 112 muted_video_histogram.Count( |
83 static_cast<int>(AutoplaySource::kDualSource)); | 113 static_cast<int>(AutoplaySource::kDualSource)); |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
399 | 429 |
400 DEFINE_TRACE(AutoplayUmaHelper) { | 430 DEFINE_TRACE(AutoplayUmaHelper) { |
401 EventListener::Trace(visitor); | 431 EventListener::Trace(visitor); |
402 ContextLifecycleObserver::Trace(visitor); | 432 ContextLifecycleObserver::Trace(visitor); |
403 visitor->Trace(element_); | 433 visitor->Trace(element_); |
404 visitor->Trace(muted_video_play_method_visibility_observer_); | 434 visitor->Trace(muted_video_play_method_visibility_observer_); |
405 visitor->Trace(muted_video_offscreen_duration_visibility_observer_); | 435 visitor->Trace(muted_video_offscreen_duration_visibility_observer_); |
406 } | 436 } |
407 | 437 |
408 } // namespace blink | 438 } // namespace blink |
OLD | NEW |