| Index: content/browser/media/session/audio_focus_manager.h
|
| diff --git a/content/browser/media/session/audio_focus_manager.h b/content/browser/media/session/audio_focus_manager.h
|
| index 9cbf13f06daac2de74f3edf743a510ee5d18ad1f..6844ae767c402324872af4f787b100f3722e0222 100644
|
| --- a/content/browser/media/session/audio_focus_manager.h
|
| +++ b/content/browser/media/session/audio_focus_manager.h
|
| @@ -5,7 +5,6 @@
|
| #ifndef CONTENT_BROWSER_MEDIA_SESSION_AUDIO_FOCUS_MANAGER_H_
|
| #define CONTENT_BROWSER_MEDIA_SESSION_AUDIO_FOCUS_MANAGER_H_
|
|
|
| -#include <list>
|
| #include <unordered_map>
|
|
|
| #include "base/memory/singleton.h"
|
| @@ -15,6 +14,7 @@
|
| namespace content {
|
|
|
| class MediaSession;
|
| +class WebContents;
|
|
|
| class CONTENT_EXPORT AudioFocusManager {
|
| public:
|
| @@ -34,14 +34,61 @@
|
| friend struct base::DefaultSingletonTraits<AudioFocusManager>;
|
| friend class AudioFocusManagerTest;
|
|
|
| + // TODO(mlamouri): in order to allow multiple MediaSession per WebContents, we
|
| + // will have to keep track of MediaSession's. Though, we can easily keep track
|
| + // of WebContents' life time right now but not MediaSession's.
|
| + class AudioFocusEntry : public WebContentsObserver {
|
| + public:
|
| + AudioFocusEntry(WebContents* web_contents,
|
| + AudioFocusManager* audio_focus_manager,
|
| + AudioFocusType type);
|
| +
|
| + AudioFocusType type() const;
|
| +
|
| + private:
|
| + // WebContentsObserver implementation.
|
| + void WebContentsDestroyed() override;
|
| +
|
| + AudioFocusManager* audio_focus_manager_; // Owns |this|.
|
| + AudioFocusType type_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(AudioFocusEntry);
|
| + };
|
| +
|
| AudioFocusManager();
|
| ~AudioFocusManager();
|
|
|
| - void MaybeRemoveFocusEntry(MediaSession* media_session);
|
| + void OnWebContentsDestroyed(WebContents* web_contents);
|
|
|
| - // Weak reference of managed MediaSessions. A MediaSession must abandon audio
|
| - // foucs before its destruction.
|
| - std::list<MediaSession*> audio_focus_stack_;
|
| + // Internal usage of AbandonAudioFocus using WebContents.
|
| + void AbandonAudioFocusInternal(WebContents* web_contents);
|
| +
|
| + // This method is meant to be called when a new session is of type
|
| + // GainTransientMayDuck. If it is the first one, other clients will be asked
|
| + // to duck.
|
| + void MaybeStartDucking() const;
|
| +
|
| + // This method is meant to be called when a session is no longer of type
|
| + // GainTransientMayDuck. If it was the last one, other clients will be asked
|
| + // to no longer duck.
|
| + void MaybeStopDucking() const;
|
| +
|
| + // Returns how many sessions require current audio focused session to duck.
|
| + int TransientMayDuckEntriesCount() const;
|
| +
|
| + // Internal method to request audio focus of type AudioFocusType::Gain.
|
| + void RequestAudioFocusGain(WebContents* web_contents);
|
| +
|
| + // Removes the entry associated with |web_contents| from the
|
| + // |transient_entries_| if there is one.
|
| + void MaybeRemoveTransientEntry(WebContents* web_contents);
|
| +
|
| + // Removes the focused session if it is associated with |web_contents|.
|
| + void MaybeRemoveFocusEntry(WebContents* web_contents);
|
| +
|
| + std::unordered_map<WebContents*, std::unique_ptr<AudioFocusEntry>>
|
| + transient_entries_;
|
| + std::unique_ptr<AudioFocusEntry> focus_entry_;
|
| };
|
|
|
| } // namespace content
|
|
|