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_SESSION_MEDIA_SESSION_H_ | 5 #ifndef CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_H_ |
6 #define CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_H_ | 6 #define CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include "base/callback_list.h" | 10 #include "base/callback_list.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 // Suspended by the page via script or user interaction. | 56 // Suspended by the page via script or user interaction. |
57 CONTENT, | 57 CONTENT, |
58 }; | 58 }; |
59 | 59 |
60 // Returns the MediaSession associated to this WebContents. Creates one if | 60 // Returns the MediaSession associated to this WebContents. Creates one if |
61 // none is currently available. | 61 // none is currently available. |
62 CONTENT_EXPORT static MediaSession* Get(WebContents* web_contents); | 62 CONTENT_EXPORT static MediaSession* Get(WebContents* web_contents); |
63 | 63 |
64 ~MediaSession() override; | 64 ~MediaSession() override; |
65 | 65 |
66 void WasShown() override; | |
mlamouri (slow - plz ping)
2016/09/05 09:40:36
To simplify understanding this, can you explain wh
Zhiqiang Zhang (Slow)
2016/09/05 09:54:21
Oh, it seems like the code when I was doing experi
| |
67 | |
66 void SetMetadata(const MediaMetadata& metadata); | 68 void SetMetadata(const MediaMetadata& metadata); |
67 const MediaMetadata& metadata() const { return metadata_; } | 69 const MediaMetadata& metadata() const { return metadata_; } |
68 | 70 |
69 // Adds the given player to the current media session. Returns whether the | 71 // Adds the given player to the current media session. Returns whether the |
70 // player was successfully added. If it returns false, AddPlayer() should be | 72 // player was successfully added. If it returns false, AddPlayer() should be |
71 // called again later. | 73 // called again later. |
72 CONTENT_EXPORT bool AddPlayer(MediaSessionObserver* observer, | 74 CONTENT_EXPORT bool AddPlayer(MediaSessionObserver* observer, |
73 int player_id, | 75 int player_id, |
74 media::MediaContentType media_content_type); | 76 media::MediaContentType media_content_type); |
75 | 77 |
(...skipping 28 matching lines...) Expand all Loading... | |
104 CONTENT_EXPORT void Stop(SuspendType suspend_type); | 106 CONTENT_EXPORT void Stop(SuspendType suspend_type); |
105 | 107 |
106 // Let the media session start ducking such that the volume multiplier is | 108 // Let the media session start ducking such that the volume multiplier is |
107 // reduced. | 109 // reduced. |
108 CONTENT_EXPORT void StartDucking(); | 110 CONTENT_EXPORT void StartDucking(); |
109 | 111 |
110 // Let the media session stop ducking such that the volume multiplier is | 112 // Let the media session stop ducking such that the volume multiplier is |
111 // recovered. | 113 // recovered. |
112 CONTENT_EXPORT void StopDucking(); | 114 CONTENT_EXPORT void StopDucking(); |
113 | 115 |
116 CONTENT_EXPORT bool IsDucking() { return is_ducking_; } | |
117 | |
114 // Returns if the session can be controlled by Resume() and Suspend calls | 118 // Returns if the session can be controlled by Resume() and Suspend calls |
115 // above. | 119 // above. |
116 CONTENT_EXPORT bool IsControllable() const; | 120 CONTENT_EXPORT bool IsControllable() const; |
117 | 121 |
118 // Returns if the session is currently active. | 122 // Returns if the session is currently active. |
119 CONTENT_EXPORT bool IsActive() const; | 123 CONTENT_EXPORT bool IsActive() const; |
120 | 124 |
121 // Returns if the session is currently suspended. | 125 // Returns if the session is currently suspended. |
122 // TODO(mlamouri): IsSuspended() below checks if the state is not ACTIVE | 126 // TODO(mlamouri): IsSuspended() below checks if the state is not ACTIVE |
123 // instead of checking if the state is SUSPENDED. In order to not have to | 127 // instead of checking if the state is SUSPENDED. In order to not have to |
124 // change all the callers and make the current refactoring ridiculously huge, | 128 // change all the callers and make the current refactoring ridiculously huge, |
125 // this method is introduced temporarily and will be removed later. | 129 // this method is introduced temporarily and will be removed later. |
126 bool IsReallySuspended() const; | 130 bool IsReallySuspended() const; |
127 | 131 |
128 // Returns if the session is currently suspended or inactive. | 132 // Returns if the session is currently suspended or inactive. |
129 CONTENT_EXPORT bool IsSuspended() const; | 133 CONTENT_EXPORT bool IsSuspended() const; |
130 | 134 |
135 void SetOnTop(bool is_on_top); | |
mlamouri (slow - plz ping)
2016/09/05 09:40:36
ditto, what's `SetOnTop` for?
Zhiqiang Zhang (Slow)
2016/09/05 09:54:21
I discussed this with Anton, and the method is act
| |
136 | |
131 private: | 137 private: |
132 friend class content::WebContentsUserData<MediaSession>; | 138 friend class content::WebContentsUserData<MediaSession>; |
133 friend class ::MediaSessionBrowserTest; | 139 friend class ::MediaSessionBrowserTest; |
134 friend class content::MediaSessionVisibilityBrowserTest; | 140 friend class content::MediaSessionVisibilityBrowserTest; |
135 friend class content::AudioFocusManagerTest; | 141 friend class content::AudioFocusManagerTest; |
136 friend class content::MediaSessionStateObserver; | 142 friend class content::MediaSessionStateObserver; |
137 | 143 |
138 CONTENT_EXPORT void SetDelegateForTests( | 144 CONTENT_EXPORT void SetDelegateForTests( |
139 std::unique_ptr<MediaSessionDelegate> delegate); | 145 std::unique_ptr<MediaSessionDelegate> delegate); |
140 CONTENT_EXPORT bool IsActiveForTest() const; | 146 CONTENT_EXPORT bool IsActiveForTest() const; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 // Internal method that should be used instead of setting audio_focus_state_. | 197 // Internal method that should be used instead of setting audio_focus_state_. |
192 // It sets audio_focus_state_ and notifies observers about the state change. | 198 // It sets audio_focus_state_ and notifies observers about the state change. |
193 void SetAudioFocusState(State audio_focus_state); | 199 void SetAudioFocusState(State audio_focus_state); |
194 | 200 |
195 // Update the volume multiplier when ducking state changes. | 201 // Update the volume multiplier when ducking state changes. |
196 void UpdateVolumeMultiplier(); | 202 void UpdateVolumeMultiplier(); |
197 | 203 |
198 // Get the volume multiplier, which depends on whether the media session is | 204 // Get the volume multiplier, which depends on whether the media session is |
199 // ducking. | 205 // ducking. |
200 double GetVolumeMultiplier() const; | 206 double GetVolumeMultiplier() const; |
207 double GetPepperVolumeMultiplier() const; | |
201 | 208 |
202 // Registers a MediaSession state change callback. | 209 // Registers a MediaSession state change callback. |
203 CONTENT_EXPORT std::unique_ptr<base::CallbackList<void(State)>::Subscription> | 210 CONTENT_EXPORT std::unique_ptr<base::CallbackList<void(State)>::Subscription> |
204 RegisterMediaSessionStateChangedCallbackForTest( | 211 RegisterMediaSessionStateChangedCallbackForTest( |
205 const StateChangedCallback& cb); | 212 const StateChangedCallback& cb); |
206 | 213 |
214 CONTENT_EXPORT bool AddPepperPlayer(MediaSessionObserver* observer, | |
215 int player_id); | |
216 | |
207 std::unique_ptr<MediaSessionDelegate> delegate_; | 217 std::unique_ptr<MediaSessionDelegate> delegate_; |
208 PlayersMap players_; | 218 PlayersMap players_; |
219 PlayersMap pepper_players_; | |
209 | 220 |
210 State audio_focus_state_; | 221 State audio_focus_state_; |
211 SuspendType suspend_type_; | 222 SuspendType suspend_type_; |
212 AudioFocusManager::AudioFocusType audio_focus_type_; | 223 AudioFocusManager::AudioFocusType audio_focus_type_; |
213 | 224 |
214 MediaSessionUmaHelper uma_helper_; | 225 MediaSessionUmaHelper uma_helper_; |
215 | 226 |
216 // The ducking state of this media session. The initial value is |false|, and | 227 // The ducking state of this media session. The initial value is |false|, and |
217 // is set to |true| after StartDucking(), and will be set to |false| after | 228 // is set to |true| after StartDucking(), and will be set to |false| after |
218 // StopDucking(). | 229 // StopDucking(). |
219 bool is_ducking_; | 230 bool is_ducking_; |
231 bool is_on_top_; | |
220 | 232 |
221 MediaMetadata metadata_; | 233 MediaMetadata metadata_; |
222 base::CallbackList<void(State)> media_session_state_listeners_; | 234 base::CallbackList<void(State)> media_session_state_listeners_; |
223 | 235 |
224 DISALLOW_COPY_AND_ASSIGN(MediaSession); | 236 DISALLOW_COPY_AND_ASSIGN(MediaSession); |
225 }; | 237 }; |
226 | 238 |
227 } // namespace content | 239 } // namespace content |
228 | 240 |
229 #endif // CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_H_ | 241 #endif // CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_H_ |
OLD | NEW |