OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_BROWSER_MEDIA_MEDIA_WEB_CONTENTS_OBSERVER_H_ | 5 #ifndef CONTENT_BROWSER_MEDIA_MEDIA_WEB_CONTENTS_OBSERVER_H_ |
6 #define CONTENT_BROWSER_MEDIA_MEDIA_WEB_CONTENTS_OBSERVER_H_ | 6 #define CONTENT_BROWSER_MEDIA_MEDIA_WEB_CONTENTS_OBSERVER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 30 matching lines...) Expand all Loading... |
41 | 41 |
42 bool has_audio_power_save_blocker_for_testing() const { | 42 bool has_audio_power_save_blocker_for_testing() const { |
43 return !!audio_power_save_blocker_; | 43 return !!audio_power_save_blocker_; |
44 } | 44 } |
45 | 45 |
46 bool has_video_power_save_blocker_for_testing() const { | 46 bool has_video_power_save_blocker_for_testing() const { |
47 return !!video_power_save_blocker_; | 47 return !!video_power_save_blocker_; |
48 } | 48 } |
49 | 49 |
50 private: | 50 private: |
51 void OnMediaPlayingNotification(RenderFrameHost* render_frame_host, | 51 void OnMediaDestroyed(RenderFrameHost* render_frame_host, int delegate_id); |
52 int64_t player_cookie, | 52 void OnMediaPaused(RenderFrameHost* render_frame_host, |
53 bool has_video, | 53 int delegate_id, |
54 bool has_audio, | 54 bool reached_end_of_stream); |
55 bool is_remote); | 55 void OnMediaPlaying(RenderFrameHost* render_frame_host, |
56 void OnMediaPausedNotification(RenderFrameHost* render_frame_host, | 56 int delegate_id, |
57 int64_t player_cookie); | 57 bool has_video, |
| 58 bool has_audio, |
| 59 bool is_remote, |
| 60 base::TimeDelta duration); |
58 | 61 |
59 // Clear |render_frame_host|'s tracking entry for its power save blockers. | 62 // Clear |render_frame_host|'s tracking entry for its power save blockers. |
60 void ClearPowerSaveBlockers(RenderFrameHost* render_frame_host); | 63 void ClearPowerSaveBlockers(RenderFrameHost* render_frame_host); |
61 | 64 |
62 // Creates an audio or video power save blocker respectively. | 65 // Creates an audio or video power save blocker respectively. |
63 void CreateAudioPowerSaveBlocker(); | 66 void CreateAudioPowerSaveBlocker(); |
64 void CreateVideoPowerSaveBlocker(); | 67 void CreateVideoPowerSaveBlocker(); |
65 | 68 |
66 // Releases the audio power save blockers if |active_audio_players_| is empty. | 69 // Releases the audio power save blockers if |active_audio_players_| is empty. |
67 // Likewise, releases the video power save blockers if |active_video_players_| | 70 // Likewise, releases the video power save blockers if |active_video_players_| |
68 // is empty. | 71 // is empty. |
69 void MaybeReleasePowerSaveBlockers(); | 72 void MaybeReleasePowerSaveBlockers(); |
70 | 73 |
71 // Helper methods for adding or removing player entries in |player_map|. | 74 // Helper methods for adding or removing player entries in |player_map|. |
72 using PlayerList = std::vector<int64_t>; | 75 using PlayerList = std::vector<int>; |
73 using ActiveMediaPlayerMap = std::map<RenderFrameHost*, PlayerList>; | 76 using ActiveMediaPlayerMap = std::map<RenderFrameHost*, PlayerList>; |
74 void AddMediaPlayerEntry(const MediaPlayerId& id, | 77 void AddMediaPlayerEntry(const MediaPlayerId& id, |
75 ActiveMediaPlayerMap* player_map); | 78 ActiveMediaPlayerMap* player_map); |
76 // Returns true if an entry is actually removed. | 79 // Returns true if an entry is actually removed. |
77 bool RemoveMediaPlayerEntry(const MediaPlayerId& id, | 80 bool RemoveMediaPlayerEntry(const MediaPlayerId& id, |
78 ActiveMediaPlayerMap* player_map); | 81 ActiveMediaPlayerMap* player_map); |
79 // Removes all entries from |player_map| for |render_frame_host|. Removed | 82 // Removes all entries from |player_map| for |render_frame_host|. Removed |
80 // entries are added to |removed_players|. | 83 // entries are added to |removed_players|. |
81 void RemoveAllMediaPlayerEntries(RenderFrameHost* render_frame_host, | 84 void RemoveAllMediaPlayerEntries(RenderFrameHost* render_frame_host, |
82 ActiveMediaPlayerMap* player_map, | 85 ActiveMediaPlayerMap* player_map, |
83 std::set<MediaPlayerId>* removed_players); | 86 std::set<MediaPlayerId>* removed_players); |
84 | 87 |
85 // Tracking variables and associated power save blockers for media playback. | 88 // Tracking variables and associated power save blockers for media playback. |
86 ActiveMediaPlayerMap active_audio_players_; | 89 ActiveMediaPlayerMap active_audio_players_; |
87 ActiveMediaPlayerMap active_video_players_; | 90 ActiveMediaPlayerMap active_video_players_; |
88 scoped_ptr<PowerSaveBlocker> audio_power_save_blocker_; | 91 scoped_ptr<PowerSaveBlocker> audio_power_save_blocker_; |
89 scoped_ptr<PowerSaveBlocker> video_power_save_blocker_; | 92 scoped_ptr<PowerSaveBlocker> video_power_save_blocker_; |
90 | 93 |
91 DISALLOW_COPY_AND_ASSIGN(MediaWebContentsObserver); | 94 DISALLOW_COPY_AND_ASSIGN(MediaWebContentsObserver); |
92 }; | 95 }; |
93 | 96 |
94 } // namespace content | 97 } // namespace content |
95 | 98 |
96 #endif // CONTENT_BROWSER_MEDIA_MEDIA_WEB_CONTENTS_OBSERVER_H_ | 99 #endif // CONTENT_BROWSER_MEDIA_MEDIA_WEB_CONTENTS_OBSERVER_H_ |
OLD | NEW |