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_SESSION_MEDIA_SESSION_DELEGATE_ANDROID_H_ |
| 6 #define CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_DELEGATE_ANDROID_H_ |
| 7 |
| 8 #include <jni.h> |
| 9 |
| 10 #include "base/android/jni_weak_ref.h" |
| 11 #include "content/browser/media/session/media_session_observer.h" |
| 12 |
| 13 namespace content { |
| 14 |
| 15 // The class for listening to MediaSession messages and perform actions on the |
| 16 // MediaSession. This class is the native counterpart of Java |
| 17 // MediaSessionDelegate. The native object and the linked Java object must |
| 18 // notify each other when any of them is destroyed. |
| 19 class MediaSessionDelegateAndroid : public MediaSessionObserver { |
| 20 public: |
| 21 static bool Register(JNIEnv* env); |
| 22 |
| 23 // Create a native MediaSessionDelegate object, start observe |media_session|, |
| 24 // and link it to the |j_delegate| (its Java counterpart). |
| 25 static void CreateAndConnect( |
| 26 MediaSession* media_session, |
| 27 JNIEnv* env, |
| 28 const base::android::JavaParamRef<jobject>& j_delegate); |
| 29 |
| 30 ~MediaSessionDelegateAndroid() override; |
| 31 |
| 32 // MediaSessionObserver implementations |
| 33 void MediaSessionDisconnected() override; |
| 34 void MediaSessionStateChanged(bool is_controllable, |
| 35 bool is_suspended) override; |
| 36 void MediaSessionMetadataChanged( |
| 37 const base::Optional<MediaMetadata>& metadata) override; |
| 38 |
| 39 // Resume the connected MediaSession. |
| 40 void ResumeMediaSession(JNIEnv* env, |
| 41 const base::android::JavaParamRef<jobject>& obj); |
| 42 // Suspend the connected MediaSession. |
| 43 void SuspendMediaSession(JNIEnv* env, |
| 44 const base::android::JavaParamRef<jobject>& obj); |
| 45 // Stop the connected MediaSession. |
| 46 void StopMediaSession(JNIEnv* env, |
| 47 const base::android::JavaParamRef<jobject>& obj); |
| 48 // Disconnect the connected MediaSession. |
| 49 void DisconnectMediaSession(JNIEnv* env, |
| 50 const base::android::JavaParamRef<jobject>& obj); |
| 51 |
| 52 private: |
| 53 // Create a MediaSessionDelegateAndroid object and start observing |
| 54 // |media_session|. Does not tell |j_delegate| to connect this object. |
| 55 MediaSessionDelegateAndroid( |
| 56 MediaSession* media_session, |
| 57 JNIEnv* env, |
| 58 const base::android::JavaParamRef<jobject>& j_delegate); |
| 59 |
| 60 // The linked Java counterpart. |
| 61 JavaObjectWeakGlobalRef j_delegate_; |
| 62 |
| 63 DISALLOW_COPY_AND_ASSIGN(MediaSessionDelegateAndroid); |
| 64 }; |
| 65 |
| 66 } // namespace content |
| 67 |
| 68 #endif // CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_DELEGATE_ANDROID_H_ |
OLD | NEW |