Chromium Code Reviews| 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/id_map.h" | 11 #include "base/id_map.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "content/browser/media/session/media_session_uma_helper.h" | 13 #include "content/browser/media/session/media_session_uma_helper.h" |
| 13 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
| 14 #include "content/public/browser/web_contents_observer.h" | 15 #include "content/public/browser/web_contents_observer.h" |
| 15 #include "content/public/browser/web_contents_user_data.h" | 16 #include "content/public/browser/web_contents_user_data.h" |
| 16 #include "content/public/common/media_metadata.h" | 17 #include "content/public/common/media_metadata.h" |
| 17 | 18 |
| 18 class MediaSessionBrowserTest; | 19 class MediaSessionBrowserTest; |
| 19 | 20 |
| 20 namespace content { | 21 namespace content { |
| 21 | 22 |
| 22 class MediaSessionDelegate; | 23 class MediaSessionDelegate; |
| 23 class MediaSessionObserver; | 24 class MediaSessionObserver; |
| 25 class MediaSessionStateObserver; | |
| 26 class MediaSessionVisibilityBrowserTestBase; | |
| 24 | 27 |
| 25 // MediaSession manages the media session and audio focus for a given | 28 // MediaSession manages the media session and audio focus for a given |
| 26 // WebContents. It is requesting the audio focus, pausing when requested by the | 29 // WebContents. It is requesting the audio focus, pausing when requested by the |
| 27 // system and dropping it on demand. | 30 // system and dropping it on demand. |
| 28 // The audio focus can be of two types: Transient or Content. A Transient audio | 31 // The audio focus can be of two types: Transient or Content. A Transient audio |
| 29 // focus will allow other players to duck instead of pausing and will be | 32 // focus will allow other players to duck instead of pausing and will be |
| 30 // declared as temporary to the system. A Content audio focus will not be | 33 // declared as temporary to the system. A Content audio focus will not be |
| 31 // declared as temporary and will not allow other players to duck. If a given | 34 // declared as temporary and will not allow other players to duck. If a given |
| 32 // WebContents can only have one audio focus at a time, it will be Content in | 35 // WebContents can only have one audio focus at a time, it will be Content in |
| 33 // case of Transient and Content audio focus are both requested. | 36 // case of Transient and Content audio focus are both requested. |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 // change all the callers and make the current refactoring ridiculously huge, | 119 // change all the callers and make the current refactoring ridiculously huge, |
| 117 // this method is introduced temporarily and will be removed later. | 120 // this method is introduced temporarily and will be removed later. |
| 118 bool IsReallySuspended() const; | 121 bool IsReallySuspended() const; |
| 119 | 122 |
| 120 // Returns if the session is currently suspended or inactive. | 123 // Returns if the session is currently suspended or inactive. |
| 121 CONTENT_EXPORT bool IsSuspended() const; | 124 CONTENT_EXPORT bool IsSuspended() const; |
| 122 | 125 |
| 123 private: | 126 private: |
| 124 friend class content::WebContentsUserData<MediaSession>; | 127 friend class content::WebContentsUserData<MediaSession>; |
| 125 friend class ::MediaSessionBrowserTest; | 128 friend class ::MediaSessionBrowserTest; |
| 129 friend class content::MediaSessionVisibilityBrowserTestBase; | |
| 130 friend class content::MediaSessionStateObserver; | |
| 126 | 131 |
| 127 CONTENT_EXPORT void SetDelegateForTests( | 132 CONTENT_EXPORT void SetDelegateForTests( |
| 128 scoped_ptr<MediaSessionDelegate> delegate); | 133 scoped_ptr<MediaSessionDelegate> delegate); |
| 129 CONTENT_EXPORT bool IsActiveForTest() const; | 134 CONTENT_EXPORT bool IsActiveForTest() const; |
| 130 CONTENT_EXPORT Type audio_focus_type_for_test() const; | 135 CONTENT_EXPORT Type audio_focus_type_for_test() const; |
| 131 CONTENT_EXPORT void RemoveAllPlayersForTest(); | 136 CONTENT_EXPORT void RemoveAllPlayersForTest(); |
| 132 CONTENT_EXPORT MediaSessionUmaHelper* uma_helper_for_test(); | 137 CONTENT_EXPORT MediaSessionUmaHelper* uma_helper_for_test(); |
| 133 | 138 |
| 134 enum class State { | 139 enum class State { |
| 135 ACTIVE, | 140 ACTIVE, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 147 | 152 |
| 148 // Hash operator for base::hash_map<>. | 153 // Hash operator for base::hash_map<>. |
| 149 struct Hash { | 154 struct Hash { |
| 150 size_t operator()(const PlayerIdentifier& player_identifier) const; | 155 size_t operator()(const PlayerIdentifier& player_identifier) const; |
| 151 }; | 156 }; |
| 152 | 157 |
| 153 MediaSessionObserver* observer; | 158 MediaSessionObserver* observer; |
| 154 int player_id; | 159 int player_id; |
| 155 }; | 160 }; |
| 156 using PlayersMap = base::hash_set<PlayerIdentifier, PlayerIdentifier::Hash>; | 161 using PlayersMap = base::hash_set<PlayerIdentifier, PlayerIdentifier::Hash>; |
| 162 typedef base::Callback<void(State)> StateChangedCallback; | |
|
DaleCurtis
2016/03/31 16:50:26
as of c++11 we use 'using' now, check out http://c
Zhiqiang Zhang (Slow)
2016/03/31 19:58:39
Done.
| |
| 157 | 163 |
| 158 CONTENT_EXPORT explicit MediaSession(WebContents* web_contents); | 164 CONTENT_EXPORT explicit MediaSession(WebContents* web_contents); |
| 159 | 165 |
| 160 void Initialize(); | 166 void Initialize(); |
| 161 | 167 |
| 162 CONTENT_EXPORT void OnSuspendInternal(SuspendType type, State new_state); | 168 CONTENT_EXPORT void OnSuspendInternal(SuspendType type, State new_state); |
| 163 CONTENT_EXPORT void OnResumeInternal(SuspendType type); | 169 CONTENT_EXPORT void OnResumeInternal(SuspendType type); |
| 164 | 170 |
| 165 // Requests audio focus to the MediaSessionDelegate. | 171 // Requests audio focus to the MediaSessionDelegate. |
| 166 // Returns whether the request was granted. | 172 // Returns whether the request was granted. |
| 167 bool RequestSystemAudioFocus(Type type); | 173 bool RequestSystemAudioFocus(Type type); |
| 168 | 174 |
| 169 // To be called after a call to AbandonAudioFocus() in order request the | 175 // To be called after a call to AbandonAudioFocus() in order request the |
| 170 // delegate to abandon the audio focus. | 176 // delegate to abandon the audio focus. |
| 171 void AbandonSystemAudioFocusIfNeeded(); | 177 void AbandonSystemAudioFocusIfNeeded(); |
| 172 | 178 |
| 173 // Notifies WebContents about the state change of the media session. | 179 // Notifies WebContents about the state change of the media session. |
| 174 void UpdateWebContents(); | 180 void UpdateWebContents(); |
| 175 | 181 |
| 176 // Internal method that should be used instead of setting audio_focus_state_. | 182 // Internal method that should be used instead of setting audio_focus_state_. |
| 177 // It sets audio_focus_state_ and notifies observers about the state change. | 183 // It sets audio_focus_state_ and notifies observers about the state change. |
| 178 void SetAudioFocusState(State audio_focus_state); | 184 void SetAudioFocusState(State audio_focus_state); |
| 179 | 185 |
| 186 // Registers a MediaSession state change callback. | |
| 187 CONTENT_EXPORT scoped_ptr<base::CallbackList<void(State)>::Subscription> | |
| 188 RegisterMediaSessionStateChangedCallbackForTest( | |
| 189 const StateChangedCallback& cb); | |
| 190 | |
| 180 scoped_ptr<MediaSessionDelegate> delegate_; | 191 scoped_ptr<MediaSessionDelegate> delegate_; |
| 181 PlayersMap players_; | 192 PlayersMap players_; |
| 182 | 193 |
| 183 State audio_focus_state_; | 194 State audio_focus_state_; |
| 184 SuspendType suspend_type_; | 195 SuspendType suspend_type_; |
| 185 Type audio_focus_type_; | 196 Type audio_focus_type_; |
| 186 | 197 |
| 187 MediaSessionUmaHelper uma_helper_; | 198 MediaSessionUmaHelper uma_helper_; |
| 188 | 199 |
| 189 // The volume multiplier of this session. All players in this session should | 200 // The volume multiplier of this session. All players in this session should |
| 190 // multiply their volume with this multiplier to get the effective volume. | 201 // multiply their volume with this multiplier to get the effective volume. |
| 191 double volume_multiplier_; | 202 double volume_multiplier_; |
| 192 | 203 |
| 193 MediaMetadata metadata_; | 204 MediaMetadata metadata_; |
| 205 base::CallbackList<void(State)> media_session_state_listeners_; | |
| 194 | 206 |
| 195 DISALLOW_COPY_AND_ASSIGN(MediaSession); | 207 DISALLOW_COPY_AND_ASSIGN(MediaSession); |
| 196 }; | 208 }; |
| 197 | 209 |
| 198 } // namespace content | 210 } // namespace content |
| 199 | 211 |
| 200 #endif // CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_H_ | 212 #endif // CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_H_ |
| OLD | NEW |