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> |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 void OnMediaDelegatePlay(int delegate_id); | 79 void OnMediaDelegatePlay(int delegate_id); |
80 void OnMediaDelegateSuspendAllMediaPlayers(); | 80 void OnMediaDelegateSuspendAllMediaPlayers(); |
81 void OnMediaDelegateVolumeMultiplierUpdate(int delegate_id, | 81 void OnMediaDelegateVolumeMultiplierUpdate(int delegate_id, |
82 double multiplier); | 82 double multiplier); |
83 | 83 |
84 // Adds or removes a delegate from |idle_delegate_map_|. The first insertion | 84 // Adds or removes a delegate from |idle_delegate_map_|. The first insertion |
85 // or last removal will start or stop |idle_cleanup_timer_| respectively. | 85 // or last removal will start or stop |idle_cleanup_timer_| respectively. |
86 void AddIdleDelegate(int delegate_id); | 86 void AddIdleDelegate(int delegate_id); |
87 void RemoveIdleDelegate(int delegate_id); | 87 void RemoveIdleDelegate(int delegate_id); |
88 | 88 |
89 // Runs periodically to suspend idle delegates in |idle_delegate_map_|. | 89 // Runs periodically to suspend idle delegates in |idle_delegate_map_| which |
90 void CleanupIdleDelegates(); | 90 // have been idle for longer than |idle_timeout|. |
| 91 void CleanupIdleDelegates(base::TimeDelta idle_timeout); |
91 | 92 |
92 // Setter for |is_playing_background_video_| that updates the metrics. | 93 // Setter for |is_playing_background_video_| that updates the metrics. |
93 void SetIsPlayingBackgroundVideo(bool is_playing); | 94 void SetIsPlayingBackgroundVideo(bool is_playing); |
94 | 95 |
95 bool has_played_media_ = false; | 96 bool has_played_media_ = false; |
96 IDMap<Observer> id_map_; | 97 IDMap<Observer> id_map_; |
97 | 98 |
98 // Tracks which delegates have entered an idle state. After some period of | 99 // Tracks which delegates have entered an idle state. After some period of |
99 // inactivity these players will be suspended to release unused resources. | 100 // inactivity these players will be suspended to release unused resources. |
100 bool idle_cleanup_running_ = false; | 101 bool idle_cleanup_running_ = false; |
101 std::map<int, base::TimeTicks> idle_delegate_map_; | 102 std::map<int, base::TimeTicks> idle_delegate_map_; |
102 base::RepeatingTimer idle_cleanup_timer_; | 103 base::Timer idle_cleanup_timer_; |
103 | 104 |
104 // Amount of time allowed to elapse after a delegate enters the paused before | 105 // Amount of time allowed to elapse after a delegate enters the paused before |
105 // the delegate is suspended. | 106 // the delegate is suspended. |
106 base::TimeDelta idle_timeout_; | 107 base::TimeDelta idle_timeout_; |
107 | 108 |
108 // The polling interval used for checking the delegates to see if any have | 109 // The polling interval used for checking the delegates to see if any have |
109 // exceeded |idle_timeout_| since their last pause state. | 110 // exceeded |idle_timeout_| since their last pause state. |
110 base::TimeDelta idle_cleanup_interval_; | 111 base::TimeDelta idle_cleanup_interval_; |
111 | 112 |
112 // Clock used for calculating when delegates have expired. May be overridden | 113 // Clock used for calculating when delegates have expired. May be overridden |
(...skipping 15 matching lines...) Expand all Loading... |
128 // OnMediaDelegatePlay() should allow the videos to play in the background or | 129 // OnMediaDelegatePlay() should allow the videos to play in the background or |
129 // not. | 130 // not. |
130 std::set<int> playing_videos_; | 131 std::set<int> playing_videos_; |
131 | 132 |
132 DISALLOW_COPY_AND_ASSIGN(RendererWebMediaPlayerDelegate); | 133 DISALLOW_COPY_AND_ASSIGN(RendererWebMediaPlayerDelegate); |
133 }; | 134 }; |
134 | 135 |
135 } // namespace media | 136 } // namespace media |
136 | 137 |
137 #endif // CONTENT_RENDERER_MEDIA_RENDERER_WEBMEDIAPLAYER_DELEGATE_H_ | 138 #endif // CONTENT_RENDERER_MEDIA_RENDERER_WEBMEDIAPLAYER_DELEGATE_H_ |
OLD | NEW |