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

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

Issue 2488843003: Reland of Use mojo support for Blink devicechange event. (Closed)
Patch Set: Created 4 years, 1 month 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 true /* audio input */, true /* video input */, true /* audio output */, 280 true /* audio input */, true /* video input */, true /* audio output */,
281 security_origin, 281 security_origin,
282 base::Bind(&UserMediaClientImpl::FinalizeEnumerateDevices, 282 base::Bind(&UserMediaClientImpl::FinalizeEnumerateDevices,
283 weak_factory_.GetWeakPtr(), media_devices_request)); 283 weak_factory_.GetWeakPtr(), media_devices_request));
284 } 284 }
285 285
286 void UserMediaClientImpl::setMediaDeviceChangeObserver( 286 void UserMediaClientImpl::setMediaDeviceChangeObserver(
287 const blink::WebMediaDeviceChangeObserver& observer) { 287 const blink::WebMediaDeviceChangeObserver& observer) {
288 media_device_change_observer_ = observer; 288 media_device_change_observer_ = observer;
289 289
290 // Do nothing if setting a valid observer while already subscribed or setting
291 // no observer while unsubscribed.
292 if (media_device_change_observer_.isNull() ==
293 device_change_subscription_ids_.empty())
294 return;
295
296 base::WeakPtr<MediaDevicesEventDispatcher> event_dispatcher =
297 MediaDevicesEventDispatcher::GetForRenderFrame(render_frame());
290 if (media_device_change_observer_.isNull()) { 298 if (media_device_change_observer_.isNull()) {
291 media_stream_dispatcher_->CancelDeviceChangeNotifications( 299 event_dispatcher->UnsubscribeDeviceChangeNotifications(
292 weak_factory_.GetWeakPtr()); 300 device_change_subscription_ids_);
301 device_change_subscription_ids_.clear();
293 } else { 302 } else {
294 url::Origin origin = observer.getSecurityOrigin(); 303 DCHECK(device_change_subscription_ids_.empty());
295 media_stream_dispatcher_->SubscribeToDeviceChangeNotifications( 304 url::Origin security_origin =
296 weak_factory_.GetWeakPtr(), origin); 305 media_device_change_observer_.getSecurityOrigin();
306 device_change_subscription_ids_ =
307 event_dispatcher->SubscribeDeviceChangeNotifications(
308 security_origin, base::Bind(&UserMediaClientImpl::DevicesChanged,
309 weak_factory_.GetWeakPtr()));
297 } 310 }
298 } 311 }
299 312
300 // Callback from MediaStreamDispatcher. 313 // Callback from MediaStreamDispatcher.
301 // The requested stream have been generated by the MediaStreamDispatcher. 314 // The requested stream have been generated by the MediaStreamDispatcher.
302 void UserMediaClientImpl::OnStreamGenerated( 315 void UserMediaClientImpl::OnStreamGenerated(
303 int request_id, 316 int request_id,
304 const std::string& label, 317 const std::string& label,
305 const StreamDeviceInfoArray& audio_array, 318 const StreamDeviceInfoArray& audio_array,
306 const StreamDeviceInfoArray& video_array) { 319 const StreamDeviceInfoArray& video_array) {
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 for (auto& web_track : tracks) { 605 for (auto& web_track : tracks) {
593 MediaStreamTrack* track = MediaStreamTrack::GetTrack(web_track); 606 MediaStreamTrack* track = MediaStreamTrack::GetTrack(web_track);
594 if (track) 607 if (track)
595 track->Stop(); 608 track->Stop();
596 } 609 }
597 } 610 }
598 611
599 DeleteUserMediaRequestInfo(request); 612 DeleteUserMediaRequestInfo(request);
600 } 613 }
601 614
615 // TODO(guidou): Remove once this method is removed from the
616 // MediaStreamDispatcherEventHandler interface. http://648183.
602 void UserMediaClientImpl::OnDevicesEnumerated( 617 void UserMediaClientImpl::OnDevicesEnumerated(
603 int request_id, 618 int request_id,
604 const StreamDeviceInfoArray& device_array) { 619 const StreamDeviceInfoArray& device_array) {
605 NOTREACHED(); 620 NOTREACHED();
606 } 621 }
607 622
608 void UserMediaClientImpl::OnDeviceOpened( 623 void UserMediaClientImpl::OnDeviceOpened(
609 int request_id, 624 int request_id,
610 const std::string& label, 625 const std::string& label,
611 const StreamDeviceInfo& video_device) { 626 const StreamDeviceInfo& video_device) {
612 DVLOG(1) << "UserMediaClientImpl::OnDeviceOpened(" 627 DVLOG(1) << "UserMediaClientImpl::OnDeviceOpened("
613 << request_id << ", " << label << ")"; 628 << request_id << ", " << label << ")";
614 NOTIMPLEMENTED(); 629 NOTIMPLEMENTED();
615 } 630 }
616 631
617 void UserMediaClientImpl::OnDeviceOpenFailed(int request_id) { 632 void UserMediaClientImpl::OnDeviceOpenFailed(int request_id) {
618 DVLOG(1) << "UserMediaClientImpl::VideoDeviceOpenFailed(" 633 DVLOG(1) << "UserMediaClientImpl::VideoDeviceOpenFailed("
619 << request_id << ")"; 634 << request_id << ")";
620 NOTIMPLEMENTED(); 635 NOTIMPLEMENTED();
621 } 636 }
622 637
638 // TODO(guidou): Remove once this method is removed from the
639 // MediaStreamDispatcherEventHandler interface. http://648183.
623 void UserMediaClientImpl::OnDevicesChanged() { 640 void UserMediaClientImpl::OnDevicesChanged() {
624 DVLOG(1) << "UserMediaClientImpl::OnDevicesChanged()"; 641 NOTREACHED();
642 }
643
644 void UserMediaClientImpl::DevicesChanged(
645 MediaDeviceType type,
646 const MediaDeviceInfoArray& device_infos) {
625 if (!media_device_change_observer_.isNull()) 647 if (!media_device_change_observer_.isNull())
626 media_device_change_observer_.didChangeMediaDevices(); 648 media_device_change_observer_.didChangeMediaDevices();
627 } 649 }
628 650
629 void UserMediaClientImpl::GetUserMediaRequestSucceeded( 651 void UserMediaClientImpl::GetUserMediaRequestSucceeded(
630 const blink::WebMediaStream& stream, 652 const blink::WebMediaStream& stream,
631 blink::WebUserMediaRequest request_info) { 653 blink::WebUserMediaRequest request_info) {
632 // Completing the getUserMedia request can lead to that the RenderFrame and 654 // Completing the getUserMedia request can lead to that the RenderFrame and
633 // the UserMediaClientImpl is destroyed if the JavaScript code request the 655 // the UserMediaClientImpl is destroyed if the JavaScript code request the
634 // frame to be destroyed within the scope of the callback. Therefore, 656 // frame to be destroyed within the scope of the callback. Therefore,
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 992
971 bool UserMediaClientImpl::UserMediaRequestInfo::HasPendingSources() const { 993 bool UserMediaClientImpl::UserMediaRequestInfo::HasPendingSources() const {
972 return !sources_waiting_for_callback_.empty(); 994 return !sources_waiting_for_callback_.empty();
973 } 995 }
974 996
975 void UserMediaClientImpl::OnDestruct() { 997 void UserMediaClientImpl::OnDestruct() {
976 delete this; 998 delete this;
977 } 999 }
978 1000
979 } // namespace content 1001 } // 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