| Index: chrome/browser/media/router/mojo/media_router_mojo_impl.cc
|
| diff --git a/chrome/browser/media/router/mojo/media_router_mojo_impl.cc b/chrome/browser/media/router/mojo/media_router_mojo_impl.cc
|
| index 49718c8bbc7e6e1195545ad88cd622d5586f1501..cd632fe4f6cddc2c36309a414f53a55dbe93bc59 100644
|
| --- a/chrome/browser/media/router/mojo/media_router_mojo_impl.cc
|
| +++ b/chrome/browser/media/router/mojo/media_router_mojo_impl.cc
|
| @@ -21,6 +21,7 @@
|
| #include "chrome/browser/media/router/media_routes_observer.h"
|
| #include "chrome/browser/media/router/media_sinks_observer.h"
|
| #include "chrome/browser/media/router/media_source_helper.h"
|
| +#include "chrome/browser/media/router/mojo/media_remoting_session_impl.h"
|
| #include "chrome/browser/media/router/mojo/media_route_provider_util_win.h"
|
| #include "chrome/browser/media/router/mojo/media_router_mojo_metrics.h"
|
| #include "chrome/browser/media/router/mojo/media_router_type_converters.h"
|
| @@ -101,6 +102,7 @@ MediaRouterMojoImpl::MediaRouterMojoImpl(
|
|
|
| MediaRouterMojoImpl::~MediaRouterMojoImpl() {
|
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| + TerminateAllRemotingSessions("media router shutdown");
|
| }
|
|
|
| // static
|
| @@ -135,6 +137,7 @@ void MediaRouterMojoImpl::BindToMojoRequest(
|
| void MediaRouterMojoImpl::OnConnectionError() {
|
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
|
|
| + TerminateAllRemotingSessions("internal connection error");
|
| media_route_provider_.reset();
|
| binding_.reset();
|
|
|
| @@ -808,6 +811,67 @@ void MediaRouterMojoImpl::OnPresentationConnectionClosed(
|
| message);
|
| }
|
|
|
| +void MediaRouterMojoImpl::CreateRemotingSession(
|
| + const mojo::String& media_source,
|
| + interfaces::MediaRemotingProviderPtr provider,
|
| + const CreateRemotingSessionCallback& callback) {
|
| + DVLOG_WITH_INSTANCE(1)
|
| + << "CreateRemotingSession(media_source=" << media_source << ")";
|
| +
|
| + interfaces::MediaRemotingSessionPtr session_ptr;
|
| + do {
|
| + content::WebContents* const source_contents =
|
| + WebContentsFromMediaSource(MediaSource(media_source));
|
| + if (!source_contents) {
|
| + // Note: This can happen if the tab existed at the time the client called
|
| + // CreateRemotingSession(), but was closed before this service method was
|
| + // invoked.
|
| + DLOG_WITH_INSTANCE(WARNING)
|
| + << "Cannot find WebContents instance specified by the media source.";
|
| + break;
|
| + }
|
| +
|
| + if (!provider.is_bound()) {
|
| + DLOG_WITH_INSTANCE(ERROR)
|
| + << "Client did not pass a bound MediaRemotingProvider interface.";
|
| + break;
|
| + }
|
| +
|
| + std::unique_ptr<MediaRemotingSessionImpl>& session =
|
| + remoting_sessions_[media_source];
|
| + if (session) {
|
| + DLOG_WITH_INSTANCE(ERROR)
|
| + << "Cannot create multiple MediaRemotingSessions per media source.";
|
| + break;
|
| + }
|
| + session.reset(
|
| + new AutoTerminatingRemotingSession(
|
| + source_contents, std::move(provider), GetProxy(&session_ptr),
|
| + base::Bind(&MediaRouterMojoImpl::OnRemotingSessionTerminated,
|
| + base::Unretained(this), media_source)));
|
| + } while (false);
|
| +
|
| + callback.Run(std::move(session_ptr));
|
| +}
|
| +
|
| +void MediaRouterMojoImpl::OnRemotingSessionTerminated(
|
| + const MediaSource::Id& media_source) {
|
| + remoting_sessions_.erase(media_source);
|
| +}
|
| +
|
| +void MediaRouterMojoImpl::TerminateAllRemotingSessions(
|
| + const std::string& error_reason) {
|
| + // Copy pointers to a separate vector for iteration, since terminating each
|
| + // session will cause the |remoting_sessions_| map to mutate.
|
| + std::vector<MediaRemotingSessionImpl*> sessions;
|
| + for (const auto& entry : remoting_sessions_)
|
| + sessions.push_back(entry.second.get());
|
| +
|
| + for (MediaRemotingSessionImpl* session : sessions)
|
| + session->Terminate(error_reason);
|
| + DCHECK(remoting_sessions_.empty());
|
| +}
|
| +
|
| void MediaRouterMojoImpl::DoStartObservingMediaSinks(
|
| const MediaSource::Id& source_id) {
|
| DVLOG_WITH_INSTANCE(1) << "DoStartObservingMediaSinks: " << source_id;
|
|
|