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> |
11 #include <memory> | 11 #include <memory> |
12 #include <set> | 12 #include <set> |
13 | 13 |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "content/browser/media/session/media_session_controllers_manager.h" | 15 #include "content/browser/media/session/media_session_controllers_manager.h" |
16 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
17 #include "content/public/browser/web_contents_observer.h" | 17 #include "content/public/browser/web_contents_observer.h" |
18 #include "device/wake_lock/public/interfaces/wake_lock_service.mojom.h" | |
18 | 19 |
19 #if defined(OS_ANDROID) | 20 #if defined(OS_ANDROID) |
20 #include "ui/android/view_android.h" | 21 #include "ui/android/view_android.h" |
21 #endif // OS_ANDROID | 22 #endif // OS_ANDROID |
22 | 23 |
23 namespace device { | |
24 class PowerSaveBlocker; | |
25 } // namespace device | |
26 | |
27 namespace media { | 24 namespace media { |
28 enum class MediaContentType; | 25 enum class MediaContentType; |
29 } // namespace media | 26 } // namespace media |
30 | 27 |
31 namespace content { | 28 namespace content { |
32 | 29 |
33 // This class manages all RenderFrame based media related managers at the | 30 // This class manages all RenderFrame based media related managers at the |
34 // browser side. It receives IPC messages from media RenderFrameObservers and | 31 // browser side. It receives IPC messages from media RenderFrameObservers and |
35 // forwards them to the corresponding managers. The managers are responsible | 32 // forwards them to the corresponding managers. The managers are responsible |
36 // for sending IPCs back to the RenderFrameObservers at the render side. | 33 // for sending IPCs back to the RenderFrameObservers at the render side. |
(...skipping 19 matching lines...) Expand all Loading... | |
56 RenderFrameHost* render_frame_host) override; | 53 RenderFrameHost* render_frame_host) override; |
57 void WasShown() override; | 54 void WasShown() override; |
58 void WasHidden() override; | 55 void WasHidden() override; |
59 | 56 |
60 // TODO(zqzhang): this method is temporarily in MediaWebContentsObserver as | 57 // TODO(zqzhang): this method is temporarily in MediaWebContentsObserver as |
61 // the effectively fullscreen video code is also here. We need to consider | 58 // the effectively fullscreen video code is also here. We need to consider |
62 // merging the logic of effectively fullscreen, hiding media controls and | 59 // merging the logic of effectively fullscreen, hiding media controls and |
63 // fullscreening video element to the same place. | 60 // fullscreening video element to the same place. |
64 void RequestPersistentVideo(bool value); | 61 void RequestPersistentVideo(bool value); |
65 | 62 |
66 bool has_audio_power_save_blocker_for_testing() const { | 63 bool has_audio_wake_lock_for_testing() const { |
67 return !!audio_power_save_blocker_; | 64 return has_audio_wake_lock_for_testing_; |
DaleCurtis
2017/05/02 17:08:42
Why change this? YOu don't need the bool variables
ke.he
2017/05/04 11:58:24
The "mojo::MakeRequest(&audio_wake_lock_)" is alwa
| |
68 } | 65 } |
69 | 66 |
70 bool has_video_power_save_blocker_for_testing() const { | 67 bool has_video_wake_lock_for_testing() const { |
71 return !!video_power_save_blocker_; | 68 return has_video_wake_lock_for_testing_; |
72 } | 69 } |
73 | 70 |
74 protected: | 71 protected: |
75 MediaSessionControllersManager* session_controllers_manager() { | 72 MediaSessionControllersManager* session_controllers_manager() { |
76 return &session_controllers_manager_; | 73 return &session_controllers_manager_; |
77 } | 74 } |
78 | 75 |
79 private: | 76 private: |
80 void OnMediaDestroyed(RenderFrameHost* render_frame_host, int delegate_id); | 77 void OnMediaDestroyed(RenderFrameHost* render_frame_host, int delegate_id); |
81 void OnMediaPaused(RenderFrameHost* render_frame_host, | 78 void OnMediaPaused(RenderFrameHost* render_frame_host, |
82 int delegate_id, | 79 int delegate_id, |
83 bool reached_end_of_stream); | 80 bool reached_end_of_stream); |
84 void OnMediaPlaying(RenderFrameHost* render_frame_host, | 81 void OnMediaPlaying(RenderFrameHost* render_frame_host, |
85 int delegate_id, | 82 int delegate_id, |
86 bool has_video, | 83 bool has_video, |
87 bool has_audio, | 84 bool has_audio, |
88 bool is_remote, | 85 bool is_remote, |
89 media::MediaContentType media_content_type); | 86 media::MediaContentType media_content_type); |
90 void OnMediaEffectivelyFullscreenChange(RenderFrameHost* render_frame_host, | 87 void OnMediaEffectivelyFullscreenChange(RenderFrameHost* render_frame_host, |
91 int delegate_id, | 88 int delegate_id, |
92 bool is_fullscreen); | 89 bool is_fullscreen); |
93 | 90 |
94 // Clear |render_frame_host|'s tracking entry for its power save blockers. | 91 // Clear |render_frame_host|'s tracking entry for its WakeLocks. |
95 void ClearPowerSaveBlockers(RenderFrameHost* render_frame_host); | 92 void ClearWakeLocks(RenderFrameHost* render_frame_host); |
96 | 93 |
97 // Creates an audio or video power save blocker respectively. | 94 device::mojom::WakeLockServicePtr& GetAudioWakeLock(); |
DaleCurtis
2017/05/02 17:08:42
Return device::mojom::WakeLockService* instead? Pe
ke.he
2017/05/04 11:58:23
Done.
| |
98 void CreateAudioPowerSaveBlocker(); | 95 device::mojom::WakeLockServicePtr& GetVideoWakeLock(); |
99 void CreateVideoPowerSaveBlocker(); | 96 bool has_audio_wake_lock_for_testing_; |
DaleCurtis
2017/05/02 17:08:42
Variables below functions.
ke.he
2017/05/04 11:58:23
Done.
| |
97 bool has_video_wake_lock_for_testing_; | |
100 | 98 |
101 // Releases the audio power save blockers if |active_audio_players_| is empty. | 99 // Try to request audio wake lock. |
DaleCurtis
2017/05/02 17:08:42
These comments aren't really useful, so no need fo
ke.he
2017/05/04 11:58:23
Done.
| |
102 // Likewise, releases the video power save blockers if |active_video_players_| | 100 void LockAudio(); |
103 // is empty. | 101 // Try to request video wake lock. |
104 void MaybeReleasePowerSaveBlockers(); | 102 void LockVideo(); |
103 | |
104 // Cancel the video wake lock if |active_video_players_| is empty. | |
105 void MaybeCancelVideoLock(); | |
106 | |
107 // Cancel the audio wake lock. | |
108 void CancelAudioLock(); | |
105 | 109 |
106 // Helper methods for adding or removing player entries in |player_map|. | 110 // Helper methods for adding or removing player entries in |player_map|. |
107 using PlayerSet = std::set<int>; | 111 using PlayerSet = std::set<int>; |
108 using ActiveMediaPlayerMap = std::map<RenderFrameHost*, PlayerSet>; | 112 using ActiveMediaPlayerMap = std::map<RenderFrameHost*, PlayerSet>; |
109 void AddMediaPlayerEntry(const MediaPlayerId& id, | 113 void AddMediaPlayerEntry(const MediaPlayerId& id, |
110 ActiveMediaPlayerMap* player_map); | 114 ActiveMediaPlayerMap* player_map); |
111 // Returns true if an entry is actually removed. | 115 // Returns true if an entry is actually removed. |
112 bool RemoveMediaPlayerEntry(const MediaPlayerId& id, | 116 bool RemoveMediaPlayerEntry(const MediaPlayerId& id, |
113 ActiveMediaPlayerMap* player_map); | 117 ActiveMediaPlayerMap* player_map); |
114 // Removes all entries from |player_map| for |render_frame_host|. Removed | 118 // Removes all entries from |player_map| for |render_frame_host|. Removed |
115 // entries are added to |removed_players|. | 119 // entries are added to |removed_players|. |
116 void RemoveAllMediaPlayerEntries(RenderFrameHost* render_frame_host, | 120 void RemoveAllMediaPlayerEntries(RenderFrameHost* render_frame_host, |
117 ActiveMediaPlayerMap* player_map, | 121 ActiveMediaPlayerMap* player_map, |
118 std::set<MediaPlayerId>* removed_players); | 122 std::set<MediaPlayerId>* removed_players); |
119 | 123 |
120 // Tracking variables and associated power save blockers for media playback. | 124 // Tracking variables and associated wake locks for media playback. |
121 ActiveMediaPlayerMap active_audio_players_; | 125 ActiveMediaPlayerMap active_audio_players_; |
122 ActiveMediaPlayerMap active_video_players_; | 126 ActiveMediaPlayerMap active_video_players_; |
123 std::unique_ptr<device::PowerSaveBlocker> audio_power_save_blocker_; | 127 device::mojom::WakeLockServicePtr audio_wake_lock_; |
124 std::unique_ptr<device::PowerSaveBlocker> video_power_save_blocker_; | 128 device::mojom::WakeLockServicePtr video_wake_lock_; |
125 base::Optional<MediaPlayerId> fullscreen_player_; | 129 base::Optional<MediaPlayerId> fullscreen_player_; |
126 | 130 |
127 MediaSessionControllersManager session_controllers_manager_; | 131 MediaSessionControllersManager session_controllers_manager_; |
128 | 132 |
129 DISALLOW_COPY_AND_ASSIGN(MediaWebContentsObserver); | 133 DISALLOW_COPY_AND_ASSIGN(MediaWebContentsObserver); |
130 }; | 134 }; |
131 | 135 |
132 } // namespace content | 136 } // namespace content |
133 | 137 |
134 #endif // CONTENT_BROWSER_MEDIA_MEDIA_WEB_CONTENTS_OBSERVER_H_ | 138 #endif // CONTENT_BROWSER_MEDIA_MEDIA_WEB_CONTENTS_OBSERVER_H_ |
OLD | NEW |