Commit 8a194dea authored by Josh Nohle's avatar Josh Nohle Committed by Chromium LUCI CQ

[Nearby] Support user cancellation before a connection is established

Previously, a user cancellation of an outgoing share from a Chromebook
would have no effect if a connection with the receiving device was
not already established. (The connection is established in roughly
a 3-second window after the share target is selected.) So, an immediate
cancellation previously had no effect, and the transfer proceeded.

In this CL, we support cancellation before a connection is established.
We also bring the Chrome OS cancellation method more in line with the
GmsCore implementation. Notably, we report a cancellation before
disconnecting to provide a more accurate transfer update status of
"cancelled" instead of "failed".

Manually verified cancellation in the following scenarios:
 * sending to and receiving from a phone;
 * cancelling on both the phone and Chromebook;
 * cancelling before a connection was established, after a connection
   was established, and during a payload transfer.

One scenario--cancelling a Chromebook-to-phone share from the phone
while the payload transfer was in progress--resulted in a failure
notification on the Chromebook instead of a cancellation notification.
This seems unrelated to this CL, and it is being tracked in
crbug/1155412.

Fixed: 1154926
Change-Id: I5ac141904af2fc614256b3c14e2ba3a99a984556
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2573884
Auto-Submit: Josh Nohle <nohle@chromium.org>
Commit-Queue: James Vecore <vecore@google.com>
Reviewed-by: default avatarJames Vecore <vecore@google.com>
Cr-Commit-Position: refs/heads/master@{#833627}
parent fb7f48cc
......@@ -767,7 +767,7 @@ void NearbySharingServiceImpl::DoCancel(
bool write_cancel_frame) {
ShareTargetInfo* info = GetShareTargetInfo(share_target);
if (!info || !info->connection() || !info->endpoint_id()) {
if (!info || !info->endpoint_id()) {
NS_LOG(ERROR) << __func__
<< ": Cancel invoked for unknown share target, returning "
"kOutOfOrderApiCall";
......@@ -777,20 +777,10 @@ void NearbySharingServiceImpl::DoCancel(
return;
}
base::SequencedTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE,
base::BindOnce(&NearbySharingServiceImpl::CloseConnection,
weak_ptr_factory_.GetWeakPtr(), share_target),
kIncomingCancelDelay);
info->connection()->SetDisconnectionListener(
base::BindOnce(&NearbySharingServiceImpl::UnregisterShareTarget,
weak_ptr_factory_.GetWeakPtr(), share_target));
if (write_cancel_frame) {
WriteCancel(*info->connection());
}
// We immediately inform the user that the transfer has been cancelled because
// subsequent disconnections might be interpreted as failure. The
// TransferUpdateDecorator will ignore subsequent statuses in favor of this
// cancelled status.
if (info->transfer_update_callback()) {
info->transfer_update_callback()->OnTransferUpdate(
share_target, TransferMetadataBuilder()
......@@ -798,6 +788,36 @@ void NearbySharingServiceImpl::DoCancel(
.build());
}
// Before disconnecting, cancel all ongoing payloads.
for (int64_t attachment_id : share_target.GetAttachmentIds()) {
base::Optional<int64_t> payload_id = GetAttachmentPayloadId(attachment_id);
if (payload_id) {
nearby_connections_manager_->Cancel(*payload_id);
}
}
// If a connection exists, close the connection. Otherwise disconnect from
// endpoint id directly. Note: A share attempt can be cancelled by the user
// before a connection is fully established, so info->connection() might be
// null.
if (info->connection()) {
info->connection()->SetDisconnectionListener(
base::BindOnce(&NearbySharingServiceImpl::UnregisterShareTarget,
weak_ptr_factory_.GetWeakPtr(), share_target));
base::SequencedTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE,
base::BindOnce(&NearbySharingServiceImpl::CloseConnection,
weak_ptr_factory_.GetWeakPtr(), share_target),
kIncomingCancelDelay);
if (write_cancel_frame) {
WriteCancel(*info->connection());
}
} else {
nearby_connections_manager_->Disconnect(*info->endpoint_id());
}
std::move(status_codes_callback).Run(StatusCodes::kOk);
}
......
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