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

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

Issue 446553002: Add histogram WebRTC.UserMediaRequest.NoResultState to track user media requests with no result. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@b399835
Patch Set: Diffbase https://codereview.chromium.org/427713004/ Created 6 years, 4 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/media_stream_impl.h" 5 #include "content/renderer/media/media_stream_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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 } 192 }
193 193
194 void MediaStreamImpl::cancelUserMediaRequest( 194 void MediaStreamImpl::cancelUserMediaRequest(
195 const blink::WebUserMediaRequest& user_media_request) { 195 const blink::WebUserMediaRequest& user_media_request) {
196 DCHECK(CalledOnValidThread()); 196 DCHECK(CalledOnValidThread());
197 UserMediaRequestInfo* request = FindUserMediaRequestInfo(user_media_request); 197 UserMediaRequestInfo* request = FindUserMediaRequestInfo(user_media_request);
198 if (request) { 198 if (request) {
199 // We can't abort the stream generation process. 199 // We can't abort the stream generation process.
200 // Instead, erase the request. Once the stream is generated we will stop the 200 // Instead, erase the request. Once the stream is generated we will stop the
201 // stream if the request does not exist. 201 // stream if the request does not exist.
202 LogUserMediaRequestWithNoResult(true,
vrk (LEFT CHROMIUM) 2014/08/05 19:05:40 In general, boolean parameters are not good practi
andresp-chromium 2014/08/06 10:13:56 Done.
203 request->generated,
204 request->HasPendingSources());
202 DeleteUserMediaRequestInfo(request); 205 DeleteUserMediaRequestInfo(request);
203 } 206 }
204 } 207 }
205 208
206 void MediaStreamImpl::requestMediaDevices( 209 void MediaStreamImpl::requestMediaDevices(
207 const blink::WebMediaDevicesRequest& media_devices_request) { 210 const blink::WebMediaDevicesRequest& media_devices_request) {
208 UpdateWebRTCMethodCount(WEBKIT_GET_MEDIA_DEVICES); 211 UpdateWebRTCMethodCount(WEBKIT_GET_MEDIA_DEVICES);
209 DCHECK(CalledOnValidThread()); 212 DCHECK(CalledOnValidThread());
210 213
211 int audio_input_request_id = g_next_request_id++; 214 int audio_input_request_id = g_next_request_id++;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 void MediaStreamImpl::OnStreamGenerated( 269 void MediaStreamImpl::OnStreamGenerated(
267 int request_id, 270 int request_id,
268 const std::string& label, 271 const std::string& label,
269 const StreamDeviceInfoArray& audio_array, 272 const StreamDeviceInfoArray& audio_array,
270 const StreamDeviceInfoArray& video_array) { 273 const StreamDeviceInfoArray& video_array) {
271 DCHECK(CalledOnValidThread()); 274 DCHECK(CalledOnValidThread());
272 DVLOG(1) << "MediaStreamImpl::OnStreamGenerated stream:" << label; 275 DVLOG(1) << "MediaStreamImpl::OnStreamGenerated stream:" << label;
273 276
274 UserMediaRequestInfo* request_info = FindUserMediaRequestInfo(request_id); 277 UserMediaRequestInfo* request_info = FindUserMediaRequestInfo(request_id);
275 if (!request_info) { 278 if (!request_info) {
276 // This can happen if the request is canceled or the frame reloads while
277 // MediaStreamDispatcher is processing the request.
278 // Only stop the device if the device is not used in another MediaStream.
279 for (StreamDeviceInfoArray::const_iterator device_it = audio_array.begin();
280 device_it != audio_array.end(); ++device_it) {
281 if (!FindLocalSource(*device_it))
282 media_stream_dispatcher_->StopStreamDevice(*device_it);
283 }
284
285 for (StreamDeviceInfoArray::const_iterator device_it = video_array.begin();
286 device_it != video_array.end(); ++device_it) {
287 if (!FindLocalSource(*device_it))
288 media_stream_dispatcher_->StopStreamDevice(*device_it);
289 }
290
291 DVLOG(1) << "Request ID not found"; 279 DVLOG(1) << "Request ID not found";
292 return; 280 return OnStreamGeneratedForCancelledRequest(audio_array, video_array);
vrk (LEFT CHROMIUM) 2014/08/05 19:05:40 Why did you make this into its own function? Also
andresp-chromium 2014/08/06 10:13:56 This was re factoring when reading the code. Origi
293 } 281 }
294 request_info->generated = true; 282 request_info->generated = true;
295 283
296 // WebUserMediaRequest don't have an implementation in unit tests. 284 // WebUserMediaRequest don't have an implementation in unit tests.
297 // Therefore we need to check for isNull here and initialize the 285 // Therefore we need to check for isNull here and initialize the
298 // constraints. 286 // constraints.
299 blink::WebUserMediaRequest* request = &(request_info->request); 287 blink::WebUserMediaRequest* request = &(request_info->request);
300 blink::WebMediaConstraints audio_constraints; 288 blink::WebMediaConstraints audio_constraints;
301 blink::WebMediaConstraints video_constraints; 289 blink::WebMediaConstraints video_constraints;
302 if (request->isNull()) { 290 if (request->isNull()) {
(...skipping 22 matching lines...) Expand all
325 web_stream->setExtraData( 313 web_stream->setExtraData(
326 new MediaStream( 314 new MediaStream(
327 *web_stream)); 315 *web_stream));
328 316
329 // Wait for the tracks to be started successfully or to fail. 317 // Wait for the tracks to be started successfully or to fail.
330 request_info->CallbackOnTracksStarted( 318 request_info->CallbackOnTracksStarted(
331 base::Bind(&MediaStreamImpl::OnCreateNativeTracksCompleted, 319 base::Bind(&MediaStreamImpl::OnCreateNativeTracksCompleted,
332 weak_factory_.GetWeakPtr())); 320 weak_factory_.GetWeakPtr()));
333 } 321 }
334 322
323 // This can happen if the request is canceled or the frame reloads while
324 // MediaStreamDispatcher is processing the request.
325 // Only stop the device if the device is not used in another MediaStream.
326 void MediaStreamImpl::OnStreamGeneratedForCancelledRequest(
327 const StreamDeviceInfoArray& audio_array,
328 const StreamDeviceInfoArray& video_array) {
329 for (StreamDeviceInfoArray::const_iterator device_it = audio_array.begin();
330 device_it != audio_array.end(); ++device_it) {
331 if (!FindLocalSource(*device_it))
332 media_stream_dispatcher_->StopStreamDevice(*device_it);
333 }
334
335 for (StreamDeviceInfoArray::const_iterator device_it = video_array.begin();
336 device_it != video_array.end(); ++device_it) {
337 if (!FindLocalSource(*device_it))
338 media_stream_dispatcher_->StopStreamDevice(*device_it);
339 }
340 }
341
vrk (LEFT CHROMIUM) 2014/08/05 19:05:40 nit: extra line
andresp-chromium 2014/08/06 10:13:56 Done.
342
335 // Callback from MediaStreamDispatcher. 343 // Callback from MediaStreamDispatcher.
336 // The requested stream failed to be generated. 344 // The requested stream failed to be generated.
337 void MediaStreamImpl::OnStreamGenerationFailed( 345 void MediaStreamImpl::OnStreamGenerationFailed(
338 int request_id, 346 int request_id,
339 content::MediaStreamRequestResult result) { 347 content::MediaStreamRequestResult result) {
340 DCHECK(CalledOnValidThread()); 348 DCHECK(CalledOnValidThread());
341 DVLOG(1) << "MediaStreamImpl::OnStreamGenerationFailed(" 349 DVLOG(1) << "MediaStreamImpl::OnStreamGenerationFailed("
342 << request_id << ")"; 350 << request_id << ")";
343 UserMediaRequestInfo* request_info = FindUserMediaRequestInfo(request_id); 351 UserMediaRequestInfo* request_info = FindUserMediaRequestInfo(request_id);
344 if (!request_info) { 352 if (!request_info) {
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 UserMediaRequests::iterator it = user_media_requests_.begin(); 702 UserMediaRequests::iterator it = user_media_requests_.begin();
695 for (; it != user_media_requests_.end(); ++it) { 703 for (; it != user_media_requests_.end(); ++it) {
696 if ((*it) == request) { 704 if ((*it) == request) {
697 user_media_requests_.erase(it); 705 user_media_requests_.erase(it);
698 return; 706 return;
699 } 707 }
700 } 708 }
701 NOTREACHED(); 709 NOTREACHED();
702 } 710 }
703 711
712 void MediaStreamImpl::DeleteAllUserMediaRequests() {
713 UserMediaRequests::iterator request_it = user_media_requests_.begin();
714 while (request_it != user_media_requests_.end()) {
715 DVLOG(1) << "MediaStreamImpl@" << this << "::DeleteAllUserMediaRequests: "
716 << "Cancel user media request " << (*request_it)->request_id;
717 // If the request is not generated, it means that a request
718 // has been sent to the MediaStreamDispatcher to generate a stream
719 // but MediaStreamDispatcher has not yet responded and we need to cancel
720 // the request.
721 if (!(*request_it)->generated) {
722 media_stream_dispatcher_->CancelGenerateStream(
723 (*request_it)->request_id, weak_factory_.GetWeakPtr());
724 }
725 LogUserMediaRequestWithNoResult(false,
vrk (LEFT CHROMIUM) 2014/08/05 19:05:40 As stated elsewhere, this call should instead look
andresp-chromium 2014/08/06 10:13:56 Done. I liked this suggestion.
726 (*request_it)->generated,
727 (*request_it)->HasPendingSources());
728 request_it = user_media_requests_.erase(request_it);
729 }
730 }
731
704 MediaStreamImpl::MediaDevicesRequestInfo* 732 MediaStreamImpl::MediaDevicesRequestInfo*
705 MediaStreamImpl::FindMediaDevicesRequestInfo( 733 MediaStreamImpl::FindMediaDevicesRequestInfo(
706 int request_id) { 734 int request_id) {
707 MediaDevicesRequests::iterator it = media_devices_requests_.begin(); 735 MediaDevicesRequests::iterator it = media_devices_requests_.begin();
708 for (; it != media_devices_requests_.end(); ++it) { 736 for (; it != media_devices_requests_.end(); ++it) {
709 if ((*it)->audio_input_request_id == request_id || 737 if ((*it)->audio_input_request_id == request_id ||
710 (*it)->video_input_request_id == request_id || 738 (*it)->video_input_request_id == request_id ||
711 (*it)->audio_output_request_id == request_id) { 739 (*it)->audio_output_request_id == request_id) {
712 return (*it); 740 return (*it);
713 } 741 }
(...skipping 27 matching lines...) Expand all
741 769
742 media_devices_requests_.erase(it); 770 media_devices_requests_.erase(it);
743 return; 771 return;
744 } 772 }
745 } 773 }
746 NOTREACHED(); 774 NOTREACHED();
747 } 775 }
748 776
749 void MediaStreamImpl::FrameWillClose() { 777 void MediaStreamImpl::FrameWillClose() {
750 // Cancel all outstanding UserMediaRequests. 778 // Cancel all outstanding UserMediaRequests.
751 UserMediaRequests::iterator request_it = user_media_requests_.begin(); 779 DeleteAllUserMediaRequests();
vrk (LEFT CHROMIUM) 2014/08/05 19:05:40 Why did you move this into its own function?
andresp-chromium 2014/08/06 10:13:56 Re-factoring when reading the code. I wanted to is
752 while (request_it != user_media_requests_.end()) {
753 DVLOG(1) << "MediaStreamImpl@" << this << "::FrameWillClose: "
754 << "Cancel user media request " << (*request_it)->request_id;
755 // If the request is not generated, it means that a request
756 // has been sent to the MediaStreamDispatcher to generate a stream
757 // but MediaStreamDispatcher has not yet responded and we need to cancel
758 // the request.
759 if (!(*request_it)->generated) {
760 media_stream_dispatcher_->CancelGenerateStream(
761 (*request_it)->request_id, weak_factory_.GetWeakPtr());
762 }
763 request_it = user_media_requests_.erase(request_it);
764 }
765 780
766 // Loop through all current local sources and stop the sources. 781 // Loop through all current local sources and stop the sources.
767 LocalStreamSources::iterator sources_it = local_sources_.begin(); 782 LocalStreamSources::iterator sources_it = local_sources_.begin();
768 while (sources_it != local_sources_.end()) { 783 while (sources_it != local_sources_.end()) {
769 StopLocalSource(*sources_it, true); 784 StopLocalSource(*sources_it, true);
770 sources_it = local_sources_.erase(sources_it); 785 sources_it = local_sources_.erase(sources_it);
771 } 786 }
772 } 787 }
773 788
774 void MediaStreamImpl::OnLocalSourceStopped( 789 void MediaStreamImpl::OnLocalSourceStopped(
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 sources_.begin(); 919 sources_.begin();
905 it != sources_.end(); ++it) { 920 it != sources_.end(); ++it) {
906 if (source.id() == it->id()) { 921 if (source.id() == it->id()) {
907 sources_.erase(it); 922 sources_.erase(it);
908 return; 923 return;
909 } 924 }
910 } 925 }
911 } 926 }
912 927
913 } // namespace content 928 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698