Chromium Code Reviews| Index: content/renderer/media/media_stream_impl.h |
| diff --git a/content/renderer/media/media_stream_impl.h b/content/renderer/media/media_stream_impl.h |
| index ad960201f361df85e1c55c96ba6b3241288ae89e..0effc2a9074863c3dc6764625a4d2839a3332a31 100644 |
| --- a/content/renderer/media/media_stream_impl.h |
| +++ b/content/renderer/media/media_stream_impl.h |
| @@ -16,7 +16,7 @@ |
| #include "base/memory/weak_ptr.h" |
| #include "base/threading/non_thread_safe.h" |
| #include "content/common/content_export.h" |
| -#include "content/public/renderer/render_view_observer.h" |
| +#include "content/public/renderer/render_frame_observer.h" |
| #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" |
| #include "content/renderer/media/media_stream_source.h" |
| #include "third_party/WebKit/public/platform/WebMediaStream.h" |
| @@ -38,20 +38,23 @@ class VideoCapturerDelegate; |
| // (via MediaStreamDispatcher and MediaStreamDispatcherHost) |
| // in the browser process. It must be created, called and destroyed on the |
| // render thread. |
| -// MediaStreamImpl have weak pointers to a MediaStreamDispatcher. |
| class CONTENT_EXPORT MediaStreamImpl |
| - : public RenderViewObserver, |
| + : public RenderFrameObserver, |
| NON_EXPORTED_BASE(public blink::WebUserMediaClient), |
| public MediaStreamDispatcherEventHandler, |
| - public base::SupportsWeakPtr<MediaStreamImpl>, |
| NON_EXPORTED_BASE(public base::NonThreadSafe) { |
| public: |
| + // |render_frame| and |dependency_factory| must outlive this instance. |
| MediaStreamImpl( |
| - RenderView* render_view, |
| - MediaStreamDispatcher* media_stream_dispatcher, |
| - PeerConnectionDependencyFactory* dependency_factory); |
| + RenderFrame* render_frame, |
| + PeerConnectionDependencyFactory* dependency_factory, |
| + scoped_ptr<MediaStreamDispatcher> media_stream_dispatcher); |
| virtual ~MediaStreamImpl(); |
| + MediaStreamDispatcher* media_stream_dispatcher() const { |
| + return media_stream_dispatcher_.get(); |
|
tommi (sloooow) - chröme
2014/07/09 07:46:55
add a thread check?
miu
2014/07/09 19:48:07
A valid concern, but I think it's unnecessary: 1)
|
| + } |
| + |
| // blink::WebUserMediaClient implementation |
| virtual void requestUserMedia( |
| const blink::WebUserMediaRequest& user_media_request); |
| @@ -82,9 +85,8 @@ class CONTENT_EXPORT MediaStreamImpl |
| const StreamDeviceInfo& device_info) OVERRIDE; |
| virtual void OnDeviceOpenFailed(int request_id) OVERRIDE; |
| - // RenderViewObserver OVERRIDE |
| - virtual void FrameDetached(blink::WebFrame* frame) OVERRIDE; |
| - virtual void FrameWillClose(blink::WebFrame* frame) OVERRIDE; |
| + // RenderFrameObserver OVERRIDE |
| + virtual void FrameWillClose() OVERRIDE; |
| protected: |
| // Called when |source| has been stopped from JavaScript. |
| @@ -119,7 +121,6 @@ class CONTENT_EXPORT MediaStreamImpl |
| ResourcesReady; |
| UserMediaRequestInfo(int request_id, |
| - blink::WebFrame* frame, |
| const blink::WebUserMediaRequest& request, |
| bool enable_automatic_output_device_selection); |
| ~UserMediaRequestInfo(); |
| @@ -128,7 +129,6 @@ class CONTENT_EXPORT MediaStreamImpl |
| // OnStreamGenerated. |
| bool generated; |
| const bool enable_automatic_output_device_selection; |
| - blink::WebFrame* frame; // WebFrame that requested the MediaStream. |
| blink::WebMediaStream web_stream; |
| blink::WebUserMediaRequest request; |
| @@ -160,17 +160,7 @@ class CONTENT_EXPORT MediaStreamImpl |
| }; |
| typedef ScopedVector<UserMediaRequestInfo> UserMediaRequests; |
| - struct LocalStreamSource { |
| - LocalStreamSource(blink::WebFrame* frame, |
| - const blink::WebMediaStreamSource& source) |
| - : frame(frame), source(source) { |
| - } |
| - // |frame| is the WebFrame that requested |source|. NULL in unit tests. |
| - // TODO(perkj): Change so that |frame| is not NULL in unit tests. |
| - blink::WebFrame* frame; |
| - blink::WebMediaStreamSource source; |
| - }; |
| - typedef std::vector<LocalStreamSource> LocalStreamSources; |
| + typedef std::vector<blink::WebMediaStreamSource> LocalStreamSources; |
| struct MediaDevicesRequestInfo; |
| typedef ScopedVector<MediaDevicesRequestInfo> MediaDevicesRequests; |
| @@ -181,7 +171,6 @@ class CONTENT_EXPORT MediaStreamImpl |
| const StreamDeviceInfo& device, |
| blink::WebMediaStreamSource::Type type, |
| const blink::WebMediaConstraints& constraints, |
| - blink::WebFrame* frame, |
| blink::WebMediaStreamSource* webkit_source); |
| void CreateVideoTracks( |
| @@ -210,7 +199,7 @@ class CONTENT_EXPORT MediaStreamImpl |
| MediaDevicesRequestInfo* FindMediaDevicesRequestInfo(int request_id); |
| MediaDevicesRequestInfo* FindMediaDevicesRequestInfo( |
| const blink::WebMediaDevicesRequest& request); |
| - void DeleteMediaDevicesRequestInfo(MediaDevicesRequestInfo* request); |
| + void CancelAndDeleteMediaDevicesRequest(MediaDevicesRequestInfo* request); |
| // Returns the source that use a device with |device.session_id| |
| // and |device.device.id|. NULL if such source doesn't exist. |
| @@ -224,11 +213,11 @@ class CONTENT_EXPORT MediaStreamImpl |
| // It's valid for the lifetime of RenderThread. |
| // TODO(xians): Remove this dependency once audio do not need it for local |
| // audio. |
| - PeerConnectionDependencyFactory* dependency_factory_; |
| + PeerConnectionDependencyFactory* const dependency_factory_; |
| - // media_stream_dispatcher_ is a weak reference, owned by RenderView. It's |
| - // valid for the lifetime of RenderView. |
| - MediaStreamDispatcher* media_stream_dispatcher_; |
| + // MediaStreamImpl owns MediaStreamDispatcher instead of RenderFrameImpl |
| + // (or RenderFrameObserver) to ensure tear-down occurs in the right order. |
| + const scoped_ptr<MediaStreamDispatcher> media_stream_dispatcher_; |
| LocalStreamSources local_sources_; |
| @@ -237,6 +226,10 @@ class CONTENT_EXPORT MediaStreamImpl |
| // Requests to enumerate media devices. |
| MediaDevicesRequests media_devices_requests_; |
| + // Note: This member must be the last to ensure all outstanding weak pointers |
| + // are invalidated first. |
| + base::WeakPtrFactory<MediaStreamImpl> weak_factory_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(MediaStreamImpl); |
| }; |