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 |
11 // The minimum amount of media playback which can elapse before we'll report | 11 // The minimum amount of media playback which can elapse before we'll report |
12 // watch time metrics for a playback. | 12 // watch time metrics for a playback. |
13 constexpr base::TimeDelta kMinimumElapsedWatchTime = | 13 constexpr base::TimeDelta kMinimumElapsedWatchTime = |
14 base::TimeDelta::FromSeconds(7); | 14 base::TimeDelta::FromSeconds(7); |
15 | 15 |
16 // The minimum width and height of videos to report watch time metrics for. | 16 // The minimum width and height of videos to report watch time metrics for. |
17 constexpr gfx::Size kMinimumVideoSize = gfx::Size(200, 200); | 17 constexpr gfx::Size kMinimumVideoSize = gfx::Size(200, 200); |
18 | 18 |
19 static bool IsOnBatteryPower() { | 19 static bool IsOnBatteryPower() { |
20 if (base::PowerMonitor* pm = base::PowerMonitor::Get()) | 20 if (base::PowerMonitor* pm = base::PowerMonitor::Get()) |
21 return pm->IsOnBatteryPower(); | 21 return pm->IsOnBatteryPower(); |
22 return false; | 22 return false; |
23 } | 23 } |
24 | 24 |
25 WatchTimeReporter::WatchTimeReporter(bool has_audio, | 25 WatchTimeReporter::WatchTimeReporter(bool has_audio, |
26 bool has_video, | 26 bool has_video, |
27 bool is_mse, | 27 bool is_mse, |
28 bool is_encrypted, | 28 bool is_encrypted, |
29 bool is_embedded_media_experience_enabled, | 29 bool is_embedded_media_experience_enabled, |
30 scoped_refptr<MediaLog> media_log, | 30 MediaLog* media_log, |
31 const gfx::Size& initial_video_size, | 31 const gfx::Size& initial_video_size, |
32 const GetMediaTimeCB& get_media_time_cb) | 32 const GetMediaTimeCB& get_media_time_cb) |
33 : WatchTimeReporter(has_audio, | 33 : WatchTimeReporter(has_audio, |
34 has_video, | 34 has_video, |
35 is_mse, | 35 is_mse, |
36 is_encrypted, | 36 is_encrypted, |
37 is_embedded_media_experience_enabled, | 37 is_embedded_media_experience_enabled, |
38 std::move(media_log), | 38 media_log, |
39 initial_video_size, | 39 initial_video_size, |
40 get_media_time_cb, | 40 get_media_time_cb, |
41 false) {} | 41 false) {} |
42 | 42 |
43 WatchTimeReporter::WatchTimeReporter(bool has_audio, | 43 WatchTimeReporter::WatchTimeReporter(bool has_audio, |
44 bool has_video, | 44 bool has_video, |
45 bool is_mse, | 45 bool is_mse, |
46 bool is_encrypted, | 46 bool is_encrypted, |
47 bool is_embedded_media_experience_enabled, | 47 bool is_embedded_media_experience_enabled, |
48 scoped_refptr<MediaLog> media_log, | 48 MediaLog* media_log, |
49 const gfx::Size& initial_video_size, | 49 const gfx::Size& initial_video_size, |
50 const GetMediaTimeCB& get_media_time_cb, | 50 const GetMediaTimeCB& get_media_time_cb, |
51 bool is_background) | 51 bool is_background) |
52 : has_audio_(has_audio), | 52 : has_audio_(has_audio), |
53 has_video_(has_video), | 53 has_video_(has_video), |
54 is_mse_(is_mse), | 54 is_mse_(is_mse), |
55 is_encrypted_(is_encrypted), | 55 is_encrypted_(is_encrypted), |
56 is_embedded_media_experience_enabled_( | 56 is_embedded_media_experience_enabled_( |
57 is_embedded_media_experience_enabled), | 57 is_embedded_media_experience_enabled), |
58 media_log_(std::move(media_log)), | 58 media_log_(media_log), |
59 initial_video_size_(initial_video_size), | 59 initial_video_size_(initial_video_size), |
60 get_media_time_cb_(get_media_time_cb), | 60 get_media_time_cb_(get_media_time_cb), |
61 is_background_(is_background) { | 61 is_background_(is_background) { |
62 DCHECK(!get_media_time_cb_.is_null()); | 62 DCHECK(!get_media_time_cb_.is_null()); |
63 DCHECK(has_audio_ || has_video_); | 63 DCHECK(has_audio_ || has_video_); |
64 | 64 |
65 if (base::PowerMonitor* pm = base::PowerMonitor::Get()) | 65 if (base::PowerMonitor* pm = base::PowerMonitor::Get()) |
66 pm->AddObserver(this); | 66 pm->AddObserver(this); |
67 | 67 |
68 if (is_background_) { | 68 if (is_background_) { |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 } | 335 } |
336 | 336 |
337 // 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. |
338 if (is_finalizing) { | 338 if (is_finalizing) { |
339 end_timestamp_ = kNoTimestamp; | 339 end_timestamp_ = kNoTimestamp; |
340 reporting_timer_.Stop(); | 340 reporting_timer_.Stop(); |
341 } | 341 } |
342 } | 342 } |
343 | 343 |
344 } // namespace media | 344 } // namespace media |
OLD | NEW |