0

scanner: Add action specific strings for action failure toast.

Show a different error message depending on the failed action type.

Bug: b:383926250
Change-Id: I6a588887a4d6ccced9b012488720be804f394c71
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6211277
Reviewed-by: Michael Cui <mlcui@google.com>
Commit-Queue: Michelle Chen <michellegc@google.com>
Cr-Commit-Position: refs/heads/main@{#1412716}
This commit is contained in:
Michelle Chen
2025-01-28 22:33:36 -08:00
committed by Chromium LUCI CQ
parent 09a53dfba2
commit b2431293c2
7 changed files with 49 additions and 6 deletions

@ -6862,6 +6862,21 @@ Here are some things you can try to get started.
<message name="IDS_ASH_SCANNER_ACTION_COPY_TEXT_AND_FORMAT" desc="The label on a button that can be clicked to copy text with formatting from the contents of a screenshot." translateable="false">
Copy text and format
</message>
<message name="IDS_ASH_SCANNER_ACTION_FAILURE_TOAST_CREATE_EVENT" desc="The message shown on a toast to indicate an error occurred when trying to add an event to the user's calendar from the contents of a screenshot.">
Couldn't add to Calendar
</message>
<message name="IDS_ASH_SCANNER_ACTION_FAILURE_TOAST_CREATE_CONTACT" desc="The message shown on a toast to indicate an error occurred when trying to create a new contact from the contents of a screenshot.">
Couldnt create contact
</message>
<message name="IDS_ASH_SCANNER_ACTION_FAILURE_TOAST_CREATE_DOC" desc="The message shown on a toast to indicate an error occurred when trying to create a new Google Doc from the contents of a screenshot.">
Couldnt create Google Doc
</message>
<message name="IDS_ASH_SCANNER_ACTION_FAILURE_TOAST_CREATE_SHEET" desc="The message shown on a toast to indicate an error occurred when trying to create a new Google Sheet from the contents of a screenshot.">
Couldnt create Google Sheet
</message>
<message name="IDS_ASH_SCANNER_ACTION_FAILURE_TOAST_COPY_TEXT_AND_FORMAT" desc="The message shown on a toast to indicate an error occurred when trying to copy text with formatting from the contents of a screenshot.">
Couldnt copy with formatting
</message>
<!-- Snap Group -->
<message name="IDS_ASH_SNAP_GROUP_CLICK_TO_LOCK_WINDOWS" desc="Click to lock the windows.">

@ -0,0 +1 @@
a8cbaebedfea44a27b7a45f3c7b784ff71ec62e9

@ -0,0 +1 @@
5a4fc7aa0fd428a81970a7e6fa47fbda29a3d2d5

@ -0,0 +1 @@
c8bbff9244315656e7b519c667e7e4ba77d5a500

@ -0,0 +1 @@
769d695d4608b0ce17b8618fbbbd75b3d2433bd3

@ -0,0 +1 @@
e016c00e910760c9a8e2ed70207990ede926a7fc

@ -29,6 +29,7 @@
#include "ash/session/session_controller_impl.h"
#include "ash/shell.h"
#include "ash/shell_delegate.h"
#include "ash/strings/grit/ash_strings.h"
#include "base/check.h"
#include "base/check_is_test.h"
#include "base/containers/span.h"
@ -39,12 +40,14 @@
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/notreached.h"
#include "base/strings/strcat.h"
#include "base/time/time.h"
#include "base/values.h"
#include "components/account_id/account_id.h"
#include "components/feedback/feedback_constants.h"
#include "components/manta/proto/scanner.pb.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/public/cpp/notification.h"
#include "ui/message_center/public/cpp/notifier_id.h"
@ -61,6 +64,29 @@ constexpr char kScannerNotifierId[] = "ash.scanner";
constexpr char kScannerActionSuccessToastId[] = "scanner_action_success";
constexpr char kScannerActionFailureToastId[] = "scanner_action_failure";
std::u16string GetToastMessageForActionFailure(
manta::proto::ScannerAction::ActionCase action_case) {
switch (action_case) {
case manta::proto::ScannerAction::kNewEvent:
return l10n_util::GetStringUTF16(
IDS_ASH_SCANNER_ACTION_FAILURE_TOAST_CREATE_EVENT);
case manta::proto::ScannerAction::kNewContact:
return l10n_util::GetStringUTF16(
IDS_ASH_SCANNER_ACTION_FAILURE_TOAST_CREATE_CONTACT);
case manta::proto::ScannerAction::kNewGoogleDoc:
return l10n_util::GetStringUTF16(
IDS_ASH_SCANNER_ACTION_FAILURE_TOAST_CREATE_DOC);
case manta::proto::ScannerAction::kNewGoogleSheet:
return l10n_util::GetStringUTF16(
IDS_ASH_SCANNER_ACTION_FAILURE_TOAST_CREATE_SHEET);
case manta::proto::ScannerAction::kCopyToClipboard:
return l10n_util::GetStringUTF16(
IDS_ASH_SCANNER_ACTION_FAILURE_TOAST_COPY_TEXT_AND_FORMAT);
case manta::proto::ScannerAction::ACTION_NOT_SET:
NOTREACHED();
}
}
// Shows an action progress notification. Note that this will remove the
// previous action notification if there is one.
void ShowActionProgressNotification(
@ -440,12 +466,9 @@ void ScannerController::OnActionFinished(
ToastManager::Get()->Show(std::move(toast_data));
} else {
// TODO: crbug.com/383926250 - The action failure text should depend on the
// type of action attempted.
constexpr char16_t kPlaceholderActionFailureText[] = u"Action Failed";
ToastManager::Get()->Show(ToastData(kScannerActionFailureToastId,
ToastCatalogName::kScannerActionFailure,
kPlaceholderActionFailureText));
ToastManager::Get()->Show(ToastData(
kScannerActionFailureToastId, ToastCatalogName::kScannerActionFailure,
GetToastMessageForActionFailure(action_case)));
}
if (!on_action_finished_for_testing_.is_null()) {