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

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

Issue 2379703002: [Presentation API] (alternative) 1-UA: send message between controller and receiver page (Closed)
Patch Set: resolve code review comments from Mark 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 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>
11 11
12 #include "base/containers/small_map.h" 12 #include "base/containers/small_map.h"
13 #include "base/guid.h" 13 #include "base/guid.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
17 #include "chrome/browser/media/router/create_presentation_connection_request.h" 17 #include "chrome/browser/media/router/create_presentation_connection_request.h"
18 #include "chrome/browser/media/router/media_route.h" 18 #include "chrome/browser/media/router/media_route.h"
19 #include "chrome/browser/media/router/media_router.h" 19 #include "chrome/browser/media/router/media_router.h"
20 #include "chrome/browser/media/router/media_router_dialog_controller.h" 20 #include "chrome/browser/media/router/media_router_dialog_controller.h"
21 #include "chrome/browser/media/router/media_router_factory.h" 21 #include "chrome/browser/media/router/media_router_factory.h"
22 #include "chrome/browser/media/router/media_sink.h" 22 #include "chrome/browser/media/router/media_sink.h"
23 #include "chrome/browser/media/router/media_source_helper.h" 23 #include "chrome/browser/media/router/media_source_helper.h"
24 #include "chrome/browser/media/router/offscreen_presentation_manager.h"
25 #include "chrome/browser/media/router/offscreen_presentation_manager_factory.h"
24 #include "chrome/browser/media/router/presentation_media_sinks_observer.h" 26 #include "chrome/browser/media/router/presentation_media_sinks_observer.h"
25 #include "chrome/browser/media/router/route_message.h" 27 #include "chrome/browser/media/router/route_message.h"
26 #include "chrome/browser/media/router/route_message_observer.h" 28 #include "chrome/browser/media/router/route_message_observer.h"
27 #include "chrome/browser/media/router/route_request_result.h" 29 #include "chrome/browser/media/router/route_request_result.h"
28 #include "chrome/browser/sessions/session_tab_helper.h" 30 #include "chrome/browser/sessions/session_tab_helper.h"
29 #include "content/public/browser/browser_context.h" 31 #include "content/public/browser/browser_context.h"
30 #include "content/public/browser/presentation_screen_availability_listener.h" 32 #include "content/public/browser/presentation_screen_availability_listener.h"
31 #include "content/public/browser/presentation_session.h" 33 #include "content/public/browser/presentation_session.h"
32 #include "content/public/browser/render_frame_host.h" 34 #include "content/public/browser/render_frame_host.h"
33 #include "content/public/browser/render_process_host.h" 35 #include "content/public/browser/render_process_host.h"
36 #include "url/gurl.h"
34 37
35 DEFINE_WEB_CONTENTS_USER_DATA_KEY( 38 DEFINE_WEB_CONTENTS_USER_DATA_KEY(
36 media_router::PresentationServiceDelegateImpl); 39 media_router::PresentationServiceDelegateImpl);
37 40
38 using content::RenderFrameHost; 41 using content::RenderFrameHost;
39 42
40 namespace media_router { 43 namespace media_router {
41 44
42 namespace { 45 namespace {
43 46
44 using DelegateObserver = content::PresentationServiceDelegate::Observer; 47 using DelegateObserver = content::PresentationServiceDelegateBase::Observer;
45 48
46 // Returns the unique identifier for the supplied RenderFrameHost. 49 // Returns the unique identifier for the supplied RenderFrameHost.
47 RenderFrameHostId GetRenderFrameHostId(RenderFrameHost* render_frame_host) { 50 RenderFrameHostId GetRenderFrameHostId(RenderFrameHost* render_frame_host) {
48 int render_process_id = render_frame_host->GetProcess()->GetID(); 51 int render_process_id = render_frame_host->GetProcess()->GetID();
49 int render_frame_id = render_frame_host->GetRoutingID(); 52 int render_frame_id = render_frame_host->GetRoutingID();
50 return RenderFrameHostId(render_process_id, render_frame_id); 53 return RenderFrameHostId(render_process_id, render_frame_id);
51 } 54 }
52 55
53 // Gets the last committed URL for the render frame specified by 56 // Gets the last committed URL for the render frame specified by
54 // |render_frame_host_id|. 57 // |render_frame_host_id|.
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 PresentationServiceDelegateImpl::CreateForWebContents(web_contents); 659 PresentationServiceDelegateImpl::CreateForWebContents(web_contents);
657 return PresentationServiceDelegateImpl::FromWebContents(web_contents); 660 return PresentationServiceDelegateImpl::FromWebContents(web_contents);
658 } 661 }
659 662
660 PresentationServiceDelegateImpl::PresentationServiceDelegateImpl( 663 PresentationServiceDelegateImpl::PresentationServiceDelegateImpl(
661 content::WebContents* web_contents) 664 content::WebContents* web_contents)
662 : web_contents_(web_contents), 665 : web_contents_(web_contents),
663 router_(MediaRouterFactory::GetApiForBrowserContext( 666 router_(MediaRouterFactory::GetApiForBrowserContext(
664 web_contents_->GetBrowserContext())), 667 web_contents_->GetBrowserContext())),
665 frame_manager_(new PresentationFrameManager(web_contents, router_)), 668 frame_manager_(new PresentationFrameManager(web_contents, router_)),
669 offscreen_presentation_manager_(
670 OffscreenPresentationManagerFactory::
671 GetOrCreateForControllerBrowserContext(web_contents_)),
imcheng 2016/11/01 17:20:29 that means we are creating an OffscreenPresentatio
zhaobin 2016/11/02 03:55:47 Done.
666 weak_factory_(this) { 672 weak_factory_(this) {
667 DCHECK(web_contents_); 673 DCHECK(web_contents_);
668 DCHECK(router_); 674 DCHECK(router_);
669 } 675 }
670 676
671 PresentationServiceDelegateImpl::~PresentationServiceDelegateImpl() { 677 PresentationServiceDelegateImpl::~PresentationServiceDelegateImpl() {
672 } 678 }
673 679
674 void PresentationServiceDelegateImpl::AddObserver(int render_process_id, 680 void PresentationServiceDelegateImpl::AddObserver(int render_process_id,
675 int render_frame_id, 681 int render_frame_id,
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 result.route()->media_route_id()); 752 result.route()->media_route_id());
747 success_cb.Run(session); 753 success_cb.Run(session);
748 } 754 }
749 } 755 }
750 756
751 void PresentationServiceDelegateImpl::OnStartSessionSucceeded( 757 void PresentationServiceDelegateImpl::OnStartSessionSucceeded(
752 int render_process_id, 758 int render_process_id,
753 int render_frame_id, 759 int render_frame_id,
754 const content::PresentationSessionStartedCallback& success_cb, 760 const content::PresentationSessionStartedCallback& success_cb,
755 const content::PresentationSessionInfo& new_session, 761 const content::PresentationSessionInfo& new_session,
756 const MediaRoute::Id& route_id) { 762 const MediaRoute& route) {
763 const MediaRoute::Id& route_id = route.media_route_id();
757 DVLOG(1) << "OnStartSessionSucceeded: " 764 DVLOG(1) << "OnStartSessionSucceeded: "
758 << "route_id: " << route_id 765 << "route_id: " << route_id
759 << ", presentation URL: " << new_session.presentation_url 766 << ", presentation URL: " << new_session.presentation_url
760 << ", presentation ID: " << new_session.presentation_id; 767 << ", presentation ID: " << new_session.presentation_id
768 << ", is_offscreen_presentation: " << new_session.is_offscreen;
761 frame_manager_->OnPresentationSessionStarted( 769 frame_manager_->OnPresentationSessionStarted(
762 RenderFrameHostId(render_process_id, render_frame_id), new_session, 770 RenderFrameHostId(render_process_id, render_frame_id), new_session,
763 route_id); 771 route_id);
764 success_cb.Run(new_session); 772 success_cb.Run(new_session);
765 } 773 }
766 774
767 void PresentationServiceDelegateImpl::StartSession( 775 void PresentationServiceDelegateImpl::StartSession(
768 int render_process_id, 776 int render_process_id,
769 int render_frame_id, 777 int render_frame_id,
770 const std::vector<GURL>& presentation_urls, 778 const std::vector<GURL>& presentation_urls,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 int render_process_id, 913 int render_process_id,
906 int render_frame_id, 914 int render_frame_id,
907 const content::PresentationSessionInfo& connection, 915 const content::PresentationSessionInfo& connection,
908 const content::PresentationConnectionStateChangedCallback& 916 const content::PresentationConnectionStateChangedCallback&
909 state_changed_cb) { 917 state_changed_cb) {
910 frame_manager_->ListenForConnectionStateChange( 918 frame_manager_->ListenForConnectionStateChange(
911 RenderFrameHostId(render_process_id, render_frame_id), connection, 919 RenderFrameHostId(render_process_id, render_frame_id), connection,
912 state_changed_cb); 920 state_changed_cb);
913 } 921 }
914 922
923 void PresentationServiceDelegateImpl::ConnectToOffscreenPresentation(
924 int render_process_id,
925 int render_frame_id,
926 const content::PresentationSessionInfo& session,
927 content::PresentationConnectionPtr connection) {
928 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id);
929 offscreen_presentation_manager_->RegisterOffscreenPresentationController(
930 session.presentation_id, GURL(session.presentation_url),
931 render_frame_host_id, std::move(connection));
932 }
933
915 void PresentationServiceDelegateImpl::OnRouteResponse( 934 void PresentationServiceDelegateImpl::OnRouteResponse(
916 const PresentationRequest& presentation_request, 935 const PresentationRequest& presentation_request,
917 const RouteRequestResult& result) { 936 const RouteRequestResult& result) {
918 if (!result.route()) 937 if (!result.route())
919 return; 938 return;
920 939
921 content::PresentationSessionInfo session_info( 940 content::PresentationSessionInfo session_info(
922 presentation_request.presentation_url(), result.presentation_id()); 941 presentation_request.presentation_url(), result.presentation_id());
923 frame_manager_->OnDefaultPresentationSessionStarted( 942 frame_manager_->OnDefaultPresentationSessionStarted(
924 presentation_request, session_info, result.route()->media_route_id()); 943 presentation_request, session_info, result.route()->media_route_id());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( 977 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest(
959 int render_process_id, 978 int render_process_id,
960 int render_frame_id, 979 int render_frame_id,
961 const MediaSource::Id& source_id) const { 980 const MediaSource::Id& source_id) const {
962 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); 981 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id);
963 return frame_manager_->HasScreenAvailabilityListenerForTest( 982 return frame_manager_->HasScreenAvailabilityListenerForTest(
964 render_frame_host_id, source_id); 983 render_frame_host_id, source_id);
965 } 984 }
966 985
967 } // namespace media_router 986 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698