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

Side by Side Diff: chrome/browser/media/router/presentation_service_delegate_impl.cc

Issue 2547703002: [Media Router] Handle multiple Presentation URLs when creating routes (Closed)
Patch Set: fix unittests Created 4 years 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/browser/media/router/presentation_service_delegate_impl.h" 5 #include "chrome/browser/media/router/presentation_service_delegate_impl.h"
6 6
7 #include <string> 7 #include <string>
8 #include <unordered_map> 8 #include <unordered_map>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 const content::PresentationConnectionStateChangedCallback& 352 const content::PresentationConnectionStateChangedCallback&
353 state_changed_cb); 353 state_changed_cb);
354 void ListenForSessionMessages( 354 void ListenForSessionMessages(
355 const RenderFrameHostId& render_frame_host_id, 355 const RenderFrameHostId& render_frame_host_id,
356 const content::PresentationSessionInfo& session, 356 const content::PresentationSessionInfo& session,
357 const content::PresentationSessionMessageCallback& message_cb); 357 const content::PresentationSessionMessageCallback& message_cb);
358 358
359 // Sets or clears the default presentation request and callback for the given 359 // Sets or clears the default presentation request and callback for the given
360 // frame. Also sets / clears the default presentation requests for the owning 360 // frame. Also sets / clears the default presentation requests for the owning
361 // tab WebContents. 361 // tab WebContents.
362 void SetDefaultPresentationUrl( 362 void SetDefaultPresentationUrls(
363 const RenderFrameHostId& render_frame_host_id, 363 const RenderFrameHostId& render_frame_host_id,
364 const GURL& default_presentation_url, 364 const std::vector<GURL>& default_presentation_urls,
365 const content::PresentationSessionStartedCallback& callback); 365 const content::PresentationSessionStartedCallback& callback);
366 void AddDelegateObserver(const RenderFrameHostId& render_frame_host_id, 366 void AddDelegateObserver(const RenderFrameHostId& render_frame_host_id,
367 DelegateObserver* observer); 367 DelegateObserver* observer);
368 void RemoveDelegateObserver(const RenderFrameHostId& render_frame_host_id); 368 void RemoveDelegateObserver(const RenderFrameHostId& render_frame_host_id);
369 void AddDefaultPresentationRequestObserver( 369 void AddDefaultPresentationRequestObserver(
370 PresentationServiceDelegateImpl::DefaultPresentationRequestObserver* 370 PresentationServiceDelegateImpl::DefaultPresentationRequestObserver*
371 observer); 371 observer);
372 void RemoveDefaultPresentationRequestObserver( 372 void RemoveDefaultPresentationRequestObserver(
373 PresentationServiceDelegateImpl::DefaultPresentationRequestObserver* 373 PresentationServiceDelegateImpl::DefaultPresentationRequestObserver*
374 observer); 374 observer);
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 const auto it = presentation_frames_.find(render_frame_host_id); 531 const auto it = presentation_frames_.find(render_frame_host_id);
532 if (it == presentation_frames_.end()) { 532 if (it == presentation_frames_.end()) {
533 DVLOG(2) << "ListenForSessionMessages: PresentationFrame does not exist " 533 DVLOG(2) << "ListenForSessionMessages: PresentationFrame does not exist "
534 << "for: (" << render_frame_host_id.first << ", " 534 << "for: (" << render_frame_host_id.first << ", "
535 << render_frame_host_id.second << ")"; 535 << render_frame_host_id.second << ")";
536 return; 536 return;
537 } 537 }
538 it->second->ListenForSessionMessages(session, message_cb); 538 it->second->ListenForSessionMessages(session, message_cb);
539 } 539 }
540 540
541 void PresentationFrameManager::SetDefaultPresentationUrl( 541 void PresentationFrameManager::SetDefaultPresentationUrls(
542 const RenderFrameHostId& render_frame_host_id, 542 const RenderFrameHostId& render_frame_host_id,
543 const GURL& default_presentation_url, 543 const std::vector<GURL>& default_presentation_urls,
544 const content::PresentationSessionStartedCallback& callback) { 544 const content::PresentationSessionStartedCallback& callback) {
545 if (!IsMainFrame(render_frame_host_id)) 545 if (!IsMainFrame(render_frame_host_id))
546 return; 546 return;
547 547
548 if (default_presentation_url.is_empty()) { 548 if (default_presentation_urls.empty()) {
549 ClearDefaultPresentationRequest(); 549 ClearDefaultPresentationRequest();
550 } else { 550 } else {
551 DCHECK(!callback.is_null()); 551 DCHECK(!callback.is_null());
552 GURL frame_url(GetLastCommittedURLForFrame(render_frame_host_id)); 552 GURL frame_url(GetLastCommittedURLForFrame(render_frame_host_id));
553 PresentationRequest request(render_frame_host_id, 553 PresentationRequest request(render_frame_host_id, default_presentation_urls,
554 std::vector<GURL>({default_presentation_url}),
555 frame_url); 554 frame_url);
556 default_presentation_started_callback_ = callback; 555 default_presentation_started_callback_ = callback;
557 SetDefaultPresentationRequest(request); 556 SetDefaultPresentationRequest(request);
558 } 557 }
559 } 558 }
560 559
561 void PresentationFrameManager::AddDelegateObserver( 560 void PresentationFrameManager::AddDelegateObserver(
562 const RenderFrameHostId& render_frame_host_id, 561 const RenderFrameHostId& render_frame_host_id,
563 DelegateObserver* observer) { 562 DelegateObserver* observer) {
564 auto* presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); 563 auto* presentation_frame = GetOrAddPresentationFrame(render_frame_host_id);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); 710 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id);
712 frame_manager_->Reset(render_frame_host_id); 711 frame_manager_->Reset(render_frame_host_id);
713 } 712 }
714 713
715 void PresentationServiceDelegateImpl::SetDefaultPresentationUrls( 714 void PresentationServiceDelegateImpl::SetDefaultPresentationUrls(
716 int render_process_id, 715 int render_process_id,
717 int render_frame_id, 716 int render_frame_id,
718 const std::vector<GURL>& default_presentation_urls, 717 const std::vector<GURL>& default_presentation_urls,
719 const content::PresentationSessionStartedCallback& callback) { 718 const content::PresentationSessionStartedCallback& callback) {
720 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); 719 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id);
721 if (default_presentation_urls.empty()) { 720 frame_manager_->SetDefaultPresentationUrls(
722 frame_manager_->SetDefaultPresentationUrl(render_frame_host_id, GURL(), 721 render_frame_host_id, default_presentation_urls, callback);
723 callback);
724 } else {
725 // TODO(crbug.com/627655): Handle multiple URLs.
726 frame_manager_->SetDefaultPresentationUrl(
727 render_frame_host_id, default_presentation_urls[0], callback);
728 }
729 } 722 }
730 723
731 void PresentationServiceDelegateImpl::OnJoinRouteResponse( 724 void PresentationServiceDelegateImpl::OnJoinRouteResponse(
732 int render_process_id, 725 int render_process_id,
733 int render_frame_id, 726 int render_frame_id,
734 const GURL& presentation_url, 727 const GURL& presentation_url,
735 const std::string& presentation_id, 728 const std::string& presentation_id,
736 const content::PresentationSessionStartedCallback& success_cb, 729 const content::PresentationSessionStartedCallback& success_cb,
737 const content::PresentationSessionErrorCallback& error_cb, 730 const content::PresentationSessionErrorCallback& error_cb,
738 const RouteRequestResult& result) { 731 const RouteRequestResult& result) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 int render_frame_id, 768 int render_frame_id,
776 const std::vector<GURL>& presentation_urls, 769 const std::vector<GURL>& presentation_urls,
777 const content::PresentationSessionStartedCallback& success_cb, 770 const content::PresentationSessionStartedCallback& success_cb,
778 const content::PresentationSessionErrorCallback& error_cb) { 771 const content::PresentationSessionErrorCallback& error_cb) {
779 if (presentation_urls.empty()) { 772 if (presentation_urls.empty()) {
780 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN, 773 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN,
781 "Invalid presentation arguments.")); 774 "Invalid presentation arguments."));
782 return; 775 return;
783 } 776 }
784 777
785 // TODO(crbug.com/627655): Handle multiple URLs. 778 if (presentation_urls.empty() ||
786 const GURL& presentation_url = presentation_urls[0]; 779 std::find_if_not(presentation_urls.begin(), presentation_urls.end(),
787 if (presentation_url.is_empty() || 780 IsValidPresentationUrl) != presentation_urls.end()) {
788 !IsValidPresentationUrl(presentation_url)) {
789 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN, 781 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN,
mark a. foltz 2016/12/02 20:59:08 A couple of things: - Ideally the validation in t
zhaobin 2016/12/02 22:50:57 Done.
790 "Invalid presentation arguments.")); 782 "Invalid presentation arguments."));
mark a. foltz 2016/12/02 20:59:08 Nit: "Invalid presentation URL."
zhaobin 2016/12/02 22:50:57 Done.
791 return; 783 return;
792 } 784 }
793 785
794 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); 786 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id);
795 std::unique_ptr<CreatePresentationConnectionRequest> request( 787 std::unique_ptr<CreatePresentationConnectionRequest> request(
796 new CreatePresentationConnectionRequest( 788 new CreatePresentationConnectionRequest(
797 render_frame_host_id, presentation_url, 789 render_frame_host_id, presentation_urls,
798 GetLastCommittedURLForFrame(render_frame_host_id), 790 GetLastCommittedURLForFrame(render_frame_host_id),
799 base::Bind(&PresentationServiceDelegateImpl::OnStartSessionSucceeded, 791 base::Bind(&PresentationServiceDelegateImpl::OnStartSessionSucceeded,
800 weak_factory_.GetWeakPtr(), render_process_id, 792 weak_factory_.GetWeakPtr(), render_process_id,
801 render_frame_id, success_cb), 793 render_frame_id, success_cb),
802 error_cb)); 794 error_cb));
803 MediaRouterDialogController* controller = 795 MediaRouterDialogController* controller =
804 MediaRouterDialogController::GetOrCreateForWebContents(web_contents_); 796 MediaRouterDialogController::GetOrCreateForWebContents(web_contents_);
805 if (!controller->ShowMediaRouterDialogForPresentation(std::move(request))) { 797 if (!controller->ShowMediaRouterDialogForPresentation(std::move(request))) {
806 LOG(ERROR) << "Media router dialog already exists. Ignoring StartSession."; 798 LOG(ERROR) << "Media router dialog already exists. Ignoring StartSession.";
807 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN, 799 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN,
808 "Unable to create dialog.")); 800 "Unable to create dialog."));
809 return; 801 return;
810 } 802 }
811 } 803 }
812 804
813 void PresentationServiceDelegateImpl::JoinSession( 805 void PresentationServiceDelegateImpl::JoinSession(
814 int render_process_id, 806 int render_process_id,
815 int render_frame_id, 807 int render_frame_id,
816 const std::vector<GURL>& presentation_urls, 808 const std::vector<GURL>& presentation_urls,
817 const std::string& presentation_id, 809 const std::string& presentation_id,
818 const content::PresentationSessionStartedCallback& success_cb, 810 const content::PresentationSessionStartedCallback& success_cb,
819 const content::PresentationSessionErrorCallback& error_cb) { 811 const content::PresentationSessionErrorCallback& error_cb) {
812 DVLOG(2) << "PresentationServiceDelegateImpl::JoinSession";
820 if (presentation_urls.empty()) { 813 if (presentation_urls.empty()) {
821 error_cb.Run(content::PresentationError( 814 error_cb.Run(content::PresentationError(
822 content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND, 815 content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND,
823 "Invalid presentation arguments.")); 816 "Invalid presentation arguments."));
817 return;
824 } 818 }
825 819
826 // TODO(crbug.com/627655): Handle multiple URLs. 820 // TODO(zhaobin): This may break if we have multiple cast specific urls.
mark a. foltz 2016/12/02 20:59:09 Can you elaborate on this? I would say: To fix t
zhaobin 2016/12/02 22:50:57 Done.
827 const GURL& presentation_url = presentation_urls[0]; 821 auto presentation_url = std::find_if(
822 presentation_urls.begin(), presentation_urls.end(), [](const GURL& url) {
823 return CanConnectToMediaSource(MediaSource(url));
824 });
825 if (presentation_url == presentation_urls.end()) {
826 error_cb.Run(
827 content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN,
828 "Presentation urls do support reconnect."));
mark a. foltz 2016/12/02 20:59:09 This should probably be content::PRESENTATION_ERRO
zhaobin 2016/12/02 22:50:57 Done.
829 return;
830 }
831
828 bool incognito = web_contents_->GetBrowserContext()->IsOffTheRecord(); 832 bool incognito = web_contents_->GetBrowserContext()->IsOffTheRecord();
829 std::vector<MediaRouteResponseCallback> route_response_callbacks; 833 std::vector<MediaRouteResponseCallback> route_response_callbacks;
830 route_response_callbacks.push_back( 834 route_response_callbacks.push_back(
831 base::Bind(&PresentationServiceDelegateImpl::OnJoinRouteResponse, 835 base::Bind(&PresentationServiceDelegateImpl::OnJoinRouteResponse,
832 weak_factory_.GetWeakPtr(), render_process_id, render_frame_id, 836 weak_factory_.GetWeakPtr(), render_process_id, render_frame_id,
833 presentation_url, presentation_id, success_cb, error_cb)); 837 *presentation_url, presentation_id, success_cb, error_cb));
834 router_->JoinRoute( 838 router_->JoinRoute(
835 MediaSourceForPresentationUrl(presentation_url).id(), presentation_id, 839 MediaSourceForPresentationUrl(*presentation_url).id(), presentation_id,
836 GetLastCommittedURLForFrame( 840 GetLastCommittedURLForFrame(
837 RenderFrameHostId(render_process_id, render_frame_id)) 841 RenderFrameHostId(render_process_id, render_frame_id))
838 .GetOrigin(), 842 .GetOrigin(),
839 web_contents_, route_response_callbacks, base::TimeDelta(), incognito); 843 web_contents_, route_response_callbacks, base::TimeDelta(), incognito);
840 } 844 }
841 845
842 void PresentationServiceDelegateImpl::CloseConnection( 846 void PresentationServiceDelegateImpl::CloseConnection(
843 int render_process_id, 847 int render_process_id,
844 int render_frame_id, 848 int render_frame_id,
845 const std::string& presentation_id) { 849 const std::string& presentation_id) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 const content::PresentationConnectionStateChangedCallback& 917 const content::PresentationConnectionStateChangedCallback&
914 state_changed_cb) { 918 state_changed_cb) {
915 frame_manager_->ListenForConnectionStateChange( 919 frame_manager_->ListenForConnectionStateChange(
916 RenderFrameHostId(render_process_id, render_frame_id), connection, 920 RenderFrameHostId(render_process_id, render_frame_id), connection,
917 state_changed_cb); 921 state_changed_cb);
918 } 922 }
919 923
920 void PresentationServiceDelegateImpl::OnRouteResponse( 924 void PresentationServiceDelegateImpl::OnRouteResponse(
921 const PresentationRequest& presentation_request, 925 const PresentationRequest& presentation_request,
922 const RouteRequestResult& result) { 926 const RouteRequestResult& result) {
923 if (!result.route()) 927 if (!result.route() ||
928 base::STLCount(presentation_request.presentation_urls(),
929 result.presentation_url()) == 0) {
924 return; 930 return;
931 }
925 932
926 content::PresentationSessionInfo session_info( 933 content::PresentationSessionInfo session_info(result.presentation_url(),
927 presentation_request.presentation_url(), result.presentation_id()); 934 result.presentation_id());
928 frame_manager_->OnDefaultPresentationSessionStarted( 935 frame_manager_->OnDefaultPresentationSessionStarted(
929 presentation_request, session_info, *result.route()); 936 presentation_request, session_info, *result.route());
930 } 937 }
931 938
932 void PresentationServiceDelegateImpl::AddDefaultPresentationRequestObserver( 939 void PresentationServiceDelegateImpl::AddDefaultPresentationRequestObserver(
933 DefaultPresentationRequestObserver* observer) { 940 DefaultPresentationRequestObserver* observer) {
934 frame_manager_->AddDefaultPresentationRequestObserver(observer); 941 frame_manager_->AddDefaultPresentationRequestObserver(observer);
935 } 942 }
936 943
937 void PresentationServiceDelegateImpl::RemoveDefaultPresentationRequestObserver( 944 void PresentationServiceDelegateImpl::RemoveDefaultPresentationRequestObserver(
(...skipping 25 matching lines...) Expand all
963 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( 970 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest(
964 int render_process_id, 971 int render_process_id,
965 int render_frame_id, 972 int render_frame_id,
966 const MediaSource::Id& source_id) const { 973 const MediaSource::Id& source_id) const {
967 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); 974 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id);
968 return frame_manager_->HasScreenAvailabilityListenerForTest( 975 return frame_manager_->HasScreenAvailabilityListenerForTest(
969 render_frame_host_id, source_id); 976 render_frame_host_id, source_id);
970 } 977 }
971 978
972 } // namespace media_router 979 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698