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 "media/blink/watch_time_reporter.h" | 5 #include "media/blink/watch_time_reporter.h" |
6 | 6 |
7 #include "base/power_monitor/power_monitor.h" | 7 #include "base/power_monitor/power_monitor.h" |
8 | 8 |
9 namespace media { | 9 namespace media { |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... |
31 const GetMediaTimeCB& get_media_time_cb) | 31 const GetMediaTimeCB& get_media_time_cb) |
32 : has_audio_(has_audio), | 32 : has_audio_(has_audio), |
33 has_video_(has_video), | 33 has_video_(has_video), |
34 is_mse_(is_mse), | 34 is_mse_(is_mse), |
35 is_encrypted_(is_encrypted), | 35 is_encrypted_(is_encrypted), |
36 media_log_(std::move(media_log)), | 36 media_log_(std::move(media_log)), |
37 initial_video_size_(initial_video_size), | 37 initial_video_size_(initial_video_size), |
38 get_media_time_cb_(get_media_time_cb) { | 38 get_media_time_cb_(get_media_time_cb) { |
39 DCHECK(!get_media_time_cb_.is_null()); | 39 DCHECK(!get_media_time_cb_.is_null()); |
40 DCHECK(has_audio_ || has_video_); | 40 DCHECK(has_audio_ || has_video_); |
41 if (has_video_) | |
42 DCHECK(!initial_video_size_.IsEmpty()); | |
43 | 41 |
44 if (base::PowerMonitor* pm = base::PowerMonitor::Get()) | 42 if (base::PowerMonitor* pm = base::PowerMonitor::Get()) |
45 pm->AddObserver(this); | 43 pm->AddObserver(this); |
46 } | 44 } |
47 | 45 |
48 WatchTimeReporter::~WatchTimeReporter() { | 46 WatchTimeReporter::~WatchTimeReporter() { |
49 // If the timer is still running, finalize immediately, this is our last | 47 // If the timer is still running, finalize immediately, this is our last |
50 // chance to capture metrics. | 48 // chance to capture metrics. |
51 if (reporting_timer_.IsRunning()) | 49 if (reporting_timer_.IsRunning()) |
52 MaybeFinalizeWatchTime(FinalizeTime::IMMEDIATELY); | 50 MaybeFinalizeWatchTime(FinalizeTime::IMMEDIATELY); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 &WatchTimeReporter::UpdateWatchTime); | 111 &WatchTimeReporter::UpdateWatchTime); |
114 return; | 112 return; |
115 } | 113 } |
116 | 114 |
117 end_timestamp_for_power_ = kNoTimestamp; | 115 end_timestamp_for_power_ = kNoTimestamp; |
118 } | 116 } |
119 | 117 |
120 bool WatchTimeReporter::ShouldReportWatchTime() { | 118 bool WatchTimeReporter::ShouldReportWatchTime() { |
121 // Only report watch time for media of sufficient size with both audio and | 119 // Only report watch time for media of sufficient size with both audio and |
122 // video tracks present. | 120 // video tracks present. |
| 121 // TODO(tguilbert): HLS playback will always have an |initial_video_size_| of |
| 122 // (0,0) and never report watchtime. Fix this as part of HLS UMA cleanup. |
| 123 // See crbug.com/650891. |
123 return has_audio_ && has_video_ && | 124 return has_audio_ && has_video_ && |
124 initial_video_size_.height() >= kMinimumVideoSize.height() && | 125 initial_video_size_.height() >= kMinimumVideoSize.height() && |
125 initial_video_size_.width() >= kMinimumVideoSize.width(); | 126 initial_video_size_.width() >= kMinimumVideoSize.width(); |
126 } | 127 } |
127 | 128 |
128 void WatchTimeReporter::MaybeStartReportingTimer( | 129 void WatchTimeReporter::MaybeStartReportingTimer( |
129 base::TimeDelta start_timestamp) { | 130 base::TimeDelta start_timestamp) { |
130 // Don't start the timer if any of our state indicates we shouldn't; this | 131 // Don't start the timer if any of our state indicates we shouldn't; this |
131 // check is important since the various event handlers do not have to care | 132 // check is important since the various event handlers do not have to care |
132 // about the state of other events. | 133 // about the state of other events. |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 } | 254 } |
254 | 255 |
255 // Stop the timer if this is supposed to be our last tick. | 256 // Stop the timer if this is supposed to be our last tick. |
256 if (is_finalizing) { | 257 if (is_finalizing) { |
257 end_timestamp_ = kNoTimestamp; | 258 end_timestamp_ = kNoTimestamp; |
258 reporting_timer_.Stop(); | 259 reporting_timer_.Stop(); |
259 } | 260 } |
260 } | 261 } |
261 | 262 |
262 } // namespace media | 263 } // namespace media |
OLD | NEW |