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

Side by Side Diff: content/renderer/media/user_media_client_impl.cc

Issue 1075833002: Delay completion of getUserMedia in UserMediaClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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
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/renderer/media/user_media_client_impl.h" 5 #include "content/renderer/media/user_media_client_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/hash.h" 9 #include "base/hash.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 DVLOG(1) << "UserMediaClientImpl::OnStreamGenerationFailed(" 492 DVLOG(1) << "UserMediaClientImpl::OnStreamGenerationFailed("
493 << request_id << ")"; 493 << request_id << ")";
494 UserMediaRequestInfo* request_info = FindUserMediaRequestInfo(request_id); 494 UserMediaRequestInfo* request_info = FindUserMediaRequestInfo(request_id);
495 if (!request_info) { 495 if (!request_info) {
496 // This can happen if the request is canceled or the frame reloads while 496 // This can happen if the request is canceled or the frame reloads while
497 // MediaStreamDispatcher is processing the request. 497 // MediaStreamDispatcher is processing the request.
498 DVLOG(1) << "Request ID not found"; 498 DVLOG(1) << "Request ID not found";
499 return; 499 return;
500 } 500 }
501 501
502 GetUserMediaRequestFailed(&request_info->request, result, ""); 502 GetUserMediaRequestFailed(request_info->request, result, "");
503 DeleteUserMediaRequestInfo(request_info); 503 DeleteUserMediaRequestInfo(request_info);
504 } 504 }
505 505
506 // Callback from MediaStreamDispatcher. 506 // Callback from MediaStreamDispatcher.
507 // The browser process has stopped a device used by a MediaStream. 507 // The browser process has stopped a device used by a MediaStream.
508 void UserMediaClientImpl::OnDeviceStopped( 508 void UserMediaClientImpl::OnDeviceStopped(
509 const std::string& label, 509 const std::string& label,
510 const StreamDeviceInfo& device_info) { 510 const StreamDeviceInfo& device_info) {
511 DCHECK(CalledOnValidThread()); 511 DCHECK(CalledOnValidThread());
512 DVLOG(1) << "UserMediaClientImpl::OnDeviceStopped(" 512 DVLOG(1) << "UserMediaClientImpl::OnDeviceStopped("
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 } 647 }
648 648
649 void UserMediaClientImpl::OnCreateNativeTracksCompleted( 649 void UserMediaClientImpl::OnCreateNativeTracksCompleted(
650 UserMediaRequestInfo* request, 650 UserMediaRequestInfo* request,
651 MediaStreamRequestResult result, 651 MediaStreamRequestResult result,
652 const blink::WebString& result_name) { 652 const blink::WebString& result_name) {
653 DVLOG(1) << "UserMediaClientImpl::OnCreateNativeTracksComplete(" 653 DVLOG(1) << "UserMediaClientImpl::OnCreateNativeTracksComplete("
654 << "{request_id = " << request->request_id << "} " 654 << "{request_id = " << request->request_id << "} "
655 << "{result = " << result << "})"; 655 << "{result = " << result << "})";
656 656
657 // Completing the request can lead to that blink call 657 if (result == content::MEDIA_DEVICE_OK)
658 // cancelUserMediaRequest with the blink request and the UserMediaClientImpl 658 GetUserMediaRequestSucceeded(request->web_stream, request->request);
659 // is destroyed. Therefore, we copy (blink objects are smart pointers) the 659 else
660 // following objects and delete |request| before completing the blink request. 660 GetUserMediaRequestFailed(request->request, result, result_name);
661 blink::WebMediaStream stream = request->web_stream; 661
662 blink::WebUserMediaRequest blink_request = request->request;
663 blink::WebString result_name_copy = result_name;
664 DeleteUserMediaRequestInfo(request); 662 DeleteUserMediaRequestInfo(request);
665
666 if (result == content::MEDIA_DEVICE_OK)
667 GetUserMediaRequestSucceeded(stream, &blink_request);
668 else
669 GetUserMediaRequestFailed(&blink_request, result, result_name_copy);
670 } 663 }
671 664
672 void UserMediaClientImpl::OnDevicesEnumerated( 665 void UserMediaClientImpl::OnDevicesEnumerated(
673 int request_id, 666 int request_id,
674 const StreamDeviceInfoArray& device_array) { 667 const StreamDeviceInfoArray& device_array) {
675 DVLOG(1) << "UserMediaClientImpl::OnDevicesEnumerated(" << request_id << ")"; 668 DVLOG(1) << "UserMediaClientImpl::OnDevicesEnumerated(" << request_id << ")";
676 669
677 MediaDevicesRequestInfo* request = FindMediaDevicesRequestInfo(request_id); 670 MediaDevicesRequestInfo* request = FindMediaDevicesRequestInfo(request_id);
678 DCHECK(request); 671 DCHECK(request);
679 672
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 } 710 }
718 711
719 void UserMediaClientImpl::OnDeviceOpenFailed(int request_id) { 712 void UserMediaClientImpl::OnDeviceOpenFailed(int request_id) {
720 DVLOG(1) << "UserMediaClientImpl::VideoDeviceOpenFailed(" 713 DVLOG(1) << "UserMediaClientImpl::VideoDeviceOpenFailed("
721 << request_id << ")"; 714 << request_id << ")";
722 NOTIMPLEMENTED(); 715 NOTIMPLEMENTED();
723 } 716 }
724 717
725 void UserMediaClientImpl::GetUserMediaRequestSucceeded( 718 void UserMediaClientImpl::GetUserMediaRequestSucceeded(
726 const blink::WebMediaStream& stream, 719 const blink::WebMediaStream& stream,
727 blink::WebUserMediaRequest* request_info) { 720 blink::WebUserMediaRequest request_info) {
728 DVLOG(1) << "UserMediaClientImpl::GetUserMediaRequestSucceeded"; 721 // Completing the getUserMedia request can lead to that the RenderFrame and
722 // the UserMediaClientImpl is destroyed if the JavaScript code request the
723 // frame to be destroyed within the scope of the callback. Therefore,
724 // post a task to complete the request with a clean stack.
725 base::MessageLoop::current()->PostTask(
726 FROM_HERE,
727 base::Bind(&UserMediaClientImpl::DelayedGetUserMediaRequestSucceeded,
728 weak_factory_.GetWeakPtr(), stream, request_info));
729 }
730
731 void UserMediaClientImpl::DelayedGetUserMediaRequestSucceeded(
732 const blink::WebMediaStream& stream,
733 blink::WebUserMediaRequest request_info) {
734 DVLOG(1) << "UserMediaClientImpl::DelayedGetUserMediaRequestSucceeded";
729 LogUserMediaRequestResult(MEDIA_DEVICE_OK); 735 LogUserMediaRequestResult(MEDIA_DEVICE_OK);
730 request_info->requestSucceeded(stream); 736 request_info.requestSucceeded(stream);
731 } 737 }
732 738
733 void UserMediaClientImpl::GetUserMediaRequestFailed( 739 void UserMediaClientImpl::GetUserMediaRequestFailed(
734 blink::WebUserMediaRequest* request_info, 740 blink::WebUserMediaRequest request_info,
741 MediaStreamRequestResult result,
742 const blink::WebString& result_name) {
743 // Completing the getUserMedia request can lead to that the RenderFrame and
744 // the UserMediaClientImpl is destroyed if the JavaScript code request the
745 // frame to be destroyed within the scope of the callback. Therefore,
746 // post a task to complete the request with a clean stack.
747 base::MessageLoop::current()->PostTask(
748 FROM_HERE,
749 base::Bind(&UserMediaClientImpl::DelayedGetUserMediaRequestFailed,
750 weak_factory_.GetWeakPtr(), request_info, result,
751 result_name));
752 }
753
754 void UserMediaClientImpl::DelayedGetUserMediaRequestFailed(
755 blink::WebUserMediaRequest request_info,
735 MediaStreamRequestResult result, 756 MediaStreamRequestResult result,
736 const blink::WebString& result_name) { 757 const blink::WebString& result_name) {
737 LogUserMediaRequestResult(result); 758 LogUserMediaRequestResult(result);
738 switch (result) { 759 switch (result) {
739 case MEDIA_DEVICE_OK: 760 case MEDIA_DEVICE_OK:
740 case NUM_MEDIA_REQUEST_RESULTS: 761 case NUM_MEDIA_REQUEST_RESULTS:
741 NOTREACHED(); 762 NOTREACHED();
742 return; 763 return;
743 case MEDIA_DEVICE_PERMISSION_DENIED: 764 case MEDIA_DEVICE_PERMISSION_DENIED:
744 request_info->requestDenied(); 765 request_info.requestDenied();
745 return; 766 return;
746 case MEDIA_DEVICE_PERMISSION_DISMISSED: 767 case MEDIA_DEVICE_PERMISSION_DISMISSED:
747 request_info->requestFailedUASpecific("PermissionDismissedError"); 768 request_info.requestFailedUASpecific("PermissionDismissedError");
748 return; 769 return;
749 case MEDIA_DEVICE_INVALID_STATE: 770 case MEDIA_DEVICE_INVALID_STATE:
750 request_info->requestFailedUASpecific("InvalidStateError"); 771 request_info.requestFailedUASpecific("InvalidStateError");
751 return; 772 return;
752 case MEDIA_DEVICE_NO_HARDWARE: 773 case MEDIA_DEVICE_NO_HARDWARE:
753 request_info->requestFailedUASpecific("DevicesNotFoundError"); 774 request_info.requestFailedUASpecific("DevicesNotFoundError");
754 return; 775 return;
755 case MEDIA_DEVICE_INVALID_SECURITY_ORIGIN: 776 case MEDIA_DEVICE_INVALID_SECURITY_ORIGIN:
756 request_info->requestFailedUASpecific("InvalidSecurityOriginError"); 777 request_info.requestFailedUASpecific("InvalidSecurityOriginError");
757 return; 778 return;
758 case MEDIA_DEVICE_TAB_CAPTURE_FAILURE: 779 case MEDIA_DEVICE_TAB_CAPTURE_FAILURE:
759 request_info->requestFailedUASpecific("TabCaptureError"); 780 request_info.requestFailedUASpecific("TabCaptureError");
760 return; 781 return;
761 case MEDIA_DEVICE_SCREEN_CAPTURE_FAILURE: 782 case MEDIA_DEVICE_SCREEN_CAPTURE_FAILURE:
762 request_info->requestFailedUASpecific("ScreenCaptureError"); 783 request_info.requestFailedUASpecific("ScreenCaptureError");
763 return; 784 return;
764 case MEDIA_DEVICE_CAPTURE_FAILURE: 785 case MEDIA_DEVICE_CAPTURE_FAILURE:
765 request_info->requestFailedUASpecific("DeviceCaptureError"); 786 request_info.requestFailedUASpecific("DeviceCaptureError");
766 return; 787 return;
767 case MEDIA_DEVICE_CONSTRAINT_NOT_SATISFIED: 788 case MEDIA_DEVICE_CONSTRAINT_NOT_SATISFIED:
768 request_info->requestFailedConstraint(result_name); 789 request_info.requestFailedConstraint(result_name);
769 return; 790 return;
770 case MEDIA_DEVICE_TRACK_START_FAILURE: 791 case MEDIA_DEVICE_TRACK_START_FAILURE:
771 request_info->requestFailedUASpecific("TrackStartError"); 792 request_info.requestFailedUASpecific("TrackStartError");
772 return; 793 return;
773 case MEDIA_DEVICE_NOT_SUPPORTED: 794 case MEDIA_DEVICE_NOT_SUPPORTED:
774 request_info->requestFailedUASpecific("MediaDeviceNotSupported"); 795 request_info.requestFailedUASpecific("MediaDeviceNotSupported");
775 return; 796 return;
776 case MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN: 797 case MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN:
777 request_info->requestFailedUASpecific("MediaDeviceFailedDueToShutdown"); 798 request_info.requestFailedUASpecific("MediaDeviceFailedDueToShutdown");
778 return; 799 return;
779 } 800 }
780 NOTREACHED(); 801 NOTREACHED();
781 request_info->requestFailed(); 802 request_info.requestFailed();
782 } 803 }
783 804
784 void UserMediaClientImpl::EnumerateDevicesSucceded( 805 void UserMediaClientImpl::EnumerateDevicesSucceded(
785 blink::WebMediaDevicesRequest* request, 806 blink::WebMediaDevicesRequest* request,
786 blink::WebVector<blink::WebMediaDeviceInfo>& devices) { 807 blink::WebVector<blink::WebMediaDeviceInfo>& devices) {
787 request->requestSucceeded(devices); 808 request->requestSucceeded(devices);
788 } 809 }
789 810
790 void UserMediaClientImpl::EnumerateSourcesSucceded( 811 void UserMediaClientImpl::EnumerateSourcesSucceded(
791 blink::WebMediaStreamTrackSourcesRequest* request, 812 blink::WebMediaStreamTrackSourcesRequest* request,
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 return; 1085 return;
1065 } 1086 }
1066 } 1087 }
1067 } 1088 }
1068 1089
1069 bool UserMediaClientImpl::UserMediaRequestInfo::HasPendingSources() const { 1090 bool UserMediaClientImpl::UserMediaRequestInfo::HasPendingSources() const {
1070 return !sources_waiting_for_callback_.empty(); 1091 return !sources_waiting_for_callback_.empty();
1071 } 1092 }
1072 1093
1073 } // namespace content 1094 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/user_media_client_impl.h ('k') | content/renderer/media/user_media_client_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698