Commit 7f9377ad authored by Curt Clemens's avatar Curt Clemens Committed by Commit Bot

[Nearby] Error notifications for background sharing

Instead of a generic failure message, show a specific error string that
depends on the TransferMetadata::Status.

Change-Id: I86b6549c4f6de0477f9a63ef71f9298796f10065
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2551078Reviewed-by: default avatarJames Vecore <vecore@google.com>
Commit-Queue: Curt Clemens <cclem@google.com>
Cr-Commit-Position: refs/heads/master@{#829871}
parent 039670a4
......@@ -122,6 +122,9 @@
<message name="IDS_NEARBY_ERROR_NO_RESPONSE" desc="Notify user that the file share failed because the receiver neither accepted nor declined the share.">
The device you're sharing with didn't respond
</message>
<message name="IDS_NEARBY_ERROR_NOT_ENOUGH_SPACE" desc="Notify user that the file can't be shared because there isn't enough disk space to store it. Displayed as a subtitle under a more generic file-couldn't-be-shared message.">
Not enough disk space
</message>
<message name="IDS_NEARBY_ERROR_REJECTED" desc="Notify sender that receiver declined the file share.">
The device you’re trying to share with did not accept
</message>
......
7df1723c66d444204194927a80ea52f6a28d85bc
\ No newline at end of file
......@@ -170,6 +170,20 @@ base::string16 GetFailureNotificationTitle(const ShareTarget& share_target) {
: IDS_NEARBY_NOTIFICATION_SEND_FAILURE_TITLE);
}
base::Optional<base::string16> GetFailureNotificationMessage(
TransferMetadata::Status status) {
switch (status) {
case TransferMetadata::Status::kTimedOut:
return l10n_util::GetStringUTF16(IDS_NEARBY_ERROR_TIME_OUT);
case TransferMetadata::Status::kNotEnoughSpace:
return l10n_util::GetStringUTF16(IDS_NEARBY_ERROR_NOT_ENOUGH_SPACE);
case TransferMetadata::Status::kUnsupportedAttachmentType:
return l10n_util::GetStringUTF16(IDS_NEARBY_ERROR_UNSUPPORTED_FILE_TYPE);
default:
return base::nullopt;
}
}
base::string16 GetConnectionRequestNotificationMessage(
const ShareTarget& share_target,
const TransferMetadata& transfer_metadata) {
......@@ -545,11 +559,11 @@ void NearbyNotificationManager::OnTransferUpdate(
case TransferMetadata::Status::kFailed:
case TransferMetadata::Status::kNotEnoughSpace:
case TransferMetadata::Status::kUnsupportedAttachmentType:
ShowFailure(share_target);
ShowFailure(share_target, transfer_metadata);
break;
default:
if (transfer_metadata.is_final_status())
ShowFailure(share_target);
ShowFailure(share_target, transfer_metadata);
break;
}
......@@ -742,13 +756,21 @@ void NearbyNotificationManager::ShowIncomingSuccess(
}
}
void NearbyNotificationManager::ShowFailure(const ShareTarget& share_target) {
void NearbyNotificationManager::ShowFailure(
const ShareTarget& share_target,
const TransferMetadata& transfer_metadata) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
message_center::Notification notification =
CreateNearbyNotification(kNearbyNotificationId);
notification.set_title(GetFailureNotificationTitle(share_target));
base::Optional<base::string16> message =
GetFailureNotificationMessage(transfer_metadata.status());
if (message) {
notification.set_message(*message);
}
delegate_map_.erase(kNearbyNotificationId);
notification_display_service_->Display(
......
......@@ -79,7 +79,8 @@ class NearbyNotificationManager : public TransferUpdateCallback,
void ShowSuccess(const ShareTarget& share_target);
// Shows a notification for send or receive failure.
void ShowFailure(const ShareTarget& share_target);
void ShowFailure(const ShareTarget& share_target,
const TransferMetadata& transfer_metadata);
// Closes any currently shown transfer notification (e.g. progress or
// connection).
......
......@@ -463,19 +463,39 @@ TEST_P(NearbyNotificationManagerAttachmentsTest, ShowFailure) {
for (FileAttachment::Type type : param.file_attachments)
share_target.file_attachments.push_back(CreateFileAttachment(type));
manager()->ShowFailure(share_target);
base::string16 expected = FormatNotificationTitle(
is_incoming ? IDS_NEARBY_NOTIFICATION_RECEIVE_FAILURE_TITLE
: IDS_NEARBY_NOTIFICATION_SEND_FAILURE_TITLE,
param, device_name);
std::vector<message_center::Notification> notifications =
GetDisplayedNotifications();
ASSERT_EQ(1u, notifications.size());
const message_center::Notification& notification = notifications[0];
EXPECT_EQ(expected, notification.title());
for (std::pair<TransferMetadata::Status, int> error :
std::vector<std::pair<TransferMetadata::Status, int>>{
{TransferMetadata::Status::kNotEnoughSpace,
IDS_NEARBY_ERROR_NOT_ENOUGH_SPACE},
{TransferMetadata::Status::kTimedOut, IDS_NEARBY_ERROR_TIME_OUT},
{TransferMetadata::Status::kUnsupportedAttachmentType,
IDS_NEARBY_ERROR_UNSUPPORTED_FILE_TYPE},
{TransferMetadata::Status::kFailed, 0},
}) {
manager()->ShowFailure(
share_target,
TransferMetadataBuilder().set_status(error.first).build());
base::string16 expected_title = FormatNotificationTitle(
is_incoming ? IDS_NEARBY_NOTIFICATION_RECEIVE_FAILURE_TITLE
: IDS_NEARBY_NOTIFICATION_SEND_FAILURE_TITLE,
param, device_name);
base::string16 expected_message =
error.second ? l10n_util::GetStringUTF16(error.second)
: base::string16();
std::vector<message_center::Notification> notifications =
GetDisplayedNotifications();
ASSERT_EQ(1u, notifications.size());
const message_center::Notification& notification = notifications[0];
EXPECT_EQ(expected_title, notification.title());
EXPECT_EQ(expected_message, notification.message());
notification_tester_->RemoveNotification(
NotificationHandler::Type::NEARBY_SHARE, notifications[0].id(),
/*by_user=*/true);
}
}
INSTANTIATE_TEST_SUITE_P(
......@@ -610,7 +630,7 @@ TEST_F(NearbyNotificationManagerTest, ShowSuccess_ShowsNotification) {
}
TEST_F(NearbyNotificationManagerTest, ShowFailure_ShowsNotification) {
manager()->ShowFailure(ShareTarget());
manager()->ShowFailure(ShareTarget(), TransferMetadataBuilder().build());
std::vector<message_center::Notification> notifications =
GetDisplayedNotifications();
......
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