Chromium Code Reviews| Index: content/browser/media/session/media_session_android.h |
| diff --git a/content/browser/media/session/media_session_android.h b/content/browser/media/session/media_session_android.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..635d79ccfc6698351f8126aba8ba4bc53cd8a40f |
| --- /dev/null |
| +++ b/content/browser/media/session/media_session_android.h |
| @@ -0,0 +1,57 @@ |
| +// 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_ANDROID_H_ |
| +#define CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_ANDROID_H_ |
| + |
| +#include <jni.h> |
| +#include <memory> |
| +#include <vector> |
| + |
| +#include "base/android/scoped_java_ref.h" |
| +#include "content/public/browser/media_session_observer.h" |
| + |
| +namespace content { |
| + |
| +class MediaSessionImpl; |
| + |
| +bool RegisterMediaSessionNatives(JNIEnv* env); |
|
boliu
2016/10/29 01:11:28
remove
Zhiqiang Zhang (Slow)
2016/10/31 11:57:34
Done.
|
| + |
| +// This class is interlayer between native MediaSession and Java |
| +// MediaSession. This class is owned by the native MediaSession and will |
| +// teardown Java MediaSession when the native MediaSession is destroyed. |
| +// Java MediaSessionObservers are also proxied via this class. |
| +class MediaSessionAndroid final : public MediaSessionObserver { |
| + public: |
| + static bool Register(JNIEnv* env); |
| + |
| + explicit MediaSessionAndroid(MediaSession* session); |
| + ~MediaSessionAndroid() override; |
| + |
| + base::android::ScopedJavaLocalRef<jobject> GetJavaObject(); |
|
boliu
2016/10/29 01:11:28
Leaking the java object outside of class is genera
Zhiqiang Zhang (Slow)
2016/10/31 11:57:34
Ugh, I tried but failed. The problem is that the j
boliu
2016/10/31 18:58:55
Oh, static :/
You could declare another function,
Zhiqiang Zhang (Slow)
2016/10/31 22:22:26
Done. But actually I found other files including t
boliu
2016/10/31 22:44:02
Really? I'd expect a link error. Perhaps a runtime
Zhiqiang Zhang (Slow)
2016/10/31 23:30:28
Maybe...
|
| + |
| + // MediaSessionObserver implementation. |
| + void MediaSessionDestroyed() override; |
| + void MediaSessionStateChanged(bool is_controllable, |
| + bool is_suspended) override; |
| + void MediaSessionMetadataChanged( |
| + const base::Optional<MediaMetadata>& metadata) override; |
| + |
| + // MediaSession method wrappers. |
| + void Resume(JNIEnv* env, const base::android::JavaParamRef<jobject>& j_obj); |
| + void Suspend(JNIEnv* env, const base::android::JavaParamRef<jobject>& j_obj); |
| + void Stop(JNIEnv* env, const base::android::JavaParamRef<jobject>& j_obj); |
| + |
| + private: |
| + // The linked Java object |
| + base::android::ScopedJavaGlobalRef<jobject> j_media_session_; |
|
boliu
2016/10/29 01:11:28
I raised the point about strong reference from nat
Zhiqiang Zhang (Slow)
2016/10/31 11:57:34
I don't know about how GC on WebContentsImpl.java
boliu
2016/10/31 18:58:55
Yes in webview, where native WebContentsImpl destr
Zhiqiang Zhang (Slow)
2016/10/31 19:50:03
I think the problem lies in the client side.
If w
boliu
2016/10/31 20:13:19
Meaning outside of content?
Zhiqiang Zhang (Slow)
2016/10/31 22:22:26
Yes.
boliu
2016/10/31 22:44:02
That's a good point. Yes it will still be referenc
Zhiqiang Zhang (Slow)
2016/10/31 23:30:28
Acknowledged.
|
| + // The native MediaSession object |
| + MediaSessionImpl* media_session_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(MediaSessionAndroid); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_ANDROID_H_ |