Index: content/browser/media/session/media_session.h |
diff --git a/content/browser/media/session/media_session.h b/content/browser/media/session/media_session.h |
index 9239c7854a18b18326e2c2983451e49490922982..ae0b5a2b429005877bc33108266eddf57ccad062 100644 |
--- a/content/browser/media/session/media_session.h |
+++ b/content/browser/media/session/media_session.h |
@@ -10,6 +10,7 @@ |
#include "base/callback_list.h" |
#include "base/id_map.h" |
#include "base/macros.h" |
+#include "base/observer_list.h" |
#include "base/optional.h" |
#include "content/browser/media/session/audio_focus_manager.h" |
#include "content/browser/media/session/media_session_uma_helper.h" |
@@ -29,6 +30,7 @@ namespace content { |
class AudioFocusDelegate; |
class AudioFocusManagerTest; |
class MediaSessionPlayerObserver; |
+class MediaSessionObserver; |
class MediaSessionStateObserver; |
class MediaSessionVisibilityBrowserTest; |
@@ -71,6 +73,17 @@ class MediaSession : public WebContentsObserver, |
~MediaSession() override; |
+ // Add and remove an observer for MediaSession messages. Clients must remove |
+ // the observer before they go away, or pass the observer ownership to |
+ // MediaSession via PassObserverOwnership (then the observer will go away when |
+ // the session is destroyed. |
+ void AddObserver(MediaSessionObserver* observer); |
+ void RemoveObserver(MediaSessionObserver* observer); |
+ |
+ // Pass a MediaSessionObserver to be owned and managed by this session. The |
+ // observer will be removed when the session is destroyed. |
+ void PassObserverOwnership(std::unique_ptr<MediaSessionObserver> observer); |
whywhat
2016/10/21 18:28:14
what I don't like about this is that it's only use
|
+ |
void SetMetadata(const base::Optional<MediaMetadata>& metadata); |
const base::Optional<MediaMetadata>& metadata() const { return metadata_; } |
@@ -237,6 +250,13 @@ class MediaSession : public WebContentsObserver, |
base::Optional<MediaMetadata> metadata_; |
base::CallbackList<void(State)> media_session_state_listeners_; |
+ // The list of observers notified when the MediaSession changes. |
+ base::ObserverList<MediaSessionObserver> observers_; |
+ |
+ // The MediaSessionObservers that are owned by this session, they will be |
+ // destroyed and removed. |
+ std::vector<std::unique_ptr<MediaSessionObserver>> owned_observers_; |
+ |
DISALLOW_COPY_AND_ASSIGN(MediaSession); |
}; |