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

Unified Diff: media/base/android/media_player_listener.h

Issue 899473002: Fix a crash that MediaPlayerAndroid weak_ptr is incorrectly used across thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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
« no previous file with comments | « media/base/android/media_player_android.h ('k') | media/base/android/media_player_listener.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/android/media_player_listener.h
diff --git a/media/base/android/media_player_listener.h b/media/base/android/media_player_listener.h
index 018a5d618fde11441e4c77044caf6dd50331a58b..513a400f463ef0f5129ffe5a3d63ef9aab99274e 100644
--- a/media/base/android/media_player_listener.h
+++ b/media/base/android/media_player_listener.h
@@ -19,6 +19,32 @@ namespace media {
class MediaPlayerAndroid;
+// Helper class for posting MediaPlayerAndroid tasks on the UI thread.
+class MediaPlayerListenerProxy
+ : public base::RefCountedThreadSafe<MediaPlayerListenerProxy> {
+ public:
+ MediaPlayerListenerProxy(
+ const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
+ base::WeakPtr<MediaPlayerAndroid> media_player);
+ void OnMediaError(int error_type);
+ void OnVideoSizeChanged(int width, int height);
+ void OnBufferingUpdate(int percent);
+ void OnPlaybackComplete();
+ void OnSeekComplete();
+ void OnMediaPrepared();
+ void OnMediaInterrupted();
+
+ private:
+ friend class base::RefCountedThreadSafe<MediaPlayerListenerProxy>;
+ ~MediaPlayerListenerProxy();
+
+ // The message loop where |media_player_| lives.
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
+
+ // The MediaPlayerAndroid object all the callbacks should be sent to.
+ base::WeakPtr<MediaPlayerAndroid> media_player_;
+};
+
// Acts as a thread proxy between java MediaPlayerListener object and
// MediaPlayerAndroid so that callbacks are posted onto the UI thread.
class MediaPlayerListener {
@@ -29,7 +55,7 @@ class MediaPlayerListener {
MediaPlayerListener(
const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
base::WeakPtr<MediaPlayerAndroid> media_player);
- virtual ~MediaPlayerListener();
+ virtual ~MediaPlayerListener();
// Called by the Java MediaPlayerListener and mirrored to corresponding
// callbacks.
@@ -52,11 +78,8 @@ class MediaPlayerListener {
static bool RegisterMediaPlayerListener(JNIEnv* env);
private:
- // The message loop where |media_player_| lives.
- scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
-
- // The MediaPlayerAndroid object all the callbacks should be sent to.
- base::WeakPtr<MediaPlayerAndroid> media_player_;
+ // Proxy for posting tasks to the UI thread.
+ scoped_refptr<MediaPlayerListenerProxy> proxy_;
base::android::ScopedJavaGlobalRef<jobject> j_media_player_listener_;
« no previous file with comments | « media/base/android/media_player_android.h ('k') | media/base/android/media_player_listener.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698