Index: chrome/browser/media/router/presentation_service_delegate_impl.cc |
diff --git a/chrome/browser/media/router/presentation_service_delegate_impl.cc b/chrome/browser/media/router/presentation_service_delegate_impl.cc |
index 581357dced0c7900c4062f72870482a748830424..4987b05fca4651b7db68884c34f562b856c8d071 100644 |
--- a/chrome/browser/media/router/presentation_service_delegate_impl.cc |
+++ b/chrome/browser/media/router/presentation_service_delegate_impl.cc |
@@ -21,6 +21,8 @@ |
#include "chrome/browser/media/router/media_router_factory.h" |
#include "chrome/browser/media/router/media_sink.h" |
#include "chrome/browser/media/router/media_source_helper.h" |
+#include "chrome/browser/media/router/offscreen_presentation_manager.h" |
+#include "chrome/browser/media/router/offscreen_presentation_manager_factory.h" |
#include "chrome/browser/media/router/presentation_media_sinks_observer.h" |
#include "chrome/browser/media/router/route_message.h" |
#include "chrome/browser/media/router/route_message_observer.h" |
@@ -148,6 +150,11 @@ class PresentationFrame { |
delegate_observer_ = observer; |
} |
+ void SetOffscreenPresentationClient( |
+ content::OffscreenPresentationClient* client) { |
+ offscreen_presentation_client_ = client; |
+ } |
+ |
private: |
MediaSource GetMediaSourceFromListener( |
content::PresentationScreenAvailabilityListener* listener) const; |
@@ -171,7 +178,9 @@ class PresentationFrame { |
const content::WebContents* web_contents_; |
MediaRouter* router_; |
+ OffscreenPresentationManager* const offscreen_presentation_manager_; |
DelegateObserver* delegate_observer_; |
+ content::OffscreenPresentationClient* offscreen_presentation_client_; |
}; |
PresentationFrame::PresentationFrame( |
@@ -181,7 +190,11 @@ PresentationFrame::PresentationFrame( |
: render_frame_host_id_(render_frame_host_id), |
web_contents_(web_contents), |
router_(router), |
- delegate_observer_(nullptr) { |
+ offscreen_presentation_manager_( |
+ OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext( |
+ web_contents_->GetBrowserContext())), |
+ delegate_observer_(nullptr), |
+ offscreen_presentation_client_(nullptr) { |
DCHECK(web_contents_); |
DCHECK(router_); |
} |
@@ -198,6 +211,9 @@ void PresentationFrame::OnPresentationSessionStarted( |
const content::PresentationSessionInfo& session, |
const MediaRoute::Id& route_id) { |
presentation_id_to_route_id_[session.presentation_id] = route_id; |
+ offscreen_presentation_manager_->RegisterOffscreenPresentationController( |
imcheng
2016/09/28 07:28:37
Don't we need to check the started presentation is
zhaobin
2016/09/29 17:20:44
Yes, we need to check if it is offscreen presentat
|
+ session.presentation_id, render_frame_host_id_.second, |
+ offscreen_presentation_client_); |
} |
const MediaRoute::Id PresentationFrame::GetRouteId( |
@@ -251,8 +267,11 @@ bool PresentationFrame::HasScreenAvailabilityListenerForTest( |
} |
void PresentationFrame::Reset() { |
- for (const auto& pid_route_id : presentation_id_to_route_id_) |
+ for (const auto& pid_route_id : presentation_id_to_route_id_) { |
router_->DetachRoute(pid_route_id.second); |
+ offscreen_presentation_manager_->UnregisterOffscreenPresentationController( |
imcheng
2016/09/28 07:28:37
Something to think about: how do we tell the recei
zhaobin
2016/09/29 17:20:44
Original plan: In receiver's PSImpl::CloseConnecti
|
+ pid_route_id.first, render_frame_host_id_.second); |
+ } |
presentation_id_to_route_id_.clear(); |
url_to_sinks_observer_.clear(); |
@@ -270,6 +289,9 @@ void PresentationFrame::RemoveConnection(const std::string& presentation_id, |
// We keep the PresentationConnectionStateChangedCallback registered with MR |
// so the MRP can tell us when terminate() completed. |
+ |
+ offscreen_presentation_manager_->UnregisterOffscreenPresentationController( |
+ presentation_id, render_frame_host_id_.second); |
} |
void PresentationFrame::ListenForConnectionStateChange( |
@@ -387,6 +409,9 @@ class PresentationFrameManager { |
const PresentationRequest& request, |
const content::PresentationSessionInfo& session, |
const MediaRoute::Id& route_id); |
+ void RegisterOffscreenPresentationClient( |
+ const RenderFrameHostId& render_frame_host_id, |
+ content::OffscreenPresentationClient* client); |
const MediaRoute::Id GetRouteId(const RenderFrameHostId& render_frame_host_id, |
const std::string& presentation_id) const; |
@@ -651,6 +676,13 @@ void PresentationFrameManager::SetMediaRouterForTest(MediaRouter* router) { |
router_ = router; |
} |
+void PresentationFrameManager::RegisterOffscreenPresentationClient( |
+ const RenderFrameHostId& render_frame_host_id, |
+ content::OffscreenPresentationClient* client) { |
+ auto* presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); |
+ presentation_frame->SetOffscreenPresentationClient(client); |
+} |
+ |
PresentationServiceDelegateImpl* |
PresentationServiceDelegateImpl::GetOrCreateForWebContents( |
content::WebContents* web_contents) { |
@@ -966,4 +998,13 @@ bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( |
render_frame_host_id, source_id); |
} |
+void PresentationServiceDelegateImpl::RegisterOffscreenPresentationClient( |
+ int render_process_id, |
+ int render_frame_id, |
+ content::OffscreenPresentationClient* client) { |
+ RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); |
+ frame_manager_->RegisterOffscreenPresentationClient(render_frame_host_id, |
+ client); |
+} |
+ |
} // namespace media_router |