Index: content/browser/media/android/media_session.cc |
diff --git a/content/browser/media/android/media_session.cc b/content/browser/media/android/media_session.cc |
index a32159679fa0711ca3c059b47a1b5a190683ff87..c9eab552a91a706f8d8d2aae2fe81f44c902370a 100644 |
--- a/content/browser/media/android/media_session.cc |
+++ b/content/browser/media/android/media_session.cc |
@@ -54,11 +54,38 @@ MediaSession* MediaSession::Get(WebContents* web_contents) { |
return session; |
} |
+// static |
+MediaSession* MediaSession::Create(WebContents* web_contents, int session_id) { |
+ MediaSession* session = new MediaSession(web_contents, session_id); |
+ session->Initialize(); |
+ return session; |
+} |
+ |
MediaSession::~MediaSession() { |
DCHECK(players_.empty()); |
DCHECK(audio_focus_state_ == State::INACTIVE); |
} |
+bool MediaSession::Activate() { |
+ if (audio_focus_state_ == State::ACTIVE) |
+ return true; |
+ |
+ const Type type = Type::Content; |
+ if (!RequestSystemAudioFocus(type)) |
+ return false; |
+ |
+ audio_focus_state_ = State::ACTIVE; |
+ audio_focus_type_ = type; |
+ UpdateWebContents(); |
+ |
+ return true; |
+} |
+ |
+void MediaSession::Deactivate() { |
+ AbandonSystemAudioFocusIfNeeded(); |
+ DCHECK(audio_focus_state_ == State::INACTIVE); |
+} |
+ |
bool MediaSession::AddPlayer(MediaSessionObserver* observer, |
int player_id, |
Type type) { |
@@ -267,10 +294,11 @@ void MediaSession::OnResumeInternal(SuspendType type) { |
UpdateWebContents(); |
} |
-MediaSession::MediaSession(WebContents* web_contents) |
+MediaSession::MediaSession(WebContents* web_contents, int session_id_) |
: WebContentsObserver(web_contents), |
audio_focus_state_(State::INACTIVE), |
- audio_focus_type_(Type::Transient) {} |
+ audio_focus_type_(Type::Transient), |
+ session_id_(session_id_) {} |
void MediaSession::Initialize() { |
JNIEnv* env = base::android::AttachCurrentThread(); |
@@ -310,7 +338,8 @@ void MediaSession::AbandonSystemAudioFocusIfNeeded() { |
} |
void MediaSession::UpdateWebContents() { |
- static_cast<WebContentsImpl*>(web_contents())->OnMediaSessionStateChanged(); |
+ static_cast<WebContentsImpl*>(web_contents()) |
+ ->OnMediaSessionStateChanged(this); |
} |
void MediaSession::SetAudioFocusState(State audio_focus_state) { |