| OLD | NEW |
| 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" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 friend class content::WebContentsUserData<MediaSession>; | 86 friend class content::WebContentsUserData<MediaSession>; |
| 87 friend class ::MediaSessionBrowserTest; | 87 friend class ::MediaSessionBrowserTest; |
| 88 | 88 |
| 89 // Resets the |j_media_session_| ref to prevent calling the Java backend | 89 // Resets the |j_media_session_| ref to prevent calling the Java backend |
| 90 // during content_browsertests. | 90 // during content_browsertests. |
| 91 void ResetJavaRefForTest(); | 91 void ResetJavaRefForTest(); |
| 92 bool IsActiveForTest() const; | 92 bool IsActiveForTest() const; |
| 93 Type audio_focus_type_for_test() const; | 93 Type audio_focus_type_for_test() const; |
| 94 void RemoveAllPlayersForTest(); | 94 void RemoveAllPlayersForTest(); |
| 95 | 95 |
| 96 void OnSuspendInternal(bool temporary); | 96 enum class State { |
| 97 void OnResumeInternal(); | 97 ACTIVE, |
| 98 SUSPENDED, |
| 99 INACTIVE |
| 100 }; |
| 98 | 101 |
| 99 enum class State { | 102 enum class SuspendType { |
| 100 Active, | 103 // Suspended by the system because a transient sound needs to be played. |
| 101 TemporarilySuspended, | 104 SYSTEM, |
| 102 Suspended, | 105 // Suspended by the UI. |
| 106 UI, |
| 103 }; | 107 }; |
| 104 | 108 |
| 105 // Representation of a player for the MediaSession. | 109 // Representation of a player for the MediaSession. |
| 106 struct PlayerIdentifier { | 110 struct PlayerIdentifier { |
| 107 PlayerIdentifier(MediaSessionObserver* observer, int player_id); | 111 PlayerIdentifier(MediaSessionObserver* observer, int player_id); |
| 108 PlayerIdentifier(const PlayerIdentifier&) = default; | 112 PlayerIdentifier(const PlayerIdentifier&) = default; |
| 109 | 113 |
| 110 void operator=(const PlayerIdentifier&) = delete; | 114 void operator=(const PlayerIdentifier&) = delete; |
| 111 bool operator==(const PlayerIdentifier& player_identifier) const; | 115 bool operator==(const PlayerIdentifier& player_identifier) const; |
| 112 | 116 |
| 113 // Hash operator for base::hash_map<>. | 117 // Hash operator for base::hash_map<>. |
| 114 struct Hash { | 118 struct Hash { |
| 115 size_t operator()(const PlayerIdentifier& player_identifier) const; | 119 size_t operator()(const PlayerIdentifier& player_identifier) const; |
| 116 }; | 120 }; |
| 117 | 121 |
| 118 MediaSessionObserver* observer; | 122 MediaSessionObserver* observer; |
| 119 int player_id; | 123 int player_id; |
| 120 }; | 124 }; |
| 121 using PlayersMap = base::hash_set<PlayerIdentifier, PlayerIdentifier::Hash>; | 125 using PlayersMap = base::hash_set<PlayerIdentifier, PlayerIdentifier::Hash>; |
| 122 | 126 |
| 123 explicit MediaSession(WebContents* web_contents); | 127 explicit MediaSession(WebContents* web_contents); |
| 124 | 128 |
| 125 // Setup the JNI. | 129 // Setup the JNI. |
| 126 void Initialize(); | 130 void Initialize(); |
| 127 | 131 |
| 132 void OnSuspendInternal(SuspendType type); |
| 133 void OnResumeInternal(SuspendType type); |
| 134 |
| 128 // Requests audio focus to Android using |j_media_session_|. | 135 // Requests audio focus to Android using |j_media_session_|. |
| 129 // Returns whether the request was granted. If |j_media_session_| is null, it | 136 // Returns whether the request was granted. If |j_media_session_| is null, it |
| 130 // will always return true. | 137 // will always return true. |
| 131 bool RequestSystemAudioFocus(Type type); | 138 bool RequestSystemAudioFocus(Type type); |
| 132 | 139 |
| 133 // To be called after a call to AbandonAudioFocus() in order to call the Java | 140 // To be called after a call to AbandonAudioFocus() in order to call the Java |
| 134 // MediaSession if the audio focus really need to be abandoned. | 141 // MediaSession if the audio focus really need to be abandoned. |
| 135 void AbandonSystemAudioFocusIfNeeded(); | 142 void AbandonSystemAudioFocusIfNeeded(); |
| 136 | 143 |
| 137 // Notifies WebContents about the state change of the media session. | 144 // Notifies WebContents about the state change of the media session. |
| 138 void UpdateWebContents(); | 145 void UpdateWebContents(); |
| 139 | 146 |
| 140 base::android::ScopedJavaGlobalRef<jobject> j_media_session_; | 147 base::android::ScopedJavaGlobalRef<jobject> j_media_session_; |
| 141 PlayersMap players_; | 148 PlayersMap players_; |
| 142 | 149 |
| 143 State audio_focus_state_; | 150 State audio_focus_state_; |
| 151 SuspendType suspend_type_; |
| 144 Type audio_focus_type_; | 152 Type audio_focus_type_; |
| 145 | 153 |
| 146 DISALLOW_COPY_AND_ASSIGN(MediaSession); | 154 DISALLOW_COPY_AND_ASSIGN(MediaSession); |
| 147 }; | 155 }; |
| 148 | 156 |
| 149 } // namespace content | 157 } // namespace content |
| 150 | 158 |
| 151 #endif // CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_SESSION_H_ | 159 #endif // CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_SESSION_H_ |
| OLD | NEW |