Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_MEDIA_SESSION_AUDIO_FOCUS_MANAGER_H_ | |
| 6 #define CONTENT_BROWSER_MEDIA_SESSION_AUDIO_FOCUS_MANAGER_H_ | |
| 7 | |
| 8 #include <unordered_map> | |
| 9 | |
| 10 #include "base/memory/singleton.h" | |
| 11 #include "content/common/content_export.h" | |
| 12 #include "content/public/browser/web_contents_observer.h" | |
| 13 | |
| 14 namespace content { | |
| 15 | |
| 16 class MediaSession; | |
| 17 class WebContents; | |
| 18 | |
| 19 class CONTENT_EXPORT AudioFocusManager { | |
| 20 public: | |
| 21 enum class AudioFocusType { | |
|
Zhiqiang Zhang (Slow)
2016/07/07 16:04:25
Maybe we can merge this with MediaSession::Type? I
mlamouri (slow - plz ping)
2016/07/08 13:20:47
I don't think it would make sense for now. In gene
| |
| 22 Gain, | |
| 23 GainTransientMayDuck, | |
| 24 }; | |
| 25 | |
| 26 // Returns Chromium's internal AudioFocusManager. | |
| 27 static AudioFocusManager* GetInstance(); | |
| 28 | |
| 29 void RequestAudioFocus(MediaSession* media_session, AudioFocusType type); | |
| 30 | |
| 31 void AbandonAudioFocus(MediaSession* media_session); | |
| 32 | |
| 33 private: | |
| 34 friend struct base::DefaultSingletonTraits<AudioFocusManager>; | |
| 35 friend class AudioFocusManagerTest; | |
| 36 | |
| 37 // 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 // of WebContents' life time right now but not MediaSession's. | |
| 40 class AudioFocusEntry : public WebContentsObserver { | |
|
Zhiqiang Zhang (Slow)
2016/07/07 16:04:25
As I use WebContentsObserver in the Pepper CL, one
mlamouri (slow - plz ping)
2016/07/08 13:20:47
This is on-demand so it's probably not that bad. T
| |
| 41 public: | |
| 42 AudioFocusEntry(WebContents* web_contents, | |
| 43 AudioFocusManager* audio_focus_manager, | |
| 44 AudioFocusType type); | |
| 45 | |
| 46 AudioFocusType type() const; | |
| 47 | |
| 48 private: | |
| 49 // WebContentsObserver implementation. | |
| 50 void WebContentsDestroyed() override; | |
| 51 | |
| 52 AudioFocusManager* audio_focus_manager_; // Owns |this|. | |
| 53 AudioFocusType type_; | |
| 54 | |
| 55 DISALLOW_COPY_AND_ASSIGN(AudioFocusEntry); | |
| 56 }; | |
| 57 | |
| 58 AudioFocusManager(); | |
| 59 ~AudioFocusManager(); | |
| 60 | |
| 61 void OnWebContentsDestroyed(WebContents* web_contents); | |
| 62 | |
| 63 // This method is meant to be called when a new session is of type | |
| 64 // GainTransientMayDuck. If it is the first one, other clients will be asked | |
| 65 // to duck. | |
| 66 void MaybeStartDucking() const; | |
| 67 | |
| 68 // This method is meant to be called when a session is no longer of type | |
| 69 // GainTransientMayDuck. If it was the last one, other clients will be asked | |
| 70 // to no longer duck. | |
| 71 void MaybeStopDucking() const; | |
| 72 | |
| 73 // Returns how many sessions require current audio focused session to duck. | |
| 74 int TransientMayDuckEntriesCount() const; | |
| 75 | |
| 76 // Internal method to request audio focus of type AudioFocusType::Gain. | |
| 77 void RequestAudioFocusGain(WebContents* web_contents); | |
| 78 | |
| 79 // Removes the entry associated with |web_contents| from the | |
| 80 // |transient_entries_| if there is one. | |
| 81 void MaybeRemoveTransientEntry(WebContents* web_contents); | |
| 82 | |
| 83 // Removes the focused session if it is associated with |web_contents|. | |
| 84 void MaybeRemoveFocusEntry(WebContents* web_contents); | |
| 85 | |
| 86 std::unordered_map<WebContents*, std::unique_ptr<AudioFocusEntry>> | |
| 87 transient_entries_; | |
| 88 std::unique_ptr<AudioFocusEntry> focus_entry_; | |
|
Zhiqiang Zhang (Slow)
2016/07/07 16:04:25
Maybe we should keep all MediaSession entries? Pep
mlamouri (slow - plz ping)
2016/07/08 13:20:47
Let's deal with Flash in a follow-up :) We need to
| |
| 89 }; | |
| 90 | |
| 91 } // namespace content | |
| 92 | |
| 93 #endif // CONTENT_BROWSER_MEDIA_SESSION_AUDIO_FOCUS_MANAGER_H_ | |
| OLD | NEW |