Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_SESSION_H_ | |
| 6 #define CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_SESSION_H_ | |
| 7 | |
| 8 #include <jni.h> | |
| 9 | |
| 10 #include "base/android/scoped_java_ref.h" | |
| 11 #include "base/id_map.h" | |
| 12 #include "content/public/browser/web_contents_observer.h" | |
| 13 #include "content/public/browser/web_contents_user_data.h" | |
| 14 | |
| 15 namespace content { | |
| 16 | |
| 17 class MediaSessionDelegate; | |
| 18 | |
| 19 // MediaSession manages the Android AudioFocus for a given WebContents. It is | |
|
whywhat
2015/05/12 12:50:45
I believe a more expanded comment would be welcome
mlamouri (slow - plz ping)
2015/05/19 21:56:16
Done.
| |
| 20 // requesting the audio focus, pausing when requested by the system and dropping | |
| 21 // it on demand. | |
| 22 class MediaSession : public content::WebContentsObserver, | |
|
qinmin
2015/05/15 18:06:19
Can we merge this class with MediaWebContentsObser
mlamouri (slow - plz ping)
2015/05/19 21:56:16
They are not quite doing the same thing. MediaSess
| |
| 23 protected content::WebContentsUserData<MediaSession> { | |
| 24 public: | |
| 25 enum class Type { | |
| 26 Content, | |
| 27 Transient | |
| 28 }; | |
| 29 | |
| 30 static bool RegisterMediaSession(JNIEnv* env); | |
| 31 static MediaSession* Get(WebContents* web_contents); | |
| 32 | |
| 33 ~MediaSession() override; | |
| 34 | |
| 35 bool RequestAudioFocus(MediaSessionDelegate* delegate, | |
|
whywhat
2015/05/12 12:50:45
Document the public methods.
mlamouri (slow - plz ping)
2015/05/19 21:56:16
Done.
| |
| 36 int player_id, | |
|
whywhat
2015/05/12 12:50:45
This sounds more like "EnsureSufficientAudioFocus"
mlamouri (slow - plz ping)
2015/05/19 21:56:16
Renamed AddPlayer(). I changed how things behave t
| |
| 37 Type type); | |
| 38 void AbandonAudioFocus(MediaSessionDelegate* delegate, | |
|
whywhat
2015/05/12 12:50:46
Could be OnPlayerStopped then if you accept the su
mlamouri (slow - plz ping)
2015/05/19 21:56:16
Renamed RemovePlayer(). OnPlayerStopped() is confu
| |
| 39 int player_id); | |
| 40 void AbandonAudioFocus(MediaSessionDelegate* delegate); | |
|
whywhat
2015/05/12 12:50:46
Ditto. OnAllPlayersStopped() maybe?
mlamouri (slow - plz ping)
2015/05/19 21:56:16
RemovePlayers()
mlamouri (slow - plz ping)
2015/05/19 21:56:16
RemovePlayers()
| |
| 41 | |
| 42 // Called by Java trough JNI. | |
| 43 void OnSuspend(JNIEnv* env, jobject obj); | |
| 44 void OnResume(JNIEnv* env, jobject obj); | |
| 45 | |
| 46 private: | |
| 47 friend class content::WebContentsUserData<MediaSession>; | |
| 48 | |
| 49 struct PlayerIdentifier { | |
| 50 PlayerIdentifier(MediaSessionDelegate* delegate, int id) | |
| 51 : delegate_(delegate), | |
| 52 id_(id) {}; | |
| 53 MediaSessionDelegate* delegate_; | |
| 54 int id_; | |
| 55 | |
| 56 DISALLOW_COPY_AND_ASSIGN(PlayerIdentifier); | |
|
whywhat
2015/05/12 12:50:46
nit: is it common for structs? not sure if this is
mlamouri (slow - plz ping)
2015/05/19 21:56:16
AFAIK, it is recommended if not required.
| |
| 57 }; | |
| 58 using PlayersMap = IDMap<PlayerIdentifier, IDMapOwnPointer>; | |
| 59 | |
| 60 explicit MediaSession(WebContents* web_contents); | |
| 61 | |
| 62 // Setup the JNI. | |
| 63 void Initialize(); | |
| 64 | |
| 65 // To be called after a call to AbandonAudioFocus() in order to call the Java | |
| 66 // MediaSession if the audio focus really need to be abandoned. | |
| 67 void AbandonAudioFocusIfNeeded(); | |
|
whywhat
2015/05/12 12:50:45
s/AbandonAudioFocus/AbandonSystemAudioFocus?
mlamouri (slow - plz ping)
2015/05/19 21:56:16
Done.
| |
| 68 | |
| 69 base::android::ScopedJavaGlobalRef<jobject> j_media_session_; | |
| 70 PlayersMap players_; | |
| 71 | |
| 72 bool has_audio_focus_; | |
|
whywhat
2015/05/12 12:50:46
Add None to Type and just have one three-state mem
mlamouri (slow - plz ping)
2015/05/19 21:56:16
When ::OnResume() is called, the boolean is toggle
| |
| 73 Type audio_focus_type_; | |
| 74 | |
| 75 DISALLOW_COPY_AND_ASSIGN(MediaSession); | |
| 76 }; | |
| 77 | |
| 78 } // namespace content | |
| 79 | |
| 80 #endif // CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_SESSION_H_ | |
| OLD | NEW |