diff options
| author | yujie.mao@intel.com <yujie.mao@intel.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-06 10:47:04 +0000 |
|---|---|---|
| committer | yujie.mao@intel.com <yujie.mao@intel.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-06 10:47:04 +0000 |
| commit | 7225440953f38c425dbc21a6f3c94b6649fcdd3a (patch) | |
| tree | 86af70357c2a830de4287c8e92c82eeba37a98a9 | |
| parent | 501c47dba8851c5c399943828fc072138dad1724 (diff) | |
| download | chromium_src-7225440953f38c425dbc21a6f3c94b6649fcdd3a.zip chromium_src-7225440953f38c425dbc21a6f3c94b6649fcdd3a.tar.gz chromium_src-7225440953f38c425dbc21a6f3c94b6649fcdd3a.tar.bz2 | |
Implement CancelUserMediaRequest for the browser part
BUG=126081
TEST=content_unittests, manual test
Review URL: https://chromiumcodereview.appspot.com/10534004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@140738 0039d316-1c4b-4281-b951-d872f2087c98
6 files changed, 74 insertions, 2 deletions
diff --git a/content/browser/renderer_host/media/media_stream_device_settings.cc b/content/browser/renderer_host/media/media_stream_device_settings.cc index 78b895d..39d66e7 100644 --- a/content/browser/renderer_host/media/media_stream_device_settings.cc +++ b/content/browser/renderer_host/media/media_stream_device_settings.cc @@ -134,6 +134,18 @@ void MediaStreamDeviceSettings::RequestCaptureDeviceUsage( render_process_id, render_view_id, security_origin, request_options))); } +void MediaStreamDeviceSettings::RemovePendingCaptureRequest( + const std::string& label) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + + SettingsRequests::iterator request_it = requests_.find(label); + if (request_it != requests_.end()) { + MediaStreamDeviceSettingsRequest* request = request_it->second; + requests_.erase(request_it); + delete request; + } +} + void MediaStreamDeviceSettings::AvailableDevices( const std::string& label, MediaStreamType stream_type, diff --git a/content/browser/renderer_host/media/media_stream_device_settings.h b/content/browser/renderer_host/media/media_stream_device_settings.h index 11358cb..50a9fbc 100644 --- a/content/browser/renderer_host/media/media_stream_device_settings.h +++ b/content/browser/renderer_host/media/media_stream_device_settings.h @@ -45,6 +45,10 @@ class CONTENT_EXPORT MediaStreamDeviceSettings const StreamOptions& stream_components, const GURL& security_origin); + // Called to remove a pending request of capture device usage when the user + // has no action for the media stream InfoBar. + void RemovePendingCaptureRequest(const std::string& label); + // Called to pass in an array of available devices for a request represented // by |label|. There could be multiple calls for a request. void AvailableDevices(const std::string& label, MediaStreamType stream_type, diff --git a/content/browser/renderer_host/media/media_stream_dispatcher_host.cc b/content/browser/renderer_host/media/media_stream_dispatcher_host.cc index 96eeb25..fd980c5 100644 --- a/content/browser/renderer_host/media/media_stream_dispatcher_host.cc +++ b/content/browser/renderer_host/media/media_stream_dispatcher_host.cc @@ -214,8 +214,13 @@ void MediaStreamDispatcherHost::OnCancelGenerateStream(int render_view_id, DVLOG(1) << "MediaStreamDispatcherHost::OnCancelGenerateStream(" << render_view_id << ", " << page_request_id << ")"; - // TODO(perkj): Implement - NOTIMPLEMENTED(); + + for (StreamMap::iterator it = streams_.begin(); it != streams_.end(); ++it) { + if (it->second.render_view_id == render_view_id && + it->second.page_request_id == page_request_id) { + manager()->CancelGenerateStream(it->first); + } + } } void MediaStreamDispatcherHost::OnStopGeneratedStream( diff --git a/content/browser/renderer_host/media/media_stream_manager.cc b/content/browser/renderer_host/media/media_stream_manager.cc index ca2d285..be92120 100644 --- a/content/browser/renderer_host/media/media_stream_manager.cc +++ b/content/browser/renderer_host/media/media_stream_manager.cc @@ -214,6 +214,42 @@ void MediaStreamManager::CancelRequests(MediaStreamRequester* requester) { } } +void MediaStreamManager::CancelGenerateStream(const std::string& label) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + + DeviceRequests::iterator it = requests_.find(label); + if (it != requests_.end()) { + // The request isn't complete. + if (!RequestDone(it->second)) { + DeviceRequest* request = &(it->second); + if (request->state[content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE] == + DeviceRequest::kOpening) { + for (StreamDeviceInfoArray::iterator it = + request->audio_devices.begin(); it != request->audio_devices.end(); + ++it) { + if (it->in_use) { + audio_input_device_manager()->Close(it->session_id); + } + } + } + if (request->state[content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE] == + DeviceRequest::kOpening) { + for (StreamDeviceInfoArray::iterator it = + request->video_devices.begin(); it != request->video_devices.end(); + ++it) { + if (it->in_use) { + video_capture_manager()->Close(it->session_id); + } + } + } + requests_.erase(it); + } else { + StopGeneratedStream(label); + } + device_settings_->RemovePendingCaptureRequest(label); + } +} + void MediaStreamManager::StopGeneratedStream(const std::string& label) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); // Find the request and close all open devices for the request. diff --git a/content/browser/renderer_host/media/media_stream_manager.h b/content/browser/renderer_host/media/media_stream_manager.h index 25af8c9..17f863e 100644 --- a/content/browser/renderer_host/media/media_stream_manager.h +++ b/content/browser/renderer_host/media/media_stream_manager.h @@ -85,6 +85,9 @@ class CONTENT_EXPORT MediaStreamManager // StreamGenerated hasn't been called. void CancelRequests(MediaStreamRequester* requester); + // Cancel generate stream. + void CancelGenerateStream(const std::string& label); + // Closes generated stream. void StopGeneratedStream(const std::string& label); diff --git a/content/renderer/media/media_stream_impl.cc b/content/renderer/media/media_stream_impl.cc index 4c6751d..2d772d5 100644 --- a/content/renderer/media/media_stream_impl.cc +++ b/content/renderer/media/media_stream_impl.cc @@ -262,6 +262,7 @@ void MediaStreamImpl::OnStreamGenerated( MediaRequestMap::iterator it = user_media_requests_.find(request_id); if (it == user_media_requests_.end()) { DVLOG(1) << "Request ID not found"; + media_stream_dispatcher_->StopStream(label); return; } @@ -354,6 +355,17 @@ void MediaStreamImpl::OnDeviceOpenFailed(int request_id) { } void MediaStreamImpl::FrameWillClose(WebKit::WebFrame* frame) { + MediaRequestMap::iterator request_it = user_media_requests_.begin(); + while (request_it != user_media_requests_.end()) { + if (request_it->second.frame_ == frame) { + DVLOG(1) << "MediaStreamImpl::FrameWillClose: " + << "Cancel user media request " << request_it->first; + cancelUserMediaRequest(request_it->second.request_); + request_it = user_media_requests_.begin(); + } else { + ++request_it; + } + } LocalNativeStreamMap::iterator it = local_media_streams_.begin(); while (it != local_media_streams_.end()) { if (it->second == frame) { |
