| 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/android/scoped_java_ref.h" | 
|   10 #include "base/callback_list.h" |   11 #include "base/callback_list.h" | 
|   11 #include "base/id_map.h" |   12 #include "base/id_map.h" | 
|   12 #include "base/macros.h" |   13 #include "base/macros.h" | 
 |   14 #include "base/observer_list.h" | 
|   13 #include "base/optional.h" |   15 #include "base/optional.h" | 
|   14 #include "content/browser/media/session/audio_focus_manager.h" |   16 #include "content/browser/media/session/audio_focus_manager.h" | 
|   15 #include "content/browser/media/session/media_session_uma_helper.h" |   17 #include "content/browser/media/session/media_session_uma_helper.h" | 
|   16 #include "content/common/content_export.h" |   18 #include "content/common/content_export.h" | 
|   17 #include "content/public/browser/web_contents_observer.h" |   19 #include "content/public/browser/web_contents_observer.h" | 
|   18 #include "content/public/browser/web_contents_user_data.h" |   20 #include "content/public/browser/web_contents_user_data.h" | 
|   19 #include "content/public/common/media_metadata.h" |   21 #include "content/public/common/media_metadata.h" | 
|   20  |   22  | 
|   21 class MediaSessionBrowserTest; |   23 class MediaSessionBrowserTest; | 
|   22  |   24  | 
|   23 namespace media { |   25 namespace media { | 
|   24 enum class MediaContentType; |   26 enum class MediaContentType; | 
|   25 }  // namespace media |   27 }  // namespace media | 
|   26  |   28  | 
|   27 namespace content { |   29 namespace content { | 
|   28  |   30  | 
|   29 class AudioFocusDelegate; |   31 class AudioFocusDelegate; | 
|   30 class AudioFocusManagerTest; |   32 class AudioFocusManagerTest; | 
|   31 class MediaSessionPlayerObserver; |   33 class MediaSessionPlayerObserver; | 
 |   34 class MediaSessionObserver; | 
|   32 class MediaSessionStateObserver; |   35 class MediaSessionStateObserver; | 
|   33 class MediaSessionVisibilityBrowserTest; |   36 class MediaSessionVisibilityBrowserTest; | 
|   34  |   37  | 
 |   38 #if defined(OS_ANDROID) | 
 |   39 class MediaSessionAndroid; | 
 |   40 #endif  // defined(OS_ANDROID) | 
 |   41  | 
|   35 // MediaSession manages the media session and audio focus for a given |   42 // MediaSession manages the media session and audio focus for a given | 
|   36 // WebContents. It is requesting the audio focus, pausing when requested by the |   43 // WebContents. It is requesting the audio focus, pausing when requested by the | 
|   37 // system and dropping it on demand. |   44 // system and dropping it on demand. | 
|   38 // The audio focus can be of two types: Transient or Content. A Transient audio |   45 // 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 |   46 // 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 |   47 // 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 |   48 // declared as temporary and will not allow other players to duck. If a given | 
|   42 // WebContents can only have one audio focus at a time, it will be Content in |   49 // WebContents can only have one audio focus at a time, it will be Content in | 
|   43 // case of Transient and Content audio focus are both requested. |   50 // case of Transient and Content audio focus are both requested. | 
|   44 // TODO(thakis,mlamouri): MediaSession isn't CONTENT_EXPORT'd because it creates |   51 // TODO(thakis,mlamouri): MediaSession isn't CONTENT_EXPORT'd because it creates | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
|   64     SUSPENDED, |   71     SUSPENDED, | 
|   65     INACTIVE |   72     INACTIVE | 
|   66   }; |   73   }; | 
|   67  |   74  | 
|   68   // Returns the MediaSession associated to this WebContents. Creates one if |   75   // Returns the MediaSession associated to this WebContents. Creates one if | 
|   69   // none is currently available. |   76   // none is currently available. | 
|   70   CONTENT_EXPORT static MediaSession* Get(WebContents* web_contents); |   77   CONTENT_EXPORT static MediaSession* Get(WebContents* web_contents); | 
|   71  |   78  | 
|   72   ~MediaSession() override; |   79   ~MediaSession() override; | 
|   73  |   80  | 
 |   81 #if defined(OS_ANDROID) | 
 |   82   static MediaSession* FromJavaMediaSession( | 
 |   83       const base::android::JavaRef<jobject>& j_media_session); | 
 |   84   MediaSessionAndroid* session_android() const { | 
 |   85     return session_android_.get(); | 
 |   86   } | 
 |   87 #endif  // defined(OS_ANDROID) | 
 |   88  | 
 |   89   // Add and remove an observer for MediaSession messages. Clients must remove | 
 |   90   // the observer before they go away, or pass the observer ownership to | 
 |   91   // MediaSession via PassObserverOwnership (then the observer will go away when | 
 |   92   // the session is destroyed. AddObserver() can only be called in | 
 |   93   // MediaSessionObserver constructor, and cannot be called explicitly. | 
 |   94   void AddObserver(MediaSessionObserver* observer); | 
 |   95   void RemoveObserver(MediaSessionObserver* observer); | 
 |   96  | 
|   74   void SetMetadata(const base::Optional<MediaMetadata>& metadata); |   97   void SetMetadata(const base::Optional<MediaMetadata>& metadata); | 
|   75   const base::Optional<MediaMetadata>& metadata() const { return metadata_; } |   98   const base::Optional<MediaMetadata>& metadata() const { return metadata_; } | 
|   76  |   99  | 
|   77   // Adds the given player to the current media session. Returns whether the |  100   // Adds the given player to the current media session. Returns whether the | 
|   78   // player was successfully added. If it returns false, AddPlayer() should be |  101   // player was successfully added. If it returns false, AddPlayer() should be | 
|   79   // called again later. |  102   // called again later. | 
|   80   CONTENT_EXPORT bool AddPlayer(MediaSessionPlayerObserver* observer, |  103   CONTENT_EXPORT bool AddPlayer(MediaSessionPlayerObserver* observer, | 
|   81                                 int player_id, |  104                                 int player_id, | 
|   82                                 media::MediaContentType media_content_type); |  105                                 media::MediaContentType media_content_type); | 
|   83  |  106  | 
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  230   MediaSessionUmaHelper uma_helper_; |  253   MediaSessionUmaHelper uma_helper_; | 
|  231  |  254  | 
|  232   // The ducking state of this media session. The initial value is |false|, and |  255   // 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 |  256   // is set to |true| after StartDucking(), and will be set to |false| after | 
|  234   // StopDucking(). |  257   // StopDucking(). | 
|  235   bool is_ducking_; |  258   bool is_ducking_; | 
|  236  |  259  | 
|  237   base::Optional<MediaMetadata> metadata_; |  260   base::Optional<MediaMetadata> metadata_; | 
|  238   base::CallbackList<void(State)> media_session_state_listeners_; |  261   base::CallbackList<void(State)> media_session_state_listeners_; | 
|  239  |  262  | 
 |  263   // The list of observers notified when the MediaSession changes. | 
 |  264   base::ObserverList<MediaSessionObserver> observers_; | 
 |  265  | 
 |  266 #if defined(OS_ANDROID) | 
 |  267   std::unique_ptr<MediaSessionAndroid> session_android_; | 
 |  268 #endif  // defined(OS_ANDROID) | 
 |  269  | 
|  240   DISALLOW_COPY_AND_ASSIGN(MediaSession); |  270   DISALLOW_COPY_AND_ASSIGN(MediaSession); | 
|  241 }; |  271 }; | 
|  242  |  272  | 
|  243 }  // namespace content |  273 }  // namespace content | 
|  244  |  274  | 
|  245 #endif  // CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_H_ |  275 #endif  // CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_H_ | 
| OLD | NEW |