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

Unified Diff: content/public/android/java/src/org/chromium/content_public/browser/MediaSessionDelegate.java

Issue 2439483003: Link MediaSessionTabHelper with native MediaSession [CL is going to be split] (Closed)
Patch Set: addressed nits Created 4 years, 2 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/public/android/java/src/org/chromium/content_public/browser/MediaSessionDelegate.java
diff --git a/content/public/android/java/src/org/chromium/content_public/browser/MediaSessionDelegate.java b/content/public/android/java/src/org/chromium/content_public/browser/MediaSessionDelegate.java
new file mode 100644
index 0000000000000000000000000000000000000000..b3c89dd8d3b34b13e33ef32c8b500e7b53ca9f80
--- /dev/null
+++ b/content/public/android/java/src/org/chromium/content_public/browser/MediaSessionDelegate.java
@@ -0,0 +1,102 @@
+// 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.
+
+package org.chromium.content_public.browser;
+
+import org.chromium.base.annotations.CalledByNative;
+import org.chromium.base.annotations.JNINamespace;
+import org.chromium.content_public.common.MediaMetadata;
+
+/**
+ * The class for listening to native {@link MediaSession} and operating on it. It is the Java
+ * counterpart of {@link MediaSessionDelegateAndroid}. The Java object and its linked native object
+ * must notify each other when anyone of them is destroyed. Clients of this class should create a
+ * {@link MediaSessionDelegate} object and explicitly call
+ * {@link WebContents#addMediaSessionDelegate} with the object as an argument. Clients of this class
+ * should also call {@link MediaSessionDelegate#disconnectMediaSession} when dereferencing the
+ * object.
+ */
+@JNINamespace("content")
+public class MediaSessionDelegate {
whywhat 2016/10/20 22:56:53 Do you expect other derived classes from this one?
Zhiqiang Zhang (Slow) 2016/10/21 13:43:53 I prefer not to merge it, since the subclass in MS
+ // The native MediaSessionDelegateAndroid object
+ private long mNativeMediaSessionDelegateAndroid;
+
+ /**
+ * Disconnects this delegate from the associated MediaSession. Clients of this class must call
+ * this method when dereferencing this object. The clean up is done in
+ * {@link MediaSessionDelegate#mediaSessionDisconnected}.
+ */
+ public final void disconnectMediaSession() {
+ if (hasNativeMediaSession()) {
+ nativeDisconnectMediaSession(mNativeMediaSessionDelegateAndroid);
+ }
+ }
+
+ /**
+ * Called when this {@link MediaSessionDelegate} has been disconnected from a native
+ * {@link MediaSession}.
+ */
+ public void mediaSessionDisconnected() {}
+
+ /**
+ * Called when the native {@link MediaSession} state has changed.
+ * @param isControllable Whether the native {@link MediaSession} is controllable.
+ * @param isSuspended Whether the native {@link MediaSession} is suspended.
+ */
+ @CalledByNative
+ public void mediaSessionStateChanged(boolean isControllable, boolean isSuspended) {}
+
+ /**
+ * Called when the native {@link MediaSession} has changed metadata.
+ * @param metadata The new metadata of the native {@link MediaSession}. "null" is for unsetting
+ * metadata.
+ */
+ @CalledByNative
+ public void mediaSessionMetadataChanged(MediaMetadata metadata) {}
+
+ /**
+ * Resume the native {@link MediaSession}.
+ */
+ public void resumeMediaSession() {
+ if (hasNativeMediaSession()) nativeResumeMediaSession(mNativeMediaSessionDelegateAndroid);
whywhat 2016/10/20 22:56:53 I think if you set mMediaSessionDelegate to null i
Zhiqiang Zhang (Slow) 2016/10/21 13:43:53 Yes. Just in case the client still somehow calls t
whywhat 2016/10/21 15:51:36 How? If you set the only reference to it to null,
+ }
+
+ /**
+ * Suspend the native {@link MediaSession}.
+ */
+ public void suspendMediaSession() {
+ if (hasNativeMediaSession()) nativeSuspendMediaSession(mNativeMediaSessionDelegateAndroid);
+ }
+
+ /**
+ * Stop the native {@link MediaSession}.
+ */
+ public void stopMediaSession() {
+ if (hasNativeMediaSession()) nativeStopMediaSession(mNativeMediaSessionDelegateAndroid);
+ }
+
+ @CalledByNative
+ private final void mediaSessionConnected(long nativeMediaSessionDelegateAndroid) {
+ mNativeMediaSessionDelegateAndroid = nativeMediaSessionDelegateAndroid;
+ }
+
+ @CalledByNative
+ private void mediaSessionDisconnectedWrapper() {
whywhat 2016/10/20 22:56:53 why wrapper? Perhaps you could've: @CalledByNati
Zhiqiang Zhang (Slow) 2016/10/21 13:43:53 Yes, sorry I'm bad at names. Using "on-" now. Howe
whywhat 2016/10/21 15:51:36 Does it matter that MediaSession is still alive if
+ mNativeMediaSessionDelegateAndroid = 0;
+ mediaSessionDisconnected();
+ }
+
+ /**
+ * @return Whether this {@link MediaSessionDelegate} object is connected to a native
+ * MediaSession.
+ */
+ private boolean hasNativeMediaSession() {
+ return mNativeMediaSessionDelegateAndroid != 0;
+ }
+
+ private native void nativeResumeMediaSession(long nativeMediaSessionDelegateAndroid);
+ private native void nativeSuspendMediaSession(long nativeMediaSessionDelegateAndroid);
+ private native void nativeStopMediaSession(long nativeMediaSessionDelegateAndroid);
+ private native void nativeDisconnectMediaSession(long nativeMediaSessionDelegateAndroid);
+}

Powered by Google App Engine
This is Rietveld 408576698