Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(548)

Side by Side Diff: media/blink/watch_time_reporter.cc

Issue 2822543006: Start reporting watch time if ABR adapts above 200p. (Closed)
Patch Set: Simplify Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/blink/watch_time_reporter.h ('k') | media/blink/watch_time_reporter_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 if (background_reporter_ && is_playing_) 155 if (background_reporter_ && is_playing_)
156 background_reporter_->OnPlaying(); 156 background_reporter_->OnPlaying();
157 157
158 if (!has_video_) 158 if (!has_video_)
159 return; 159 return;
160 160
161 is_visible_ = false; 161 is_visible_ = false;
162 MaybeFinalizeWatchTime(FinalizeTime::ON_NEXT_UPDATE); 162 MaybeFinalizeWatchTime(FinalizeTime::ON_NEXT_UPDATE);
163 } 163 }
164 164
165 bool WatchTimeReporter::IsSizeLargeEnoughToReportWatchTime() const {
166 return initial_video_size_.height() >= kMinimumVideoSize.height() &&
167 initial_video_size_.width() >= kMinimumVideoSize.width();
168 }
169
165 void WatchTimeReporter::OnPowerStateChange(bool on_battery_power) { 170 void WatchTimeReporter::OnPowerStateChange(bool on_battery_power) {
166 if (!reporting_timer_.IsRunning()) 171 if (!reporting_timer_.IsRunning())
167 return; 172 return;
168 173
169 // Defer changing |is_on_battery_power_| until the next watch time report to 174 // Defer changing |is_on_battery_power_| until the next watch time report to
170 // avoid momentary power changes from affecting the results. 175 // avoid momentary power changes from affecting the results.
171 if (is_on_battery_power_ != on_battery_power) { 176 if (is_on_battery_power_ != on_battery_power) {
172 end_timestamp_for_power_ = get_media_time_cb_.Run(); 177 end_timestamp_for_power_ = get_media_time_cb_.Run();
173 178
174 // Restart the reporting timer so the full hysteresis is afforded. 179 // Restart the reporting timer so the full hysteresis is afforded.
175 reporting_timer_.Start(FROM_HERE, reporting_interval_, this, 180 reporting_timer_.Start(FROM_HERE, reporting_interval_, this,
176 &WatchTimeReporter::UpdateWatchTime); 181 &WatchTimeReporter::UpdateWatchTime);
177 return; 182 return;
178 } 183 }
179 184
180 end_timestamp_for_power_ = kNoTimestamp; 185 end_timestamp_for_power_ = kNoTimestamp;
181 } 186 }
182 187
183 bool WatchTimeReporter::ShouldReportWatchTime() { 188 bool WatchTimeReporter::ShouldReportWatchTime() {
184 // Report listen time or watch time only for tracks that are audio-only or 189 // Report listen time or watch time only for tracks that are audio-only or
185 // have both an audio and video track of sufficient size. 190 // have both an audio and video track of sufficient size.
186 return (!has_video_ && has_audio_) || 191 return (!has_video_ && has_audio_) ||
187 (has_video_ && has_audio_ && 192 (has_video_ && has_audio_ && IsSizeLargeEnoughToReportWatchTime());
188 initial_video_size_.height() >= kMinimumVideoSize.height() &&
189 initial_video_size_.width() >= kMinimumVideoSize.width());
190 } 193 }
191 194
192 void WatchTimeReporter::MaybeStartReportingTimer( 195 void WatchTimeReporter::MaybeStartReportingTimer(
193 base::TimeDelta start_timestamp) { 196 base::TimeDelta start_timestamp) {
194 // Don't start the timer if any of our state indicates we shouldn't; this 197 // Don't start the timer if any of our state indicates we shouldn't; this
195 // check is important since the various event handlers do not have to care 198 // check is important since the various event handlers do not have to care
196 // about the state of other events. 199 // about the state of other events.
197 if (!ShouldReportWatchTime() || !is_playing_ || !volume_ || !is_visible_) { 200 if (!ShouldReportWatchTime() || !is_playing_ || !volume_ || !is_visible_) {
198 // If we reach this point the timer should already have been stopped or 201 // If we reach this point the timer should already have been stopped or
199 // there is a pending finalize in flight. 202 // there is a pending finalize in flight.
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 } 335 }
333 336
334 // Stop the timer if this is supposed to be our last tick. 337 // Stop the timer if this is supposed to be our last tick.
335 if (is_finalizing) { 338 if (is_finalizing) {
336 end_timestamp_ = kNoTimestamp; 339 end_timestamp_ = kNoTimestamp;
337 reporting_timer_.Stop(); 340 reporting_timer_.Stop();
338 } 341 }
339 } 342 }
340 343
341 } // namespace media 344 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/watch_time_reporter.h ('k') | media/blink/watch_time_reporter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698