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

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

Issue 344653003: Revert 274608 "Implement getMediaDevices." (Closed) Base URL: svn://svn.chromium.org/chrome/branches/2057/src/
Patch Set: Created 6 years, 6 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 } 154 }
155 } 155 }
156 return output_string; 156 return output_string;
157 } 157 }
158 158
159 // Needed for MediaStreamManager::GenerateStream below. 159 // Needed for MediaStreamManager::GenerateStream below.
160 std::string ReturnEmptySalt() { 160 std::string ReturnEmptySalt() {
161 return std::string(); 161 return std::string();
162 } 162 }
163 163
164 // Clears the MediaStreamDevice.name from all devices in |devices|.
165 static void ClearDeviceLabels(content::StreamDeviceInfoArray* devices) {
166 for (content::StreamDeviceInfoArray::iterator device_itr = devices->begin();
167 device_itr != devices->end();
168 ++device_itr) {
169 device_itr->device.name.clear();
170 }
171 }
172
173 } // namespace 164 } // namespace
174 165
175 166
176 // MediaStreamManager::DeviceRequest represents a request to either enumerate 167 // MediaStreamManager::DeviceRequest represents a request to either enumerate
177 // available devices or open one or more devices. 168 // available devices or open one or more devices.
178 // TODO(perkj): MediaStreamManager still needs refactoring. I propose we create 169 // TODO(perkj): MediaStreamManager still needs refactoring. I propose we create
179 // several subclasses of DeviceRequest and move some of the responsibility of 170 // several subclasses of DeviceRequest and move some of the responsibility of
180 // the MediaStreamManager to the subclasses to get rid of the way too many if 171 // the MediaStreamManager to the subclasses to get rid of the way too many if
181 // statements in MediaStreamManager. 172 // statements in MediaStreamManager.
182 class MediaStreamManager::DeviceRequest { 173 class MediaStreamManager::DeviceRequest {
183 public: 174 public:
184 DeviceRequest(MediaStreamRequester* requester, 175 DeviceRequest(MediaStreamRequester* requester,
185 int requesting_process_id, 176 int requesting_process_id,
186 int requesting_view_id, 177 int requesting_view_id,
187 int page_request_id, 178 int page_request_id,
188 const GURL& security_origin, 179 const GURL& security_origin,
189 bool have_permission,
190 bool user_gesture, 180 bool user_gesture,
191 MediaStreamRequestType request_type, 181 MediaStreamRequestType request_type,
192 const StreamOptions& options, 182 const StreamOptions& options,
193 const ResourceContext::SaltCallback& salt_callback) 183 const ResourceContext::SaltCallback& salt_callback)
194 : requester(requester), 184 : requester(requester),
195 requesting_process_id(requesting_process_id), 185 requesting_process_id(requesting_process_id),
196 requesting_view_id(requesting_view_id), 186 requesting_view_id(requesting_view_id),
197 page_request_id(page_request_id), 187 page_request_id(page_request_id),
198 security_origin(security_origin), 188 security_origin(security_origin),
199 have_permission(have_permission),
200 user_gesture(user_gesture), 189 user_gesture(user_gesture),
201 request_type(request_type), 190 request_type(request_type),
202 options(options), 191 options(options),
203 salt_callback(salt_callback), 192 salt_callback(salt_callback),
204 state_(NUM_MEDIA_TYPES, MEDIA_REQUEST_STATE_NOT_REQUESTED), 193 state_(NUM_MEDIA_TYPES, MEDIA_REQUEST_STATE_NOT_REQUESTED),
205 audio_type_(MEDIA_NO_SERVICE), 194 audio_type_(MEDIA_NO_SERVICE),
206 video_type_(MEDIA_NO_SERVICE) { 195 video_type_(MEDIA_NO_SERVICE) {
207 } 196 }
208 197
209 ~DeviceRequest() {} 198 ~DeviceRequest() {}
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 // will receive a handle to the MediaStream. This may be different from 300 // will receive a handle to the MediaStream. This may be different from
312 // MediaStreamRequest::render_view_id which in the tab capture case 301 // MediaStreamRequest::render_view_id which in the tab capture case
313 // specifies the target renderer from which audio and video is captured. 302 // specifies the target renderer from which audio and video is captured.
314 const int requesting_view_id; 303 const int requesting_view_id;
315 304
316 // An ID the render view provided to identify this request. 305 // An ID the render view provided to identify this request.
317 const int page_request_id; 306 const int page_request_id;
318 307
319 const GURL security_origin; 308 const GURL security_origin;
320 309
321 // This is used when enumerating devices; if we don't have device access
322 // permission, we remove the device label.
323 bool have_permission;
324
325 const bool user_gesture; 310 const bool user_gesture;
326 311
327 const MediaStreamRequestType request_type; 312 const MediaStreamRequestType request_type;
328 313
329 const StreamOptions options; 314 const StreamOptions options;
330 315
331 ResourceContext::SaltCallback salt_callback; 316 ResourceContext::SaltCallback salt_callback;
332 317
333 StreamDeviceInfoArray devices; 318 StreamDeviceInfoArray devices;
334 319
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 const MediaRequestResponseCallback& callback) { 404 const MediaRequestResponseCallback& callback) {
420 DCHECK_CURRENTLY_ON(BrowserThread::IO); 405 DCHECK_CURRENTLY_ON(BrowserThread::IO);
421 406
422 // TODO(perkj): The argument list with NULL parameters to DeviceRequest 407 // TODO(perkj): The argument list with NULL parameters to DeviceRequest
423 // suggests that this is the wrong design. Can this be refactored? 408 // suggests that this is the wrong design. Can this be refactored?
424 DeviceRequest* request = new DeviceRequest(NULL, 409 DeviceRequest* request = new DeviceRequest(NULL,
425 render_process_id, 410 render_process_id,
426 render_view_id, 411 render_view_id,
427 page_request_id, 412 page_request_id,
428 security_origin, 413 security_origin,
429 true,
430 false, // user gesture 414 false, // user gesture
431 MEDIA_DEVICE_ACCESS, 415 MEDIA_DEVICE_ACCESS,
432 options, 416 options,
433 base::Bind(&ReturnEmptySalt)); 417 base::Bind(&ReturnEmptySalt));
434 418
435 const std::string& label = AddRequest(request); 419 const std::string& label = AddRequest(request);
436 420
437 request->callback = callback; 421 request->callback = callback;
438 // Post a task and handle the request asynchronously. The reason is that the 422 // Post a task and handle the request asynchronously. The reason is that the
439 // requester won't have a label for the request until this function returns 423 // requester won't have a label for the request until this function returns
(...skipping 20 matching lines...) Expand all
460 if (CommandLine::ForCurrentProcess()->HasSwitch( 444 if (CommandLine::ForCurrentProcess()->HasSwitch(
461 switches::kUseFakeUIForMediaStream)) { 445 switches::kUseFakeUIForMediaStream)) {
462 UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy>()); 446 UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy>());
463 } 447 }
464 448
465 DeviceRequest* request = new DeviceRequest(requester, 449 DeviceRequest* request = new DeviceRequest(requester,
466 render_process_id, 450 render_process_id,
467 render_view_id, 451 render_view_id,
468 page_request_id, 452 page_request_id,
469 security_origin, 453 security_origin,
470 true,
471 user_gesture, 454 user_gesture,
472 MEDIA_GENERATE_STREAM, 455 MEDIA_GENERATE_STREAM,
473 options, 456 options,
474 sc); 457 sc);
475 458
476 const std::string& label = AddRequest(request); 459 const std::string& label = AddRequest(request);
477 460
478 // Post a task and handle the request asynchronously. The reason is that the 461 // Post a task and handle the request asynchronously. The reason is that the
479 // requester won't have a label for the request until this function returns 462 // requester won't have a label for the request until this function returns
480 // and thus can not handle a response. Using base::Unretained is safe since 463 // and thus can not handle a response. Using base::Unretained is safe since
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 } 626 }
644 } 627 }
645 628
646 std::string MediaStreamManager::EnumerateDevices( 629 std::string MediaStreamManager::EnumerateDevices(
647 MediaStreamRequester* requester, 630 MediaStreamRequester* requester,
648 int render_process_id, 631 int render_process_id,
649 int render_view_id, 632 int render_view_id,
650 const ResourceContext::SaltCallback& sc, 633 const ResourceContext::SaltCallback& sc,
651 int page_request_id, 634 int page_request_id,
652 MediaStreamType type, 635 MediaStreamType type,
653 const GURL& security_origin, 636 const GURL& security_origin) {
654 bool have_permission) {
655 DCHECK_CURRENTLY_ON(BrowserThread::IO); 637 DCHECK_CURRENTLY_ON(BrowserThread::IO);
656 DCHECK(requester); 638 DCHECK(requester);
657 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || 639 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
658 type == MEDIA_DEVICE_VIDEO_CAPTURE); 640 type == MEDIA_DEVICE_VIDEO_CAPTURE);
659 641
660 DeviceRequest* request = new DeviceRequest(requester, 642 DeviceRequest* request = new DeviceRequest(requester,
661 render_process_id, 643 render_process_id,
662 render_view_id, 644 render_view_id,
663 page_request_id, 645 page_request_id,
664 security_origin, 646 security_origin,
665 have_permission,
666 false, // user gesture 647 false, // user gesture
667 MEDIA_ENUMERATE_DEVICES, 648 MEDIA_ENUMERATE_DEVICES,
668 StreamOptions(), 649 StreamOptions(),
669 sc); 650 sc);
670 if (IsAudioMediaType(type)) 651 if (IsAudioMediaType(type))
671 request->SetAudioType(type); 652 request->SetAudioType(type);
672 else if (IsVideoMediaType(type)) 653 else if (IsVideoMediaType(type))
673 request->SetVideoType(type); 654 request->SetVideoType(type);
674 655
675 const std::string& label = AddRequest(request); 656 const std::string& label = AddRequest(request);
(...skipping 16 matching lines...) Expand all
692 return; // This can happen if the request has been canceled. 673 return; // This can happen if the request has been canceled.
693 674
694 MediaStreamType type; 675 MediaStreamType type;
695 EnumerationCache* cache; 676 EnumerationCache* cache;
696 if (request->audio_type() == MEDIA_DEVICE_AUDIO_CAPTURE) { 677 if (request->audio_type() == MEDIA_DEVICE_AUDIO_CAPTURE) {
697 DCHECK_EQ(MEDIA_NO_SERVICE, request->video_type()); 678 DCHECK_EQ(MEDIA_NO_SERVICE, request->video_type());
698 type = MEDIA_DEVICE_AUDIO_CAPTURE; 679 type = MEDIA_DEVICE_AUDIO_CAPTURE;
699 cache = &audio_enumeration_cache_; 680 cache = &audio_enumeration_cache_;
700 } else { 681 } else {
701 DCHECK_EQ(MEDIA_DEVICE_VIDEO_CAPTURE, request->video_type()); 682 DCHECK_EQ(MEDIA_DEVICE_VIDEO_CAPTURE, request->video_type());
702 DCHECK_EQ(MEDIA_NO_SERVICE, request->audio_type());
703 type = MEDIA_DEVICE_VIDEO_CAPTURE; 683 type = MEDIA_DEVICE_VIDEO_CAPTURE;
704 cache = &video_enumeration_cache_; 684 cache = &video_enumeration_cache_;
705 } 685 }
706 686
707 if (!EnumerationRequired(cache, type)) { 687 if (!EnumerationRequired(cache, type)) {
708 // Cached device list of this type exists. Just send it out. 688 // Cached device list of this type exists. Just send it out.
709 request->SetState(type, MEDIA_REQUEST_STATE_REQUESTED); 689 request->SetState(type, MEDIA_REQUEST_STATE_REQUESTED);
710 request->devices = cache->devices; 690 request->devices = cache->devices;
711 FinalizeEnumerateDevices(label, request); 691 FinalizeEnumerateDevices(label, request);
712 } else { 692 } else {
(...skipping 24 matching lines...) Expand all
737 options.mandatory_video.push_back( 717 options.mandatory_video.push_back(
738 StreamOptions::Constraint(kMediaStreamSourceInfoId, device_id)); 718 StreamOptions::Constraint(kMediaStreamSourceInfoId, device_id));
739 } else { 719 } else {
740 NOTREACHED(); 720 NOTREACHED();
741 } 721 }
742 DeviceRequest* request = new DeviceRequest(requester, 722 DeviceRequest* request = new DeviceRequest(requester,
743 render_process_id, 723 render_process_id,
744 render_view_id, 724 render_view_id,
745 page_request_id, 725 page_request_id,
746 security_origin, 726 security_origin,
747 true,
748 false, // user gesture 727 false, // user gesture
749 MEDIA_OPEN_DEVICE, 728 MEDIA_OPEN_DEVICE,
750 options, 729 options,
751 sc); 730 sc);
752 731
753 const std::string& label = AddRequest(request); 732 const std::string& label = AddRequest(request);
754 // Post a task and handle the request asynchronously. The reason is that the 733 // Post a task and handle the request asynchronously. The reason is that the
755 // requester won't have a label for the request until this function returns 734 // requester won't have a label for the request until this function returns
756 // and thus can not handle a response. Using base::Unretained is safe since 735 // and thus can not handle a response. Using base::Unretained is safe since
757 // MediaStreamManager is deleted on the UI thread, after the IO thread has 736 // MediaStreamManager is deleted on the UI thread, after the IO thread has
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
1389 1368
1390 if (request->security_origin.is_valid()) { 1369 if (request->security_origin.is_valid()) {
1391 for (StreamDeviceInfoArray::iterator it = request->devices.begin(); 1370 for (StreamDeviceInfoArray::iterator it = request->devices.begin();
1392 it != request->devices.end(); ++it) { 1371 it != request->devices.end(); ++it) {
1393 TranslateDeviceIdToSourceId(request, &it->device); 1372 TranslateDeviceIdToSourceId(request, &it->device);
1394 } 1373 }
1395 } else { 1374 } else {
1396 request->devices.clear(); 1375 request->devices.clear();
1397 } 1376 }
1398 1377
1399 if (!request->have_permission)
1400 ClearDeviceLabels(&request->devices);
1401
1402 request->requester->DevicesEnumerated( 1378 request->requester->DevicesEnumerated(
1403 request->requesting_view_id, 1379 request->requesting_view_id,
1404 request->page_request_id, 1380 request->page_request_id,
1405 label, 1381 label,
1406 request->devices); 1382 request->devices);
1407 1383
1408 // TODO(tommi): 1384 // TODO(tommi):
1409 // Ideally enumeration requests should be deleted once they have been served 1385 // Ideally enumeration requests should be deleted once they have been served
1410 // (as any request). However, this implementation mixes requests and 1386 // (as any request). However, this implementation mixes requests and
1411 // notifications together so enumeration requests are kept open by some 1387 // notifications together so enumeration requests are kept open by some
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
1952 if (it->device.type == MEDIA_DESKTOP_VIDEO_CAPTURE) { 1928 if (it->device.type == MEDIA_DESKTOP_VIDEO_CAPTURE) {
1953 video_capture_manager_->SetDesktopCaptureWindowId(it->session_id, 1929 video_capture_manager_->SetDesktopCaptureWindowId(it->session_id,
1954 window_id); 1930 window_id);
1955 break; 1931 break;
1956 } 1932 }
1957 } 1933 }
1958 } 1934 }
1959 } 1935 }
1960 1936
1961 } // namespace content 1937 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698