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

Side by Side Diff: content/browser/media/android/media_session.cc

Issue 1259633002: NOT FOR LANDING Implement WebMediaSession (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: hack until something works Created 5 years, 4 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 unified diff | Download patch
OLDNEW
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 #include "content/browser/media/android/media_session.h" 5 #include "content/browser/media/android/media_session.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "content/browser/media/android/media_session_observer.h" 8 #include "content/browser/media/android/media_session_observer.h"
9 #include "content/browser/web_contents/web_contents_impl.h" 9 #include "content/browser/web_contents/web_contents_impl.h"
10 #include "content/public/browser/web_contents.h" 10 #include "content/public/browser/web_contents.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 session->Initialize(); 48 session->Initialize();
49 } 49 }
50 return session; 50 return session;
51 } 51 }
52 52
53 MediaSession::~MediaSession() { 53 MediaSession::~MediaSession() {
54 DCHECK(players_.empty()); 54 DCHECK(players_.empty());
55 DCHECK(audio_focus_state_ == State::INACTIVE); 55 DCHECK(audio_focus_state_ == State::INACTIVE);
56 } 56 }
57 57
58 bool MediaSession::Activate() {
59 if (audio_focus_state_ == State::ACTIVE)
60 return true;
61
62 const Type type = Type::Content;
63 if (!RequestSystemAudioFocus(type))
64 return false;
65
66 audio_focus_state_ = State::ACTIVE;
67 audio_focus_type_ = type;
68 UpdateWebContents();
69
70 return true;
71 }
72
73 void MediaSession::Deactivate() {
74 AbandonSystemAudioFocusIfNeeded();
mlamouri (slow - plz ping) 2015/08/24 12:55:24 Looking at that code, it's a bit odd that RequestS
philipj_slow 2015/08/26 07:39:48 Yes, this doesn't make any sense, I just hacked un
75 DCHECK(audio_focus_state_ == State::INACTIVE);
76 }
77
58 bool MediaSession::AddPlayer(MediaSessionObserver* observer, 78 bool MediaSession::AddPlayer(MediaSessionObserver* observer,
59 int player_id, 79 int player_id,
60 Type type) { 80 Type type) {
61 // If the audio focus is already granted and is of type Content, there is 81 // If the audio focus is already granted and is of type Content, there is
62 // nothing to do. If it is granted of type Transient the requested type is 82 // nothing to do. If it is granted of type Transient the requested type is
63 // also transient, there is also nothing to do. Otherwise, the session needs 83 // also transient, there is also nothing to do. Otherwise, the session needs
64 // to request audio focus again. 84 // to request audio focus again.
65 if (audio_focus_state_ == State::ACTIVE && 85 if (audio_focus_state_ == State::ACTIVE &&
66 (audio_focus_type_ == Type::Content || audio_focus_type_ == type)) { 86 (audio_focus_type_ == Type::Content || audio_focus_type_ == type)) {
67 players_.insert(PlayerIdentifier(observer, player_id)); 87 players_.insert(PlayerIdentifier(observer, player_id));
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 249
230 audio_focus_state_ = State::INACTIVE; 250 audio_focus_state_ = State::INACTIVE;
231 UpdateWebContents(); 251 UpdateWebContents();
232 } 252 }
233 253
234 void MediaSession::UpdateWebContents() { 254 void MediaSession::UpdateWebContents() {
235 static_cast<WebContentsImpl*>(web_contents())->OnMediaSessionStateChanged(); 255 static_cast<WebContentsImpl*>(web_contents())->OnMediaSessionStateChanged();
236 } 256 }
237 257
238 } // namespace content 258 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698