Commit 12c3f476 authored by Takumi Fujimoto's avatar Takumi Fujimoto Committed by Commit Bot

Establish a strong virtual connection for mirroring

For Cast SDK sessions, a strong VC is made for the cast source's sender
ID, and for mirroring sessions, one is made for CastMessageHandler's
sender ID. This CL ensures that for mirroring started via Cast SDK, the
latter is strongly established.

Bug: 1144364, b/172094267
Change-Id: Ibf2eb3dc893d92b8f3de1e1f244354a35ff71e56
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2514673
Commit-Queue: Takumi Fujimoto <takumif@chromium.org>
Reviewed-by: default avatarmark a. foltz <mfoltz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823433}
parent f5003195
......@@ -818,19 +818,31 @@ void CastActivityManager::HandleLaunchSessionResponse(
}
RecordLaunchSessionResponseAppType(session->value().FindKey("appType"));
std::string client_id = cast_source.client_id();
// Mirroring sessions do not have |client_id| set here.
if (client_id.empty()) {
client_id = message_handler_->sender_id();
} else {
// Cast SDK sessions have a |client_id|, and we ensure a virtual connection
// for them. For mirroring sessions, we ensure a strong virtual connection for
// |message_handler_|. Mirroring initiated via the Cast SDK will have
// EnsureConnection() called for both.
const std::string& client_id = cast_source.client_id();
if (!client_id.empty()) {
activity_it->second->SendMessageToClient(
client_id,
CreateNewSessionMessage(*session, client_id, sink, hash_token_));
message_handler_->EnsureConnection(sink.cast_data().cast_channel_id,
client_id, session->transport_id(),
cast_source.connection_type());
// TODO(jrw): Query media status.
}
message_handler_->EnsureConnection(sink.cast_data().cast_channel_id,
client_id, session->transport_id(),
cast_source.connection_type());
if (cast_source.ContainsStreamingApp()) {
message_handler_->EnsureConnection(
sink.cast_data().cast_channel_id, message_handler_->sender_id(),
session->transport_id(), cast_channel::VirtualConnectionType::kStrong);
} else if (client_id.empty()) {
logger_->LogError(
mojom::LogCategory::kRoute, kLoggerComponent,
"The client ID was unexpectedly empty for a non-mirroring app.",
sink.id(), cast_source.source_id(),
MediaRoute::GetPresentationIdFromMediaRouteId(route_id));
}
activity_it->second->SetOrUpdateSession(*session, sink, hash_token_);
NotifyAllOnRoutesUpdated();
......
......@@ -313,11 +313,31 @@ class CastActivityManagerTest : public testing::Test,
}
}
void LaunchMirroringSession() {
CallLaunchSession(kCastStreamingAppId);
void LaunchNonSdkMirroringSession() {
CallLaunchSession(kCastStreamingAppId, /* app_params */ "",
/* client_id */ "");
ResolveMirroringSessionLaunch();
}
void LaunchCastSdkMirroringSession() {
CallLaunchSession(kCastStreamingAppId, kAppParams, kClientId);
// We expect EnsureConnection() to be called for both the sender client and
// |message_handler_.sender_id()|. The latter is captured in
// ResolveMirroringSessionLaunch().
//
// CallLaunchSession() calls VerifyAndClearExpectations() on
// |message_handler_|, so this EXPECT_CALL() must come after that.
EXPECT_CALL(message_handler_,
EnsureConnection(kChannelId, "theClientId", "theTransportId",
cast_channel::VirtualConnectionType::kStrong));
ResolveMirroringSessionLaunch();
}
void ResolveMirroringSessionLaunch() {
EXPECT_CALL(message_handler_,
EnsureConnection(kChannelId, message_handler_.sender_id(),
"theTransportId",
cast_channel::VirtualConnectionType::kStrong));
auto response = GetSuccessLaunchResponse();
SetSessionForTest(route_->media_sink_id(),
CastSession::From(sink_, *response.receiver_status));
......@@ -440,7 +460,12 @@ TEST_F(CastActivityManagerTest, LaunchAppSessionWithAppParams) {
}
TEST_F(CastActivityManagerTest, LaunchMirroringSession) {
LaunchMirroringSession();
LaunchNonSdkMirroringSession();
EXPECT_EQ(RouteControllerType::kMirroring, route_->controller_type());
}
TEST_F(CastActivityManagerTest, LaunchMirroringSessionViaCastSdk) {
LaunchCastSdkMirroringSession();
EXPECT_EQ(RouteControllerType::kMirroring, route_->controller_type());
}
......@@ -453,7 +478,7 @@ TEST_F(CastActivityManagerTest, LaunchSiteInitiatedMirroringSession) {
}
TEST_F(CastActivityManagerTest, MirroringSessionStopped) {
LaunchMirroringSession();
LaunchNonSdkMirroringSession();
ExpectMirroringActivityStoppedTimes(1);
mirroring_activity_->DidStop();
}
......@@ -624,7 +649,7 @@ TEST_F(CastActivityManagerTest, TerminateSessionFails) {
}
TEST_F(CastActivityManagerTest, DestructorClosesLocalMirroringSession) {
LaunchMirroringSession();
LaunchNonSdkMirroringSession();
ExpectMirroringActivityStoppedTimes(1);
manager_.reset();
}
......
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