Chromium Code Reviews| Index: content/browser/renderer_host/media/media_stream_manager.cc |
| diff --git a/content/browser/renderer_host/media/media_stream_manager.cc b/content/browser/renderer_host/media/media_stream_manager.cc |
| index 110abfbdc20c6387fe47cb3db22dca7435602a4c..0a58610a6d06fe0b6fd87e103375f5dd259a6ae9 100644 |
| --- a/content/browser/renderer_host/media/media_stream_manager.cc |
| +++ b/content/browser/renderer_host/media/media_stream_manager.cc |
| @@ -64,17 +64,18 @@ static bool Requested(const MediaStreamRequest& request, |
| request.video_type == stream_type); |
| } |
| -// TODO(xians): Merge DeviceRequest with MediaStreamRequest. |
| class MediaStreamManager::DeviceRequest { |
| public: |
| DeviceRequest(MediaStreamRequester* requester, |
| const MediaStreamRequest& request, |
| int requesting_process_id, |
| - int requesting_view_id) |
| + int requesting_view_id, |
| + ResourceContext* resource_context) |
| : requester(requester), |
| request(request), |
| requesting_process_id(requesting_process_id), |
| requesting_view_id(requesting_view_id), |
| + resource_context(resource_context), |
| state_(NUM_MEDIA_TYPES, MEDIA_REQUEST_STATE_NOT_REQUESTED) { |
| } |
| @@ -134,6 +135,8 @@ class MediaStreamManager::DeviceRequest { |
| // specifies the target renderer from which audio and video is captured. |
| const int requesting_view_id; |
| + ResourceContext* resource_context; |
| + |
| StreamDeviceInfoArray devices; |
| // Callback to the requester which audio/video devices have been selected. |
| @@ -213,7 +216,8 @@ std::string MediaStreamManager::MakeMediaAccessRequest( |
| security_origin, MEDIA_DEVICE_ACCESS, std::string(), std::string(), |
| options.audio_type, options.video_type); |
| DeviceRequest* request = new DeviceRequest(NULL, stream_request, |
| - render_process_id, render_view_id); |
| + render_process_id, render_view_id, |
| + NULL); |
| const std::string& label = AddRequest(request); |
| request->callback = callback; |
| @@ -228,6 +232,7 @@ std::string MediaStreamManager::GenerateStream( |
| MediaStreamRequester* requester, |
| int render_process_id, |
| int render_view_id, |
| + ResourceContext* rc, |
| int page_request_id, |
| const StreamOptions& options, |
| const GURL& security_origin) { |
| @@ -249,7 +254,8 @@ std::string MediaStreamManager::GenerateStream( |
| options.audio_type, options.video_type); |
| DeviceRequest* request = new DeviceRequest(requester, stream_request, |
| render_process_id, |
| - render_view_id); |
| + render_view_id, |
| + rc); |
| const std::string& label = AddRequest(request); |
| // Need to post a task since the requester won't have label till |
| @@ -399,6 +405,7 @@ std::string MediaStreamManager::EnumerateDevices( |
| MediaStreamRequester* requester, |
| int render_process_id, |
| int render_view_id, |
| + ResourceContext* rc, |
| int page_request_id, |
| MediaStreamType type, |
| const GURL& security_origin) { |
| @@ -431,8 +438,8 @@ std::string MediaStreamManager::EnumerateDevices( |
| security_origin, MEDIA_ENUMERATE_DEVICES, std::string(), std::string(), |
| options.audio_type, options.video_type); |
| DeviceRequest* request = new DeviceRequest(requester, stream_request, |
| - render_process_id, |
| - render_view_id); |
| + render_process_id, render_view_id, |
| + rc); |
| const std::string& label = AddRequest(request); |
| BrowserThread::PostTask( |
| BrowserThread::IO, FROM_HERE, |
| @@ -472,6 +479,7 @@ std::string MediaStreamManager::OpenDevice( |
| MediaStreamRequester* requester, |
| int render_process_id, |
| int render_view_id, |
| + ResourceContext* rc, |
| int page_request_id, |
| const std::string& device_id, |
| MediaStreamType type, |
| @@ -498,8 +506,8 @@ std::string MediaStreamManager::OpenDevice( |
| security_origin, MEDIA_OPEN_DEVICE, options.audio_device_id, |
| options.video_device_id, options.audio_type, options.video_type); |
| DeviceRequest* request = new DeviceRequest(requester, stream_request, |
| - render_process_id, |
| - render_view_id); |
| + render_process_id, render_view_id, |
| + rc); |
| const std::string& label = AddRequest(request); |
| BrowserThread::PostTask( |
| BrowserThread::IO, FROM_HERE, |
| @@ -538,14 +546,16 @@ void MediaStreamManager::StopMonitoring() { |
| } |
| bool MediaStreamManager::TranslateRequestedSourceIdToDeviceId( |
| - MediaStreamRequest* request) { |
| + DeviceRequest* request) { |
| + MediaStreamRequest* ms_request = &request->request; |
| // If a specific device has been requested we need to find the real device id. |
| - if (request->audio_type == MEDIA_DEVICE_AUDIO_CAPTURE && |
| - !request->requested_audio_device_id.empty()) { |
| + if (ms_request->audio_type == MEDIA_DEVICE_AUDIO_CAPTURE && |
| + !ms_request->requested_audio_device_id.empty()) { |
| if (!TranslateSourceIdToDeviceId(MEDIA_DEVICE_AUDIO_CAPTURE, |
| - request->security_origin, |
| - request->requested_audio_device_id, |
| - &request->requested_audio_device_id)) { |
| + request->resource_context, |
| + ms_request->security_origin, |
| + ms_request->requested_audio_device_id, |
| + &ms_request->requested_audio_device_id)) { |
| // TODO(perkj): gUM should support mandatory and optional constraints. |
| // Ie - if the sourceId is optional but it does not match - gUM should |
| // not fail. For now we treat sourceId as a mandatory constraint. |
| @@ -554,30 +564,34 @@ bool MediaStreamManager::TranslateRequestedSourceIdToDeviceId( |
| } |
| } |
| - if (request->video_type == MEDIA_DEVICE_VIDEO_CAPTURE && |
| - !request->requested_video_device_id.empty()) { |
| + if (ms_request->video_type == MEDIA_DEVICE_VIDEO_CAPTURE && |
| + !ms_request->requested_video_device_id.empty()) { |
| if (!TranslateSourceIdToDeviceId(MEDIA_DEVICE_VIDEO_CAPTURE, |
| - request->security_origin, |
| - request->requested_video_device_id, |
| - &request->requested_video_device_id)) { |
| + request->resource_context, |
| + ms_request->security_origin, |
| + ms_request->requested_video_device_id, |
| + &ms_request->requested_video_device_id)) { |
| // TODO(perkj): guM should support mandatory and optional constraints. |
| // Ie - if the sourceId is optional but it does not match - guM should |
| // not fail. For now we treat sourceId as a mandatory constraint. |
| return false; |
| } |
| } |
| - DVLOG(3) << "Requested audio device " << request->requested_audio_device_id |
| - << "Requested video device " << request->requested_video_device_id; |
| + DVLOG(3) << "Requested audio device " |
| + << ms_request->requested_audio_device_id |
| + << "Requested video device " |
| + << ms_request->requested_video_device_id; |
| return true; |
| } |
| void MediaStreamManager::TranslateDeviceIdToSourceId( |
| - const MediaStreamRequest& request, |
| + DeviceRequest* request, |
| MediaStreamDevice* device) { |
| - if (request.audio_type == MEDIA_DEVICE_AUDIO_CAPTURE || |
| - request.video_type == MEDIA_DEVICE_VIDEO_CAPTURE) { |
| + if (request->request.audio_type == MEDIA_DEVICE_AUDIO_CAPTURE || |
| + request->request.video_type == MEDIA_DEVICE_VIDEO_CAPTURE) { |
| device->id = content::GetHMACForMediaDeviceID( |
| - request.security_origin, |
| + request->resource_context, |
| + request->request.security_origin, |
| device->id); |
| return; |
| } |
| @@ -586,6 +600,7 @@ void MediaStreamManager::TranslateDeviceIdToSourceId( |
| bool MediaStreamManager::TranslateSourceIdToDeviceId( |
| MediaStreamType stream_type, |
| + ResourceContext* rc, |
| const GURL& security_origin, |
| const std::string& source_id, |
| std::string* device_id) { |
| @@ -604,7 +619,7 @@ bool MediaStreamManager::TranslateSourceIdToDeviceId( |
| for (StreamDeviceInfoArray::const_iterator it = cache->devices.begin(); |
| it != cache->devices.end(); |
| ++it) { |
| - if (content::DoesMediaDeviceIDMatchHMAC(security_origin, source_id, |
| + if (content::DoesMediaDeviceIDMatchHMAC(rc, security_origin, source_id, |
| it->device.id)) { |
| *device_id = it->device.id; |
| return true; |
| @@ -735,7 +750,7 @@ void MediaStreamManager::HandleRequest(const std::string& label) { |
| } |
| // If a specific device has been requested we need to find the real device id. |
| - if (!TranslateRequestedSourceIdToDeviceId(&request->request)) { |
| + if (!TranslateRequestedSourceIdToDeviceId(request)) { |
| FinalizeRequestFailed(label, request); |
| return; |
| } |
| @@ -832,6 +847,11 @@ const StreamDeviceInfo* MediaStreamManager::FindRequestedDeviceInfoForTest( |
| } |
| bool MediaStreamManager::FindExistingRequestedDeviceInfo( |
| + const DeviceRequest* new_request, |
| + const MediaStreamDevice& new_device_info, |
| + StreamDeviceInfo* existing_device_info, |
| + MediaRequestState* existing_request_state) const { |
| +/*bool MediaStreamManager::FindExistingRequestedDeviceInfo( |
|
Jói
2013/10/31 16:14:47
Did you mean to leave this commented-out block of
perkj_chrome
2013/10/31 17:05:44
eh- nope- sorry.
|
| int render_process_id, |
| int render_view_id, |
| const GURL& security_origin, |
| @@ -839,27 +859,30 @@ bool MediaStreamManager::FindExistingRequestedDeviceInfo( |
| const std::string& device_id, |
| MediaStreamType device_type, |
| StreamDeviceInfo* device_info, |
| - MediaRequestState* request_state) const { |
| - DCHECK(device_info); |
| - DCHECK(request_state); |
| + MediaRequestState* request_state) const {*/ |
| + DCHECK(existing_device_info); |
| + DCHECK(existing_request_state); |
| + |
| + const MediaStreamRequest& new_ms_request = new_request->request; |
| std::string source_id = content::GetHMACForMediaDeviceID( |
| - security_origin, |
| - device_id); |
| + new_request->resource_context, |
| + new_ms_request.security_origin, |
| + new_device_info.id); |
| for (DeviceRequests::const_iterator it = requests_.begin(); |
| it != requests_.end() ; ++it) { |
| const DeviceRequest* request = it->second; |
| - if (request->requesting_process_id == render_process_id && |
| - request->requesting_view_id == render_view_id && |
| - request->request.request_type == type) { |
| + if (request->requesting_process_id == new_request->requesting_process_id && |
| + request->requesting_view_id == new_request->requesting_view_id && |
| + request->request.request_type == new_ms_request.request_type) { |
| for (StreamDeviceInfoArray::const_iterator device_it = |
| request->devices.begin(); |
| device_it != request->devices.end(); ++device_it) { |
| if (device_it->device.id == source_id && |
| - device_it->device.type == device_type) { |
| - *device_info = *device_it; |
| - *request_state = request->state(device_it->device.type); |
| + device_it->device.type == new_device_info.type) { |
| + *existing_device_info = *device_it; |
| + *existing_request_state = request->state(device_it->device.type); |
| return true; |
| } |
| } |
| @@ -913,7 +936,7 @@ void MediaStreamManager::FinalizeEnumerateDevices(const std::string& label, |
| DeviceRequest* request) { |
| for (StreamDeviceInfoArray::iterator it = request->devices.begin(); |
| it != request->devices.end(); ++it) { |
| - TranslateDeviceIdToSourceId(request->request, &it->device); |
| + TranslateDeviceIdToSourceId(request, &it->device); |
| } |
| request->requester->DevicesEnumerated(label, request->devices); |
| } |
| @@ -1160,25 +1183,21 @@ void MediaStreamManager::HandleAccessRequestResponse( |
| // MediaStreams it is being used in. |
| if (request->request.request_type == MEDIA_GENERATE_STREAM) { |
| MediaRequestState state; |
| - if (FindExistingRequestedDeviceInfo(request->requesting_process_id, |
| - request->requesting_view_id, |
| - request->request.security_origin, |
| - request->request.request_type, |
| - device_info.device.id, |
| - device_info.device.type, |
| + if (FindExistingRequestedDeviceInfo(request, |
| + device_info.device, |
| &device_info, |
| &state)) { |
| request->devices.push_back(device_info); |
| request->SetState(device_info.device.type, state); |
| DVLOG(1) << "HandleAccessRequestResponse - device already opened " |
| - << ", {label = " << label << "}" |
| - << ", device_id = " << device_it->id << "}"; |
| + << ", {label = " << label << "}" |
| + << ", device_id = " << device_it->id << "}"; |
| continue; |
| } |
| } |
| device_info.session_id = |
| GetDeviceManager(device_info.device.type)->Open(device_info); |
| - TranslateDeviceIdToSourceId(request->request, &device_info.device); |
| + TranslateDeviceIdToSourceId(request, &device_info.device); |
| request->devices.push_back(device_info); |
| request->SetState(device_info.device.type, MEDIA_REQUEST_STATE_OPENING); |