Commit 9869d38a authored by Xiangjun Zhang's avatar Xiangjun Zhang Committed by Commit Bot

Media Remoting: Wait for permission check before starting.

To support the new media remoting UI, for each cast session, permission
is checked once at the first time render requests to start remoting.

TBR=imcheng@chromium.org

Bug: 849020
Change-Id: I0663190707e2fed9ae5cf2392a57c0b79475dd0c
Reviewed-on: https://chromium-review.googlesource.com/1099267
Commit-Queue: Xiangjun Zhang <xjz@chromium.org>
Reviewed-by: default avatarYuri Wiitala <miu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#571578}
parent fc75d32a
...@@ -199,6 +199,10 @@ void CastRemotingConnector::ConnectToService( ...@@ -199,6 +199,10 @@ void CastRemotingConnector::ConnectToService(
&CastRemotingConnector::OnMirrorServiceStopped, base::Unretained(this))); &CastRemotingConnector::OnMirrorServiceStopped, base::Unretained(this)));
} }
void CastRemotingConnector::ResetRemotingPermission() {
remoting_allowed_.reset();
}
void CastRemotingConnector::OnMirrorServiceStopped() { void CastRemotingConnector::OnMirrorServiceStopped() {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
VLOG(2) << __func__; VLOG(2) << __func__;
...@@ -226,7 +230,7 @@ void CastRemotingConnector::RegisterBridge(RemotingBridge* bridge) { ...@@ -226,7 +230,7 @@ void CastRemotingConnector::RegisterBridge(RemotingBridge* bridge) {
DCHECK(bridges_.find(bridge) == bridges_.end()); DCHECK(bridges_.find(bridge) == bridges_.end());
bridges_.insert(bridge); bridges_.insert(bridge);
if (remoter_ && !active_bridge_) if (remoter_ && !active_bridge_ && remoting_allowed_.value_or(true))
bridge->OnSinkAvailable(sink_metadata_); bridge->OnSinkAvailable(sink_metadata_);
} }
...@@ -269,11 +273,44 @@ void CastRemotingConnector::StartRemoting(RemotingBridge* bridge) { ...@@ -269,11 +273,44 @@ void CastRemotingConnector::StartRemoting(RemotingBridge* bridge) {
} }
active_bridge_ = bridge; active_bridge_ = bridge;
remoter_->Start();
// Assume the remoting session is always started successfully. If any failure if (remoting_allowed_.has_value()) {
// occurs, OnError() will be called. StartRemotingIfPermitted();
bridge->OnStarted(); } else {
base::OnceCallback<void(bool)> dialog_result_callback(base::BindOnce(
[](base::WeakPtr<CastRemotingConnector> connector, bool is_allowed) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (!connector)
return;
connector->remoting_allowed_ = is_allowed;
connector->StartRemotingIfPermitted();
},
weak_factory_.GetWeakPtr()));
// TODO(http://crbug.com/849020): Show the remoting dialog to get user's
// permission.
std::move(dialog_result_callback).Run(true);
}
}
void CastRemotingConnector::StartRemotingIfPermitted() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (!active_bridge_)
return;
if (remoting_allowed_.value()) {
remoter_->Start();
// Assume the remoting session is always started successfully. If any
// failure occurs, OnError() will be called.
active_bridge_->OnStarted();
} else {
// TODO(xjz): Add an extra reason for this failure.
active_bridge_->OnStartFailed(RemotingStartFailReason::ROUTE_TERMINATED);
active_bridge_->OnSinkGone();
active_bridge_ = nullptr;
}
} }
void CastRemotingConnector::StartRemotingDataStreams( void CastRemotingConnector::StartRemotingDataStreams(
...@@ -432,8 +469,10 @@ void CastRemotingConnector::OnSinkAvailable( ...@@ -432,8 +469,10 @@ void CastRemotingConnector::OnSinkAvailable(
media::mojom::RemotingSinkFeature::RENDERING); media::mojom::RemotingSinkFeature::RENDERING);
#endif #endif
for (RemotingBridge* notifyee : bridges_) if (remoting_allowed_.value_or(true)) {
notifyee->OnSinkAvailable(sink_metadata_); for (RemotingBridge* notifyee : bridges_)
notifyee->OnSinkAvailable(sink_metadata_);
}
} }
void CastRemotingConnector::OnError() { void CastRemotingConnector::OnError() {
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <set> #include <set>
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "base/supports_user_data.h" #include "base/supports_user_data.h"
#include "components/sessions/core/session_id.h" #include "components/sessions/core/session_id.h"
#include "media/mojo/interfaces/mirror_service_remoting.mojom.h" #include "media/mojo/interfaces/mirror_service_remoting.mojom.h"
...@@ -93,6 +94,9 @@ class CastRemotingConnector : public base::SupportsUserData::Data, ...@@ -93,6 +94,9 @@ class CastRemotingConnector : public base::SupportsUserData::Data,
media::mojom::MirrorServiceRemotingSourceRequest source_request, media::mojom::MirrorServiceRemotingSourceRequest source_request,
media::mojom::MirrorServiceRemoterPtr remoter); media::mojom::MirrorServiceRemoterPtr remoter);
// Called at the start of mirroring to reset the permission.
void ResetRemotingPermission();
private: private:
// Allow unit tests access to the private constructor and CreateBridge() // Allow unit tests access to the private constructor and CreateBridge()
// method, since unit tests don't have a complete browser (i.e., with a // method, since unit tests don't have a complete browser (i.e., with a
...@@ -146,6 +150,10 @@ class CastRemotingConnector : public base::SupportsUserData::Data, ...@@ -146,6 +150,10 @@ class CastRemotingConnector : public base::SupportsUserData::Data,
void EstimateTransmissionCapacity( void EstimateTransmissionCapacity(
media::mojom::Remoter::EstimateTransmissionCapacityCallback callback); media::mojom::Remoter::EstimateTransmissionCapacityCallback callback);
// Called after permission check. Either call |remoter_| to start remoting or
// notify the source that start fails due to no permission.
void StartRemotingIfPermitted();
// Called when RTP streams are started. // Called when RTP streams are started.
void OnDataStreamsStarted( void OnDataStreamsStarted(
mojo::ScopedDataPipeConsumerHandle audio_pipe, mojo::ScopedDataPipeConsumerHandle audio_pipe,
...@@ -183,6 +191,10 @@ class CastRemotingConnector : public base::SupportsUserData::Data, ...@@ -183,6 +191,10 @@ class CastRemotingConnector : public base::SupportsUserData::Data,
mojo::Binding<media::mojom::MirrorServiceRemotingSource> binding_; mojo::Binding<media::mojom::MirrorServiceRemotingSource> binding_;
media::mojom::MirrorServiceRemoterPtr remoter_; media::mojom::MirrorServiceRemoterPtr remoter_;
// Permission is checked the first time remoting requested to start for each
// casting session.
base::Optional<bool> remoting_allowed_;
// Produces weak pointers that are only valid for the current remoting // Produces weak pointers that are only valid for the current remoting
// session. This is used to cancel any outstanding callbacks when a remoting // session. This is used to cancel any outstanding callbacks when a remoting
// session is stopped. // session is stopped.
......
...@@ -230,7 +230,9 @@ void MediaRouterMojoImpl::CreateRoute( ...@@ -230,7 +230,9 @@ void MediaRouterMojoImpl::CreateRoute(
if (IsTabMirroringMediaSource(MediaSource(source_id))) { if (IsTabMirroringMediaSource(MediaSource(source_id))) {
// Ensure the CastRemotingConnector is created before mirroring starts. // Ensure the CastRemotingConnector is created before mirroring starts.
CastRemotingConnector::Get(web_contents); CastRemotingConnector* const connector =
CastRemotingConnector::Get(web_contents);
connector->ResetRemotingPermission();
} }
MediaRouterMetrics::RecordMediaSinkType(sink->icon_type()); MediaRouterMetrics::RecordMediaSinkType(sink->icon_type());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment