Index: content/browser/media/session/media_session_delegate_android.h |
diff --git a/content/browser/media/session/media_session_delegate_android.h b/content/browser/media/session/media_session_delegate_android.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..dfc55719e215fc6fd0419c57f81be1fefaa45815 |
--- /dev/null |
+++ b/content/browser/media/session/media_session_delegate_android.h |
@@ -0,0 +1,68 @@ |
+// 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_SESSION_MEDIA_SESSION_DELEGATE_ANDROID_H_ |
+#define CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_DELEGATE_ANDROID_H_ |
+ |
+#include <jni.h> |
+ |
+#include "base/android/jni_weak_ref.h" |
+#include "content/browser/media/session/media_session_observer.h" |
+ |
+namespace content { |
+ |
+// The class for listening to MediaSession messages and perform actions on the |
+// MediaSession. This class is the native counterpart of Java |
+// MediaSessionDelegate. The native object and the linked Java object must |
+// notify each other when any of them is destroyed. |
+class MediaSessionDelegateAndroid : public MediaSessionObserver { |
+ public: |
+ static bool Register(JNIEnv* env); |
+ |
+ // Create a native MediaSessionDelegate object, start observe |media_session|, |
+ // and link it to the |j_delegate| (its Java counterpart). |
+ static void CreateAndConnect( |
+ MediaSession* media_session, |
+ JNIEnv* env, |
+ const base::android::JavaParamRef<jobject>& j_delegate); |
+ |
+ ~MediaSessionDelegateAndroid() override; |
+ |
+ // MediaSessionObserver implementations |
+ void MediaSessionDisconnected() override; |
+ void MediaSessionStateChanged(bool is_controllable, |
+ bool is_suspended) override; |
+ void MediaSessionMetadataChanged( |
+ const base::Optional<MediaMetadata>& metadata) override; |
+ |
+ // Resume the connected MediaSession. |
+ void ResumeMediaSession(JNIEnv* env, |
+ const base::android::JavaParamRef<jobject>& obj); |
+ // Suspend the connected MediaSession. |
+ void SuspendMediaSession(JNIEnv* env, |
+ const base::android::JavaParamRef<jobject>& obj); |
+ // Stop the connected MediaSession. |
+ void StopMediaSession(JNIEnv* env, |
+ const base::android::JavaParamRef<jobject>& obj); |
+ // Disconnect the connected MediaSession. |
+ void DisconnectMediaSession(JNIEnv* env, |
+ const base::android::JavaParamRef<jobject>& obj); |
+ |
+ private: |
+ // Create a MediaSessionDelegateAndroid object and start observing |
+ // |media_session|. Does not tell |j_delegate| to connect this object. |
+ MediaSessionDelegateAndroid( |
+ MediaSession* media_session, |
+ JNIEnv* env, |
+ const base::android::JavaParamRef<jobject>& j_delegate); |
+ |
+ // The linked Java counterpart. |
+ JavaObjectWeakGlobalRef j_delegate_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(MediaSessionDelegateAndroid); |
+}; |
+ |
+} // namespace content |
+ |
+#endif // CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_DELEGATE_ANDROID_H_ |