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

Side by Side Diff: media/base/android/media_player_android.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, 10 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 unified diff | Download patch
« no previous file with comments | « no previous file | media/base/android/media_player_listener.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_BASE_ANDROID_MEDIA_PLAYER_ANDROID_H_ 5 #ifndef MEDIA_BASE_ANDROID_MEDIA_PLAYER_ANDROID_H_
6 #define MEDIA_BASE_ANDROID_MEDIA_PLAYER_ANDROID_H_ 6 #define MEDIA_BASE_ANDROID_MEDIA_PLAYER_ANDROID_H_
7 7
8 #include <jni.h> 8 #include <jni.h>
9 #include <string> 9 #include <string>
10 10
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 virtual bool IsPlayerReady() = 0; 68 virtual bool IsPlayerReady() = 0;
69 virtual bool CanPause() = 0; 69 virtual bool CanPause() = 0;
70 virtual bool CanSeekForward() = 0; 70 virtual bool CanSeekForward() = 0;
71 virtual bool CanSeekBackward() = 0; 71 virtual bool CanSeekBackward() = 0;
72 virtual GURL GetUrl(); 72 virtual GURL GetUrl();
73 virtual GURL GetFirstPartyForCookies(); 73 virtual GURL GetFirstPartyForCookies();
74 74
75 // Associates the |cdm| with this player. 75 // Associates the |cdm| with this player.
76 virtual void SetCdm(BrowserCdm* cdm); 76 virtual void SetCdm(BrowserCdm* cdm);
77 77
78 int player_id() { return player_id_; }
79
80 GURL frame_url() { return frame_url_; }
81
82 protected:
83 MediaPlayerAndroid(int player_id,
84 MediaPlayerManager* manager,
85 const RequestMediaResourcesCB& request_media_resources_cb,
86 const GURL& frame_url);
87
88 // TODO(qinmin): Simplify the MediaPlayerListener class to only listen to 78 // TODO(qinmin): Simplify the MediaPlayerListener class to only listen to
89 // media interrupt events. And have a separate child class to listen to all 79 // media interrupt events. And have a separate child class to listen to all
90 // the events needed by MediaPlayerBridge. http://crbug.com/422597. 80 // the events needed by MediaPlayerBridge. http://crbug.com/422597.
91 // MediaPlayerListener callbacks. 81 // MediaPlayerListener callbacks.
92 virtual void OnVideoSizeChanged(int width, int height); 82 virtual void OnVideoSizeChanged(int width, int height);
93 virtual void OnMediaError(int error_type); 83 virtual void OnMediaError(int error_type);
94 virtual void OnBufferingUpdate(int percent); 84 virtual void OnBufferingUpdate(int percent);
95 virtual void OnPlaybackComplete(); 85 virtual void OnPlaybackComplete();
96 virtual void OnMediaInterrupted(); 86 virtual void OnMediaInterrupted();
97 virtual void OnSeekComplete(); 87 virtual void OnSeekComplete();
98 virtual void OnMediaPrepared(); 88 virtual void OnMediaPrepared();
99 89
90 int player_id() { return player_id_; }
91
92 GURL frame_url() { return frame_url_; }
93
94 protected:
95 MediaPlayerAndroid(int player_id,
96 MediaPlayerManager* manager,
97 const RequestMediaResourcesCB& request_media_resources_cb,
98 const GURL& frame_url);
99
100 // Attach/Detaches |listener_| for listening to all the media events. If 100 // Attach/Detaches |listener_| for listening to all the media events. If
101 // |j_media_player| is NULL, |listener_| only listens to the system media 101 // |j_media_player| is NULL, |listener_| only listens to the system media
102 // events. Otherwise, it also listens to the events from |j_media_player|. 102 // events. Otherwise, it also listens to the events from |j_media_player|.
103 void AttachListener(jobject j_media_player); 103 void AttachListener(jobject j_media_player);
104 void DetachListener(); 104 void DetachListener();
105 105
106 MediaPlayerManager* manager() { return manager_; } 106 MediaPlayerManager* manager() { return manager_; }
107 107
108 RequestMediaResourcesCB request_media_resources_cb_; 108 RequestMediaResourcesCB request_media_resources_cb_;
109 109
110 private: 110 private:
111 friend class MediaPlayerListener;
112
113 // Player ID assigned to this player. 111 // Player ID assigned to this player.
114 int player_id_; 112 int player_id_;
115 113
116 // Resource manager for all the media players. 114 // Resource manager for all the media players.
117 MediaPlayerManager* manager_; 115 MediaPlayerManager* manager_;
118 116
119 // Url for the frame that contains this player. 117 // Url for the frame that contains this player.
120 GURL frame_url_; 118 GURL frame_url_;
121 119
122 // Listener object that listens to all the media player events. 120 // Listener object that listens to all the media player events.
123 scoped_ptr<MediaPlayerListener> listener_; 121 scoped_ptr<MediaPlayerListener> listener_;
124 122
125 // Weak pointer passed to |listener_| for callbacks. 123 // Weak pointer passed to |listener_| for callbacks.
126 // NOTE: Weak pointers must be invalidated before all other member variables. 124 // NOTE: Weak pointers must be invalidated before all other member variables.
127 base::WeakPtrFactory<MediaPlayerAndroid> weak_factory_; 125 base::WeakPtrFactory<MediaPlayerAndroid> weak_factory_;
128 126
129 DISALLOW_COPY_AND_ASSIGN(MediaPlayerAndroid); 127 DISALLOW_COPY_AND_ASSIGN(MediaPlayerAndroid);
130 }; 128 };
131 129
132 } // namespace media 130 } // namespace media
133 131
134 #endif // MEDIA_BASE_ANDROID_MEDIA_PLAYER_ANDROID_H_ 132 #endif // MEDIA_BASE_ANDROID_MEDIA_PLAYER_ANDROID_H_
OLDNEW
« no previous file with comments | « no previous file | media/base/android/media_player_listener.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698