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/containers/scoped_ptr_hash_map.h" |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "content/browser/media/session/media_session_controllers_manager.h" | 16 #include "content/browser/media/session/media_session_controllers_manager.h" |
16 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
17 #include "content/public/browser/web_contents_observer.h" | 18 #include "content/public/browser/web_contents_observer.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 namespace device { |
24 class PowerSaveBlocker; | 25 class PowerSaveBlocker; |
25 } // namespace device | 26 } // namespace device |
26 | 27 |
27 namespace media { | 28 namespace media { |
28 enum class MediaContentType; | 29 enum class MediaContentType; |
29 } // namespace media | 30 } // namespace media |
30 | 31 |
31 namespace content { | 32 namespace content { |
32 | 33 |
| 34 class BrowserMediaSessionManager; |
| 35 |
33 // This class manages all RenderFrame based media related managers at the | 36 // This class manages all RenderFrame based media related managers at the |
34 // browser side. It receives IPC messages from media RenderFrameObservers and | 37 // browser side. It receives IPC messages from media RenderFrameObservers and |
35 // forwards them to the corresponding managers. The managers are responsible | 38 // forwards them to the corresponding managers. The managers are responsible |
36 // for sending IPCs back to the RenderFrameObservers at the render side. | 39 // for sending IPCs back to the RenderFrameObservers at the render side. |
37 class CONTENT_EXPORT MediaWebContentsObserver : public WebContentsObserver { | 40 class CONTENT_EXPORT MediaWebContentsObserver : public WebContentsObserver { |
38 public: | 41 public: |
39 explicit MediaWebContentsObserver(WebContents* web_contents); | 42 explicit MediaWebContentsObserver(WebContents* web_contents); |
40 ~MediaWebContentsObserver() override; | 43 ~MediaWebContentsObserver() override; |
41 | 44 |
| 45 // Gets the BrowserMediaSessionManager associated with the given |
| 46 // |render_frame_host|. Creates a new one if it doesn't exist. The caller |
| 47 // doesn't own the returned pointer. |
| 48 BrowserMediaSessionManager* GetMediaSessionManager( |
| 49 RenderFrameHost* render_frame_host); |
| 50 |
| 51 // Sets or overrides the BrowserMediaSessionManager for the given |
| 52 // |render_frame_host|. |
| 53 void SetMediaSessionManagerForTest( |
| 54 RenderFrameHost* render_frame_host, |
| 55 std::unique_ptr<BrowserMediaSessionManager> manager); |
| 56 |
42 // Called by WebContentsImpl when the audible state may have changed. | 57 // Called by WebContentsImpl when the audible state may have changed. |
43 void MaybeUpdateAudibleState(); | 58 void MaybeUpdateAudibleState(); |
44 | 59 |
45 // WebContentsObserver implementation. | 60 // WebContentsObserver implementation. |
46 void WebContentsDestroyed() override; | 61 void WebContentsDestroyed() override; |
47 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override; | 62 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override; |
48 bool OnMessageReceived(const IPC::Message& message, | 63 bool OnMessageReceived(const IPC::Message& message, |
49 RenderFrameHost* render_frame_host) override; | 64 RenderFrameHost* render_frame_host) override; |
50 void WasShown() override; | 65 void WasShown() override; |
51 void WasHidden() override; | 66 void WasHidden() override; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 std::set<MediaPlayerId>* removed_players); | 117 std::set<MediaPlayerId>* removed_players); |
103 | 118 |
104 // Tracking variables and associated power save blockers for media playback. | 119 // Tracking variables and associated power save blockers for media playback. |
105 ActiveMediaPlayerMap active_audio_players_; | 120 ActiveMediaPlayerMap active_audio_players_; |
106 ActiveMediaPlayerMap active_video_players_; | 121 ActiveMediaPlayerMap active_video_players_; |
107 std::unique_ptr<device::PowerSaveBlocker> audio_power_save_blocker_; | 122 std::unique_ptr<device::PowerSaveBlocker> audio_power_save_blocker_; |
108 std::unique_ptr<device::PowerSaveBlocker> video_power_save_blocker_; | 123 std::unique_ptr<device::PowerSaveBlocker> video_power_save_blocker_; |
109 | 124 |
110 MediaSessionControllersManager session_controllers_manager_; | 125 MediaSessionControllersManager session_controllers_manager_; |
111 | 126 |
| 127 // Map from RenderFrameHost* to BrowserMediaSessionManager. |
| 128 using MediaSessionManagerMap = |
| 129 base::ScopedPtrHashMap<RenderFrameHost*, |
| 130 std::unique_ptr<BrowserMediaSessionManager>>; |
| 131 MediaSessionManagerMap media_session_managers_; |
| 132 |
112 DISALLOW_COPY_AND_ASSIGN(MediaWebContentsObserver); | 133 DISALLOW_COPY_AND_ASSIGN(MediaWebContentsObserver); |
113 }; | 134 }; |
114 | 135 |
115 } // namespace content | 136 } // namespace content |
116 | 137 |
117 #endif // CONTENT_BROWSER_MEDIA_MEDIA_WEB_CONTENTS_OBSERVER_H_ | 138 #endif // CONTENT_BROWSER_MEDIA_MEDIA_WEB_CONTENTS_OBSERVER_H_ |
OLD | NEW |