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

Unified Diff: content/browser/media/session/audio_focus_manager.h

Issue 1971443002: Implement Audio Focus Manager for desktop. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
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
new file mode 100644
index 0000000000000000000000000000000000000000..1fa9c307381507a908fba630ce327770881eadd9
--- /dev/null
+++ b/content/browser/media/session/audio_focus_manager.h
@@ -0,0 +1,82 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_BROWSER_MEDIA_SESSION_AUDIO_FOCUS_MANAGER_H_
+#define CONTENT_BROWSER_MEDIA_SESSION_AUDIO_FOCUS_MANAGER_H_
+
+#include "base/memory/singleton.h"
+#include "content/public/browser/web_contents_observer.h"
+
+#include <list>
+#include <unordered_map>
+
+namespace content {
+
+class MediaSession;
+class WebContents;
+
+class AudioFocusManager {
+ public:
+ enum class AudioFocusType {
+ Gain,
+ GainTransientMayDuck,
+ };
+
+ // Returns Chromium's internal AudioFocusManager.
+ static AudioFocusManager* GetInstance();
+
+ void RequestAudioFocus(MediaSession* media_session, AudioFocusType type);
+
+ void AbandonAudioFocus(MediaSession* media_session);
+
+ private:
+ friend struct base::DefaultSingletonTraits<AudioFocusManager>;
+
+ // 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;
+ void set_type(AudioFocusType type);
+
+ private:
+ // WebContentsObserver implementation.
+ void WebContentsDestroyed() override;
+
+ AudioFocusManager* audio_focus_manager_; // Owns |this|.
+ AudioFocusType type_;
+
+ DISALLOW_COPY_AND_ASSIGN(AudioFocusEntry);
+ };
+
+ AudioFocusManager();
+ ~AudioFocusManager();
+
+ void OnWebContentsDestroyed(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 ducking.
+ int TransientMayDuckEntriesCount() const;
+
+ void RemoveFromFocusStack(WebContents* web_contents);
+
+ std::unordered_map<WebContents*, std::unique_ptr<AudioFocusEntry>> entries_;
+ std::list<WebContents*> focus_stack_;
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_MEDIA_SESSION_AUDIO_FOCUS_MANAGER_H_

Powered by Google App Engine
This is Rietveld 408576698