| 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 #ifndef MEDIA_BLINK_WATCH_TIME_REPORTER_H_ | 5 #ifndef MEDIA_BLINK_WATCH_TIME_REPORTER_H_ |
| 6 #define MEDIA_BLINK_WATCH_TIME_REPORTER_H_ | 6 #define MEDIA_BLINK_WATCH_TIME_REPORTER_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/power_monitor/power_observer.h" | 9 #include "base/power_monitor/power_observer.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 // time, not wall clock time! Using media time instead of wall clock time | 59 // time, not wall clock time! Using media time instead of wall clock time |
| 60 // allows us to avoid a whole class of issues around clock changes during | 60 // allows us to avoid a whole class of issues around clock changes during |
| 61 // suspend and resume. | 61 // suspend and resume. |
| 62 // TODO(dalecurtis): Should we only report when rate == 1.0? Should we scale | 62 // TODO(dalecurtis): Should we only report when rate == 1.0? Should we scale |
| 63 // the elapsed media time instead? | 63 // the elapsed media time instead? |
| 64 WatchTimeReporter(bool has_audio, | 64 WatchTimeReporter(bool has_audio, |
| 65 bool has_video, | 65 bool has_video, |
| 66 bool is_mse, | 66 bool is_mse, |
| 67 bool is_encrypted, | 67 bool is_encrypted, |
| 68 bool is_embedded_media_experience_enabled, | 68 bool is_embedded_media_experience_enabled, |
| 69 scoped_refptr<MediaLog> media_log, | 69 MediaLog* media_log, |
| 70 const gfx::Size& initial_video_size, | 70 const gfx::Size& initial_video_size, |
| 71 const GetMediaTimeCB& get_media_time_cb); | 71 const GetMediaTimeCB& get_media_time_cb); |
| 72 ~WatchTimeReporter() override; | 72 ~WatchTimeReporter() override; |
| 73 | 73 |
| 74 // These methods are used to ensure that watch time is only reported for | 74 // These methods are used to ensure that watch time is only reported for |
| 75 // media that is actually playing. They should be called whenever the media | 75 // media that is actually playing. They should be called whenever the media |
| 76 // starts or stops playing for any reason. If the media is audio+video and | 76 // starts or stops playing for any reason. If the media is audio+video and |
| 77 // currently hidden, OnPlaying() will start background watch time reporting. | 77 // currently hidden, OnPlaying() will start background watch time reporting. |
| 78 void OnPlaying(); | 78 void OnPlaying(); |
| 79 void OnPaused(); | 79 void OnPaused(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 | 123 |
| 124 private: | 124 private: |
| 125 friend class WatchTimeReporterTest; | 125 friend class WatchTimeReporterTest; |
| 126 | 126 |
| 127 // Internal constructor for marking background status. | 127 // Internal constructor for marking background status. |
| 128 WatchTimeReporter(bool has_audio, | 128 WatchTimeReporter(bool has_audio, |
| 129 bool has_video, | 129 bool has_video, |
| 130 bool is_mse, | 130 bool is_mse, |
| 131 bool is_encrypted, | 131 bool is_encrypted, |
| 132 bool is_embedded_media_experience_enabled, | 132 bool is_embedded_media_experience_enabled, |
| 133 scoped_refptr<MediaLog> media_log, | 133 MediaLog* media_log, |
| 134 const gfx::Size& initial_video_size, | 134 const gfx::Size& initial_video_size, |
| 135 const GetMediaTimeCB& get_media_time_cb, | 135 const GetMediaTimeCB& get_media_time_cb, |
| 136 bool is_background); | 136 bool is_background); |
| 137 | 137 |
| 138 // base::PowerObserver implementation. | 138 // base::PowerObserver implementation. |
| 139 // | 139 // |
| 140 // We only observe power source changes. We don't need to observe suspend and | 140 // We only observe power source changes. We don't need to observe suspend and |
| 141 // resume events because we report watch time in terms of elapsed media time | 141 // resume events because we report watch time in terms of elapsed media time |
| 142 // and not in terms of elapsed real time. | 142 // and not in terms of elapsed real time. |
| 143 void OnPowerStateChange(bool on_battery_power) override; | 143 void OnPowerStateChange(bool on_battery_power) override; |
| 144 | 144 |
| 145 bool ShouldReportWatchTime(); | 145 bool ShouldReportWatchTime(); |
| 146 void MaybeStartReportingTimer(base::TimeDelta start_timestamp); | 146 void MaybeStartReportingTimer(base::TimeDelta start_timestamp); |
| 147 enum class FinalizeTime { IMMEDIATELY, ON_NEXT_UPDATE }; | 147 enum class FinalizeTime { IMMEDIATELY, ON_NEXT_UPDATE }; |
| 148 void MaybeFinalizeWatchTime(FinalizeTime finalize_time); | 148 void MaybeFinalizeWatchTime(FinalizeTime finalize_time); |
| 149 void UpdateWatchTime(); | 149 void UpdateWatchTime(); |
| 150 | 150 |
| 151 // Initialized during construction. | 151 // Initialized during construction. |
| 152 const bool has_audio_; | 152 const bool has_audio_; |
| 153 const bool has_video_; | 153 const bool has_video_; |
| 154 const bool is_mse_; | 154 const bool is_mse_; |
| 155 const bool is_encrypted_; | 155 const bool is_encrypted_; |
| 156 const bool is_embedded_media_experience_enabled_; | 156 const bool is_embedded_media_experience_enabled_; |
| 157 scoped_refptr<MediaLog> media_log_; | 157 MediaLog* media_log_; |
| 158 const gfx::Size initial_video_size_; | 158 const gfx::Size initial_video_size_; |
| 159 const GetMediaTimeCB get_media_time_cb_; | 159 const GetMediaTimeCB get_media_time_cb_; |
| 160 const bool is_background_; | 160 const bool is_background_; |
| 161 | 161 |
| 162 // The amount of time between each UpdateWatchTime(); this is the frequency by | 162 // The amount of time between each UpdateWatchTime(); this is the frequency by |
| 163 // which the watch times are updated. In the event of a process crash or kill | 163 // which the watch times are updated. In the event of a process crash or kill |
| 164 // this is also the most amount of watch time that we might lose. | 164 // this is also the most amount of watch time that we might lose. |
| 165 base::TimeDelta reporting_interval_ = base::TimeDelta::FromSeconds(5); | 165 base::TimeDelta reporting_interval_ = base::TimeDelta::FromSeconds(5); |
| 166 | 166 |
| 167 base::RepeatingTimer reporting_timer_; | 167 base::RepeatingTimer reporting_timer_; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 188 // Special case reporter for handling background video watch time. Configured | 188 // Special case reporter for handling background video watch time. Configured |
| 189 // as an audio only WatchTimeReporter with |is_background_| set to true. | 189 // as an audio only WatchTimeReporter with |is_background_| set to true. |
| 190 std::unique_ptr<WatchTimeReporter> background_reporter_; | 190 std::unique_ptr<WatchTimeReporter> background_reporter_; |
| 191 | 191 |
| 192 DISALLOW_COPY_AND_ASSIGN(WatchTimeReporter); | 192 DISALLOW_COPY_AND_ASSIGN(WatchTimeReporter); |
| 193 }; | 193 }; |
| 194 | 194 |
| 195 } // namespace media | 195 } // namespace media |
| 196 | 196 |
| 197 #endif // MEDIA_BLINK_WATCH_TIME_REPORTER_H_ | 197 #endif // MEDIA_BLINK_WATCH_TIME_REPORTER_H_ |
| OLD | NEW |