| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 CONTENT_RENDERER_MEDIA_RENDERER_WEBMEDIAPLAYER_DELEGATE_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_RENDERER_WEBMEDIAPLAYER_DELEGATE_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_RENDERER_WEBMEDIAPLAYER_DELEGATE_H_ | 6 #define CONTENT_RENDERER_MEDIA_RENDERER_WEBMEDIAPLAYER_DELEGATE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <set> | 10 #include <set> |
| 11 | 11 |
| 12 #include "base/id_map.h" | 12 #include "base/id_map.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/time/default_tick_clock.h" | 15 #include "base/time/default_tick_clock.h" |
| 16 #include "base/time/time.h" |
| 16 #include "base/timer/timer.h" | 17 #include "base/timer/timer.h" |
| 17 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
| 18 #include "content/public/renderer/render_frame_observer.h" | 19 #include "content/public/renderer/render_frame_observer.h" |
| 19 #include "media/blink/webmediaplayer_delegate.h" | 20 #include "media/blink/webmediaplayer_delegate.h" |
| 20 | 21 |
| 21 namespace blink { | 22 namespace blink { |
| 22 class WebMediaPlayer; | 23 class WebMediaPlayer; |
| 23 } | 24 } |
| 24 | 25 |
| 25 namespace media { | 26 namespace media { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 double multiplier); | 77 double multiplier); |
| 77 | 78 |
| 78 // Adds or removes a delegate from |idle_delegate_map_|. The first insertion | 79 // Adds or removes a delegate from |idle_delegate_map_|. The first insertion |
| 79 // or last removal will start or stop |idle_cleanup_timer_| respectively. | 80 // or last removal will start or stop |idle_cleanup_timer_| respectively. |
| 80 void AddIdleDelegate(int delegate_id); | 81 void AddIdleDelegate(int delegate_id); |
| 81 void RemoveIdleDelegate(int delegate_id); | 82 void RemoveIdleDelegate(int delegate_id); |
| 82 | 83 |
| 83 // Runs periodically to suspend idle delegates in |idle_delegate_map_|. | 84 // Runs periodically to suspend idle delegates in |idle_delegate_map_|. |
| 84 void CleanupIdleDelegates(); | 85 void CleanupIdleDelegates(); |
| 85 | 86 |
| 87 // Setter for |is_playing_background_video_| that updates the metrics. |
| 88 void SetIsPlayingBackgroundVideo(bool is_playing); |
| 89 |
| 86 bool has_played_media_ = false; | 90 bool has_played_media_ = false; |
| 87 IDMap<Observer> id_map_; | 91 IDMap<Observer> id_map_; |
| 88 | 92 |
| 89 // Tracks which delegates have entered an idle state. After some period of | 93 // Tracks which delegates have entered an idle state. After some period of |
| 90 // inactivity these players will be suspended to release unused resources. | 94 // inactivity these players will be suspended to release unused resources. |
| 91 bool idle_cleanup_running_ = false; | 95 bool idle_cleanup_running_ = false; |
| 92 std::map<int, base::TimeTicks> idle_delegate_map_; | 96 std::map<int, base::TimeTicks> idle_delegate_map_; |
| 93 base::RepeatingTimer idle_cleanup_timer_; | 97 base::RepeatingTimer idle_cleanup_timer_; |
| 94 | 98 |
| 95 // Amount of time allowed to elapse after a delegate enters the paused before | 99 // Amount of time allowed to elapse after a delegate enters the paused before |
| 96 // the delegate is suspended. | 100 // the delegate is suspended. |
| 97 base::TimeDelta idle_timeout_; | 101 base::TimeDelta idle_timeout_; |
| 98 | 102 |
| 99 // The polling interval used for checking the delegates to see if any have | 103 // The polling interval used for checking the delegates to see if any have |
| 100 // exceeded |idle_timeout_| since their last pause state. | 104 // exceeded |idle_timeout_| since their last pause state. |
| 101 base::TimeDelta idle_cleanup_interval_; | 105 base::TimeDelta idle_cleanup_interval_; |
| 102 | 106 |
| 103 // Clock used for calculating when delegates have expired. May be overridden | 107 // Clock used for calculating when delegates have expired. May be overridden |
| 104 // for testing. | 108 // for testing. |
| 105 std::unique_ptr<base::DefaultTickClock> default_tick_clock_; | 109 std::unique_ptr<base::DefaultTickClock> default_tick_clock_; |
| 106 base::TickClock* tick_clock_; | 110 base::TickClock* tick_clock_; |
| 107 | 111 |
| 108 // If a video is playing in the background. Set when user resumes a video | 112 // If a video is playing in the background. Set when user resumes a video |
| 109 // allowing it to play and reset when either user pauses it or it goes | 113 // allowing it to play and reset when either user pauses it or it goes |
| 110 // foreground. | 114 // foreground. |
| 111 bool is_playing_background_video_ = false; | 115 bool is_playing_background_video_ = false; |
| 112 | 116 |
| 117 // Keeps track of when the background video playback started for metrics. |
| 118 base::TimeTicks background_video_playing_start_time_; |
| 119 |
| 113 // The currently playing local videos. Used to determine whether | 120 // The currently playing local videos. Used to determine whether |
| 114 // OnMediaDelegatePlay() should allow the videos to play in the background or | 121 // OnMediaDelegatePlay() should allow the videos to play in the background or |
| 115 // not. | 122 // not. |
| 116 std::set<int> playing_videos_; | 123 std::set<int> playing_videos_; |
| 117 | 124 |
| 118 DISALLOW_COPY_AND_ASSIGN(RendererWebMediaPlayerDelegate); | 125 DISALLOW_COPY_AND_ASSIGN(RendererWebMediaPlayerDelegate); |
| 119 }; | 126 }; |
| 120 | 127 |
| 121 } // namespace media | 128 } // namespace media |
| 122 | 129 |
| 123 #endif // CONTENT_RENDERER_MEDIA_RENDERER_WEBMEDIAPLAYER_DELEGATE_H_ | 130 #endif // CONTENT_RENDERER_MEDIA_RENDERER_WEBMEDIAPLAYER_DELEGATE_H_ |
| OLD | NEW |