Skip to content

Commit 91a06b6

Browse files
ftsuicopybara-github
authored andcommitted
Split frame handler for incoming and outgoing sessions.
PiperOrigin-RevId: 870909627
1 parent 80a263e commit 91a06b6

12 files changed

+153
-335
lines changed

sharing/incoming_frames_reader.cc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ void IncomingFramesReader::OnDataReadFromConnection(
159159
{
160160
absl::MutexLock lock(mutex_);
161161
if (read_frame_info_queue_.empty()) {
162+
// Drop the frame if no one is waiting.
162163
return;
163164
}
164165
const ReadFrameInfo& frame_info = read_frame_info_queue_.front();
@@ -210,12 +211,9 @@ void IncomingFramesReader::Done(std::unique_ptr<V1Frame> frame) {
210211
read_frame_info_queue_.pop();
211212
}
212213

213-
if (read_frame_info.timeout != absl::ZeroDuration()) {
214-
ReadFrame(*read_frame_info.frame_type, std::move(read_frame_info.callback),
215-
read_frame_info.timeout);
216-
} else {
217-
ReadFrame(std::move(read_frame_info.callback), read_frame_info.timeout);
218-
}
214+
ProcessReadRequest(read_frame_info.frame_type,
215+
std::move(read_frame_info.callback),
216+
read_frame_info.timeout);
219217
}
220218

221219
std::unique_ptr<V1Frame> IncomingFramesReader::PopCachedFrame(

sharing/incoming_share_session.cc

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -192,30 +192,6 @@ IncomingShareSession::ProcessIntroduction(
192192
return std::nullopt;
193193
}
194194

195-
bool IncomingShareSession::ProcessKeyVerificationResult(
196-
PairedKeyVerificationRunner::PairedKeyVerificationResult result,
197-
OSType share_target_os_type,
198-
std::function<void(std::optional<IntroductionFrame>)>
199-
introduction_callback) {
200-
if (!HandleKeyVerificationResult(result, share_target_os_type)) {
201-
return false;
202-
}
203-
LOG(INFO) << ":Waiting for introduction from " << share_target().id;
204-
205-
frames_reader()->ReadFrame(
206-
V1Frame::INTRODUCTION,
207-
[callback = std::move(introduction_callback)](
208-
bool is_timeout, std::optional<V1Frame> frame) {
209-
if (!frame.has_value()) {
210-
callback(std::nullopt);
211-
} else {
212-
callback(frame->introduction());
213-
}
214-
},
215-
kReadFramesTimeout);
216-
return true;
217-
}
218-
219195
bool IncomingShareSession::ReadyForTransfer(
220196
std::function<void()> accept_timeout_callback,
221197
std::function<void(bool is_timeout, std::optional<V1Frame> frame)>

sharing/incoming_share_session.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,6 @@ class IncomingShareSession : public ShareSession {
6161
const nearby::sharing::service::proto::IntroductionFrame&
6262
introduction_frame);
6363

64-
// Processes the PairedKeyVerificationResult.
65-
// Returns true if verification was successful and the session is now waiting
66-
// for the introduction frame. Calls |introduction_callback| when it is
67-
// received.
68-
bool ProcessKeyVerificationResult(
69-
PairedKeyVerificationRunner::PairedKeyVerificationResult result,
70-
location::nearby::proto::sharing::OSType share_target_os_type,
71-
std::function<void(
72-
std::optional<nearby::sharing::service::proto::IntroductionFrame>)>
73-
introduction_callback);
74-
7564
// Returns true if the transfer can begin and AcceptTransfer should be called
7665
// immediately.
7766
// Returns false if user needs to accept the transfer.

sharing/incoming_share_session_test.cc

Lines changed: 0 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,139 +1235,6 @@ TEST_F(IncomingShareSessionTest, AcceptTransferSuccess) {
12351235
ConnectionResponseFrame::ACCEPT);
12361236
}
12371237

1238-
TEST_F(IncomingShareSessionTest, ProcessKeyVerificationResultSuccess) {
1239-
session_.OnConnected(&connection_);
1240-
session_.SetTokenForTests("1234");
1241-
1242-
bool introduction_received = false;
1243-
EXPECT_THAT(
1244-
session_.ProcessKeyVerificationResult(
1245-
PairedKeyVerificationRunner::PairedKeyVerificationResult::kSuccess,
1246-
OSType::WINDOWS,
1247-
[&introduction_received](std::optional<IntroductionFrame>) {
1248-
introduction_received = true;
1249-
}),
1250-
IsTrue());
1251-
1252-
EXPECT_THAT(session_.self_share(), IsFalse());
1253-
EXPECT_THAT(session_.token(), IsEmpty());
1254-
EXPECT_THAT(session_.os_type(), Eq(OSType::WINDOWS));
1255-
EXPECT_THAT(introduction_received, IsFalse());
1256-
1257-
// Send Introduction frame
1258-
nearby::sharing::service::proto::Frame frame =
1259-
nearby::sharing::service::proto::Frame();
1260-
frame.set_version(nearby::sharing::service::proto::Frame::V1);
1261-
V1Frame* v1frame = frame.mutable_v1();
1262-
v1frame->set_type(service::proto::V1Frame::INTRODUCTION);
1263-
v1frame->mutable_introduction();
1264-
std::vector<uint8_t> data;
1265-
data.resize(frame.ByteSizeLong());
1266-
EXPECT_THAT(frame.SerializeToArray(data.data(), data.size()), IsTrue());
1267-
connection_.WriteMessage(std::move(data));
1268-
1269-
EXPECT_THAT(introduction_received, IsTrue());
1270-
}
1271-
1272-
TEST_F(IncomingShareSessionTest, ProcessKeyVerificationResultFail) {
1273-
session_.OnConnected(&connection_);
1274-
session_.SetTokenForTests("1234");
1275-
1276-
bool introduction_received = false;
1277-
EXPECT_THAT(
1278-
session_.ProcessKeyVerificationResult(
1279-
PairedKeyVerificationRunner::PairedKeyVerificationResult::kFail,
1280-
OSType::WINDOWS,
1281-
[&introduction_received](std::optional<IntroductionFrame>) {
1282-
introduction_received = true;
1283-
}),
1284-
IsFalse());
1285-
1286-
EXPECT_THAT(session_.token(), Eq("1234"));
1287-
EXPECT_THAT(session_.os_type(), Eq(OSType::WINDOWS));
1288-
EXPECT_THAT(introduction_received, IsFalse());
1289-
1290-
// Send Introduction frame
1291-
nearby::sharing::service::proto::Frame frame =
1292-
nearby::sharing::service::proto::Frame();
1293-
frame.set_version(nearby::sharing::service::proto::Frame::V1);
1294-
V1Frame* v1frame = frame.mutable_v1();
1295-
v1frame->set_type(service::proto::V1Frame::INTRODUCTION);
1296-
v1frame->mutable_introduction();
1297-
std::vector<uint8_t> data;
1298-
data.resize(frame.ByteSizeLong());
1299-
EXPECT_THAT(frame.SerializeToArray(data.data(), data.size()), IsTrue());
1300-
connection_.WriteMessage(std::move(data));
1301-
1302-
EXPECT_THAT(introduction_received, IsFalse());
1303-
}
1304-
1305-
TEST_F(IncomingShareSessionTest, ProcessKeyVerificationResultUnable) {
1306-
session_.OnConnected(&connection_);
1307-
session_.SetTokenForTests("1234");
1308-
1309-
bool introduction_received = false;
1310-
EXPECT_THAT(
1311-
session_.ProcessKeyVerificationResult(
1312-
PairedKeyVerificationRunner::PairedKeyVerificationResult::kUnable,
1313-
OSType::WINDOWS,
1314-
[&introduction_received](std::optional<IntroductionFrame>) {
1315-
introduction_received = true;
1316-
}),
1317-
IsTrue());
1318-
1319-
EXPECT_THAT(session_.token(), Eq("1234"));
1320-
EXPECT_THAT(session_.os_type(), Eq(OSType::WINDOWS));
1321-
EXPECT_THAT(introduction_received, IsFalse());
1322-
1323-
// Send Introduction frame
1324-
nearby::sharing::service::proto::Frame frame =
1325-
nearby::sharing::service::proto::Frame();
1326-
frame.set_version(nearby::sharing::service::proto::Frame::V1);
1327-
V1Frame* v1frame = frame.mutable_v1();
1328-
v1frame->set_type(service::proto::V1Frame::INTRODUCTION);
1329-
v1frame->mutable_introduction();
1330-
std::vector<uint8_t> data;
1331-
data.resize(frame.ByteSizeLong());
1332-
EXPECT_THAT(frame.SerializeToArray(data.data(), data.size()), IsTrue());
1333-
connection_.WriteMessage(std::move(data));
1334-
1335-
EXPECT_THAT(introduction_received, IsTrue());
1336-
}
1337-
1338-
TEST_F(IncomingShareSessionTest, ProcessKeyVerificationResultUnknown) {
1339-
session_.OnConnected(&connection_);
1340-
session_.SetTokenForTests("1234");
1341-
1342-
bool introduction_received = false;
1343-
EXPECT_THAT(
1344-
session_.ProcessKeyVerificationResult(
1345-
PairedKeyVerificationRunner::PairedKeyVerificationResult::kUnknown,
1346-
OSType::WINDOWS,
1347-
[&introduction_received](std::optional<IntroductionFrame>) {
1348-
introduction_received = true;
1349-
}),
1350-
IsFalse());
1351-
1352-
EXPECT_THAT(session_.token(), Eq("1234"));
1353-
EXPECT_THAT(session_.os_type(), Eq(OSType::WINDOWS));
1354-
EXPECT_THAT(introduction_received, IsFalse());
1355-
1356-
// Send Introduction frame
1357-
nearby::sharing::service::proto::Frame frame =
1358-
nearby::sharing::service::proto::Frame();
1359-
frame.set_version(nearby::sharing::service::proto::Frame::V1);
1360-
V1Frame* v1frame = frame.mutable_v1();
1361-
v1frame->set_type(service::proto::V1Frame::INTRODUCTION);
1362-
v1frame->mutable_introduction();
1363-
std::vector<uint8_t> data;
1364-
data.resize(frame.ByteSizeLong());
1365-
EXPECT_THAT(frame.SerializeToArray(data.data(), data.size()), IsTrue());
1366-
connection_.WriteMessage(std::move(data));
1367-
1368-
EXPECT_THAT(introduction_received, IsFalse());
1369-
}
1370-
13711238
TEST_F(IncomingShareSessionTest, TryUpgradeBandwidthNotNeeded) {
13721239
session_.OnConnected(&connection_);
13731240

0 commit comments

Comments
 (0)