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

Side by Side Diff: content/browser/renderer_host/media/media_stream_manager.cc

Issue 180633008: Add different error codes for getUserMedia. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed comments Created 6 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "content/browser/renderer_host/media/media_stream_manager.h" 5 #include "content/browser/renderer_host/media/media_stream_manager.h"
6 6
7 #include <list> 7 #include <list>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 1012 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1023 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1024 DeviceRequest* request = FindRequest(label); 1024 DeviceRequest* request = FindRequest(label);
1025 if (!request) { 1025 if (!request) {
1026 DVLOG(1) << "SetupRequest label " << label << " doesn't exist!!"; 1026 DVLOG(1) << "SetupRequest label " << label << " doesn't exist!!";
1027 return; // This can happen if the request has been canceled. 1027 return; // This can happen if the request has been canceled.
1028 } 1028 }
1029 1029
1030 if (!request->security_origin.is_valid()) { 1030 if (!request->security_origin.is_valid()) {
1031 LOG(ERROR) << "Invalid security origin. " 1031 LOG(ERROR) << "Invalid security origin. "
1032 << request->security_origin; 1032 << request->security_origin;
1033 FinalizeRequestFailed(label, request); 1033 FinalizeRequestFailed(label, request, content::INVALID_SECURITY_ORIGIN);
1034 return; 1034 return;
1035 } 1035 }
1036 1036
1037 MediaStreamType audio_type = MEDIA_NO_SERVICE; 1037 MediaStreamType audio_type = MEDIA_NO_SERVICE;
1038 MediaStreamType video_type = MEDIA_NO_SERVICE; 1038 MediaStreamType video_type = MEDIA_NO_SERVICE;
1039 ParseStreamType(request->options, &audio_type, &video_type); 1039 ParseStreamType(request->options, &audio_type, &video_type);
1040 request->SetAudioType(audio_type); 1040 request->SetAudioType(audio_type);
1041 request->SetVideoType(video_type); 1041 request->SetVideoType(video_type);
1042 1042
1043 bool is_web_contents_capture = 1043 bool is_web_contents_capture =
1044 audio_type == MEDIA_TAB_AUDIO_CAPTURE || 1044 audio_type == MEDIA_TAB_AUDIO_CAPTURE ||
1045 video_type == MEDIA_TAB_VIDEO_CAPTURE; 1045 video_type == MEDIA_TAB_VIDEO_CAPTURE;
1046 if (is_web_contents_capture && !SetupTabCaptureRequest(request)) { 1046 if (is_web_contents_capture && !SetupTabCaptureRequest(request)) {
1047 FinalizeRequestFailed(label, request); 1047 FinalizeRequestFailed(label, request, content::TAB_CAPTURE_FAILURE);
1048 return; 1048 return;
1049 } 1049 }
1050 1050
1051 bool is_screen_capture = 1051 bool is_screen_capture =
1052 video_type == MEDIA_DESKTOP_VIDEO_CAPTURE; 1052 video_type == MEDIA_DESKTOP_VIDEO_CAPTURE;
1053 if (is_screen_capture && !SetupScreenCaptureRequest(request)) { 1053 if (is_screen_capture && !SetupScreenCaptureRequest(request)) {
1054 FinalizeRequestFailed(label, request); 1054 FinalizeRequestFailed(label, request, content::SCREEN_CAPTURE_FAILURE);
1055 return; 1055 return;
1056 } 1056 }
1057 1057
1058 if (!is_web_contents_capture && !is_screen_capture) { 1058 if (!is_web_contents_capture && !is_screen_capture) {
1059 if (EnumerationRequired(&audio_enumeration_cache_, audio_type) || 1059 if (EnumerationRequired(&audio_enumeration_cache_, audio_type) ||
1060 EnumerationRequired(&video_enumeration_cache_, video_type)) { 1060 EnumerationRequired(&video_enumeration_cache_, video_type)) {
1061 // Enumerate the devices if there is no valid device lists to be used. 1061 // Enumerate the devices if there is no valid device lists to be used.
1062 StartEnumeration(request); 1062 StartEnumeration(request);
1063 return; 1063 return;
1064 } else { 1064 } else {
1065 // Cache is valid, so log the cached devices for MediaStream requests. 1065 // Cache is valid, so log the cached devices for MediaStream requests.
1066 if (request->request_type == MEDIA_GENERATE_STREAM) { 1066 if (request->request_type == MEDIA_GENERATE_STREAM) {
1067 std::string log_message("Using cached devices for request.\n"); 1067 std::string log_message("Using cached devices for request.\n");
1068 if (audio_type != MEDIA_NO_SERVICE) { 1068 if (audio_type != MEDIA_NO_SERVICE) {
1069 log_message += 1069 log_message +=
1070 GetLogMessageString(audio_type, audio_enumeration_cache_.devices); 1070 GetLogMessageString(audio_type, audio_enumeration_cache_.devices);
1071 } 1071 }
1072 if (video_type != MEDIA_NO_SERVICE) { 1072 if (video_type != MEDIA_NO_SERVICE) {
1073 log_message += 1073 log_message +=
1074 GetLogMessageString(video_type, video_enumeration_cache_.devices); 1074 GetLogMessageString(video_type, video_enumeration_cache_.devices);
1075 } 1075 }
1076 SendMessageToNativeLog(log_message); 1076 SendMessageToNativeLog(log_message);
1077 } 1077 }
1078 } 1078 }
1079 1079
1080 if (!SetupDeviceCaptureRequest(request)) { 1080 if (!SetupDeviceCaptureRequest(request)) {
1081 FinalizeRequestFailed(label, request); 1081 FinalizeRequestFailed(label, request, content::DEVICE_CAPTURE_FAILURE);
1082 return; 1082 return;
1083 } 1083 }
1084 } 1084 }
1085 PostRequestToUI(label, request); 1085 PostRequestToUI(label, request);
1086 } 1086 }
1087 1087
1088 bool MediaStreamManager::SetupDeviceCaptureRequest(DeviceRequest* request) { 1088 bool MediaStreamManager::SetupDeviceCaptureRequest(DeviceRequest* request) {
1089 DCHECK((request->audio_type() == MEDIA_DEVICE_AUDIO_CAPTURE || 1089 DCHECK((request->audio_type() == MEDIA_DEVICE_AUDIO_CAPTURE ||
1090 request->audio_type() == MEDIA_NO_SERVICE) && 1090 request->audio_type() == MEDIA_NO_SERVICE) &&
1091 (request->video_type() == MEDIA_DEVICE_VIDEO_CAPTURE || 1091 (request->video_type() == MEDIA_DEVICE_VIDEO_CAPTURE ||
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1266 } 1266 }
1267 1267
1268 request->requester->StreamGenerated( 1268 request->requester->StreamGenerated(
1269 request->requesting_view_id, 1269 request->requesting_view_id,
1270 request->page_request_id, 1270 request->page_request_id,
1271 label, audio_devices, video_devices); 1271 label, audio_devices, video_devices);
1272 } 1272 }
1273 1273
1274 void MediaStreamManager::FinalizeRequestFailed( 1274 void MediaStreamManager::FinalizeRequestFailed(
1275 const std::string& label, 1275 const std::string& label,
1276 DeviceRequest* request) { 1276 DeviceRequest* request,
1277 content::MediaStreamRequestResult result) {
1277 if (request->requester) 1278 if (request->requester)
1278 request->requester->StreamGenerationFailed( 1279 request->requester->StreamGenerationFailed(
1279 request->requesting_view_id, 1280 request->requesting_view_id,
1280 request->page_request_id); 1281 request->page_request_id,
1282 result);
1281 1283
1282 if (request->request_type == MEDIA_DEVICE_ACCESS && 1284 if (request->request_type == MEDIA_DEVICE_ACCESS &&
1283 !request->callback.is_null()) { 1285 !request->callback.is_null()) {
1284 request->callback.Run(MediaStreamDevices(), request->ui_proxy.Pass()); 1286 request->callback.Run(MediaStreamDevices(), request->ui_proxy.Pass());
1285 } 1287 }
1286 1288
1287 DeleteRequest(label); 1289 DeleteRequest(label);
1288 } 1290 }
1289 1291
1290 void MediaStreamManager::FinalizeOpenDevice(const std::string& label, 1292 void MediaStreamManager::FinalizeOpenDevice(const std::string& label,
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
1517 if (request->state(request->audio_type()) == 1519 if (request->state(request->audio_type()) ==
1518 MEDIA_REQUEST_STATE_REQUESTED || 1520 MEDIA_REQUEST_STATE_REQUESTED ||
1519 request->state(request->video_type()) == 1521 request->state(request->video_type()) ==
1520 MEDIA_REQUEST_STATE_REQUESTED) { 1522 MEDIA_REQUEST_STATE_REQUESTED) {
1521 // We are doing enumeration for other type of media, wait until it is 1523 // We are doing enumeration for other type of media, wait until it is
1522 // all done before posting the request to UI because UI needs 1524 // all done before posting the request to UI because UI needs
1523 // the device lists to handle the request. 1525 // the device lists to handle the request.
1524 break; 1526 break;
1525 } 1527 }
1526 if (!SetupDeviceCaptureRequest(request)) 1528 if (!SetupDeviceCaptureRequest(request))
1527 FinalizeRequestFailed(*it, request); 1529 FinalizeRequestFailed(*it, request, content::DEVICE_CAPTURE_FAILURE);
1528 else 1530 else
1529 PostRequestToUI(*it, request); 1531 PostRequestToUI(*it, request);
1530 break; 1532 break;
1531 } 1533 }
1532 } 1534 }
1533 label_list.clear(); 1535 label_list.clear();
1534 --active_enumeration_ref_count_[stream_type]; 1536 --active_enumeration_ref_count_[stream_type];
1535 DCHECK_GE(active_enumeration_ref_count_[stream_type], 0); 1537 DCHECK_GE(active_enumeration_ref_count_[stream_type], 0);
1536 } 1538 }
1537 1539
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1583 static_cast<content::RenderProcessHostImpl*>( 1585 static_cast<content::RenderProcessHostImpl*>(
1584 content::RenderProcessHost::FromID(*it)); 1586 content::RenderProcessHost::FromID(*it));
1585 if (render_process_host_impl) 1587 if (render_process_host_impl)
1586 render_process_host_impl->WebRtcLogMessage(message); 1588 render_process_host_impl->WebRtcLogMessage(message);
1587 } 1589 }
1588 #endif 1590 #endif
1589 } 1591 }
1590 1592
1591 void MediaStreamManager::HandleAccessRequestResponse( 1593 void MediaStreamManager::HandleAccessRequestResponse(
1592 const std::string& label, 1594 const std::string& label,
1593 const MediaStreamDevices& devices) { 1595 const MediaStreamDevices& devices,
1596 content::MediaStreamRequestResult result) {
1594 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1597 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1595 DVLOG(1) << "HandleAccessRequestResponse(" 1598 DVLOG(1) << "HandleAccessRequestResponse("
1596 << ", {label = " << label << "})"; 1599 << ", {label = " << label << "})";
1597 1600
1598 DeviceRequest* request = FindRequest(label); 1601 DeviceRequest* request = FindRequest(label);
1599 if (!request) { 1602 if (!request) {
1600 // The request has been canceled before the UI returned. 1603 // The request has been canceled before the UI returned.
1601 return; 1604 return;
1602 } 1605 }
1603 1606
1604 if (request->request_type == MEDIA_DEVICE_ACCESS) { 1607 if (request->request_type == MEDIA_DEVICE_ACCESS) {
1605 FinalizeMediaAccessRequest(label, request, devices); 1608 FinalizeMediaAccessRequest(label, request, devices);
1606 return; 1609 return;
1607 } 1610 }
1608 1611
1609 // Handle the case when the request was denied. 1612 // Handle the case when the request was denied.
1610 if (devices.empty()) { 1613 if (result != content::OK) {
1611 FinalizeRequestFailed(label, request); 1614 FinalizeRequestFailed(label, request, result);
1612 return; 1615 return;
1613 } 1616 }
1614 1617
1615 // Process all newly-accepted devices for this request. 1618 // Process all newly-accepted devices for this request.
1616 bool found_audio = false; 1619 bool found_audio = false;
1617 bool found_video = false; 1620 bool found_video = false;
1618 for (MediaStreamDevices::const_iterator device_it = devices.begin(); 1621 for (MediaStreamDevices::const_iterator device_it = devices.begin();
1619 device_it != devices.end(); ++device_it) { 1622 device_it != devices.end(); ++device_it) {
1620 StreamDeviceInfo device_info; 1623 StreamDeviceInfo device_info;
1621 device_info.device = *device_it; 1624 device_info.device = *device_it;
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
1816 } 1819 }
1817 1820
1818 // Always do enumeration even though some enumeration is in progress, 1821 // Always do enumeration even though some enumeration is in progress,
1819 // because those enumeration commands could be sent before these devices 1822 // because those enumeration commands could be sent before these devices
1820 // change. 1823 // change.
1821 ++active_enumeration_ref_count_[stream_type]; 1824 ++active_enumeration_ref_count_[stream_type];
1822 GetDeviceManager(stream_type)->EnumerateDevices(stream_type); 1825 GetDeviceManager(stream_type)->EnumerateDevices(stream_type);
1823 } 1826 }
1824 1827
1825 } // namespace content 1828 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698