| 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 "base/memory/singleton.h" |
| 9 #include "content/public/browser/web_contents_observer.h" |
| 10 |
| 11 #include <list> |
| 12 #include <unordered_map> |
| 13 |
| 14 namespace content { |
| 15 |
| 16 class MediaSession; |
| 17 class WebContents; |
| 18 |
| 19 class AudioFocusManager { |
| 20 public: |
| 21 enum class AudioFocusType { |
| 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 |
| 36 // TODO(mlamouri): in order to allow multiple MediaSession per WebContents, we |
| 37 // will have to keep track of MediaSession's. Though, we can easily keep track |
| 38 // of WebContents' life time right now but not MediaSession's. |
| 39 class AudioFocusEntry : public WebContentsObserver { |
| 40 public: |
| 41 AudioFocusEntry(WebContents* web_contents, AudioFocusManager* audio_focus_ma
nager, AudioFocusType type); |
| 42 |
| 43 AudioFocusType type() const; |
| 44 void set_type(AudioFocusType type); |
| 45 |
| 46 private: |
| 47 // WebContentsObserver implementation. |
| 48 void WebContentsDestroyed() override; |
| 49 |
| 50 AudioFocusManager* audio_focus_manager_; // Owns |this|. |
| 51 AudioFocusType type_; |
| 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(AudioFocusEntry); |
| 54 }; |
| 55 |
| 56 AudioFocusManager(); |
| 57 ~AudioFocusManager(); |
| 58 |
| 59 void OnWebContentsDestroyed(WebContents* web_contents); |
| 60 |
| 61 // This method is meant to be called when a new session is of type |
| 62 // GainTransientMayDuck. If it is the first one, other clients will be asked |
| 63 // to duck. |
| 64 void MaybeStartDucking() const; |
| 65 |
| 66 // This method is meant to be called when a session is no longer of type |
| 67 // GainTransientMayDuck. If it was the last one, other clients will be asked |
| 68 // to no longer duck. |
| 69 void MaybeStopDucking() const; |
| 70 |
| 71 // Returns how many sessions require ducking. |
| 72 int TransientMayDuckEntriesCount() const; |
| 73 |
| 74 void RemoveFromFocusStack(WebContents* web_contents); |
| 75 |
| 76 std::unordered_map<WebContents*, std::unique_ptr<AudioFocusEntry>> entries_; |
| 77 std::list<WebContents*> focus_stack_; |
| 78 }; |
| 79 |
| 80 } // namespace content |
| 81 |
| 82 #endif // CONTENT_BROWSER_MEDIA_SESSION_AUDIO_FOCUS_MANAGER_H_ |
| OLD | NEW |