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( ...@@ -818,19 +818,31 @@ void CastActivityManager::HandleLaunchSessionResponse(
} }
RecordLaunchSessionResponseAppType(session->value().FindKey("appType")); RecordLaunchSessionResponseAppType(session->value().FindKey("appType"));
std::string client_id = cast_source.client_id(); // Cast SDK sessions have a |client_id|, and we ensure a virtual connection
// Mirroring sessions do not have |client_id| set here. // for them. For mirroring sessions, we ensure a strong virtual connection for
if (client_id.empty()) { // |message_handler_|. Mirroring initiated via the Cast SDK will have
client_id = message_handler_->sender_id(); // EnsureConnection() called for both.
} else { const std::string& client_id = cast_source.client_id();
if (!client_id.empty()) {
activity_it->second->SendMessageToClient( activity_it->second->SendMessageToClient(
client_id, client_id,
CreateNewSessionMessage(*session, client_id, sink, hash_token_)); 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. // TODO(jrw): Query media status.
} }
message_handler_->EnsureConnection(sink.cast_data().cast_channel_id, if (cast_source.ContainsStreamingApp()) {
client_id, session->transport_id(), message_handler_->EnsureConnection(
cast_source.connection_type()); 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_); activity_it->second->SetOrUpdateSession(*session, sink, hash_token_);
NotifyAllOnRoutesUpdated(); NotifyAllOnRoutesUpdated();
......
...@@ -313,11 +313,31 @@ class CastActivityManagerTest : public testing::Test, ...@@ -313,11 +313,31 @@ class CastActivityManagerTest : public testing::Test,
} }
} }
void LaunchMirroringSession() { void LaunchNonSdkMirroringSession() {
CallLaunchSession(kCastStreamingAppId); 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_, EXPECT_CALL(message_handler_,
EnsureConnection(kChannelId, "theClientId", "theTransportId", EnsureConnection(kChannelId, "theClientId", "theTransportId",
cast_channel::VirtualConnectionType::kStrong)); 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(); auto response = GetSuccessLaunchResponse();
SetSessionForTest(route_->media_sink_id(), SetSessionForTest(route_->media_sink_id(),
CastSession::From(sink_, *response.receiver_status)); CastSession::From(sink_, *response.receiver_status));
...@@ -440,7 +460,12 @@ TEST_F(CastActivityManagerTest, LaunchAppSessionWithAppParams) { ...@@ -440,7 +460,12 @@ TEST_F(CastActivityManagerTest, LaunchAppSessionWithAppParams) {
} }
TEST_F(CastActivityManagerTest, LaunchMirroringSession) { 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()); EXPECT_EQ(RouteControllerType::kMirroring, route_->controller_type());
} }
...@@ -453,7 +478,7 @@ TEST_F(CastActivityManagerTest, LaunchSiteInitiatedMirroringSession) { ...@@ -453,7 +478,7 @@ TEST_F(CastActivityManagerTest, LaunchSiteInitiatedMirroringSession) {
} }
TEST_F(CastActivityManagerTest, MirroringSessionStopped) { TEST_F(CastActivityManagerTest, MirroringSessionStopped) {
LaunchMirroringSession(); LaunchNonSdkMirroringSession();
ExpectMirroringActivityStoppedTimes(1); ExpectMirroringActivityStoppedTimes(1);
mirroring_activity_->DidStop(); mirroring_activity_->DidStop();
} }
...@@ -624,7 +649,7 @@ TEST_F(CastActivityManagerTest, TerminateSessionFails) { ...@@ -624,7 +649,7 @@ TEST_F(CastActivityManagerTest, TerminateSessionFails) {
} }
TEST_F(CastActivityManagerTest, DestructorClosesLocalMirroringSession) { TEST_F(CastActivityManagerTest, DestructorClosesLocalMirroringSession) {
LaunchMirroringSession(); LaunchNonSdkMirroringSession();
ExpectMirroringActivityStoppedTimes(1); ExpectMirroringActivityStoppedTimes(1);
manager_.reset(); 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