Chromium Code Reviews| Index: content/browser/media/android/media_session_controller.h |
| diff --git a/content/browser/media/android/media_session_controller.h b/content/browser/media/android/media_session_controller.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..db52dcf5d36dd3477173058ba83678803a26eb71 |
| --- /dev/null |
| +++ b/content/browser/media/android/media_session_controller.h |
| @@ -0,0 +1,72 @@ |
| +// 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_ANDROID_MEDIA_SESSION_CONTROLLER_H_ |
| +#define CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_SESSION_CONTROLLER_H_ |
| + |
| +#include "base/time/time.h" |
| +#include "content/browser/media/android/media_session.h" |
| +#include "content/browser/media/android/media_session_observer.h" |
| +#include "content/common/content_export.h" |
| +#include "content/public/browser/web_contents_observer.h" |
| + |
| +namespace content { |
| +class MediaWebContentsObserver; |
|
mlamouri (slow - plz ping)
2016/01/26 21:02:50
nit: leave an empty line between `namespace` and `
DaleCurtis
2016/01/27 02:25:13
Done.
|
| + |
| +// Helper class for controlling a single player's MediaSession instance. Sends |
| +// browser side MediaSession commands back to a player hosted in the renderer |
| +// process. |
| +class CONTENT_EXPORT MediaSessionController : public MediaSessionObserver { |
| + public: |
| + MediaSessionController(const WebContentsObserver::MediaPlayerId& id, |
| + MediaWebContentsObserver* media_web_contents_observer); |
| + ~MediaSessionController() override; |
| + |
| + // Minimum duration of content for a MediaSession instance to be created. |
| + enum { kMinimumDurationForContentSecs = 5 }; |
| + |
| + // Clients must call this after construction and destroy the controller if it |
| + // returns false. May be called more than once; does nothing if none of the |
| + // input parameters have changed since the last call. |
| + // |
| + // Note: Once a session has been initialized with |has_audio| as true, all |
| + // future calls to Initialize() will retain this flag. |
| + // TODO(dalecurtis): Delete sticky audio once we're no longer using WMPA and |
| + // the BrowserMediaPlayerManagers. Tracked by http://crbug.com/580626 |
| + bool Initialize(bool has_audio, bool is_remote, base::TimeDelta duration); |
| + |
| + // Must be called when a pause occurs on the renderer side media player; keeps |
| + // the MediaSession instance in sync with renderer side behavior. |
| + void OnPlaybackPaused(); |
| + |
| + // MediaSessionObserver implementation. |
| + void OnSuspend(int player_id) override; |
| + void OnResume(int player_id) override; |
| + void OnSetVolumeMultiplier(int player_id, double volume_multiplier) override; |
| + |
| + // Test helpers. |
| + int get_player_id_for_testing() const { return player_id_; } |
| + MediaSession::Type get_session_type_for_testing() const { |
| + return session_type_; |
| + } |
| + |
| + private: |
| + const WebContentsObserver::MediaPlayerId id_; |
| + |
| + // Non-owned pointer; |media_web_contents_observer_| is the owner of |this|. |
| + MediaWebContentsObserver* const media_web_contents_observer_; |
| + |
| + // Non-owned pointer; lifetime is the same as |media_web_contents_observer_|. |
| + MediaSession* const media_session_; |
| + |
| + int player_id_ = 0; |
| + bool has_session_ = false; |
| + MediaSession::Type session_type_ = MediaSession::Type::Content; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(MediaSessionController); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_SESSION_CONTROLLER_H_ |