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

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

Issue 1159113006: [Android] A prototype of the interactive media notification. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added browser tests Created 5 years, 6 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 #ifndef CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_SESSION_H_ 5 #ifndef CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_SESSION_H_
6 #define CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_SESSION_H_ 6 #define CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_SESSION_H_
7 7
8 #include <jni.h> 8 #include <jni.h>
9 9
10 #include "base/android/scoped_java_ref.h" 10 #include "base/android/scoped_java_ref.h"
11 #include "base/id_map.h" 11 #include "base/id_map.h"
12 #include "content/common/content_export.h" 12 #include "content/common/content_export.h"
13 #include "content/public/browser/android/media_controls_delegate.h"
13 #include "content/public/browser/web_contents_observer.h" 14 #include "content/public/browser/web_contents_observer.h"
14 #include "content/public/browser/web_contents_user_data.h" 15 #include "content/public/browser/web_contents_user_data.h"
15 16
17
18 class MediaSessionBrowserTest;
19
16 namespace content { 20 namespace content {
17 21
18 class MediaSessionBrowserTest;
19 class MediaSessionObserver; 22 class MediaSessionObserver;
20 23
21 // MediaSession manages the Android AudioFocus for a given WebContents. It is 24 // MediaSession manages the Android AudioFocus for a given WebContents. It is
22 // requesting the audio focus, pausing when requested by the system and dropping 25 // requesting the audio focus, pausing when requested by the system and dropping
23 // it on demand. 26 // it on demand.
24 // The audio focus can be of two types: Transient or Content. A Transient audio 27 // The audio focus can be of two types: Transient or Content. A Transient audio
25 // focus will allow other players to duck instead of pausing and will be 28 // focus will allow other players to duck instead of pausing and will be
26 // declared as temporary to the system. A Content audio focus will not be 29 // declared as temporary to the system. A Content audio focus will not be
27 // declared as temporary and will not allow other players to duck. If a given 30 // declared as temporary and will not allow other players to duck. If a given
28 // WebContents can only have one audio focus at a time, it will be Content in 31 // WebContents can only have one audio focus at a time, it will be Content in
29 // case of Transient and Content audio focus are both requested. 32 // case of Transient and Content audio focus are both requested.
30 // Android system interaction occurs in the Java counterpart to this class. 33 // Android system interaction occurs in the Java counterpart to this class.
31 class CONTENT_EXPORT MediaSession 34 class CONTENT_EXPORT MediaSession
32 : public content::WebContentsObserver, 35 : public WebContentsObserver,
33 protected content::WebContentsUserData<MediaSession> { 36 public MediaControlsDelegate,
37 protected WebContentsUserData<MediaSession> {
34 public: 38 public:
35 enum class Type { 39 enum class Type {
36 Content, 40 Content,
37 Transient 41 Transient
38 }; 42 };
39 43
40 static bool RegisterMediaSession(JNIEnv* env); 44 static bool RegisterMediaSession(JNIEnv* env);
41 45
42 // Returns the MediaSession associated to this WebContents. Creates one if 46 // Returns the MediaSession associated to this WebContents. Creates one if
43 // none is currently available. 47 // none is currently available.
(...skipping 15 matching lines...) Expand all
59 void RemovePlayers(MediaSessionObserver* observer); 63 void RemovePlayers(MediaSessionObserver* observer);
60 64
61 // Called when the Android system requests the MediaSession to be suspended. 65 // Called when the Android system requests the MediaSession to be suspended.
62 // Called by Java through JNI. 66 // Called by Java through JNI.
63 void OnSuspend(JNIEnv* env, jobject obj, jboolean temporary); 67 void OnSuspend(JNIEnv* env, jobject obj, jboolean temporary);
64 68
65 // Called when the Android system requests the MediaSession to be resumed. 69 // Called when the Android system requests the MediaSession to be resumed.
66 // Called by Java through JNI. 70 // Called by Java through JNI.
67 void OnResume(JNIEnv* env, jobject obj); 71 void OnResume(JNIEnv* env, jobject obj);
68 72
69 protected: 73 private:
mlamouri (slow - plz ping) 2015/06/18 16:43:23 I had that so we had a very specific layer exposed
whywhat 2015/06/19 16:00:34 If you declare a friend class it has access to all
mlamouri (slow - plz ping) 2015/06/22 14:34:17 May I give you my resignation? :)
70 friend class content::MediaSessionBrowserTest; 74 friend class content::WebContentsUserData<MediaSession>;
75 friend class ::MediaSessionBrowserTest;
71 76
72 // Resets the |j_media_session_| ref to prevent calling the Java backend 77 // Resets the |j_media_session_| ref to prevent calling the Java backend
73 // during content_browsertests. 78 // during content_browsertests.
74 void ResetJavaRefForTest(); 79 void ResetJavaRefForTest();
75
76 bool IsActiveForTest() const; 80 bool IsActiveForTest() const;
77 Type audio_focus_type_for_test() const; 81 Type audio_focus_type_for_test() const;
82 void RemoveAllPlayersForTest();
78 83
79 void OnSuspend(bool temporary); 84 void OnSuspend(bool temporary);
80 void OnResume(); 85 void OnResume();
81 86
82 private: 87 // MediaControlsDelegate implementation.
83 friend class content::WebContentsUserData<MediaSession>; 88 void OnControlsPause() override;
89 void OnControlsResume() override;
90 bool IsPaused() override;
84 91
85 enum class State { 92 enum class State {
86 Active, 93 Active,
87 TemporarilySuspended, 94 TemporarilySuspended,
88 Suspended, 95 Suspended,
89 }; 96 };
90 97
91 // Representation of a player for the MediaSession. 98 // Representation of a player for the MediaSession.
92 struct PlayerIdentifier { 99 struct PlayerIdentifier {
93 PlayerIdentifier(MediaSessionObserver* observer, int player_id); 100 PlayerIdentifier(MediaSessionObserver* observer, int player_id);
(...skipping 19 matching lines...) Expand all
113 120
114 // Requests audio focus to Android using |j_media_session_|. 121 // Requests audio focus to Android using |j_media_session_|.
115 // Returns whether the request was granted. If |j_media_session_| is null, it 122 // Returns whether the request was granted. If |j_media_session_| is null, it
116 // will always return true. 123 // will always return true.
117 bool RequestSystemAudioFocus(Type type); 124 bool RequestSystemAudioFocus(Type type);
118 125
119 // To be called after a call to AbandonAudioFocus() in order to call the Java 126 // To be called after a call to AbandonAudioFocus() in order to call the Java
120 // MediaSession if the audio focus really need to be abandoned. 127 // MediaSession if the audio focus really need to be abandoned.
121 void AbandonSystemAudioFocusIfNeeded(); 128 void AbandonSystemAudioFocusIfNeeded();
122 129
130 // Shows media controls if the type is right and WebContentsDelegate is set.
131 void ShowMediaControlsIfNeeded(Type type);
132
133 // Hides media controls if the type is right and WebContentsDelegate is set.
134 void HideMediaControlsIfNeeded(Type type);
135
123 base::android::ScopedJavaGlobalRef<jobject> j_media_session_; 136 base::android::ScopedJavaGlobalRef<jobject> j_media_session_;
124 PlayersMap players_; 137 PlayersMap players_;
125 138
126 State audio_focus_state_; 139 State audio_focus_state_;
127 Type audio_focus_type_; 140 Type audio_focus_type_;
128 141
129 DISALLOW_COPY_AND_ASSIGN(MediaSession); 142 DISALLOW_COPY_AND_ASSIGN(MediaSession);
130 }; 143 };
131 144
132 } // namespace content 145 } // namespace content
133 146
134 #endif // CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_SESSION_H_ 147 #endif // CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_SESSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698