OLD | NEW |
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; |
18 | 19 |
19 class CONTENT_EXPORT AudioFocusManager { | 20 class CONTENT_EXPORT AudioFocusManager { |
20 public: | 21 public: |
21 enum class AudioFocusType { | 22 enum class AudioFocusType { |
22 Gain, | 23 Gain, |
23 GainTransientMayDuck, | 24 GainTransientMayDuck, |
24 }; | 25 }; |
25 | 26 |
26 // Returns Chromium's internal AudioFocusManager. | 27 // Returns Chromium's internal AudioFocusManager. |
27 static AudioFocusManager* GetInstance(); | 28 static AudioFocusManager* GetInstance(); |
28 | 29 |
29 void RequestAudioFocus(MediaSession* media_session, AudioFocusType type); | 30 void RequestAudioFocus(MediaSession* media_session, AudioFocusType type); |
30 | 31 void RequestPepperAudioFocus(MediaSession* media_session); |
31 void AbandonAudioFocus(MediaSession* media_session); | 32 void AbandonAudioFocus(MediaSession* media_session); |
| 33 void AbandonPepperAudioFocus(MediaSession* media_session); |
32 | 34 |
33 private: | 35 private: |
34 friend struct base::DefaultSingletonTraits<AudioFocusManager>; | 36 friend struct base::DefaultSingletonTraits<AudioFocusManager>; |
35 friend class AudioFocusManagerTest; | 37 friend class AudioFocusManagerTest; |
36 | 38 |
37 // TODO(mlamouri): in order to allow multiple MediaSession per WebContents, we | 39 // 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 | 40 // 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. | 41 // of WebContents' life time right now but not MediaSession's. |
40 class AudioFocusEntry : public WebContentsObserver { | 42 class AudioFocusEntry : public WebContentsObserver { |
41 public: | 43 public: |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 // Internal method to request audio focus of type AudioFocusType::Gain. | 81 // Internal method to request audio focus of type AudioFocusType::Gain. |
80 void RequestAudioFocusGain(WebContents* web_contents); | 82 void RequestAudioFocusGain(WebContents* web_contents); |
81 | 83 |
82 // Removes the entry associated with |web_contents| from the | 84 // Removes the entry associated with |web_contents| from the |
83 // |transient_entries_| if there is one. | 85 // |transient_entries_| if there is one. |
84 void MaybeRemoveTransientEntry(WebContents* web_contents); | 86 void MaybeRemoveTransientEntry(WebContents* web_contents); |
85 | 87 |
86 // Removes the focused session if it is associated with |web_contents|. | 88 // Removes the focused session if it is associated with |web_contents|. |
87 void MaybeRemoveFocusEntry(WebContents* web_contents); | 89 void MaybeRemoveFocusEntry(WebContents* web_contents); |
88 | 90 |
| 91 void MaybeRemovePepperEntry(WebContents* web_contents); |
| 92 |
| 93 void UpdatePepperFocus() const; |
| 94 |
89 std::unordered_map<WebContents*, std::unique_ptr<AudioFocusEntry>> | 95 std::unordered_map<WebContents*, std::unique_ptr<AudioFocusEntry>> |
90 transient_entries_; | 96 transient_entries_; |
91 std::unique_ptr<AudioFocusEntry> focus_entry_; | 97 std::unique_ptr<AudioFocusEntry> focus_entry_; |
| 98 std::list<std::unique_ptr<AudioFocusEntry>> pepper_entries_; |
92 }; | 99 }; |
93 | 100 |
94 } // namespace content | 101 } // namespace content |
95 | 102 |
96 #endif // CONTENT_BROWSER_MEDIA_SESSION_AUDIO_FOCUS_MANAGER_H_ | 103 #endif // CONTENT_BROWSER_MEDIA_SESSION_AUDIO_FOCUS_MANAGER_H_ |
OLD | NEW |