| 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 e03063d83228cd22368d63c42e78bebb6675992a..adaa9545fee4cd2996b011afc35ff28e1f963652 100644
|
| --- a/chrome/browser/media/router/presentation_service_delegate_impl.cc
|
| +++ b/chrome/browser/media/router/presentation_service_delegate_impl.cc
|
| @@ -8,7 +8,6 @@
|
|
|
| #include "base/containers/scoped_ptr_hash_map.h"
|
| #include "base/containers/small_map.h"
|
| -#include "base/guid.h"
|
| #include "base/strings/string_util.h"
|
| #include "base/strings/stringprintf.h"
|
| #include "chrome/browser/media/router/create_presentation_session_request.h"
|
| @@ -18,6 +17,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/one_ua_presentation_router.h"
|
| +#include "chrome/browser/media/router/one_ua_presentation_router_factory.h"
|
| #include "chrome/browser/media/router/presentation_media_sinks_observer.h"
|
| #include "chrome/browser/media/router/presentation_session_messages_observer.h"
|
| #include "chrome/browser/media/router/presentation_session_state_observer.h"
|
| @@ -42,8 +43,6 @@ using PresentationSessionErrorCallback =
|
| using PresentationSessionSuccessCallback =
|
| content::PresentationServiceDelegate::PresentationSessionSuccessCallback;
|
|
|
| -using RenderFrameHostId = std::pair<int, int>;
|
| -
|
| // Returns the unique identifier for the supplied RenderFrameHost.
|
| RenderFrameHostId GetRenderFrameHostId(RenderFrameHost* render_frame_host) {
|
| int render_process_id = render_frame_host->GetProcess()->GetID();
|
| @@ -249,7 +248,8 @@ MediaSource PresentationFrame::GetMediaSourceFromListener(
|
| class PresentationFrameManager {
|
| public:
|
| PresentationFrameManager(content::WebContents* web_contents,
|
| - MediaRouter* router);
|
| + MediaRouter* router,
|
| + OneUAPresentationRouter* one_ua_presentation_router);
|
| ~PresentationFrameManager();
|
|
|
| // Mirror corresponding APIs in PresentationServiceDelegateImpl.
|
| @@ -281,7 +281,8 @@ class PresentationFrameManager {
|
| const RenderFrameHostId& render_frame_host_id,
|
| bool is_default_presentation,
|
| const content::PresentationSessionInfo& session,
|
| - const MediaRoute::Id& route_id);
|
| + const MediaRoute::Id& route_id,
|
| + bool is_one_ua_presentation);
|
|
|
| void OnPresentationSessionClosed(
|
| const RenderFrameHostId& render_frame_host_id,
|
| @@ -300,17 +301,23 @@ class PresentationFrameManager {
|
| base::ScopedPtrHashMap<RenderFrameHostId, scoped_ptr<PresentationFrame>>
|
| presentation_frames_;
|
|
|
| - // References to the owning WebContents, and the corresponding MediaRouter.
|
| + // References to the owning WebContents, and the corresponding MediaRouter
|
| + // and OneUAPresenationRouter.
|
| + content::WebContents* const web_contents_;
|
| MediaRouter* router_;
|
| - content::WebContents* web_contents_;
|
| + OneUAPresentationRouter* const one_ua_presentation_router_;
|
| };
|
|
|
| PresentationFrameManager::PresentationFrameManager(
|
| content::WebContents* web_contents,
|
| - MediaRouter* router)
|
| - : router_(router), web_contents_(web_contents) {
|
| + MediaRouter* router,
|
| + OneUAPresentationRouter* one_ua_presentation_router)
|
| + : web_contents_(web_contents),
|
| + router_(router),
|
| + one_ua_presentation_router_(one_ua_presentation_router) {
|
| DCHECK(web_contents_);
|
| DCHECK(router_);
|
| + DCHECK(one_ua_presentation_router_);
|
| }
|
|
|
| PresentationFrameManager::~PresentationFrameManager() {
|
| @@ -322,11 +329,17 @@ void PresentationFrameManager::OnPresentationSessionStarted(
|
| const RenderFrameHostId& render_frame_host_id,
|
| bool is_default_presentation,
|
| const content::PresentationSessionInfo& session,
|
| - const MediaRoute::Id& route_id) {
|
| + const MediaRoute::Id& route_id,
|
| + bool is_one_ua_presentation) {
|
| auto presentation_frame = presentation_frames_.get(render_frame_host_id);
|
| - if (presentation_frame)
|
| + if (presentation_frame) {
|
| + if (is_one_ua_presentation) {
|
| + one_ua_presentation_router_->RegisterController(session,
|
| + render_frame_host_id);
|
| + }
|
| presentation_frame->OnPresentationSessionStarted(is_default_presentation,
|
| session, route_id);
|
| + }
|
| }
|
|
|
| void PresentationFrameManager::OnPresentationSessionClosed(
|
| @@ -425,6 +438,7 @@ void PresentationFrameManager::RemoveDelegateObserver(
|
|
|
| void PresentationFrameManager::Reset(
|
| const RenderFrameHostId& render_frame_host_id) {
|
| + one_ua_presentation_router_->Reset(render_frame_host_id);
|
| auto presentation_frame = presentation_frames_.get(render_frame_host_id);
|
| if (presentation_frame)
|
| presentation_frame->Reset();
|
| @@ -459,10 +473,16 @@ PresentationServiceDelegateImpl::PresentationServiceDelegateImpl(
|
| : web_contents_(web_contents),
|
| router_(MediaRouterFactory::GetApiForBrowserContext(
|
| web_contents_->GetBrowserContext())),
|
| - frame_manager_(new PresentationFrameManager(web_contents, router_)),
|
| + one_ua_presentation_router_(
|
| + OneUAPresentationRouterFactory::GetOrCreateForBrowserContext(
|
| + web_contents_->GetBrowserContext())),
|
| + frame_manager_(new PresentationFrameManager(web_contents,
|
| + router_,
|
| + one_ua_presentation_router_)),
|
| weak_factory_(this) {
|
| DCHECK(web_contents_);
|
| DCHECK(router_);
|
| + DCHECK(one_ua_presentation_router_);
|
| }
|
|
|
| PresentationServiceDelegateImpl::~PresentationServiceDelegateImpl() {
|
| @@ -558,7 +578,8 @@ void PresentationServiceDelegateImpl::OnJoinRouteResponse(
|
| const PresentationSessionErrorCallback& error_cb,
|
| const MediaRoute* route,
|
| const std::string& presentation_id,
|
| - const std::string& error_text) {
|
| + const std::string& error_text,
|
| + bool is_one_ua_presentation) {
|
| if (!route) {
|
| error_cb.Run(content::PresentationError(
|
| content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND, error_text));
|
| @@ -566,11 +587,13 @@ void PresentationServiceDelegateImpl::OnJoinRouteResponse(
|
| DVLOG(1) << "OnJoinRouteResponse: "
|
| << "route_id: " << route->media_route_id()
|
| << ", presentation URL: " << session.presentation_url
|
| - << ", presentation ID: " << session.presentation_id;
|
| + << ", presentation ID: " << session.presentation_id << ", 1UA? "
|
| + << is_one_ua_presentation;
|
| DCHECK_EQ(session.presentation_id, presentation_id);
|
| - frame_manager_->OnPresentationSessionStarted(
|
| - RenderFrameHostId(render_process_id, render_frame_id), false, session,
|
| - route->media_route_id());
|
| + RenderFrameHostId rfh_id(render_process_id, render_frame_id);
|
| + frame_manager_->OnPresentationSessionStarted(rfh_id, false, session,
|
| + route->media_route_id(),
|
| + is_one_ua_presentation);
|
| success_cb.Run(session);
|
| }
|
| }
|
| @@ -580,14 +603,15 @@ void PresentationServiceDelegateImpl::OnStartSessionSucceeded(
|
| int render_frame_id,
|
| const PresentationSessionSuccessCallback& success_cb,
|
| const content::PresentationSessionInfo& new_session,
|
| - const MediaRoute::Id& route_id) {
|
| + const MediaRoute::Id& route_id,
|
| + bool is_one_ua_presentation) {
|
| DVLOG(1) << "OnStartSessionSucceeded: "
|
| << "route_id: " << route_id
|
| << ", presentation URL: " << new_session.presentation_url
|
| << ", presentation ID: " << new_session.presentation_id;
|
| + RenderFrameHostId rfh_id(render_process_id, render_frame_id);
|
| frame_manager_->OnPresentationSessionStarted(
|
| - RenderFrameHostId(render_process_id, render_frame_id), false, new_session,
|
| - route_id);
|
| + rfh_id, false, new_session, route_id, is_one_ua_presentation);
|
| success_cb.Run(new_session);
|
| }
|
|
|
| @@ -660,9 +684,19 @@ void PresentationServiceDelegateImpl::ListenForSessionMessages(
|
| int render_frame_id,
|
| const content::PresentationSessionInfo& session,
|
| const content::PresentationSessionMessageCallback& message_cb) {
|
| - frame_manager_->ListenForSessionMessages(
|
| - RenderFrameHostId(render_process_id, render_frame_id), session,
|
| - message_cb);
|
| + DCHECK(!session.presentation_id.empty());
|
| + DCHECK(!session.presentation_url.empty());
|
| +
|
| + RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id);
|
| + if (one_ua_presentation_router_->IsController(session.presentation_id,
|
| + render_frame_host_id)) {
|
| + // 1-UA session; listen for messages with OneUAPresentationRouter.
|
| + one_ua_presentation_router_->ListenForMessages(session, message_cb);
|
| + } else {
|
| + // Non 1-UA session; listen for messages with MediaRouter.
|
| + frame_manager_->ListenForSessionMessages(render_frame_host_id, session,
|
| + message_cb);
|
| + }
|
| }
|
|
|
| void PresentationServiceDelegateImpl::SendMessage(
|
| @@ -670,21 +704,32 @@ void PresentationServiceDelegateImpl::SendMessage(
|
| int render_frame_id,
|
| const content::PresentationSessionInfo& session,
|
| scoped_ptr<content::PresentationSessionMessage> message,
|
| - const SendMessageCallback& send_message_cb) {
|
| - const MediaRoute::Id& route_id = frame_manager_->GetRouteId(
|
| - RenderFrameHostId(render_process_id, render_frame_id),
|
| - session.presentation_id);
|
| + const content::SendMessageCallback& send_message_cb) {
|
| + DCHECK(!session.presentation_id.empty());
|
| + DCHECK(!session.presentation_url.empty());
|
| +
|
| + RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id);
|
| + const MediaRoute::Id& route_id =
|
| + frame_manager_->GetRouteId(render_frame_host_id, session.presentation_id);
|
| if (route_id.empty()) {
|
| DVLOG(1) << "No active route for " << session.presentation_id;
|
| send_message_cb.Run(false);
|
| return;
|
| }
|
|
|
| - if (message->is_binary()) {
|
| - router_->SendRouteBinaryMessage(route_id, message->data.Pass(),
|
| - send_message_cb);
|
| + if (one_ua_presentation_router_->IsController(session.presentation_id,
|
| + render_frame_host_id)) {
|
| + // 1-UA session; send message with OneUAPresentationRouter.
|
| + one_ua_presentation_router_->SendMessage(session, message.Pass(),
|
| + send_message_cb);
|
| } else {
|
| - router_->SendRouteMessage(route_id, message->message, send_message_cb);
|
| + // Non 1-UA session; send message with MediaRouter.
|
| + if (message->is_binary()) {
|
| + router_->SendRouteBinaryMessage(route_id, message->data.Pass(),
|
| + send_message_cb);
|
| + } else {
|
| + router_->SendRouteMessage(route_id, message->message, send_message_cb);
|
| + }
|
| }
|
| }
|
|
|
| @@ -692,29 +737,55 @@ void PresentationServiceDelegateImpl::ListenForSessionStateChange(
|
| int render_process_id,
|
| int render_frame_id,
|
| const content::SessionStateChangedCallback& state_changed_cb) {
|
| + // TODO(imcheng): Implement 1-UA controller state change when
|
| + // ListenForSessionStateChange takes a PresentationSessionInfo as input.
|
| frame_manager_->ListenForSessionStateChange(
|
| RenderFrameHostId(render_process_id, render_frame_id), state_changed_cb);
|
| }
|
|
|
| +void PresentationServiceDelegateImpl::GetPresenterSession(
|
| + int render_process_id,
|
| + int render_frame_id,
|
| + const content::PresenterSessionAvailableCallback& success_callback,
|
| + const base::Callback<void(const std::string&)>& error_callback) {
|
| + // We only have presenters in offscreen tabs, which are created in incognito
|
| + // Profiles. See IncognitoPresentationServiceDelegate.
|
| + NOTIMPLEMENTED();
|
| + error_callback.Run("Not a presenter frame");
|
| +}
|
| +
|
| +std::vector<content::PresentationSessionInfo>
|
| +PresentationServiceDelegateImpl::GetPresenterSessions(int render_process_id,
|
| + int render_frame_id) {
|
| + // See comment on GetPresentersession().
|
| + NOTIMPLEMENTED();
|
| + return std::vector<content::PresentationSessionInfo>();
|
| +}
|
| +
|
| void PresentationServiceDelegateImpl::OnRouteResponse(
|
| const MediaRoute* route,
|
| const std::string& presentation_id,
|
| - const std::string& error) {
|
| + const std::string& error,
|
| + bool is_one_ua_presentation) {
|
| if (!route)
|
| return;
|
| +
|
| const MediaSource& source = route->media_source();
|
| DCHECK(!source.Empty());
|
| if (!default_source_.Equals(source))
|
| return;
|
| +
|
| RenderFrameHost* main_frame = web_contents_->GetMainFrame();
|
| if (!main_frame)
|
| return;
|
| +
|
| RenderFrameHostId render_frame_host_id(GetRenderFrameHostId(main_frame));
|
| - frame_manager_->OnPresentationSessionStarted(
|
| - render_frame_host_id, true,
|
| - content::PresentationSessionInfo(PresentationUrlFromMediaSource(source),
|
| - presentation_id),
|
| - route->media_route_id());
|
| + content::PresentationSessionInfo session(
|
| + PresentationUrlFromMediaSource(source), presentation_id);
|
| +
|
| + frame_manager_->OnPresentationSessionStarted(render_frame_host_id, true,
|
| + session, route->media_route_id(),
|
| + is_one_ua_presentation);
|
| }
|
|
|
| void PresentationServiceDelegateImpl::AddDefaultMediaSourceObserver(
|
|
|