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

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

Issue 1308983005: NOT FOR LANDING Implement WebMediaSession (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add forward declaration Created 4 years, 11 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 #include <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 29 matching lines...) Expand all
40 Content, 40 Content,
41 Transient 41 Transient
42 }; 42 };
43 43
44 static bool RegisterMediaSession(JNIEnv* env); 44 static bool RegisterMediaSession(JNIEnv* env);
45 45
46 // Returns the MediaSession associated to this WebContents. Creates one if 46 // Returns the MediaSession associated to this WebContents. Creates one if
47 // none is currently available. 47 // none is currently available.
48 static MediaSession* Get(WebContents* web_contents); 48 static MediaSession* Get(WebContents* web_contents);
49 49
50 // Returns a newly created standalone media session.
51 static MediaSession* Create(WebContents* web_contents, int session_id);
52
50 ~MediaSession() override; 53 ~MediaSession() override;
51 54
55 bool Activate();
56 void Deactivate();
57 int session_id() const { return session_id_; }
58
52 // Adds the given player to the current media session. Returns whether the 59 // Adds the given player to the current media session. Returns whether the
53 // player was successfully added. If it returns false, AddPlayer() should be 60 // player was successfully added. If it returns false, AddPlayer() should be
54 // called again later. 61 // called again later.
55 bool AddPlayer(MediaSessionObserver* observer, int player_id, Type type); 62 bool AddPlayer(MediaSessionObserver* observer, int player_id, Type type);
56 63
57 // Removes the given player from the current media session. Abandons audio 64 // Removes the given player from the current media session. Abandons audio
58 // focus if that was the last player in the session. 65 // focus if that was the last player in the session.
59 void RemovePlayer(MediaSessionObserver* observer, int player_id); 66 void RemovePlayer(MediaSessionObserver* observer, int player_id);
60 67
61 // Removes all the players associated with |observer|. Abandons audio focus if 68 // Removes all the players associated with |observer|. Abandons audio focus if
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 // Hash operator for base::hash_map<>. 140 // Hash operator for base::hash_map<>.
134 struct Hash { 141 struct Hash {
135 size_t operator()(const PlayerIdentifier& player_identifier) const; 142 size_t operator()(const PlayerIdentifier& player_identifier) const;
136 }; 143 };
137 144
138 MediaSessionObserver* observer; 145 MediaSessionObserver* observer;
139 int player_id; 146 int player_id;
140 }; 147 };
141 using PlayersMap = base::hash_set<PlayerIdentifier, PlayerIdentifier::Hash>; 148 using PlayersMap = base::hash_set<PlayerIdentifier, PlayerIdentifier::Hash>;
142 149
143 explicit MediaSession(WebContents* web_contents); 150 MediaSession(WebContents* web_contents, int session_id = 0);
144 151
145 // Setup the JNI. 152 // Setup the JNI.
146 void Initialize(); 153 void Initialize();
147 154
148 void OnSuspendInternal(SuspendType type, State new_state); 155 void OnSuspendInternal(SuspendType type, State new_state);
149 void OnResumeInternal(SuspendType type); 156 void OnResumeInternal(SuspendType type);
150 157
151 // Requests audio focus to Android using |j_media_session_|. 158 // Requests audio focus to Android using |j_media_session_|.
152 // Returns whether the request was granted. If |j_media_session_| is null, it 159 // Returns whether the request was granted. If |j_media_session_| is null, it
153 // will always return true. 160 // will always return true.
154 bool RequestSystemAudioFocus(Type type); 161 bool RequestSystemAudioFocus(Type type);
155 162
156 // To be called after a call to AbandonAudioFocus() in order to call the Java 163 // To be called after a call to AbandonAudioFocus() in order to call the Java
157 // MediaSession if the audio focus really need to be abandoned. 164 // MediaSession if the audio focus really need to be abandoned.
158 void AbandonSystemAudioFocusIfNeeded(); 165 void AbandonSystemAudioFocusIfNeeded();
159 166
160 // Notifies WebContents about the state change of the media session. 167 // Notifies WebContents about the state change of the media session.
161 void UpdateWebContents(); 168 void UpdateWebContents();
162 169
163 // Internal method that should be used instead of setting audio_focus_state_. 170 // Internal method that should be used instead of setting audio_focus_state_.
164 // It sets audio_focus_state_ and notifies observers about the state change. 171 // It sets audio_focus_state_ and notifies observers about the state change.
165 void SetAudioFocusState(State audio_focus_state); 172 void SetAudioFocusState(State audio_focus_state);
166 173
167 base::android::ScopedJavaGlobalRef<jobject> j_media_session_; 174 base::android::ScopedJavaGlobalRef<jobject> j_media_session_;
168 PlayersMap players_; 175 PlayersMap players_;
169 176
170 State audio_focus_state_; 177 State audio_focus_state_;
171 SuspendType suspend_type_; 178 SuspendType suspend_type_;
172 Type audio_focus_type_; 179 Type audio_focus_type_;
180 int session_id_;
173 181
174 MediaSessionUmaHelper uma_helper_; 182 MediaSessionUmaHelper uma_helper_;
175 183
176 DISALLOW_COPY_AND_ASSIGN(MediaSession); 184 DISALLOW_COPY_AND_ASSIGN(MediaSession);
177 }; 185 };
178 186
179 } // namespace content 187 } // namespace content
180 188
181 #endif // CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_SESSION_H_ 189 #endif // CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_SESSION_H_
OLDNEW
« no previous file with comments | « content/browser/media/android/browser_media_session_manager.cc ('k') | content/browser/media/android/media_session.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698