| 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_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_IMPL_H_ |
| 6 #define CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_IMPL_H_ | 6 #define CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_IMPL_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 // TODO(thakis,mlamouri): MediaSessionImpl isn't CONTENT_EXPORT'd because it | 62 // TODO(thakis,mlamouri): MediaSessionImpl isn't CONTENT_EXPORT'd because it |
| 63 // creates complicated build issues with WebContentsUserData being a | 63 // creates complicated build issues with WebContentsUserData being a |
| 64 // non-exported template, see https://crbug.com/589840. As a result, the class | 64 // non-exported template, see https://crbug.com/589840. As a result, the class |
| 65 // uses CONTENT_EXPORT for methods that are being used from tests. | 65 // uses CONTENT_EXPORT for methods that are being used from tests. |
| 66 // CONTENT_EXPORT should be moved back to the class when the Windows build will | 66 // CONTENT_EXPORT should be moved back to the class when the Windows build will |
| 67 // work with it. | 67 // work with it. |
| 68 class MediaSessionImpl : public MediaSession, | 68 class MediaSessionImpl : public MediaSession, |
| 69 public WebContentsObserver, | 69 public WebContentsObserver, |
| 70 protected WebContentsUserData<MediaSessionImpl> { | 70 protected WebContentsUserData<MediaSessionImpl> { |
| 71 public: | 71 public: |
| 72 // Only visible to tests. | |
| 73 enum class State { ACTIVE, SUSPENDED, INACTIVE }; | 72 enum class State { ACTIVE, SUSPENDED, INACTIVE }; |
| 74 | 73 |
| 75 // Returns the MediaSessionImpl associated to this WebContents. Creates one if | 74 // Returns the MediaSessionImpl associated to this WebContents. Creates one if |
| 76 // none is currently available. | 75 // none is currently available. |
| 77 CONTENT_EXPORT static MediaSessionImpl* Get(WebContents* web_contents); | 76 CONTENT_EXPORT static MediaSessionImpl* Get(WebContents* web_contents); |
| 78 | 77 |
| 79 ~MediaSessionImpl() override; | 78 ~MediaSessionImpl() override; |
| 80 | 79 |
| 81 #if defined(OS_ANDROID) | 80 #if defined(OS_ANDROID) |
| 82 static MediaSession* FromJavaMediaSession( | 81 static MediaSession* FromJavaMediaSession( |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 void RemoveObserver(MediaSessionObserver* observer) override; | 139 void RemoveObserver(MediaSessionObserver* observer) override; |
| 141 | 140 |
| 142 // Returns if the session can be controlled by Resume() and Suspend calls | 141 // Returns if the session can be controlled by Resume() and Suspend calls |
| 143 // above. | 142 // above. |
| 144 CONTENT_EXPORT bool IsControllable() const; | 143 CONTENT_EXPORT bool IsControllable() const; |
| 145 | 144 |
| 146 // Returns if the session is currently active. | 145 // Returns if the session is currently active. |
| 147 CONTENT_EXPORT bool IsActive() const; | 146 CONTENT_EXPORT bool IsActive() const; |
| 148 | 147 |
| 149 // Returns if the session is currently suspended. | 148 // Returns if the session is currently suspended. |
| 150 // TODO(mlamouri): IsSuspended() below checks if the state is not ACTIVE | |
| 151 // instead of checking if the state is SUSPENDED. In order to not have to | |
| 152 // change all the callers and make the current refactoring ridiculously huge, | |
| 153 // this method is introduced temporarily and will be removed later. | |
| 154 CONTENT_EXPORT bool IsReallySuspended() const; | |
| 155 | |
| 156 // Returns if the session is currently suspended or inactive. | |
| 157 CONTENT_EXPORT bool IsSuspended() const; | 149 CONTENT_EXPORT bool IsSuspended() const; |
| 158 | 150 |
| 159 // Returns the audio focus type. The type is updated everytime after the | 151 // Returns the audio focus type. The type is updated everytime after the |
| 160 // session requests audio focus. | 152 // session requests audio focus. |
| 161 CONTENT_EXPORT AudioFocusManager::AudioFocusType audio_focus_type() const { | 153 CONTENT_EXPORT AudioFocusManager::AudioFocusType audio_focus_type() const { |
| 162 return audio_focus_type_; | 154 return audio_focus_type_; |
| 163 } | 155 } |
| 164 | 156 |
| 165 // Returns whether the session has Pepper instances. | 157 // Returns whether the session has Pepper instances. |
| 166 bool HasPepper() const; | 158 bool HasPepper() const; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 friend class content::WebContentsUserData<MediaSessionImpl>; | 190 friend class content::WebContentsUserData<MediaSessionImpl>; |
| 199 friend class ::MediaSessionImplBrowserTest; | 191 friend class ::MediaSessionImplBrowserTest; |
| 200 friend class content::MediaSessionImplVisibilityBrowserTest; | 192 friend class content::MediaSessionImplVisibilityBrowserTest; |
| 201 friend class content::AudioFocusManagerTest; | 193 friend class content::AudioFocusManagerTest; |
| 202 friend class content::MediaSessionImplServiceRoutingTest; | 194 friend class content::MediaSessionImplServiceRoutingTest; |
| 203 friend class content::MediaSessionImplStateObserver; | 195 friend class content::MediaSessionImplStateObserver; |
| 204 friend class content::MediaSessionServiceImplBrowserTest; | 196 friend class content::MediaSessionServiceImplBrowserTest; |
| 205 | 197 |
| 206 CONTENT_EXPORT void SetDelegateForTests( | 198 CONTENT_EXPORT void SetDelegateForTests( |
| 207 std::unique_ptr<AudioFocusDelegate> delegate); | 199 std::unique_ptr<AudioFocusDelegate> delegate); |
| 208 CONTENT_EXPORT bool IsActiveForTest() const; | |
| 209 CONTENT_EXPORT void RemoveAllPlayersForTest(); | 200 CONTENT_EXPORT void RemoveAllPlayersForTest(); |
| 210 CONTENT_EXPORT MediaSessionUmaHelper* uma_helper_for_test(); | 201 CONTENT_EXPORT MediaSessionUmaHelper* uma_helper_for_test(); |
| 211 | 202 |
| 212 // Representation of a player for the MediaSessionImpl. | 203 // Representation of a player for the MediaSessionImpl. |
| 213 struct PlayerIdentifier { | 204 struct PlayerIdentifier { |
| 214 PlayerIdentifier(MediaSessionPlayerObserver* observer, int player_id); | 205 PlayerIdentifier(MediaSessionPlayerObserver* observer, int player_id); |
| 215 PlayerIdentifier(const PlayerIdentifier&) = default; | 206 PlayerIdentifier(const PlayerIdentifier&) = default; |
| 216 | 207 |
| 217 void operator=(const PlayerIdentifier&) = delete; | 208 void operator=(const PlayerIdentifier&) = delete; |
| 218 bool operator==(const PlayerIdentifier& player_identifier) const; | 209 bool operator==(const PlayerIdentifier& player_identifier) const; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 // It sets audio_focus_state_ and notifies observers about the state change. | 246 // It sets audio_focus_state_ and notifies observers about the state change. |
| 256 void SetAudioFocusState(State audio_focus_state); | 247 void SetAudioFocusState(State audio_focus_state); |
| 257 | 248 |
| 258 // Update the volume multiplier when ducking state changes. | 249 // Update the volume multiplier when ducking state changes. |
| 259 void UpdateVolumeMultiplier(); | 250 void UpdateVolumeMultiplier(); |
| 260 | 251 |
| 261 // Get the volume multiplier, which depends on whether the media session is | 252 // Get the volume multiplier, which depends on whether the media session is |
| 262 // ducking. | 253 // ducking. |
| 263 double GetVolumeMultiplier() const; | 254 double GetVolumeMultiplier() const; |
| 264 | 255 |
| 265 // Compute if the actual playback state is paused using both the | 256 // Compute if the actual playback state is paused by combining the |
| 266 // MediaSessionService declared state and guessed state. | 257 // MediaSessionService declared state and guessed state (audio_focus_state_). |
| 267 bool IsActuallyPaused() const; | 258 bool IsActuallyPaused() const; |
| 268 | 259 |
| 269 // Registers a MediaSessionImpl state change callback. | 260 // Registers a MediaSessionImpl state change callback. |
| 270 CONTENT_EXPORT std::unique_ptr<base::CallbackList<void(State)>::Subscription> | 261 CONTENT_EXPORT std::unique_ptr<base::CallbackList<void(State)>::Subscription> |
| 271 RegisterMediaSessionStateChangedCallbackForTest( | 262 RegisterMediaSessionStateChangedCallbackForTest( |
| 272 const StateChangedCallback& cb); | 263 const StateChangedCallback& cb); |
| 273 | 264 |
| 274 CONTENT_EXPORT bool AddPepperPlayer(MediaSessionPlayerObserver* observer, | 265 CONTENT_EXPORT bool AddPepperPlayer(MediaSessionPlayerObserver* observer, |
| 275 int player_id); | 266 int player_id); |
| 276 | 267 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 ServicesMap services_; | 313 ServicesMap services_; |
| 323 // The currently routed service (non-owned pointer). | 314 // The currently routed service (non-owned pointer). |
| 324 MediaSessionServiceImpl* routed_service_; | 315 MediaSessionServiceImpl* routed_service_; |
| 325 | 316 |
| 326 DISALLOW_COPY_AND_ASSIGN(MediaSessionImpl); | 317 DISALLOW_COPY_AND_ASSIGN(MediaSessionImpl); |
| 327 }; | 318 }; |
| 328 | 319 |
| 329 } // namespace content | 320 } // namespace content |
| 330 | 321 |
| 331 #endif // CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_IMPL_H_ | 322 #endif // CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_IMPL_H_ |
| OLD | NEW |