Index: content/browser/media/android/media_session.h |
diff --git a/content/browser/media/android/media_session.h b/content/browser/media/android/media_session.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..82370a16575175451ef9cfc90b0765fd48729198 |
--- /dev/null |
+++ b/content/browser/media/android/media_session.h |
@@ -0,0 +1,80 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_SESSION_H_ |
+#define CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_SESSION_H_ |
+ |
+#include <jni.h> |
+ |
+#include "base/android/scoped_java_ref.h" |
+#include "base/id_map.h" |
+#include "content/public/browser/web_contents_observer.h" |
+#include "content/public/browser/web_contents_user_data.h" |
+ |
+namespace content { |
+ |
+class MediaSessionDelegate; |
+ |
+// 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.
|
+// requesting the audio focus, pausing when requested by the system and dropping |
+// it on demand. |
+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
|
+ protected content::WebContentsUserData<MediaSession> { |
+ public: |
+ enum class Type { |
+ Content, |
+ Transient |
+ }; |
+ |
+ static bool RegisterMediaSession(JNIEnv* env); |
+ static MediaSession* Get(WebContents* web_contents); |
+ |
+ ~MediaSession() override; |
+ |
+ 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.
|
+ 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
|
+ Type type); |
+ 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
|
+ int player_id); |
+ 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()
|
+ |
+ // Called by Java trough JNI. |
+ void OnSuspend(JNIEnv* env, jobject obj); |
+ void OnResume(JNIEnv* env, jobject obj); |
+ |
+ private: |
+ friend class content::WebContentsUserData<MediaSession>; |
+ |
+ struct PlayerIdentifier { |
+ PlayerIdentifier(MediaSessionDelegate* delegate, int id) |
+ : delegate_(delegate), |
+ id_(id) {}; |
+ MediaSessionDelegate* delegate_; |
+ int id_; |
+ |
+ 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.
|
+ }; |
+ using PlayersMap = IDMap<PlayerIdentifier, IDMapOwnPointer>; |
+ |
+ explicit MediaSession(WebContents* web_contents); |
+ |
+ // Setup the JNI. |
+ void Initialize(); |
+ |
+ // To be called after a call to AbandonAudioFocus() in order to call the Java |
+ // MediaSession if the audio focus really need to be abandoned. |
+ void AbandonAudioFocusIfNeeded(); |
whywhat
2015/05/12 12:50:45
s/AbandonAudioFocus/AbandonSystemAudioFocus?
mlamouri (slow - plz ping)
2015/05/19 21:56:16
Done.
|
+ |
+ base::android::ScopedJavaGlobalRef<jobject> j_media_session_; |
+ PlayersMap players_; |
+ |
+ 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
|
+ Type audio_focus_type_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(MediaSession); |
+}; |
+ |
+} // namespace content |
+ |
+#endif // CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_SESSION_H_ |