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

Side by Side Diff: content/browser/media/android/media_session.h

Issue 1243683003: Android MediaSession: do not resume a UI suspended session on a system resume. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add tests Created 5 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_ANDROID_MEDIA_SESSION_H_ 5 #ifndef CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_SESSION_H_
6 #define CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_SESSION_H_ 6 #define CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_SESSION_H_
7 7
8 #include <jni.h> 8 #include <jni.h>
9 9
10 #include "base/android/scoped_java_ref.h" 10 #include "base/android/scoped_java_ref.h"
(...skipping 20 matching lines...) Expand all
31 // Android system interaction occurs in the Java counterpart to this class. 31 // Android system interaction occurs in the Java counterpart to this class.
32 class CONTENT_EXPORT MediaSession 32 class CONTENT_EXPORT MediaSession
33 : public WebContentsObserver, 33 : public WebContentsObserver,
34 protected WebContentsUserData<MediaSession> { 34 protected WebContentsUserData<MediaSession> {
35 public: 35 public:
36 enum class Type { 36 enum class Type {
37 Content, 37 Content,
38 Transient 38 Transient
39 }; 39 };
40 40
41 enum class SuspendType {
42 // Suspended by the system because a transient sound needs to be played.
43 System,
qinmin 2015/07/21 22:58:17 s/System/SYSTEM/
44 // Suspended by the UI.
45 UI,
46 };
47
41 static bool RegisterMediaSession(JNIEnv* env); 48 static bool RegisterMediaSession(JNIEnv* env);
42 49
43 // Returns the MediaSession associated to this WebContents. Creates one if 50 // Returns the MediaSession associated to this WebContents. Creates one if
44 // none is currently available. 51 // none is currently available.
45 static MediaSession* Get(WebContents* web_contents); 52 static MediaSession* Get(WebContents* web_contents);
46 53
47 ~MediaSession() override; 54 ~MediaSession() override;
48 55
49 // Adds the given player to the current media session. Returns whether the 56 // Adds the given player to the current media session. Returns whether the
50 // player was successfully added. If it returns false, AddPlayer() should be 57 // player was successfully added. If it returns false, AddPlayer() should be
(...skipping 11 matching lines...) Expand all
62 // Called when the Android system requests the MediaSession to be suspended. 69 // Called when the Android system requests the MediaSession to be suspended.
63 // Called by Java through JNI. 70 // Called by Java through JNI.
64 void OnSuspend(JNIEnv* env, jobject obj, jboolean temporary); 71 void OnSuspend(JNIEnv* env, jobject obj, jboolean temporary);
65 72
66 // Called when the Android system requests the MediaSession to be resumed. 73 // Called when the Android system requests the MediaSession to be resumed.
67 // Called by Java through JNI. 74 // Called by Java through JNI.
68 void OnResume(JNIEnv* env, jobject obj); 75 void OnResume(JNIEnv* env, jobject obj);
69 76
70 // Called when the user requests resuming the session. No-op if the session is 77 // Called when the user requests resuming the session. No-op if the session is
71 // not controllable. 78 // not controllable.
72 void Resume(); 79 void Resume(SuspendType type);
73 80
74 // Called when the user requests suspending the session. No-op if the session 81 // Called when the user requests suspending the session. No-op if the session
75 // is not controllable. 82 // is not controllable.
76 void Suspend(); 83 void Suspend(SuspendType type);
77 84
78 // Returns if the session can be controlled by Resume() and Suspend calls 85 // Returns if the session can be controlled by Resume() and Suspend calls
79 // above. 86 // above.
80 bool IsControllable() const; 87 bool IsControllable() const;
81 88
82 // Returns if the session is currently suspended. 89 // Returns if the session is currently suspended.
83 bool IsSuspended() const; 90 bool IsSuspended() const;
84 91
85 private: 92 private:
86 friend class content::WebContentsUserData<MediaSession>; 93 friend class content::WebContentsUserData<MediaSession>;
87 friend class ::MediaSessionBrowserTest; 94 friend class ::MediaSessionBrowserTest;
88 95
89 // Resets the |j_media_session_| ref to prevent calling the Java backend 96 // Resets the |j_media_session_| ref to prevent calling the Java backend
90 // during content_browsertests. 97 // during content_browsertests.
91 void ResetJavaRefForTest(); 98 void ResetJavaRefForTest();
92 bool IsActiveForTest() const; 99 bool IsActiveForTest() const;
93 Type audio_focus_type_for_test() const; 100 Type audio_focus_type_for_test() const;
94 void RemoveAllPlayersForTest(); 101 void RemoveAllPlayersForTest();
95 102
96 void OnSuspendInternal(bool temporary); 103 void OnSuspendInternal(SuspendType type);
97 void OnResumeInternal(); 104 void OnResumeInternal(SuspendType type);
98 105
99 enum class State { 106 enum class State {
100 Active, 107 Active,
qinmin 2015/07/21 22:58:17 change all the enum names here ACTIVE, SUSPENDED,
101 TemporarilySuspended,
102 Suspended, 108 Suspended,
109 Inactive
103 }; 110 };
104 111
105 // Representation of a player for the MediaSession. 112 // Representation of a player for the MediaSession.
106 struct PlayerIdentifier { 113 struct PlayerIdentifier {
107 PlayerIdentifier(MediaSessionObserver* observer, int player_id); 114 PlayerIdentifier(MediaSessionObserver* observer, int player_id);
108 PlayerIdentifier(const PlayerIdentifier&) = default; 115 PlayerIdentifier(const PlayerIdentifier&) = default;
109 116
110 void operator=(const PlayerIdentifier&) = delete; 117 void operator=(const PlayerIdentifier&) = delete;
111 bool operator==(const PlayerIdentifier& player_identifier) const; 118 bool operator==(const PlayerIdentifier& player_identifier) const;
112 119
(...skipping 21 matching lines...) Expand all
134 // MediaSession if the audio focus really need to be abandoned. 141 // MediaSession if the audio focus really need to be abandoned.
135 void AbandonSystemAudioFocusIfNeeded(); 142 void AbandonSystemAudioFocusIfNeeded();
136 143
137 // Notifies WebContents about the state change of the media session. 144 // Notifies WebContents about the state change of the media session.
138 void UpdateWebContents(); 145 void UpdateWebContents();
139 146
140 base::android::ScopedJavaGlobalRef<jobject> j_media_session_; 147 base::android::ScopedJavaGlobalRef<jobject> j_media_session_;
141 PlayersMap players_; 148 PlayersMap players_;
142 149
143 State audio_focus_state_; 150 State audio_focus_state_;
151 SuspendType suspend_type_;
144 Type audio_focus_type_; 152 Type audio_focus_type_;
145 153
146 DISALLOW_COPY_AND_ASSIGN(MediaSession); 154 DISALLOW_COPY_AND_ASSIGN(MediaSession);
147 }; 155 };
148 156
149 } // namespace content 157 } // namespace content
150 158
151 #endif // CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_SESSION_H_ 159 #endif // CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_SESSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698