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_BROWSER_MEDIA_SESSION_MEDIA_SESSION_H_ | 5 #ifndef CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_H_ |
6 #define CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_H_ | 6 #define CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include "base/callback_list.h" | 10 #include "base/callback_list.h" |
11 #include "base/id_map.h" | 11 #include "base/id_map.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/observer_list.h" |
13 #include "base/optional.h" | 14 #include "base/optional.h" |
14 #include "content/browser/media/session/audio_focus_manager.h" | 15 #include "content/browser/media/session/audio_focus_manager.h" |
15 #include "content/browser/media/session/media_session_uma_helper.h" | 16 #include "content/browser/media/session/media_session_uma_helper.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 #include "content/public/browser/web_contents_user_data.h" | 19 #include "content/public/browser/web_contents_user_data.h" |
19 #include "content/public/common/media_metadata.h" | 20 #include "content/public/common/media_metadata.h" |
20 | 21 |
21 class MediaSessionBrowserTest; | 22 class MediaSessionBrowserTest; |
22 | 23 |
23 namespace media { | 24 namespace media { |
24 enum class MediaContentType; | 25 enum class MediaContentType; |
25 } // namespace media | 26 } // namespace media |
26 | 27 |
27 namespace content { | 28 namespace content { |
28 | 29 |
29 class AudioFocusDelegate; | 30 class AudioFocusDelegate; |
30 class AudioFocusManagerTest; | 31 class AudioFocusManagerTest; |
31 class MediaSessionPlayerObserver; | 32 class MediaSessionPlayerObserver; |
| 33 class MediaSessionObserver; |
32 class MediaSessionStateObserver; | 34 class MediaSessionStateObserver; |
33 class MediaSessionVisibilityBrowserTest; | 35 class MediaSessionVisibilityBrowserTest; |
34 | 36 |
35 // MediaSession manages the media session and audio focus for a given | 37 // MediaSession manages the media session and audio focus for a given |
36 // WebContents. It is requesting the audio focus, pausing when requested by the | 38 // WebContents. It is requesting the audio focus, pausing when requested by the |
37 // system and dropping it on demand. | 39 // system and dropping it on demand. |
38 // The audio focus can be of two types: Transient or Content. A Transient audio | 40 // The audio focus can be of two types: Transient or Content. A Transient audio |
39 // focus will allow other players to duck instead of pausing and will be | 41 // focus will allow other players to duck instead of pausing and will be |
40 // declared as temporary to the system. A Content audio focus will not be | 42 // declared as temporary to the system. A Content audio focus will not be |
41 // declared as temporary and will not allow other players to duck. If a given | 43 // declared as temporary and will not allow other players to duck. If a given |
(...skipping 22 matching lines...) Expand all Loading... |
64 SUSPENDED, | 66 SUSPENDED, |
65 INACTIVE | 67 INACTIVE |
66 }; | 68 }; |
67 | 69 |
68 // Returns the MediaSession associated to this WebContents. Creates one if | 70 // Returns the MediaSession associated to this WebContents. Creates one if |
69 // none is currently available. | 71 // none is currently available. |
70 CONTENT_EXPORT static MediaSession* Get(WebContents* web_contents); | 72 CONTENT_EXPORT static MediaSession* Get(WebContents* web_contents); |
71 | 73 |
72 ~MediaSession() override; | 74 ~MediaSession() override; |
73 | 75 |
| 76 // Add and remove an observer for MediaSession messages. Clients must remove |
| 77 // the observer before they go away, or pass the observer ownership to |
| 78 // MediaSession via PassObserverOwnership (then the observer will go away when |
| 79 // the session is destroyed. |
| 80 void AddObserver(MediaSessionObserver* observer); |
| 81 void RemoveObserver(MediaSessionObserver* observer); |
| 82 |
| 83 // Pass a MediaSessionObserver to be owned and managed by this session. The |
| 84 // observer will be removed when the session is destroyed. |
| 85 void PassObserverOwnership(std::unique_ptr<MediaSessionObserver> observer); |
| 86 |
74 void SetMetadata(const base::Optional<MediaMetadata>& metadata); | 87 void SetMetadata(const base::Optional<MediaMetadata>& metadata); |
75 const base::Optional<MediaMetadata>& metadata() const { return metadata_; } | 88 const base::Optional<MediaMetadata>& metadata() const { return metadata_; } |
76 | 89 |
77 // Adds the given player to the current media session. Returns whether the | 90 // Adds the given player to the current media session. Returns whether the |
78 // player was successfully added. If it returns false, AddPlayer() should be | 91 // player was successfully added. If it returns false, AddPlayer() should be |
79 // called again later. | 92 // called again later. |
80 CONTENT_EXPORT bool AddPlayer(MediaSessionPlayerObserver* observer, | 93 CONTENT_EXPORT bool AddPlayer(MediaSessionPlayerObserver* observer, |
81 int player_id, | 94 int player_id, |
82 media::MediaContentType media_content_type); | 95 media::MediaContentType media_content_type); |
83 | 96 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 MediaSessionUmaHelper uma_helper_; | 243 MediaSessionUmaHelper uma_helper_; |
231 | 244 |
232 // The ducking state of this media session. The initial value is |false|, and | 245 // The ducking state of this media session. The initial value is |false|, and |
233 // is set to |true| after StartDucking(), and will be set to |false| after | 246 // is set to |true| after StartDucking(), and will be set to |false| after |
234 // StopDucking(). | 247 // StopDucking(). |
235 bool is_ducking_; | 248 bool is_ducking_; |
236 | 249 |
237 base::Optional<MediaMetadata> metadata_; | 250 base::Optional<MediaMetadata> metadata_; |
238 base::CallbackList<void(State)> media_session_state_listeners_; | 251 base::CallbackList<void(State)> media_session_state_listeners_; |
239 | 252 |
| 253 // The list of observers notified when the MediaSession changes. |
| 254 base::ObserverList<MediaSessionObserver> observers_; |
| 255 |
| 256 // The MediaSessionObservers that are owned by this session, they will be |
| 257 // destroyed and removed. |
| 258 std::vector<std::unique_ptr<MediaSessionObserver>> owned_observers_; |
| 259 |
240 DISALLOW_COPY_AND_ASSIGN(MediaSession); | 260 DISALLOW_COPY_AND_ASSIGN(MediaSession); |
241 }; | 261 }; |
242 | 262 |
243 } // namespace content | 263 } // namespace content |
244 | 264 |
245 #endif // CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_H_ | 265 #endif // CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_H_ |
OLD | NEW |