Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Unified Diff: content/browser/media/session/media_session.h

Issue 2439483003: Link MediaSessionTabHelper with native MediaSession [CL is going to be split] (Closed)
Patch Set: addressed comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);
};

Powered by Google App Engine
This is Rietveld 408576698