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

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

Issue 2274873003: Letting Flash join MediaSession (stack implementaion) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@media_session_type
Patch Set: added doc Created 4 years, 2 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_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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 public: 51 public:
52 enum class SuspendType { 52 enum class SuspendType {
53 // Suspended by the system because a transient sound needs to be played. 53 // Suspended by the system because a transient sound needs to be played.
54 SYSTEM, 54 SYSTEM,
55 // Suspended by the UI. 55 // Suspended by the UI.
56 UI, 56 UI,
57 // Suspended by the page via script or user interaction. 57 // Suspended by the page via script or user interaction.
58 CONTENT, 58 CONTENT,
59 }; 59 };
60 60
61 // Only visible to tests.
62 enum class State {
63 ACTIVE,
64 SUSPENDED,
65 INACTIVE
66 };
67
61 // Returns the MediaSession associated to this WebContents. Creates one if 68 // Returns the MediaSession associated to this WebContents. Creates one if
62 // none is currently available. 69 // none is currently available.
63 CONTENT_EXPORT static MediaSession* Get(WebContents* web_contents); 70 CONTENT_EXPORT static MediaSession* Get(WebContents* web_contents);
64 71
65 ~MediaSession() override; 72 ~MediaSession() override;
66 73
67 void SetMetadata(const base::Optional<MediaMetadata>& metadata); 74 void SetMetadata(const base::Optional<MediaMetadata>& metadata);
68 const base::Optional<MediaMetadata>& metadata() const { return metadata_; } 75 const base::Optional<MediaMetadata>& metadata() const { return metadata_; }
69 76
70 // Adds the given player to the current media session. Returns whether the 77 // Adds the given player to the current media session. Returns whether the
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 // Returns if the session is currently suspended. 129 // Returns if the session is currently suspended.
123 // TODO(mlamouri): IsSuspended() below checks if the state is not ACTIVE 130 // TODO(mlamouri): IsSuspended() below checks if the state is not ACTIVE
124 // instead of checking if the state is SUSPENDED. In order to not have to 131 // instead of checking if the state is SUSPENDED. In order to not have to
125 // change all the callers and make the current refactoring ridiculously huge, 132 // change all the callers and make the current refactoring ridiculously huge,
126 // this method is introduced temporarily and will be removed later. 133 // this method is introduced temporarily and will be removed later.
127 bool IsReallySuspended() const; 134 bool IsReallySuspended() const;
128 135
129 // Returns if the session is currently suspended or inactive. 136 // Returns if the session is currently suspended or inactive.
130 CONTENT_EXPORT bool IsSuspended() const; 137 CONTENT_EXPORT bool IsSuspended() const;
131 138
139 bool HasPepper() const;
140
132 private: 141 private:
133 friend class content::WebContentsUserData<MediaSession>; 142 friend class content::WebContentsUserData<MediaSession>;
134 friend class ::MediaSessionBrowserTest; 143 friend class ::MediaSessionBrowserTest;
135 friend class content::MediaSessionVisibilityBrowserTest; 144 friend class content::MediaSessionVisibilityBrowserTest;
136 friend class content::AudioFocusManagerTest; 145 friend class content::AudioFocusManagerTest;
137 friend class content::MediaSessionStateObserver; 146 friend class content::MediaSessionStateObserver;
138 147
139 CONTENT_EXPORT void SetDelegateForTests( 148 CONTENT_EXPORT void SetDelegateForTests(
140 std::unique_ptr<MediaSessionDelegate> delegate); 149 std::unique_ptr<MediaSessionDelegate> delegate);
141 CONTENT_EXPORT bool IsActiveForTest() const; 150 CONTENT_EXPORT bool IsActiveForTest() const;
142 CONTENT_EXPORT AudioFocusManager::AudioFocusType audio_focus_type_for_test() 151 CONTENT_EXPORT AudioFocusManager::AudioFocusType audio_focus_type_for_test()
143 const; 152 const;
144 CONTENT_EXPORT void RemoveAllPlayersForTest(); 153 CONTENT_EXPORT void RemoveAllPlayersForTest();
145 CONTENT_EXPORT MediaSessionUmaHelper* uma_helper_for_test(); 154 CONTENT_EXPORT MediaSessionUmaHelper* uma_helper_for_test();
146 155
147 enum class State {
148 ACTIVE,
149 SUSPENDED,
150 INACTIVE
151 };
152
153 // Representation of a player for the MediaSession. 156 // Representation of a player for the MediaSession.
154 struct PlayerIdentifier { 157 struct PlayerIdentifier {
155 PlayerIdentifier(MediaSessionObserver* observer, int player_id); 158 PlayerIdentifier(MediaSessionObserver* observer, int player_id);
156 PlayerIdentifier(const PlayerIdentifier&) = default; 159 PlayerIdentifier(const PlayerIdentifier&) = default;
157 160
158 void operator=(const PlayerIdentifier&) = delete; 161 void operator=(const PlayerIdentifier&) = delete;
159 bool operator==(const PlayerIdentifier& player_identifier) const; 162 bool operator==(const PlayerIdentifier& player_identifier) const;
160 163
161 // Hash operator for base::hash_map<>. 164 // Hash operator for base::hash_map<>.
162 struct Hash { 165 struct Hash {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 201
199 // Get the volume multiplier, which depends on whether the media session is 202 // Get the volume multiplier, which depends on whether the media session is
200 // ducking. 203 // ducking.
201 double GetVolumeMultiplier() const; 204 double GetVolumeMultiplier() const;
202 205
203 // Registers a MediaSession state change callback. 206 // Registers a MediaSession state change callback.
204 CONTENT_EXPORT std::unique_ptr<base::CallbackList<void(State)>::Subscription> 207 CONTENT_EXPORT std::unique_ptr<base::CallbackList<void(State)>::Subscription>
205 RegisterMediaSessionStateChangedCallbackForTest( 208 RegisterMediaSessionStateChangedCallbackForTest(
206 const StateChangedCallback& cb); 209 const StateChangedCallback& cb);
207 210
211 CONTENT_EXPORT bool AddPepperPlayer(MediaSessionObserver* observer,
212 int player_id);
213
208 std::unique_ptr<MediaSessionDelegate> delegate_; 214 std::unique_ptr<MediaSessionDelegate> delegate_;
209 PlayersMap players_; 215 PlayersMap players_;
216 PlayersMap pepper_players_;
210 217
211 State audio_focus_state_; 218 State audio_focus_state_;
212 SuspendType suspend_type_; 219 SuspendType suspend_type_;
213 AudioFocusManager::AudioFocusType audio_focus_type_; 220 AudioFocusManager::AudioFocusType audio_focus_type_;
214 221
215 MediaSessionUmaHelper uma_helper_; 222 MediaSessionUmaHelper uma_helper_;
216 223
217 // The ducking state of this media session. The initial value is |false|, and 224 // The ducking state of this media session. The initial value is |false|, and
218 // is set to |true| after StartDucking(), and will be set to |false| after 225 // is set to |true| after StartDucking(), and will be set to |false| after
219 // StopDucking(). 226 // StopDucking().
220 bool is_ducking_; 227 bool is_ducking_;
221 228
222 base::Optional<MediaMetadata> metadata_; 229 base::Optional<MediaMetadata> metadata_;
223 base::CallbackList<void(State)> media_session_state_listeners_; 230 base::CallbackList<void(State)> media_session_state_listeners_;
224 231
225 DISALLOW_COPY_AND_ASSIGN(MediaSession); 232 DISALLOW_COPY_AND_ASSIGN(MediaSession);
226 }; 233 };
227 234
228 } // namespace content 235 } // namespace content
229 236
230 #endif // CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_H_ 237 #endif // CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698