Commit 706896a3 authored by Timothy Loh's avatar Timothy Loh Committed by Commit Bot

Add UI for new error codes for when Plugin VM fails to launch

This CL updates the notification displayed when Plugin VM fails to
launch to accommodate both the new error codes, and the unknown error
cases.

A subsequent CL will probably change this notification into a dialog,
so I've temporarily omitted adding screenshots for the strings.

Bug: 1041313
Change-Id: I47b3036d167807cc611bc7d7788acc9669060a44
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2100453
Commit-Queue: Timothy Loh <timloh@chromium.org>
Reviewed-by: default avatarJulian Watson <juwa@google.com>
Cr-Commit-Position: refs/heads/master@{#750492}
parent 6491e3b8
......@@ -4427,11 +4427,23 @@
<message name="IDS_PLUGIN_VM_SHUT_DOWN_MENU_ITEM" desc="Text shown in the launcher and shelf context menus for the Plugin VM app to shut it down.">
Shut down
</message>
<message name="IDS_PLUGIN_VM_INVALID_LICENSE_NOTIFICATION_TITLE" desc="Title in the notification shown when launching the 'Plugin VM' app failed due to an invalid or missing license.">
<message name="IDS_PLUGIN_VM_INVALID_LICENSE_TITLE" desc="Title in the notification shown when launching the 'Plugin VM' app failed due to an invalid or missing license.">
Plugin VM requires a license
</message>
<message name="IDS_PLUGIN_VM_INVALID_LICENSE_NOTIFICATION_MESSAGE" desc="Message in the notification shown when launching the 'Plugin VM' app failed due to an invalid or missing license.">
Contact the device admin for your organization
<message name="IDS_PLUGIN_VM_EXPIRED_LICENSE_TITLE" desc="Title in the notification shown when launching the 'Plugin VM' app failed due to an expired license.">
Plugin VM license has expired
</message>
<message name="IDS_PLUGIN_VM_INVALID_LICENSE_MESSAGE" desc="Message in the notification shown when launching the 'Plugin VM' app failed due to an invalid, missing, or expired license.">
Contact your organization's device administrator
</message>
<message name="IDS_PLUGIN_VM_START_VM_ERROR_TITLE" desc="Title in the notification shown when launching the 'Plugin VM' app failed due to a network or unknown error.">
Couldn't open Plugin VM
</message>
<message name="IDS_PLUGIN_VM_NETWORK_ERROR_MESSAGE" desc="Message in the notification shown when launching the 'Plugin VM' app failed due to a network error.">
Connect to the internet and try again
</message>
<message name="IDS_PLUGIN_VM_START_VM_ERROR_MESSAGE" desc="Message in the notificataion shown when launching the 'Plugin VM' app failed due to an unknown error.">
Something went wrong. Please try again.
</message>
<message name="IDS_PLUGIN_VM_REMOVING_NOTIFICATION_IN_PROGRESS_MESSAGE" desc="Message in the notification shown when removing the 'Plugin VM' app.">
Uninstalling Plugin VM...
......
......@@ -32,8 +32,8 @@ namespace plugin_vm {
namespace {
constexpr char kInvalidLicenseNotificationId[] = "plugin-vm-invalid-license";
constexpr char kInvalidLicenseNotifierId[] = "plugin-vm-invalid-license";
constexpr char kStartVmFailedNotificationId[] = "plugin-vm-start-vm-failed";
constexpr char kStartVmFailedNotifierId[] = "plugin-vm-start-vm-failed";
class PluginVmManagerFactory : public BrowserContextKeyedServiceFactory {
public:
......@@ -73,19 +73,42 @@ bool VmIsStopping(vm_tools::plugin_dispatcher::VmState state) {
state == vm_tools::plugin_dispatcher::VmState::VM_STATE_PAUSING;
}
void ShowInvalidLicenseNotification(Profile* profile) {
void ShowStartVmFailedNotification(Profile* profile,
PluginVmLaunchResult result) {
LOG(ERROR) << "Failed to start VM with launch result "
<< static_cast<int>(result);
int title_id;
int message_id;
switch (result) {
default:
NOTREACHED();
FALLTHROUGH;
case PluginVmLaunchResult::kError:
title_id = IDS_PLUGIN_VM_START_VM_ERROR_TITLE;
message_id = IDS_PLUGIN_VM_START_VM_ERROR_MESSAGE;
break;
case PluginVmLaunchResult::kInvalidLicense:
title_id = IDS_PLUGIN_VM_INVALID_LICENSE_TITLE;
message_id = IDS_PLUGIN_VM_INVALID_LICENSE_MESSAGE;
break;
case PluginVmLaunchResult::kExpiredLicense:
title_id = IDS_PLUGIN_VM_EXPIRED_LICENSE_TITLE;
message_id = IDS_PLUGIN_VM_INVALID_LICENSE_MESSAGE;
break;
case PluginVmLaunchResult::kNetworkError:
title_id = IDS_PLUGIN_VM_START_VM_ERROR_TITLE;
message_id = IDS_PLUGIN_VM_NETWORK_ERROR_MESSAGE;
break;
}
std::unique_ptr<message_center::Notification> notification =
ash::CreateSystemNotification(
message_center::NOTIFICATION_TYPE_SIMPLE,
kInvalidLicenseNotificationId,
l10n_util::GetStringUTF16(
IDS_PLUGIN_VM_INVALID_LICENSE_NOTIFICATION_TITLE),
l10n_util::GetStringUTF16(
IDS_PLUGIN_VM_INVALID_LICENSE_NOTIFICATION_MESSAGE),
kStartVmFailedNotificationId, l10n_util::GetStringUTF16(title_id),
l10n_util::GetStringUTF16(message_id),
l10n_util::GetStringUTF16(IDS_PLUGIN_VM_APP_NAME), GURL(),
message_center::NotifierId(
message_center::NotifierType::SYSTEM_COMPONENT,
kInvalidLicenseNotifierId),
kStartVmFailedNotifierId),
{}, new message_center::NotificationDelegate(),
kNotificationPluginVmIcon,
message_center::SystemNotificationWarningLevel::CRITICAL_WARNING);
......@@ -374,18 +397,33 @@ void PluginVmManager::StartVm() {
void PluginVmManager::OnStartVm(
base::Optional<vm_tools::plugin_dispatcher::StartVmResponse> reply) {
if (reply &&
reply->error() ==
vm_tools::plugin_dispatcher::VmErrorCode::VM_ERR_LIC_NOT_VALID) {
VLOG(1) << "Failed to start VM due to invalid license.";
ShowInvalidLicenseNotification(profile_);
LaunchFailed(PluginVmLaunchResult::kInvalidLicense);
return;
PluginVmLaunchResult result;
if (reply) {
switch (reply->error()) {
case vm_tools::plugin_dispatcher::VmErrorCode::VM_SUCCESS:
result = PluginVmLaunchResult::kSuccess;
break;
case vm_tools::plugin_dispatcher::VmErrorCode::VM_ERR_LIC_NOT_VALID:
result = PluginVmLaunchResult::kInvalidLicense;
break;
case vm_tools::plugin_dispatcher::VmErrorCode::VM_ERR_LIC_EXPIRED:
result = PluginVmLaunchResult::kExpiredLicense;
break;
case vm_tools::plugin_dispatcher::VmErrorCode::
VM_ERR_LIC_WEB_PORTAL_UNAVAILABLE:
result = PluginVmLaunchResult::kNetworkError;
break;
default:
result = PluginVmLaunchResult::kError;
break;
}
} else {
result = PluginVmLaunchResult::kError;
}
if (!reply || reply->error()) {
LOG(ERROR) << "Failed to start VM.";
LaunchFailed();
if (result != PluginVmLaunchResult::kSuccess) {
ShowStartVmFailedNotification(profile_, result);
LaunchFailed(result);
return;
}
......
......@@ -27,7 +27,7 @@
namespace plugin_vm {
constexpr char kInvalidLicenseNotificationId[] = "plugin-vm-invalid-license";
constexpr char kStartVmFailedNotificationId[] = "plugin-vm-start-vm-failed";
class PluginVmManagerTest : public testing::Test {
public:
......@@ -263,7 +263,7 @@ TEST_F(PluginVmManagerTest, LaunchPluginVmInvalidLicense) {
task_environment_.RunUntilIdle();
EXPECT_FALSE(VmPluginDispatcherClient().show_vm_called());
EXPECT_TRUE(display_service_->GetNotification(kInvalidLicenseNotificationId));
EXPECT_TRUE(display_service_->GetNotification(kStartVmFailedNotificationId));
histogram_tester_->ExpectUniqueSample(
kPluginVmLaunchResultHistogram, PluginVmLaunchResult::kInvalidLicense, 1);
......
......@@ -25,7 +25,9 @@ enum class PluginVmLaunchResult {
kError = 1,
kInvalidLicense = 2,
kVmMissing = 3,
kMaxValue = kVmMissing,
kExpiredLicense = 4,
kNetworkError = 5,
kMaxValue = kNetworkError,
};
// These values are persisted to logs. Entries should not be renumbered and
......
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