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_ANDROID_MEDIA_SESSION_CONTROLLER_H_ | |
6 #define CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_SESSION_CONTROLLER_H_ | |
7 | |
8 #include "base/time/time.h" | |
9 #include "content/browser/media/android/media_session.h" | |
10 #include "content/browser/media/android/media_session_observer.h" | |
11 #include "content/common/content_export.h" | |
12 #include "content/public/browser/web_contents_observer.h" | |
13 | |
14 namespace content { | |
15 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.
| |
16 | |
17 // Helper class for controlling a single player's MediaSession instance. Sends | |
18 // browser side MediaSession commands back to a player hosted in the renderer | |
19 // process. | |
20 class CONTENT_EXPORT MediaSessionController : public MediaSessionObserver { | |
21 public: | |
22 MediaSessionController(const WebContentsObserver::MediaPlayerId& id, | |
23 MediaWebContentsObserver* media_web_contents_observer); | |
24 ~MediaSessionController() override; | |
25 | |
26 // Minimum duration of content for a MediaSession instance to be created. | |
27 enum { kMinimumDurationForContentSecs = 5 }; | |
28 | |
29 // Clients must call this after construction and destroy the controller if it | |
30 // returns false. May be called more than once; does nothing if none of the | |
31 // input parameters have changed since the last call. | |
32 // | |
33 // Note: Once a session has been initialized with |has_audio| as true, all | |
34 // future calls to Initialize() will retain this flag. | |
35 // TODO(dalecurtis): Delete sticky audio once we're no longer using WMPA and | |
36 // the BrowserMediaPlayerManagers. Tracked by http://crbug.com/580626 | |
37 bool Initialize(bool has_audio, bool is_remote, base::TimeDelta duration); | |
38 | |
39 // Must be called when a pause occurs on the renderer side media player; keeps | |
40 // the MediaSession instance in sync with renderer side behavior. | |
41 void OnPlaybackPaused(); | |
42 | |
43 // MediaSessionObserver implementation. | |
44 void OnSuspend(int player_id) override; | |
45 void OnResume(int player_id) override; | |
46 void OnSetVolumeMultiplier(int player_id, double volume_multiplier) override; | |
47 | |
48 // Test helpers. | |
49 int get_player_id_for_testing() const { return player_id_; } | |
50 MediaSession::Type get_session_type_for_testing() const { | |
51 return session_type_; | |
52 } | |
53 | |
54 private: | |
55 const WebContentsObserver::MediaPlayerId id_; | |
56 | |
57 // Non-owned pointer; |media_web_contents_observer_| is the owner of |this|. | |
58 MediaWebContentsObserver* const media_web_contents_observer_; | |
59 | |
60 // Non-owned pointer; lifetime is the same as |media_web_contents_observer_|. | |
61 MediaSession* const media_session_; | |
62 | |
63 int player_id_ = 0; | |
64 bool has_session_ = false; | |
65 MediaSession::Type session_type_ = MediaSession::Type::Content; | |
66 | |
67 DISALLOW_COPY_AND_ASSIGN(MediaSessionController); | |
68 }; | |
69 | |
70 } // namespace content | |
71 | |
72 #endif // CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_SESSION_CONTROLLER_H_ | |
OLD | NEW |