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

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

Issue 2274873003: Letting Flash join MediaSession (stack implementaion) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@media_session_type
Patch Set: fixed existing tests (need new tests when behavior is decided) Created 4 years, 3 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_AUDIO_FOCUS_MANAGER_H_ 5 #ifndef CONTENT_BROWSER_MEDIA_SESSION_AUDIO_FOCUS_MANAGER_H_
6 #define CONTENT_BROWSER_MEDIA_SESSION_AUDIO_FOCUS_MANAGER_H_ 6 #define CONTENT_BROWSER_MEDIA_SESSION_AUDIO_FOCUS_MANAGER_H_
7 7
8 #include <list>
8 #include <unordered_map> 9 #include <unordered_map>
9 10
10 #include "base/memory/singleton.h" 11 #include "base/memory/singleton.h"
11 #include "content/common/content_export.h" 12 #include "content/common/content_export.h"
12 #include "content/public/browser/web_contents_observer.h" 13 #include "content/public/browser/web_contents_observer.h"
13 14
14 namespace content { 15 namespace content {
15 16
16 class MediaSession; 17 class MediaSession;
17 class WebContents; 18 class WebContents;
(...skipping 19 matching lines...) Expand all
37 // TODO(mlamouri): in order to allow multiple MediaSession per WebContents, we 38 // TODO(mlamouri): in order to allow multiple MediaSession per WebContents, we
38 // will have to keep track of MediaSession's. Though, we can easily keep track 39 // will have to keep track of MediaSession's. Though, we can easily keep track
39 // of WebContents' life time right now but not MediaSession's. 40 // of WebContents' life time right now but not MediaSession's.
40 class AudioFocusEntry : public WebContentsObserver { 41 class AudioFocusEntry : public WebContentsObserver {
41 public: 42 public:
42 AudioFocusEntry(WebContents* web_contents, 43 AudioFocusEntry(WebContents* web_contents,
43 AudioFocusManager* audio_focus_manager, 44 AudioFocusManager* audio_focus_manager,
44 AudioFocusType type); 45 AudioFocusType type);
45 46
46 AudioFocusType type() const; 47 AudioFocusType type() const;
48 MediaSession* ToMediaSession() const;
whywhat 2016/09/13 00:16:17 nit: This is a misleading name that is typically u
Zhiqiang Zhang (Slow) 2016/09/22 12:30:33 I think ultimately we should use MediaSession* in
47 49
48 private: 50 private:
49 // WebContentsObserver implementation. 51 // WebContentsObserver implementation.
50 void WebContentsDestroyed() override; 52 void WebContentsDestroyed() override;
51 53
52 AudioFocusManager* audio_focus_manager_; // Owns |this|. 54 AudioFocusManager* audio_focus_manager_; // Owns |this|.
53 AudioFocusType type_; 55 AudioFocusType type_;
54 56
55 DISALLOW_COPY_AND_ASSIGN(AudioFocusEntry); 57 DISALLOW_COPY_AND_ASSIGN(AudioFocusEntry);
56 }; 58 };
57 59
58 AudioFocusManager(); 60 AudioFocusManager();
59 ~AudioFocusManager(); 61 ~AudioFocusManager();
60 62
61 void OnWebContentsDestroyed(WebContents* web_contents); 63 void OnWebContentsDestroyed(WebContents* web_contents);
62 64
63 // Internal usage of AbandonAudioFocus using WebContents.
64 void AbandonAudioFocusInternal(WebContents* web_contents);
65
66 // This method is meant to be called when a new session is of type
67 // GainTransientMayDuck. If it is the first one, other clients will be asked
68 // to duck.
69 void MaybeStartDucking() const;
70
71 // This method is meant to be called when a session is no longer of type
72 // GainTransientMayDuck. If it was the last one, other clients will be asked
73 // to no longer duck.
74 void MaybeStopDucking() const;
75
76 // Returns how many sessions require current audio focused session to duck.
77 int TransientMayDuckEntriesCount() const;
78
79 // Internal method to request audio focus of type AudioFocusType::Gain.
80 void RequestAudioFocusGain(WebContents* web_contents);
81
82 // Removes the entry associated with |web_contents| from the
83 // |transient_entries_| if there is one.
84 void MaybeRemoveTransientEntry(WebContents* web_contents);
85
86 // Removes the focused session if it is associated with |web_contents|.
87 void MaybeRemoveFocusEntry(WebContents* web_contents); 65 void MaybeRemoveFocusEntry(WebContents* web_contents);
88 66
89 std::unordered_map<WebContents*, std::unique_ptr<AudioFocusEntry>> 67 std::list<std::unique_ptr<AudioFocusEntry>> audio_focus_stack_;
90 transient_entries_;
91 std::unique_ptr<AudioFocusEntry> focus_entry_;
92 }; 68 };
93 69
94 } // namespace content 70 } // namespace content
95 71
96 #endif // CONTENT_BROWSER_MEDIA_SESSION_AUDIO_FOCUS_MANAGER_H_ 72 #endif // CONTENT_BROWSER_MEDIA_SESSION_AUDIO_FOCUS_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698