Index: content/browser/media/session/media_session.cc |
diff --git a/content/browser/media/session/media_session.cc b/content/browser/media/session/media_session.cc |
index ea25caad4df7d8adeb230f46523aa00d64e6c3d1..73b5f47941a18ac898cfb6d30aca2336fe402ef9 100644 |
--- a/content/browser/media/session/media_session.cc |
+++ b/content/browser/media/session/media_session.cc |
@@ -5,6 +5,7 @@ |
#include "content/browser/media/session/media_session.h" |
#include "content/browser/media/session/audio_focus_delegate.h" |
+#include "content/browser/media/session/media_session_observer.h" |
#include "content/browser/media/session/media_session_player_observer.h" |
#include "content/browser/web_contents/web_contents_impl.h" |
#include "content/public/browser/web_contents.h" |
@@ -57,6 +58,26 @@ MediaSession* MediaSession::Get(WebContents* web_contents) { |
MediaSession::~MediaSession() { |
DCHECK(players_.empty()); |
DCHECK(audio_focus_state_ == State::INACTIVE); |
+ owned_observers_.clear(); |
whywhat
2016/10/21 18:28:14
I think MediaSession should notify MediaSessionObs
derekjchow1
2016/10/21 20:47:30
+1. This is the pattern used in WebContentsObserve
|
+} |
+ |
+void MediaSession::AddObserver(MediaSessionObserver* observer) { |
+ observers_.AddObserver(observer); |
+} |
+ |
+void MediaSession::RemoveObserver(MediaSessionObserver* observer) { |
+ observers_.RemoveObserver(observer); |
+ for (auto iter = owned_observers_.begin(); iter != owned_observers_.end(); |
derekjchow1
2016/10/21 20:47:30
You could use std::find here.
|
+ ++iter) { |
+ if (iter->get() == observer) |
+ owned_observers_.erase(iter); |
+ return; |
whywhat
2016/10/21 18:28:14
this return belongs to the if above
|
+ } |
+} |
+ |
+void MediaSession::PassObserverOwnership( |
+ std::unique_ptr<MediaSessionObserver> observer) { |
+ owned_observers_.push_back(std::move(observer)); |
} |
void MediaSession::WebContentsDestroyed() { |
@@ -74,8 +95,9 @@ void MediaSession::WebContentsDestroyed() { |
void MediaSession::SetMetadata(const base::Optional<MediaMetadata>& metadata) { |
metadata_ = metadata; |
- static_cast<WebContentsImpl*>(web_contents()) |
- ->OnMediaSessionMetadataChanged(); |
+ |
+ for (auto& observer : observers_) |
+ observer.MediaSessionMetadataChanged(metadata_); |
} |
bool MediaSession::AddPlayer(MediaSessionPlayerObserver* observer, |
@@ -410,7 +432,8 @@ void MediaSession::AbandonSystemAudioFocusIfNeeded() { |
void MediaSession::UpdateWebContents() { |
media_session_state_listeners_.Notify(audio_focus_state_); |
- static_cast<WebContentsImpl*>(web_contents())->OnMediaSessionStateChanged(); |
+ for (auto& observer : observers_) |
+ observer.MediaSessionStateChanged(IsControllable(), IsSuspended()); |
} |
void MediaSession::SetAudioFocusState(State audio_focus_state) { |