Skip to content

Commit

Permalink
Deprecate enable_transfer_cancellation_optimization flag.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 708379483
  • Loading branch information
ftsui authored and copybara-github committed Dec 20, 2024
1 parent 0c69a1b commit 621d24a
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 143 deletions.
8 changes: 2 additions & 6 deletions sharing/flags/generated/nearby_sharing_feature_flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ constexpr auto kEnableSelfShareUi =
// Enable/disable sending desktop events
constexpr auto kEnableSendingDesktopEvents =
flags::Flag<bool>(kConfigPackage, "45459748", false);
// Enable/disable optimization for transfer cancellation.
constexpr auto kEnableTransferCancellationOptimization =
flags::Flag<bool>(kConfigPackage, "45429881", false);
// Disable/enable the WebRTC medium in Nearby Sharing SDK.
constexpr auto kEnableWebrtcMedium =
flags::Flag<bool>(kConfigPackage, "45411620", false);
Expand Down Expand Up @@ -88,8 +85,8 @@ constexpr auto kDiscoveryCacheLostExpiryMs =
// When true, honor 3P client_id & client_secret in the gRPC request
constexpr auto kHonor3PClientIdAndSecret =
flags::Flag<bool>(kConfigPackage, "45665616", false);
// When UnregisterShareTarget, the time in milliseconds a cached entry can be in
// LOST state.
// The amount of time in milliseconds a share target stays in discovery cache in
// receive disabled state after a transfer.
constexpr auto kUnregisterTargetDiscoveryCacheLostExpiryMs =
flags::Flag<int64_t>(kConfigPackage, "45663103", 10000);
// Enable/disable QR Code UI
Expand Down Expand Up @@ -120,7 +117,6 @@ inline absl::btree_map<int, const flags::Flag<bool>&> GetBoolFlags() {
{45411589, kEnableRetryResumeTransfer},
{45418908, kEnableSelfShareUi},
{45459748, kEnableSendingDesktopEvents},
{45429881, kEnableTransferCancellationOptimization},
{45411620, kEnableWebrtcMedium},
{45411353, kSenderSkipsConfirmation},
{45409033, kShowAutoUpdateSetting},
Expand Down
17 changes: 5 additions & 12 deletions sharing/nearby_sharing_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2639,15 +2639,11 @@ void NearbySharingServiceImpl::OnOutgoingTransferUpdate(
}

// check whether need to send next payload.
if (NearbyFlags::GetInstance().GetBoolFlag(
config_package_nearby::nearby_sharing_feature::
kEnableTransferCancellationOptimization)) {
if (metadata.in_progress_attachment_transferred_bytes().has_value() &&
metadata.in_progress_attachment_total_bytes().has_value() &&
*metadata.in_progress_attachment_transferred_bytes() ==
*metadata.in_progress_attachment_total_bytes()) {
session.SendNextPayload();
}
if (metadata.in_progress_attachment_transferred_bytes().has_value() &&
metadata.in_progress_attachment_total_bytes().has_value() &&
*metadata.in_progress_attachment_transferred_bytes() ==
*metadata.in_progress_attachment_total_bytes()) {
session.SendNextPayload();
}

if (has_foreground_send_surface && metadata.is_final_status()) {
Expand Down Expand Up @@ -2848,9 +2844,6 @@ void NearbySharingServiceImpl::OnReceiveConnectionResponse(
return;
}
session->SendPayloads(
NearbyFlags::GetInstance().GetBoolFlag(
config_package_nearby::nearby_sharing_feature::
kEnableTransferCancellationOptimization),
[this, share_target_id](
std::optional<nearby::sharing::service::proto::V1Frame> frame) {
OnFrameRead(share_target_id, std::move(frame));
Expand Down
4 changes: 0 additions & 4 deletions sharing/nearby_sharing_service_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3672,10 +3672,6 @@ TEST_F(NearbySharingServiceImplTest, SendFilesSuccess) {
}

TEST_F(NearbySharingServiceImplTest, SendWifiCredentialsSuccess) {
NearbyFlags::GetInstance().OverrideBoolFlagValue(
config_package_nearby::nearby_sharing_feature::
kEnableTransferCancellationOptimization,
true);
MockTransferUpdateCallback transfer_callback;
MockShareTargetDiscoveredCallback discovery_callback;
int64_t target_id =
Expand Down
41 changes: 1 addition & 40 deletions sharing/outgoing_share_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ bool OutgoingShareSession::AcceptTransfer(
}

void OutgoingShareSession::SendPayloads(
bool enable_transfer_cancellation_optimization,
std::function<
void(std::optional<nearby::sharing::service::proto::V1Frame> frame)>
frame_read_callback,
Expand All @@ -341,34 +340,8 @@ void OutgoingShareSession::SendPayloads(
/*transfer_position=*/1,
/*concurrent_connections=*/1);
VLOG(1) << "The connection was accepted. Payloads are now being sent.";
if (enable_transfer_cancellation_optimization) {
InitSendPayload(std::move(payload_transder_update_callback));
SendNextPayload();
} else {
SendAllPayloads(std::move(payload_transder_update_callback));
}
}

void OutgoingShareSession::SendAllPayloads(
std::function<void()> payload_transder_update_callback) {
InitializePayloadTracker(std::move(payload_transder_update_callback));
for (auto& payload : ExtractTextPayloads()) {
connections_manager().Send(
endpoint_id(), std::make_unique<Payload>(payload), payload_tracker());
}
for (auto& payload : ExtractFilePayloads()) {
connections_manager().Send(
endpoint_id(), std::make_unique<Payload>(payload), payload_tracker());
}
for (auto& payload : ExtractWifiCredentialsPayloads()) {
connections_manager().Send(
endpoint_id(), std::make_unique<Payload>(payload), payload_tracker());
}
}

void OutgoingShareSession::InitSendPayload(
std::function<void()> payload_transder_update_callback) {
InitializePayloadTracker(std::move(payload_transder_update_callback));
SendNextPayload();
}

void OutgoingShareSession::SendNextPayload() {
Expand Down Expand Up @@ -472,18 +445,6 @@ OutgoingShareSession::HandleConnectionResponse(
return TransferMetadata::Status::kFailed;
}

std::vector<Payload> OutgoingShareSession::ExtractTextPayloads() {
return std::move(text_payloads_);
}

std::vector<Payload> OutgoingShareSession::ExtractFilePayloads() {
return std::move(file_payloads_);
}

std::vector<Payload> OutgoingShareSession::ExtractWifiCredentialsPayloads() {
return std::move(wifi_credentials_payloads_);
}

std::optional<Payload> OutgoingShareSession::ExtractNextPayload() {
if (!text_payloads_.empty()) {
Payload payload = text_payloads_.back();
Expand Down
13 changes: 0 additions & 13 deletions sharing/outgoing_share_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ class OutgoingShareSession : public ShareSession {
// `payload_transder_update_callback`.
// Any other frames received will be passed to `frame_read_callback`.
void SendPayloads(
bool enable_transfer_cancellation_optimization,
std::function<
void(std::optional<nearby::sharing::service::proto::V1Frame> frame)>
frame_read_callback,
Expand Down Expand Up @@ -166,18 +165,6 @@ class OutgoingShareSession : public ShareSession {
// Calculates transport type based on attachment size.
TransportType GetTransportType(bool disable_wifi_hotspot) const;

// Create a payload status listener to send status change to
// `payload_transder_update_callback`.
// Send all payloads to NearbyConnectionManager.
void SendAllPayloads(std::function<void()> payload_transder_update_callback);

// Create a payload status listener to send status change to
// `payload_transder_update_callback`.
void InitSendPayload(std::function<void()> payload_transder_update_callback);

std::vector<Payload> ExtractTextPayloads();
std::vector<Payload> ExtractFilePayloads();
std::vector<Payload> ExtractWifiCredentialsPayloads();
std::optional<Payload> ExtractNextPayload();
bool FillIntroductionFrame(
nearby::sharing::service::proto::IntroductionFrame* introduction) const;
Expand Down
71 changes: 3 additions & 68 deletions sharing/outgoing_share_session_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -676,68 +676,7 @@ TEST_F(OutgoingShareSessionTest, HandleConnectionResponseAcceptResponse) {
ASSERT_THAT(status.has_value(), IsFalse());
}

TEST_F(OutgoingShareSessionTest, SendPayloadsDisableCancellationOptimization) {
InitSendAttachments(CreateDefaultAttachmentContainer());
session_.set_session_id(1234);
std::vector<NearbyFileHandler::FileInfo> file_infos;
file_infos.push_back({
.size = 12355L,
.file_path = file1_.file_path().value(),
});
session_.CreateFilePayloads(file_infos);
session_.CreateTextPayloads();
session_.CreateWifiCredentialsPayloads();
MockFunction<void()> payload_transder_update_callback;
StrictMock<MockFunction<void(
std::unique_ptr<Payload>,
std::weak_ptr<NearbyConnectionsManager::PayloadStatusListener>)>>
send_payload_callback;
connections_manager_.set_send_payload_callback(
send_payload_callback.AsStdFunction());
EXPECT_CALL(send_payload_callback, Call(_, _))
.WillOnce(Invoke(
[this](
std::unique_ptr<Payload> payload,
std::weak_ptr<NearbyConnectionsManager::PayloadStatusListener>) {
payload->id = session_.attachment_payload_map().at(file1_.id());
}))
.WillOnce(Invoke(
[this](
std::unique_ptr<Payload> payload,
std::weak_ptr<NearbyConnectionsManager::PayloadStatusListener>) {
payload->id = session_.attachment_payload_map().at(text1_.id());
}))
.WillOnce(Invoke(
[this](
std::unique_ptr<Payload> payload,
std::weak_ptr<NearbyConnectionsManager::PayloadStatusListener>) {
payload->id = session_.attachment_payload_map().at(text2_.id());
}))
.WillOnce(Invoke(
[this](
std::unique_ptr<Payload> payload,
std::weak_ptr<NearbyConnectionsManager::PayloadStatusListener>) {
payload->id = session_.attachment_payload_map().at(wifi1_.id());
}));
EXPECT_CALL(mock_event_logger_,
Log(Matcher<const SharingLog&>(
AllOf((HasCategory(EventCategory::SENDING_EVENT),
HasEventType(EventType::SEND_ATTACHMENTS_START),
Property(&SharingLog::send_attachments_start,
HasSessionId(1234)))))));
NearbyConnectionImpl connection(device_info_);
ConnectionSuccess(&connection);

session_.SendPayloads(
/*enable_transfer_cancellation_optimization=*/
false, [](std::optional<V1Frame> frame) {},
payload_transder_update_callback.AsStdFunction());

auto payload_listener = session_.payload_tracker().lock();
EXPECT_THAT(payload_listener, IsTrue());
}

TEST_F(OutgoingShareSessionTest, SendPayloadsEnableCancellationOptimization) {
TEST_F(OutgoingShareSessionTest, SendPayloads) {
InitSendAttachments(CreateDefaultAttachmentContainer());
session_.set_session_id(1234);
std::vector<NearbyFileHandler::FileInfo> file_infos;
Expand Down Expand Up @@ -771,9 +710,7 @@ TEST_F(OutgoingShareSessionTest, SendPayloadsEnableCancellationOptimization) {
NearbyConnectionImpl connection(device_info_);
ConnectionSuccess(&connection);

session_.SendPayloads(
/*enable_transfer_cancellation_optimization=*/
true, [](std::optional<V1Frame> frame) {},
session_.SendPayloads([](std::optional<V1Frame> frame) {},
payload_transder_update_callback.AsStdFunction());

auto payload_listener = session_.payload_tracker().lock();
Expand Down Expand Up @@ -815,9 +752,7 @@ TEST_F(OutgoingShareSessionTest, SendNextPayload) {
NearbyConnectionImpl connection(device_info_);
ConnectionSuccess(&connection);

session_.SendPayloads(
/*enable_transfer_cancellation_optimization=*/
true, [](std::optional<V1Frame> frame) {},
session_.SendPayloads([](std::optional<V1Frame> frame) {},
payload_transder_update_callback.AsStdFunction());

EXPECT_CALL(send_payload_callback, Call(_, _))
Expand Down

0 comments on commit 621d24a

Please sign in to comment.