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

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 comments 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..705575a3b9e826177c1ee0bd0576baf8b7aee3b2
--- /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 {
+ // 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 final void resumeMediaSession() {
+ if (hasNativeMediaSession()) nativeResumeMediaSession(mNativeMediaSessionDelegateAndroid);
+ }
+
+ /**
+ * Suspend the native {@link MediaSession}.
+ */
+ public final void suspendMediaSession() {
+ if (hasNativeMediaSession()) nativeSuspendMediaSession(mNativeMediaSessionDelegateAndroid);
+ }
+
+ /**
+ * Stop the native {@link MediaSession}.
+ */
+ public final void stopMediaSession() {
+ if (hasNativeMediaSession()) nativeStopMediaSession(mNativeMediaSessionDelegateAndroid);
+ }
+
+ @CalledByNative
+ private final void onMediaSessionConnected(long nativeMediaSessionDelegateAndroid) {
+ mNativeMediaSessionDelegateAndroid = nativeMediaSessionDelegateAndroid;
+ }
+
+ @CalledByNative
+ private final void onMediaSessionDisconnected() {
+ mNativeMediaSessionDelegateAndroid = 0;
+ mediaSessionDisconnected();
+ }
+
+ /**
+ * @return Whether this {@link MediaSessionDelegate} object is connected to a native
+ * MediaSession.
+ */
+ private final boolean hasNativeMediaSession() {
+ return mNativeMediaSessionDelegateAndroid != 0;
whywhat 2016/10/21 18:28:15 Why do you think any methods of this class can be
+ }
+
+ 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