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

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

Issue 2439483003: Link MediaSessionTabHelper with native MediaSession [CL is going to be split] (Closed)
Patch Set: Super rough, please give some initial feedbacks 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"
11 #include "base/id_map.h" 11 #include "base/id_map.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/optional.h" 13 #include "base/optional.h"
14 #include "base/observer_list.h"
14 #include "content/browser/media/session/audio_focus_manager.h" 15 #include "content/browser/media/session/audio_focus_manager.h"
15 #include "content/browser/media/session/media_session_uma_helper.h" 16 #include "content/browser/media/session/media_session_uma_helper.h"
16 #include "content/common/content_export.h" 17 #include "content/common/content_export.h"
17 #include "content/public/browser/web_contents_observer.h" 18 #include "content/public/browser/web_contents_observer.h"
18 #include "content/public/browser/web_contents_user_data.h" 19 #include "content/public/browser/web_contents_user_data.h"
19 #include "content/public/common/media_metadata.h" 20 #include "content/public/common/media_metadata.h"
20 21
21 class MediaSessionBrowserTest; 22 class MediaSessionBrowserTest;
22 23
23 namespace media { 24 namespace media {
24 enum class MediaContentType; 25 enum class MediaContentType;
25 } // namespace media 26 } // namespace media
26 27
27 namespace content { 28 namespace content {
28 29
29 class AudioFocusDelegate; 30 class AudioFocusDelegate;
30 class AudioFocusManagerTest; 31 class AudioFocusManagerTest;
31 class MediaSessionPlayerObserver; 32 class MediaSessionPlayerObserver;
33 class MediaSessionObserver;
32 class MediaSessionStateObserver; 34 class MediaSessionStateObserver;
33 class MediaSessionVisibilityBrowserTest; 35 class MediaSessionVisibilityBrowserTest;
34 36
35 // MediaSession manages the media session and audio focus for a given 37 // MediaSession manages the media session and audio focus for a given
36 // WebContents. It is requesting the audio focus, pausing when requested by the 38 // WebContents. It is requesting the audio focus, pausing when requested by the
37 // system and dropping it on demand. 39 // system and dropping it on demand.
38 // The audio focus can be of two types: Transient or Content. A Transient audio 40 // The audio focus can be of two types: Transient or Content. A Transient audio
39 // focus will allow other players to duck instead of pausing and will be 41 // focus will allow other players to duck instead of pausing and will be
40 // declared as temporary to the system. A Content audio focus will not be 42 // declared as temporary to the system. A Content audio focus will not be
41 // declared as temporary and will not allow other players to duck. If a given 43 // declared as temporary and will not allow other players to duck. If a given
(...skipping 22 matching lines...) Expand all
64 SUSPENDED, 66 SUSPENDED,
65 INACTIVE 67 INACTIVE
66 }; 68 };
67 69
68 // Returns the MediaSession associated to this WebContents. Creates one if 70 // Returns the MediaSession associated to this WebContents. Creates one if
69 // none is currently available. 71 // none is currently available.
70 CONTENT_EXPORT static MediaSession* Get(WebContents* web_contents); 72 CONTENT_EXPORT static MediaSession* Get(WebContents* web_contents);
71 73
72 ~MediaSession() override; 74 ~MediaSession() override;
73 75
76 void AddObserver(MediaSessionObserver* observer);
77 void RemoveObserver(MediaSessionObserver* observer);
78 // Only passes ownership and does not observe.
79 void PassObserverOwnership(std::unique_ptr<MediaSessionObserver> owned_observe r);
whywhat 2016/10/20 15:38:33 this seems like an antipattern, along with the map
Zhiqiang Zhang (Slow) 2016/10/20 16:22:32 It's a problem that I've been struggling with. I d
80
74 void SetMetadata(const base::Optional<MediaMetadata>& metadata); 81 void SetMetadata(const base::Optional<MediaMetadata>& metadata);
75 const base::Optional<MediaMetadata>& metadata() const { return metadata_; } 82 const base::Optional<MediaMetadata>& metadata() const { return metadata_; }
76 83
77 // Adds the given player to the current media session. Returns whether the 84 // Adds the given player to the current media session. Returns whether the
78 // player was successfully added. If it returns false, AddPlayer() should be 85 // player was successfully added. If it returns false, AddPlayer() should be
79 // called again later. 86 // called again later.
80 CONTENT_EXPORT bool AddPlayer(MediaSessionPlayerObserver* observer, 87 CONTENT_EXPORT bool AddPlayer(MediaSessionPlayerObserver* observer,
81 int player_id, 88 int player_id,
82 media::MediaContentType media_content_type); 89 media::MediaContentType media_content_type);
83 90
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 MediaSessionUmaHelper uma_helper_; 237 MediaSessionUmaHelper uma_helper_;
231 238
232 // The ducking state of this media session. The initial value is |false|, and 239 // The ducking state of this media session. The initial value is |false|, and
233 // is set to |true| after StartDucking(), and will be set to |false| after 240 // is set to |true| after StartDucking(), and will be set to |false| after
234 // StopDucking(). 241 // StopDucking().
235 bool is_ducking_; 242 bool is_ducking_;
236 243
237 base::Optional<MediaMetadata> metadata_; 244 base::Optional<MediaMetadata> metadata_;
238 base::CallbackList<void(State)> media_session_state_listeners_; 245 base::CallbackList<void(State)> media_session_state_listeners_;
239 246
247 base::ObserverList<MediaSessionObserver> observers_;
248
249 using OwnedObserversType =
250 std::map<MediaSessionObserver*, std::unique_ptr<MediaSessionObserver>>;
boliu 2016/10/19 20:39:40 would scoped_vector be better? is there going to b
Zhiqiang Zhang (Slow) 2016/10/20 16:22:32 The map is used when removing observers from the s
boliu 2016/10/20 16:28:33 Hmm? Usually the argument goes that vectors are sl
Zhiqiang Zhang (Slow) 2016/10/20 17:07:03 You are right, actually base::ObserverList uses st
251 OwnedObserversType owned_observers_;
252
240 DISALLOW_COPY_AND_ASSIGN(MediaSession); 253 DISALLOW_COPY_AND_ASSIGN(MediaSession);
241 }; 254 };
242 255
243 } // namespace content 256 } // namespace content
244 257
245 #endif // CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_H_ 258 #endif // CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698