| 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 | 9 |
| 10 #include "base/id_map.h" | 10 #include "base/id_map.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 base::TimeDelta duration) override; | 46 base::TimeDelta duration) override; |
| 47 void DidPause(int delegate_id, bool reached_end_of_stream) override; | 47 void DidPause(int delegate_id, bool reached_end_of_stream) override; |
| 48 void PlayerGone(int delegate_id) override; | 48 void PlayerGone(int delegate_id) override; |
| 49 bool IsHidden() override; | 49 bool IsHidden() override; |
| 50 | 50 |
| 51 // content::RenderFrameObserver overrides. | 51 // content::RenderFrameObserver overrides. |
| 52 void WasHidden() override; | 52 void WasHidden() override; |
| 53 void WasShown() override; | 53 void WasShown() override; |
| 54 bool OnMessageReceived(const IPC::Message& msg) override; | 54 bool OnMessageReceived(const IPC::Message& msg) override; |
| 55 | 55 |
| 56 // Sets |idle_cleanup_enabled_| to true, zeros out |idle_cleanup_interval_|, | 56 // Zeros out |idle_cleanup_interval_|, and sets |idle_timeout_| to |
| 57 // and sets |idle_timeout_| to |idle_timeout|. A zero cleanup interval will | 57 // |idle_timeout|. A zero cleanup interval will cause the idle timer to run |
| 58 // cause the idle timer to run with each run of the message loop. | 58 // with each run of the message loop. |
| 59 void EnableInstantIdleCleanupForTesting(base::TimeDelta idle_timeout, | 59 void SetIdleCleanupParamsForTesting(base::TimeDelta idle_timeout, |
| 60 base::TickClock* tick_clock); | 60 base::TickClock* tick_clock); |
| 61 bool IsIdleCleanupTimerRunningForTesting() const { | 61 bool IsIdleCleanupTimerRunningForTesting() const { |
| 62 return idle_cleanup_timer_.IsRunning(); | 62 return idle_cleanup_timer_.IsRunning(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 private: | 65 private: |
| 66 void OnMediaDelegatePause(int delegate_id); | 66 void OnMediaDelegatePause(int delegate_id); |
| 67 void OnMediaDelegatePlay(int delegate_id); | 67 void OnMediaDelegatePlay(int delegate_id); |
| 68 void OnMediaDelegateSuspendAllMediaPlayers(); | 68 void OnMediaDelegateSuspendAllMediaPlayers(); |
| 69 void OnMediaDelegateVolumeMultiplierUpdate(int delegate_id, | 69 void OnMediaDelegateVolumeMultiplierUpdate(int delegate_id, |
| 70 double multiplier); | 70 double multiplier); |
| 71 | 71 |
| 72 // Adds or removes a delegate from |idle_delegate_map_|. The first insertion | 72 // Adds or removes a delegate from |idle_delegate_map_|. The first insertion |
| 73 // or last removal will start or stop |idle_cleanup_timer_| respectively. | 73 // or last removal will start or stop |idle_cleanup_timer_| respectively. |
| 74 void AddIdleDelegate(int delegate_id); | 74 void AddIdleDelegate(int delegate_id); |
| 75 void RemoveIdleDelegate(int delegate_id); | 75 void RemoveIdleDelegate(int delegate_id); |
| 76 | 76 |
| 77 // Runs periodically to suspend idle delegates in |idle_delegate_map_|. | 77 // Runs periodically to suspend idle delegates in |idle_delegate_map_|. |
| 78 void CleanupIdleDelegates(); | 78 void CleanupIdleDelegates(); |
| 79 | 79 |
| 80 bool has_played_media_ = false; | 80 bool has_played_media_ = false; |
| 81 IDMap<Observer> id_map_; | 81 IDMap<Observer> id_map_; |
| 82 | 82 |
| 83 // Tracks which delegates have entered an idle state. After some period of | 83 // Tracks which delegates have entered an idle state. After some period of |
| 84 // inactivity these players will be suspended to release unused resources. | 84 // inactivity these players will be suspended to release unused resources. |
| 85 bool idle_cleanup_running_ = false; | 85 bool idle_cleanup_running_ = false; |
| 86 std::map<int, base::TimeTicks> idle_delegate_map_; | 86 std::map<int, base::TimeTicks> idle_delegate_map_; |
| 87 base::RepeatingTimer idle_cleanup_timer_; | 87 base::RepeatingTimer idle_cleanup_timer_; |
| 88 | 88 |
| 89 // Controls whether cleanup of idle delegates is enabled or not as well as the | |
| 90 // polling interval and timeout period for delegates; overridden for testing. | |
| 91 bool idle_cleanup_enabled_ = false; | |
| 92 | |
| 93 // Amount of time allowed to elapse after a delegate enters the paused before | 89 // Amount of time allowed to elapse after a delegate enters the paused before |
| 94 // the delegate is suspended. | 90 // the delegate is suspended. |
| 95 base::TimeDelta idle_timeout_; | 91 base::TimeDelta idle_timeout_; |
| 96 | 92 |
| 97 // The polling interval used for checking the delegates to see if any have | 93 // The polling interval used for checking the delegates to see if any have |
| 98 // exceeded |idle_timeout_| since their last pause state. | 94 // exceeded |idle_timeout_| since their last pause state. |
| 99 base::TimeDelta idle_cleanup_interval_; | 95 base::TimeDelta idle_cleanup_interval_; |
| 100 | 96 |
| 101 // Clock used for calculating when delegates have expired. May be overridden | 97 // Clock used for calculating when delegates have expired. May be overridden |
| 102 // for testing. | 98 // for testing. |
| 103 scoped_ptr<base::DefaultTickClock> default_tick_clock_; | 99 scoped_ptr<base::DefaultTickClock> default_tick_clock_; |
| 104 base::TickClock* tick_clock_; | 100 base::TickClock* tick_clock_; |
| 105 | 101 |
| 106 DISALLOW_COPY_AND_ASSIGN(RendererWebMediaPlayerDelegate); | 102 DISALLOW_COPY_AND_ASSIGN(RendererWebMediaPlayerDelegate); |
| 107 }; | 103 }; |
| 108 | 104 |
| 109 } // namespace media | 105 } // namespace media |
| 110 | 106 |
| 111 #endif // CONTENT_RENDERER_MEDIA_RENDERER_WEBMEDIAPLAYER_DELEGATE_H_ | 107 #endif // CONTENT_RENDERER_MEDIA_RENDERER_WEBMEDIAPLAYER_DELEGATE_H_ |
| OLD | NEW |