Commit 381aacbd authored by Jason Lin's avatar Jason Lin Committed by Commit Bot

Move enums from CrostiniInstallerUIDelegate to a mojom file

Enums |InstallationState| and |Error| in class |CrostiniInstallerUIDelegate|
are moved to file crostini_installer_types.mojom and renamed to
`InstallerState` and `InstallerError`. All other changes to .h and .cc files
are just simple replacement to migrate to the new types.

The purpose of this CL is to allow the js code of the new Crostini WebUI
installer to use the same enums.

Bug: 929571
Change-Id: I185bb94b79187db98850dba4d23a7ba221e1d1e0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1815797Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarTimothy Loh <timloh@chromium.org>
Commit-Queue: Jason Lin <lxj@google.com>
Cr-Commit-Position: refs/heads/master@{#698836}
parent 35ebd9d9
...@@ -54,6 +54,7 @@ source_set("chromeos") { ...@@ -54,6 +54,7 @@ source_set("chromeos") {
":print_job_info_proto", ":print_job_info_proto",
":screen_brightness_event_proto", ":screen_brightness_event_proto",
":user_activity_event_proto", ":user_activity_event_proto",
"crostini:crostini_installer_types_mojom",
"//apps", "//apps",
"//ash", "//ash",
"//ash/public/cpp", "//ash/public/cpp",
......
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//mojo/public/tools/bindings/mojom.gni")
mojom("crostini_installer_types_mojom") {
sources = [
"crostini_installer_types.mojom",
]
}
...@@ -3,4 +3,7 @@ joelhockey@chromium.org ...@@ -3,4 +3,7 @@ joelhockey@chromium.org
nverne@chromium.org nverne@chromium.org
timloh@chromium.org timloh@chromium.org
per-file *.mojom=set noparent
per-file *.mojom=file://ipc/SECURITY_OWNERS
# COMPONENT: UI>Shell>Containers # COMPONENT: UI>Shell>Containers
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/system/sys_info.h" #include "base/system/sys_info.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/chromeos/crostini/crostini_installer_types.mojom.h"
#include "chrome/browser/chromeos/crostini/crostini_manager_factory.h" #include "chrome/browser/chromeos/crostini/crostini_manager_factory.h"
#include "chrome/browser/chromeos/crostini/crostini_pref_names.h" #include "chrome/browser/chromeos/crostini/crostini_pref_names.h"
#include "chrome/browser/chromeos/crostini/crostini_terminal.h" #include "chrome/browser/chromeos/crostini/crostini_terminal.h"
...@@ -29,13 +30,13 @@ ...@@ -29,13 +30,13 @@
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/network_service_instance.h" #include "content/public/browser/network_service_instance.h"
using crostini::mojom::InstallerError;
using crostini::mojom::InstallerState;
namespace crostini { namespace crostini {
namespace { namespace {
using Error = CrostiniInstallerUIDelegate::Error;
using SetupResult = CrostiniInstaller::SetupResult; using SetupResult = CrostiniInstaller::SetupResult;
using InstallationState = CrostiniInstallerUIDelegate::InstallationState;
class CrostiniInstallerFactory : public BrowserContextKeyedServiceFactory { class CrostiniInstallerFactory : public BrowserContextKeyedServiceFactory {
public: public:
...@@ -99,57 +100,57 @@ void RecordTimeFromDeviceSetupToInstallMetric() { ...@@ -99,57 +100,57 @@ void RecordTimeFromDeviceSetupToInstallMetric() {
})); }));
} }
SetupResult ErrorToSetupResult(Error error) { SetupResult ErrorToSetupResult(InstallerError error) {
switch (error) { switch (error) {
case Error::NONE: case InstallerError::kNone:
return SetupResult::kSuccess; return SetupResult::kSuccess;
case Error::ERROR_LOADING_TERMINA: case InstallerError::kErrorLoadingTermina:
return SetupResult::kErrorLoadingTermina; return SetupResult::kErrorLoadingTermina;
case Error::ERROR_STARTING_CONCIERGE: case InstallerError::kErrorStartingConcierge:
return SetupResult::kErrorStartingConcierge; return SetupResult::kErrorStartingConcierge;
case Error::ERROR_CREATING_DISK_IMAGE: case InstallerError::kErrorCreatingDiskImage:
return SetupResult::kErrorCreatingDiskImage; return SetupResult::kErrorCreatingDiskImage;
case Error::ERROR_STARTING_TERMINA: case InstallerError::kErrorStartingTermina:
return SetupResult::kErrorStartingTermina; return SetupResult::kErrorStartingTermina;
case Error::ERROR_STARTING_CONTAINER: case InstallerError::kErrorStartingContainer:
return SetupResult::kErrorStartingContainer; return SetupResult::kErrorStartingContainer;
case Error::ERROR_OFFLINE: case InstallerError::kErrorOffline:
return SetupResult::kErrorOffline; return SetupResult::kErrorOffline;
case Error::ERROR_FETCHING_SSH_KEYS: case InstallerError::kErrorFetchingSshKeys:
return SetupResult::kErrorFetchingSshKeys; return SetupResult::kErrorFetchingSshKeys;
case Error::ERROR_MOUNTING_CONTAINER: case InstallerError::kErrorMountingContainer:
return SetupResult::kErrorMountingContainer; return SetupResult::kErrorMountingContainer;
case Error::ERROR_SETTING_UP_CONTAINER: case InstallerError::kErrorSettingUpContainer:
return SetupResult::kErrorSettingUpContainer; return SetupResult::kErrorSettingUpContainer;
case Error::ERROR_INSUFFICIENT_DISK_SPACE: case InstallerError::kErrorInsufficientDiskSpace:
return SetupResult::kErrorInsufficientDiskSpace; return SetupResult::kErrorInsufficientDiskSpace;
} }
NOTREACHED(); NOTREACHED();
} }
SetupResult InstallationStateToCancelledSetupResult( SetupResult InstallStateToCancelledSetupResult(
InstallationState installing_state) { InstallerState installing_state) {
switch (installing_state) { switch (installing_state) {
case InstallationState::START: case InstallerState::kStart:
return SetupResult::kUserCancelledStart; return SetupResult::kUserCancelledStart;
case InstallationState::INSTALL_IMAGE_LOADER: case InstallerState::kInstallImageLoader:
return SetupResult::kUserCancelledInstallImageLoader; return SetupResult::kUserCancelledInstallImageLoader;
case InstallationState::START_CONCIERGE: case InstallerState::kStartConcierge:
return SetupResult::kUserCancelledStartConcierge; return SetupResult::kUserCancelledStartConcierge;
case InstallationState::CREATE_DISK_IMAGE: case InstallerState::kCreateDiskImage:
return SetupResult::kUserCancelledCreateDiskImage; return SetupResult::kUserCancelledCreateDiskImage;
case InstallationState::START_TERMINA_VM: case InstallerState::kStartTerminaVm:
return SetupResult::kUserCancelledStartTerminaVm; return SetupResult::kUserCancelledStartTerminaVm;
case InstallationState::CREATE_CONTAINER: case InstallerState::kCreateContainer:
return SetupResult::kUserCancelledCreateContainer; return SetupResult::kUserCancelledCreateContainer;
case InstallationState::SETUP_CONTAINER: case InstallerState::kSetupContainer:
return SetupResult::kUserCancelledSetupContainer; return SetupResult::kUserCancelledSetupContainer;
case InstallationState::START_CONTAINER: case InstallerState::kStartContainer:
return SetupResult::kUserCancelledStartContainer; return SetupResult::kUserCancelledStartContainer;
case InstallationState::FETCH_SSH_KEYS: case InstallerState::kFetchSshKeys:
return SetupResult::kUserCancelledFetchSshKeys; return SetupResult::kUserCancelledFetchSshKeys;
case InstallationState::MOUNT_CONTAINER: case InstallerState::kMountContainer:
return SetupResult::kUserCancelledMountContainer; return SetupResult::kUserCancelledMountContainer;
} }
...@@ -228,7 +229,7 @@ void CrostiniInstaller::Cancel(base::OnceClosure callback) { ...@@ -228,7 +229,7 @@ void CrostiniInstaller::Cancel(base::OnceClosure callback) {
progress_callback_.Reset(); progress_callback_.Reset();
cancel_callback_ = std::move(callback); cancel_callback_ = std::move(callback);
if (installing_state_ == InstallationState::START) { if (installing_state_ == InstallerState::kStart) {
// We have not called |RestartCrostini()| yet. // We have not called |RestartCrostini()| yet.
DCHECK_EQ(restart_id_, CrostiniManager::kUninitializedRestartId); DCHECK_EQ(restart_id_, CrostiniManager::kUninitializedRestartId);
// OnAvailableDiskSpace() will take care of |cancel_callback_|. // OnAvailableDiskSpace() will take care of |cancel_callback_|.
...@@ -248,7 +249,7 @@ void CrostiniInstaller::Cancel(base::OnceClosure callback) { ...@@ -248,7 +249,7 @@ void CrostiniInstaller::Cancel(base::OnceClosure callback) {
crostini::CrostiniManager::GetForProfile(profile_)->AbortRestartCrostini( crostini::CrostiniManager::GetForProfile(profile_)->AbortRestartCrostini(
restart_id_, base::DoNothing()); restart_id_, base::DoNothing());
restart_id_ = CrostiniManager::kUninitializedRestartId; restart_id_ = CrostiniManager::kUninitializedRestartId;
RecordSetupResult(InstallationStateToCancelledSetupResult(installing_state_)); RecordSetupResult(InstallStateToCancelledSetupResult(installing_state_));
if (require_cleanup_) { if (require_cleanup_) {
// Remove anything that got installed // Remove anything that got installed
...@@ -280,37 +281,37 @@ void CrostiniInstaller::CancelBeforeStart() { ...@@ -280,37 +281,37 @@ void CrostiniInstaller::CancelBeforeStart() {
} }
void CrostiniInstaller::OnComponentLoaded(CrostiniResult result) { void CrostiniInstaller::OnComponentLoaded(CrostiniResult result) {
DCHECK_EQ(installing_state_, InstallationState::INSTALL_IMAGE_LOADER); DCHECK_EQ(installing_state_, InstallerState::kInstallImageLoader);
if (result != CrostiniResult::SUCCESS) { if (result != CrostiniResult::SUCCESS) {
if (content::GetNetworkConnectionTracker()->IsOffline()) { if (content::GetNetworkConnectionTracker()->IsOffline()) {
LOG(ERROR) << "Network connection dropped while downloading cros-termina"; LOG(ERROR) << "Network connection dropped while downloading cros-termina";
HandleError(Error::ERROR_OFFLINE); HandleError(InstallerError::kErrorOffline);
} else { } else {
LOG(ERROR) << "Failed to install the cros-termina component"; LOG(ERROR) << "Failed to install the cros-termina component";
HandleError(Error::ERROR_LOADING_TERMINA); HandleError(InstallerError::kErrorLoadingTermina);
} }
return; return;
} }
UpdateInstallingState(InstallationState::START_CONCIERGE); UpdateInstallingState(InstallerState::kStartConcierge);
} }
void CrostiniInstaller::OnConciergeStarted(bool success) { void CrostiniInstaller::OnConciergeStarted(bool success) {
DCHECK_EQ(installing_state_, InstallationState::START_CONCIERGE); DCHECK_EQ(installing_state_, InstallerState::kStartConcierge);
if (!success) { if (!success) {
HandleError(Error::ERROR_STARTING_CONCIERGE); HandleError(InstallerError::kErrorStartingConcierge);
return; return;
} }
UpdateInstallingState(InstallationState::CREATE_DISK_IMAGE); UpdateInstallingState(InstallerState::kCreateDiskImage);
} }
void CrostiniInstaller::OnDiskImageCreated( void CrostiniInstaller::OnDiskImageCreated(
bool success, bool success,
vm_tools::concierge::DiskImageStatus status, vm_tools::concierge::DiskImageStatus status,
int64_t disk_size_available) { int64_t disk_size_available) {
DCHECK_EQ(installing_state_, InstallationState::CREATE_DISK_IMAGE); DCHECK_EQ(installing_state_, InstallerState::kCreateDiskImage);
if (!success) { if (!success) {
HandleError(Error::ERROR_CREATING_DISK_IMAGE); HandleError(InstallerError::kErrorCreatingDiskImage);
return; return;
} }
if (status == vm_tools::concierge::DiskImageStatus::DISK_STATUS_EXISTS) { if (status == vm_tools::concierge::DiskImageStatus::DISK_STATUS_EXISTS) {
...@@ -320,64 +321,64 @@ void CrostiniInstaller::OnDiskImageCreated( ...@@ -320,64 +321,64 @@ void CrostiniInstaller::OnDiskImageCreated(
base::UmaHistogramCustomCounts(kCrostiniDiskImageSizeHistogram, base::UmaHistogramCustomCounts(kCrostiniDiskImageSizeHistogram,
disk_size_available >> 30, 1, 1024, 64); disk_size_available >> 30, 1, 1024, 64);
} }
UpdateInstallingState(InstallationState::START_TERMINA_VM); UpdateInstallingState(InstallerState::kStartTerminaVm);
} }
void CrostiniInstaller::OnVmStarted(bool success) { void CrostiniInstaller::OnVmStarted(bool success) {
DCHECK_EQ(installing_state_, InstallationState::START_TERMINA_VM); DCHECK_EQ(installing_state_, InstallerState::kStartTerminaVm);
if (!success) { if (!success) {
HandleError(Error::ERROR_STARTING_TERMINA); HandleError(InstallerError::kErrorStartingTermina);
return; return;
} }
UpdateInstallingState(InstallationState::CREATE_CONTAINER); UpdateInstallingState(InstallerState::kCreateContainer);
} }
void CrostiniInstaller::OnContainerDownloading(int32_t download_percent) { void CrostiniInstaller::OnContainerDownloading(int32_t download_percent) {
DCHECK_EQ(installing_state_, InstallationState::CREATE_CONTAINER); DCHECK_EQ(installing_state_, InstallerState::kCreateContainer);
container_download_percent_ = base::ClampToRange(download_percent, 0, 100); container_download_percent_ = base::ClampToRange(download_percent, 0, 100);
RunProgressCallback(); RunProgressCallback();
} }
void CrostiniInstaller::OnContainerCreated(CrostiniResult result) { void CrostiniInstaller::OnContainerCreated(CrostiniResult result) {
DCHECK_EQ(installing_state_, InstallationState::CREATE_CONTAINER); DCHECK_EQ(installing_state_, InstallerState::kCreateContainer);
UpdateInstallingState(InstallationState::SETUP_CONTAINER); UpdateInstallingState(InstallerState::kSetupContainer);
} }
void CrostiniInstaller::OnContainerSetup(bool success) { void CrostiniInstaller::OnContainerSetup(bool success) {
DCHECK_EQ(installing_state_, InstallationState::SETUP_CONTAINER); DCHECK_EQ(installing_state_, InstallerState::kSetupContainer);
if (!success) { if (!success) {
if (content::GetNetworkConnectionTracker()->IsOffline()) { if (content::GetNetworkConnectionTracker()->IsOffline()) {
LOG(ERROR) << "Network connection dropped while downloading container"; LOG(ERROR) << "Network connection dropped while downloading container";
HandleError(Error::ERROR_OFFLINE); HandleError(InstallerError::kErrorOffline);
} else { } else {
HandleError(Error::ERROR_SETTING_UP_CONTAINER); HandleError(InstallerError::kErrorSettingUpContainer);
} }
return; return;
} }
UpdateInstallingState(InstallationState::START_CONTAINER); UpdateInstallingState(InstallerState::kStartContainer);
} }
void CrostiniInstaller::OnContainerStarted(CrostiniResult result) { void CrostiniInstaller::OnContainerStarted(CrostiniResult result) {
DCHECK_EQ(installing_state_, InstallationState::START_CONTAINER); DCHECK_EQ(installing_state_, InstallerState::kStartContainer);
if (result != CrostiniResult::SUCCESS) { if (result != CrostiniResult::SUCCESS) {
LOG(ERROR) << "Failed to start container with error code: " LOG(ERROR) << "Failed to start container with error code: "
<< static_cast<int>(result); << static_cast<int>(result);
HandleError(Error::ERROR_STARTING_CONTAINER); HandleError(InstallerError::kErrorStartingContainer);
return; return;
} }
UpdateInstallingState(InstallationState::FETCH_SSH_KEYS); UpdateInstallingState(InstallerState::kFetchSshKeys);
} }
void CrostiniInstaller::OnSshKeysFetched(bool success) { void CrostiniInstaller::OnSshKeysFetched(bool success) {
DCHECK_EQ(installing_state_, InstallationState::FETCH_SSH_KEYS); DCHECK_EQ(installing_state_, InstallerState::kFetchSshKeys);
if (!success) { if (!success) {
HandleError(Error::ERROR_FETCHING_SSH_KEYS); HandleError(InstallerError::kErrorFetchingSshKeys);
return; return;
} }
UpdateInstallingState(InstallationState::MOUNT_CONTAINER); UpdateInstallingState(InstallerState::kMountContainer);
} }
bool CrostiniInstaller::CanInstall() { bool CrostiniInstaller::CanInstall() {
...@@ -397,48 +398,48 @@ void CrostiniInstaller::RunProgressCallback() { ...@@ -397,48 +398,48 @@ void CrostiniInstaller::RunProgressCallback() {
int state_max_seconds = 1; int state_max_seconds = 1;
switch (installing_state_) { switch (installing_state_) {
case InstallationState::START: case InstallerState::kStart:
state_start_mark = 0; state_start_mark = 0;
state_end_mark = 0; state_end_mark = 0;
break; break;
case InstallationState::INSTALL_IMAGE_LOADER: case InstallerState::kInstallImageLoader:
state_start_mark = 0.0; state_start_mark = 0.0;
state_end_mark = 0.25; state_end_mark = 0.25;
state_max_seconds = 30; state_max_seconds = 30;
break; break;
case InstallationState::START_CONCIERGE: case InstallerState::kStartConcierge:
state_start_mark = 0.25; state_start_mark = 0.25;
state_end_mark = 0.26; state_end_mark = 0.26;
break; break;
case InstallationState::CREATE_DISK_IMAGE: case InstallerState::kCreateDiskImage:
state_start_mark = 0.26; state_start_mark = 0.26;
state_end_mark = 0.27; state_end_mark = 0.27;
break; break;
case InstallationState::START_TERMINA_VM: case InstallerState::kStartTerminaVm:
state_start_mark = 0.27; state_start_mark = 0.27;
state_end_mark = 0.35; state_end_mark = 0.35;
state_max_seconds = 8; state_max_seconds = 8;
break; break;
case InstallationState::CREATE_CONTAINER: case InstallerState::kCreateContainer:
state_start_mark = 0.35; state_start_mark = 0.35;
state_end_mark = 0.90; state_end_mark = 0.90;
state_max_seconds = 180; state_max_seconds = 180;
break; break;
case InstallationState::SETUP_CONTAINER: case InstallerState::kSetupContainer:
state_start_mark = 0.90; state_start_mark = 0.90;
state_end_mark = 0.95; state_end_mark = 0.95;
state_max_seconds = 8; state_max_seconds = 8;
break; break;
case InstallationState::START_CONTAINER: case InstallerState::kStartContainer:
state_start_mark = 0.95; state_start_mark = 0.95;
state_end_mark = 0.99; state_end_mark = 0.99;
state_max_seconds = 8; state_max_seconds = 8;
break; break;
case InstallationState::FETCH_SSH_KEYS: case InstallerState::kFetchSshKeys:
state_start_mark = 0.99; state_start_mark = 0.99;
state_end_mark = 1; state_end_mark = 1;
break; break;
case InstallationState::MOUNT_CONTAINER: case InstallerState::kMountContainer:
state_start_mark = 1; state_start_mark = 1;
state_end_mark = 1; state_end_mark = 1;
break; break;
...@@ -448,7 +449,7 @@ void CrostiniInstaller::RunProgressCallback() { ...@@ -448,7 +449,7 @@ void CrostiniInstaller::RunProgressCallback() {
double state_fraction = time_in_state.InSecondsF() / state_max_seconds; double state_fraction = time_in_state.InSecondsF() / state_max_seconds;
if (installing_state_ == InstallationState::CREATE_CONTAINER) { if (installing_state_ == InstallerState::kCreateContainer) {
// In CREATE_CONTAINER, consume half the progress bar with downloading, // In CREATE_CONTAINER, consume half the progress bar with downloading,
// the rest with time. // the rest with time.
state_fraction = state_fraction =
...@@ -470,7 +471,8 @@ void CrostiniInstaller::UpdateState(State new_state) { ...@@ -470,7 +471,8 @@ void CrostiniInstaller::UpdateState(State new_state) {
// We are not calling the progress callback here because 1) there is nothing // We are not calling the progress callback here because 1) there is nothing
// interesting to report; 2) We reach here from |Install()|, so calling the // interesting to report; 2) We reach here from |Install()|, so calling the
// callback risk reentering |Install()|'s caller. // callback risk reentering |Install()|'s caller.
UpdateInstallingState(InstallationState::START, /*run_callback=*/false); UpdateInstallingState(InstallerState::kStart,
/*run_callback=*/false);
state_progress_timer_.Start( state_progress_timer_.Start(
FROM_HERE, base::TimeDelta::FromMilliseconds(500), FROM_HERE, base::TimeDelta::FromMilliseconds(500),
...@@ -482,7 +484,7 @@ void CrostiniInstaller::UpdateState(State new_state) { ...@@ -482,7 +484,7 @@ void CrostiniInstaller::UpdateState(State new_state) {
} }
void CrostiniInstaller::UpdateInstallingState( void CrostiniInstaller::UpdateInstallingState(
InstallationState new_installing_state, InstallerState new_installing_state,
bool run_callback) { bool run_callback) {
DCHECK_EQ(state_, State::INSTALLING); DCHECK_EQ(state_, State::INSTALLING);
installing_state_start_time_ = base::Time::Now(); installing_state_start_time_ = base::Time::Now();
...@@ -493,9 +495,9 @@ void CrostiniInstaller::UpdateInstallingState( ...@@ -493,9 +495,9 @@ void CrostiniInstaller::UpdateInstallingState(
} }
} }
void CrostiniInstaller::HandleError(Error error) { void CrostiniInstaller::HandleError(InstallerError error) {
DCHECK_EQ(state_, State::INSTALLING); DCHECK_EQ(state_, State::INSTALLING);
DCHECK_NE(error, Error::NONE); DCHECK_NE(error, InstallerError::kNone);
UMA_HISTOGRAM_LONG_TIMES(kCrostiniTimeToInstallError, UMA_HISTOGRAM_LONG_TIMES(kCrostiniTimeToInstallError,
base::TimeTicks::Now() - install_start_time_); base::TimeTicks::Now() - install_start_time_);
...@@ -540,12 +542,12 @@ void CrostiniInstaller::OnCrostiniRestartFinished(CrostiniResult result) { ...@@ -540,12 +542,12 @@ void CrostiniInstaller::OnCrostiniRestartFinished(CrostiniResult result) {
// |CrostiniRestarter::OnMountEvent()|), so if we reach here (i.e. // |CrostiniRestarter::OnMountEvent()|), so if we reach here (i.e.
// |state_| has not been set to |ERROR| but this function receives a // |state_| has not been set to |ERROR| but this function receives a
// failure result), something else is probably wrong. // failure result), something else is probably wrong.
HandleError(Error::ERROR_MOUNTING_CONTAINER); HandleError(InstallerError::kErrorMountingContainer);
} }
return; return;
} }
DCHECK_EQ(installing_state_, InstallationState::MOUNT_CONTAINER); DCHECK_EQ(installing_state_, InstallerState::kMountContainer);
// Reset state to allow |Install()| again in case the user remove and // Reset state to allow |Install()| again in case the user remove and
// re-install crostini. // re-install crostini.
UpdateState(State::IDLE); UpdateState(State::IDLE);
...@@ -561,7 +563,7 @@ void CrostiniInstaller::OnCrostiniRestartFinished(CrostiniResult result) { ...@@ -561,7 +563,7 @@ void CrostiniInstaller::OnCrostiniRestartFinished(CrostiniResult result) {
free_disk_space_ >> 20); free_disk_space_ >> 20);
} }
std::move(result_callback_).Run(Error::NONE); std::move(result_callback_).Run(InstallerError::kNone);
progress_callback_.Reset(); progress_callback_.Reset();
if (!skip_launching_terminal_for_testing_) { if (!skip_launching_terminal_for_testing_) {
...@@ -582,23 +584,23 @@ void CrostiniInstaller::OnAvailableDiskSpace(int64_t bytes) { ...@@ -582,23 +584,23 @@ void CrostiniInstaller::OnAvailableDiskSpace(int64_t bytes) {
return; return;
} }
DCHECK_EQ(installing_state_, InstallationState::START); DCHECK_EQ(installing_state_, InstallerState::kStart);
free_disk_space_ = bytes; free_disk_space_ = bytes;
// Don't enforce minimum disk size on dev box or trybots because // Don't enforce minimum disk size on dev box or trybots because
// base::SysInfo::AmountOfFreeDiskSpace returns zero in testing. // base::SysInfo::AmountOfFreeDiskSpace returns zero in testing.
if (free_disk_space_ < kMinimumFreeDiskSpace && if (free_disk_space_ < kMinimumFreeDiskSpace &&
base::SysInfo::IsRunningOnChromeOS()) { base::SysInfo::IsRunningOnChromeOS()) {
HandleError(Error::ERROR_INSUFFICIENT_DISK_SPACE); HandleError(InstallerError::kErrorInsufficientDiskSpace);
return; return;
} }
if (content::GetNetworkConnectionTracker()->IsOffline()) { if (content::GetNetworkConnectionTracker()->IsOffline()) {
HandleError(Error::ERROR_OFFLINE); HandleError(InstallerError::kErrorOffline);
return; return;
} }
UpdateInstallingState(InstallationState::INSTALL_IMAGE_LOADER); UpdateInstallingState(InstallerState::kInstallImageLoader);
// Kick off the Crostini Restart sequence. We will be added as an observer. // Kick off the Crostini Restart sequence. We will be added as an observer.
restart_id_ = restart_id_ =
......
...@@ -101,9 +101,10 @@ class CrostiniInstaller : public KeyedService, ...@@ -101,9 +101,10 @@ class CrostiniInstaller : public KeyedService,
void RunProgressCallback(); void RunProgressCallback();
void UpdateState(State new_state); void UpdateState(State new_state);
void UpdateInstallingState(InstallationState new_installing_state, void UpdateInstallingState(
crostini::mojom::InstallerState new_installing_state,
bool run_callback = true); bool run_callback = true);
void HandleError(Error error); void HandleError(crostini::mojom::InstallerError error);
void FinishCleanup(crostini::CrostiniResult result); void FinishCleanup(crostini::CrostiniResult result);
void RecordSetupResult(SetupResult result); void RecordSetupResult(SetupResult result);
...@@ -113,7 +114,7 @@ class CrostiniInstaller : public KeyedService, ...@@ -113,7 +114,7 @@ class CrostiniInstaller : public KeyedService,
Profile* profile_; Profile* profile_;
State state_ = State::IDLE; State state_ = State::IDLE;
InstallationState installing_state_; crostini::mojom::InstallerState installing_state_;
base::TimeTicks install_start_time_; base::TimeTicks install_start_time_;
base::Time installing_state_start_time_; base::Time installing_state_start_time_;
base::RepeatingTimer state_progress_timer_; base::RepeatingTimer state_progress_timer_;
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module crostini.mojom;
enum InstallerState {
kStart, // Just started installation
kInstallImageLoader, // Loading the Termina VM component.
kStartConcierge, // Starting the Concierge D-Bus client.
kCreateDiskImage, // Creating the image for the Termina VM.
kStartTerminaVm, // Starting the Termina VM.
kCreateContainer, // Creating the container inside the Termina VM.
kSetupContainer, // Setting up the container inside the Termina VM.
kStartContainer, // Starting the container inside the Termina VM.
kFetchSshKeys, // Fetch ssh keys from concierge.
kMountContainer, // Do sshfs mount of container.
};
enum InstallerError {
kNone,
kErrorLoadingTermina,
kErrorStartingConcierge,
kErrorCreatingDiskImage,
kErrorStartingTermina,
kErrorStartingContainer,
kErrorOffline,
kErrorFetchingSshKeys,
kErrorMountingContainer,
kErrorSettingUpContainer,
kErrorInsufficientDiskSpace,
};
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "chrome/browser/chromeos/crostini/crostini_installer_types.mojom-forward.h"
namespace crostini { namespace crostini {
...@@ -23,38 +24,12 @@ class CrostiniInstallerUIDelegate { ...@@ -23,38 +24,12 @@ class CrostiniInstallerUIDelegate {
crostini::CrostiniInstallerUIDelegate::kDownloadSizeInBytes + crostini::CrostiniInstallerUIDelegate::kDownloadSizeInBytes +
kMinimumDiskSize; kMinimumDiskSize;
enum class InstallationState {
START, // Just started installation
INSTALL_IMAGE_LOADER, // Loading the Termina VM component.
START_CONCIERGE, // Starting the Concierge D-Bus client.
CREATE_DISK_IMAGE, // Creating the image for the Termina VM.
START_TERMINA_VM, // Starting the Termina VM.
CREATE_CONTAINER, // Creating the container inside the Termina VM.
SETUP_CONTAINER, // Setting up the container inside the Termina VM.
START_CONTAINER, // Starting the container inside the Termina VM.
FETCH_SSH_KEYS, // Fetch ssh keys from concierge.
MOUNT_CONTAINER, // Do sshfs mount of container.
};
enum class Error {
NONE,
ERROR_LOADING_TERMINA,
ERROR_STARTING_CONCIERGE,
ERROR_CREATING_DISK_IMAGE,
ERROR_STARTING_TERMINA,
ERROR_STARTING_CONTAINER,
ERROR_OFFLINE,
ERROR_FETCHING_SSH_KEYS,
ERROR_MOUNTING_CONTAINER,
ERROR_SETTING_UP_CONTAINER,
ERROR_INSUFFICIENT_DISK_SPACE,
};
// |progress_fraction| ranges from 0.0 to 1.0. // |progress_fraction| ranges from 0.0 to 1.0.
using ProgressCallback = using ProgressCallback =
base::RepeatingCallback<void(InstallationState state, base::RepeatingCallback<void(crostini::mojom::InstallerState state,
double progress_fraction)>; double progress_fraction)>;
using ResultCallback = base::OnceCallback<void(Error error)>; using ResultCallback =
base::OnceCallback<void(crostini::mojom::InstallerError error)>;
// Start the installation. |progress_callback| will be called multiple times // Start the installation. |progress_callback| will be called multiple times
// until |result_callback| is called. The crostini terminal will be launched // until |result_callback| is called. The crostini terminal will be launched
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/test/bind_test_util.h" #include "base/test/bind_test_util.h"
#include "base/test/metrics/histogram_tester.h" #include "base/test/metrics/histogram_tester.h"
#include "chrome/browser/chromeos/crostini/crostini_installer_types.mojom.h"
#include "chrome/browser/chromeos/crostini/crostini_installer_ui_delegate.h" #include "chrome/browser/chromeos/crostini/crostini_installer_ui_delegate.h"
#include "chrome/browser/chromeos/crostini/crostini_test_helper.h" #include "chrome/browser/chromeos/crostini/crostini_test_helper.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
...@@ -22,6 +23,8 @@ ...@@ -22,6 +23,8 @@
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
using crostini::mojom::InstallerError;
using crostini::mojom::InstallerState;
using testing::_; using testing::_;
using testing::AnyNumber; using testing::AnyNumber;
using testing::Expectation; using testing::Expectation;
...@@ -38,14 +41,12 @@ class CrostiniInstallerTest : public testing::Test { ...@@ -38,14 +41,12 @@ class CrostiniInstallerTest : public testing::Test {
public: public:
using ResultCallback = CrostiniInstallerUIDelegate::ResultCallback; using ResultCallback = CrostiniInstallerUIDelegate::ResultCallback;
using ProgressCallback = CrostiniInstallerUIDelegate::ProgressCallback; using ProgressCallback = CrostiniInstallerUIDelegate::ProgressCallback;
using Error = CrostiniInstallerUIDelegate::Error;
using InstallationState = CrostiniInstallerUIDelegate::InstallationState;
class MockCallbacks { class MockCallbacks {
public: public:
MOCK_METHOD2(OnProgress, MOCK_METHOD2(OnProgress,
void(InstallationState state, double progress_fraction)); void(InstallerState state, double progress_fraction));
MOCK_METHOD1(OnFinished, void(Error error)); MOCK_METHOD1(OnFinished, void(InstallerError error));
MOCK_METHOD0(OnCanceled, void()); MOCK_METHOD0(OnCanceled, void());
}; };
...@@ -184,7 +185,8 @@ TEST_F(CrostiniInstallerTest, InstallFlow) { ...@@ -184,7 +185,8 @@ TEST_F(CrostiniInstallerTest, InstallFlow) {
MountPath("sshfs://testing_profile@hostname:", _, _, _, _, _)) MountPath("sshfs://testing_profile@hostname:", _, _, _, _, _))
.WillOnce(Invoke(&mount_path_waiter_, &MountPathWaiter::MountPath)); .WillOnce(Invoke(&mount_path_waiter_, &MountPathWaiter::MountPath));
// |OnProgress()| should not happens after |OnFinished()| // |OnProgress()| should not happens after |OnFinished()|
EXPECT_CALL(mock_callbacks_, OnFinished(Error::NONE)).After(expectation_set); EXPECT_CALL(mock_callbacks_, OnFinished(InstallerError::kNone))
.After(expectation_set);
Install(); Install();
mount_path_waiter_.WaitForMountPathCalled(); mount_path_waiter_.WaitForMountPathCalled();
...@@ -268,11 +270,12 @@ TEST_F(CrostiniInstallerTest, CancelAfterStartBeforeCheckDisk) { ...@@ -268,11 +270,12 @@ TEST_F(CrostiniInstallerTest, CancelAfterStartBeforeCheckDisk) {
<< "Installer should recover to installable state"; << "Installer should recover to installable state";
} }
TEST_F(CrostiniInstallerTest, Error) { TEST_F(CrostiniInstallerTest, InstallerError) {
Expectation expect_progresses = Expectation expect_progresses =
EXPECT_CALL(mock_callbacks_, OnProgress(_, _)).Times(AnyNumber()); EXPECT_CALL(mock_callbacks_, OnProgress(_, _)).Times(AnyNumber());
// |OnProgress()| should not happens after |OnFinished()| // |OnProgress()| should not happens after |OnFinished()|
EXPECT_CALL(mock_callbacks_, OnFinished(Error::ERROR_STARTING_TERMINA)) EXPECT_CALL(mock_callbacks_,
OnFinished(InstallerError::kErrorStartingTermina))
.After(expect_progresses); .After(expect_progresses);
// Fake a failure for starting vm. // Fake a failure for starting vm.
......
...@@ -3709,6 +3709,7 @@ jumbo_split_static_library("ui") { ...@@ -3709,6 +3709,7 @@ jumbo_split_static_library("ui") {
"views/plugin_vm/plugin_vm_launcher_view.h", "views/plugin_vm/plugin_vm_launcher_view.h",
] ]
deps += [ deps += [
"//chrome/browser/chromeos/crostini:crostini_installer_types_mojom",
"//chrome/services/app_service/public/cpp:app_update", "//chrome/services/app_service/public/cpp:app_update",
"//chrome/services/app_service/public/cpp:icon_loader", "//chrome/services/app_service/public/cpp:icon_loader",
"//components/services/app_service/public/cpp:app_file_handling", "//components/services/app_service/public/cpp:app_file_handling",
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_functions.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/crostini/crostini_installer.h" #include "chrome/browser/chromeos/crostini/crostini_installer.h"
#include "chrome/browser/chromeos/crostini/crostini_installer_types.mojom.h"
#include "chrome/browser/chromeos/crostini/crostini_installer_ui_delegate.h" #include "chrome/browser/chromeos/crostini/crostini_installer_ui_delegate.h"
#include "chrome/browser/chromeos/crostini/crostini_manager.h" #include "chrome/browser/chromeos/crostini/crostini_manager.h"
#include "chrome/browser/ui/browser_dialogs.h" #include "chrome/browser/ui/browser_dialogs.h"
...@@ -39,11 +40,11 @@ ...@@ -39,11 +40,11 @@
#include "ui/views/window/dialog_client_view.h" #include "ui/views/window/dialog_client_view.h"
using crostini::CrostiniResult; using crostini::CrostiniResult;
using crostini::mojom::InstallerError;
using crostini::mojom::InstallerState;
namespace { namespace {
using Error = crostini::CrostiniInstallerUIDelegate::Error;
CrostiniInstallerView* g_crostini_installer_view = nullptr; CrostiniInstallerView* g_crostini_installer_view = nullptr;
constexpr gfx::Insets kOOBEButtonRowInsets(32, 64, 32, 64); constexpr gfx::Insets kOOBEButtonRowInsets(32, 64, 32, 64);
...@@ -65,36 +66,36 @@ base::string16 GetHelpUrlWithBoard(const std::string& original_url) { ...@@ -65,36 +66,36 @@ base::string16 GetHelpUrlWithBoard(const std::string& original_url) {
"&b=" + base::SysInfo::GetLsbReleaseBoard()); "&b=" + base::SysInfo::GetLsbReleaseBoard());
} }
base::string16 GetErrorMessage(Error error) { base::string16 GetErrorMessage(InstallerError error) {
switch (error) { switch (error) {
case Error::ERROR_LOADING_TERMINA: case InstallerError::kErrorLoadingTermina:
return l10n_util::GetStringUTF16( return l10n_util::GetStringUTF16(
IDS_CROSTINI_INSTALLER_LOAD_TERMINA_ERROR); IDS_CROSTINI_INSTALLER_LOAD_TERMINA_ERROR);
case Error::ERROR_STARTING_CONCIERGE: case InstallerError::kErrorStartingConcierge:
return l10n_util::GetStringUTF16( return l10n_util::GetStringUTF16(
IDS_CROSTINI_INSTALLER_START_CONCIERGE_ERROR); IDS_CROSTINI_INSTALLER_START_CONCIERGE_ERROR);
case Error::ERROR_CREATING_DISK_IMAGE: case InstallerError::kErrorCreatingDiskImage:
return l10n_util::GetStringUTF16( return l10n_util::GetStringUTF16(
IDS_CROSTINI_INSTALLER_CREATE_DISK_IMAGE_ERROR); IDS_CROSTINI_INSTALLER_CREATE_DISK_IMAGE_ERROR);
case Error::ERROR_STARTING_TERMINA: case InstallerError::kErrorStartingTermina:
return l10n_util::GetStringUTF16( return l10n_util::GetStringUTF16(
IDS_CROSTINI_INSTALLER_START_TERMINA_VM_ERROR); IDS_CROSTINI_INSTALLER_START_TERMINA_VM_ERROR);
case Error::ERROR_STARTING_CONTAINER: case InstallerError::kErrorStartingContainer:
return l10n_util::GetStringUTF16( return l10n_util::GetStringUTF16(
IDS_CROSTINI_INSTALLER_START_CONTAINER_ERROR); IDS_CROSTINI_INSTALLER_START_CONTAINER_ERROR);
case Error::ERROR_OFFLINE: case InstallerError::kErrorOffline:
return l10n_util::GetStringFUTF16(IDS_CROSTINI_INSTALLER_OFFLINE_ERROR, return l10n_util::GetStringFUTF16(IDS_CROSTINI_INSTALLER_OFFLINE_ERROR,
ui::GetChromeOSDeviceName()); ui::GetChromeOSDeviceName());
case Error::ERROR_FETCHING_SSH_KEYS: case InstallerError::kErrorFetchingSshKeys:
return l10n_util::GetStringUTF16( return l10n_util::GetStringUTF16(
IDS_CROSTINI_INSTALLER_FETCH_SSH_KEYS_ERROR); IDS_CROSTINI_INSTALLER_FETCH_SSH_KEYS_ERROR);
case Error::ERROR_MOUNTING_CONTAINER: case InstallerError::kErrorMountingContainer:
return l10n_util::GetStringUTF16( return l10n_util::GetStringUTF16(
IDS_CROSTINI_INSTALLER_MOUNT_CONTAINER_ERROR); IDS_CROSTINI_INSTALLER_MOUNT_CONTAINER_ERROR);
case Error::ERROR_SETTING_UP_CONTAINER: case InstallerError::kErrorSettingUpContainer:
return l10n_util::GetStringUTF16( return l10n_util::GetStringUTF16(
IDS_CROSTINI_INSTALLER_SETUP_CONTAINER_ERROR); IDS_CROSTINI_INSTALLER_SETUP_CONTAINER_ERROR);
case Error::ERROR_INSUFFICIENT_DISK_SPACE: case InstallerError::kErrorInsufficientDiskSpace:
return l10n_util::GetStringFUTF16( return l10n_util::GetStringFUTF16(
IDS_CROSTINI_INSTALLER_INSUFFICIENT_DISK, IDS_CROSTINI_INSTALLER_INSUFFICIENT_DISK,
ui::FormatBytesWithUnits( ui::FormatBytesWithUnits(
...@@ -212,7 +213,7 @@ bool CrostiniInstallerView::Accept() { ...@@ -212,7 +213,7 @@ bool CrostiniInstallerView::Accept() {
learn_more_link_ = nullptr; learn_more_link_ = nullptr;
state_ = State::INSTALLING; state_ = State::INSTALLING;
installing_state_ = InstallationState::START; installing_state_ = InstallerState::kStart;
progress_bar_->SetValue(0); progress_bar_->SetValue(0);
progress_bar_->SetVisible(true); progress_bar_->SetVisible(true);
SetMessageLabel(); SetMessageLabel();
...@@ -367,7 +368,7 @@ CrostiniInstallerView::~CrostiniInstallerView() { ...@@ -367,7 +368,7 @@ CrostiniInstallerView::~CrostiniInstallerView() {
g_crostini_installer_view = nullptr; g_crostini_installer_view = nullptr;
} }
void CrostiniInstallerView::OnProgressUpdate(InstallationState installing_state, void CrostiniInstallerView::OnProgressUpdate(InstallerState installing_state,
double progress_fraction) { double progress_fraction) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK_EQ(state_, State::INSTALLING); DCHECK_EQ(state_, State::INSTALLING);
...@@ -382,10 +383,10 @@ void CrostiniInstallerView::OnProgressUpdate(InstallationState installing_state, ...@@ -382,10 +383,10 @@ void CrostiniInstallerView::OnProgressUpdate(InstallationState installing_state,
GetWidget()->GetRootView()->Layout(); GetWidget()->GetRootView()->Layout();
} }
void CrostiniInstallerView::OnInstallFinished(Error error) { void CrostiniInstallerView::OnInstallFinished(InstallerError error) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (error == Error::NONE) { if (error == InstallerError::kNone) {
state_ = State::SUCCESS; state_ = State::SUCCESS;
GetWidget()->Close(); GetWidget()->Close();
return; return;
...@@ -417,34 +418,34 @@ void CrostiniInstallerView::SetMessageLabel() { ...@@ -417,34 +418,34 @@ void CrostiniInstallerView::SetMessageLabel() {
int message_id = 0; int message_id = 0;
switch (installing_state_) { switch (installing_state_) {
case InstallationState::INSTALL_IMAGE_LOADER: case InstallerState::kInstallImageLoader:
message_id = IDS_CROSTINI_INSTALLER_LOAD_TERMINA_MESSAGE; message_id = IDS_CROSTINI_INSTALLER_LOAD_TERMINA_MESSAGE;
break; break;
case InstallationState::START_CONCIERGE: case InstallerState::kStartConcierge:
message_id = IDS_CROSTINI_INSTALLER_START_CONCIERGE_MESSAGE; message_id = IDS_CROSTINI_INSTALLER_START_CONCIERGE_MESSAGE;
break; break;
case InstallationState::CREATE_DISK_IMAGE: case InstallerState::kCreateDiskImage:
message_id = IDS_CROSTINI_INSTALLER_CREATE_DISK_IMAGE_MESSAGE; message_id = IDS_CROSTINI_INSTALLER_CREATE_DISK_IMAGE_MESSAGE;
break; break;
case InstallationState::START_TERMINA_VM: case InstallerState::kStartTerminaVm:
message_id = IDS_CROSTINI_INSTALLER_START_TERMINA_VM_MESSAGE; message_id = IDS_CROSTINI_INSTALLER_START_TERMINA_VM_MESSAGE;
break; break;
case InstallationState::CREATE_CONTAINER: case InstallerState::kCreateContainer:
// TODO(lxj): we are using the same message as for |START_CONTAINER|, // TODO(lxj): we are using the same message as for |START_CONTAINER|,
// which is weird because user is going to see message "start container" // which is weird because user is going to see message "start container"
// then "setup container" and then "start container" again. // then "setup container" and then "start container" again.
message_id = IDS_CROSTINI_INSTALLER_START_CONTAINER_MESSAGE; message_id = IDS_CROSTINI_INSTALLER_START_CONTAINER_MESSAGE;
break; break;
case InstallationState::SETUP_CONTAINER: case InstallerState::kSetupContainer:
message_id = IDS_CROSTINI_INSTALLER_SETUP_CONTAINER_MESSAGE; message_id = IDS_CROSTINI_INSTALLER_SETUP_CONTAINER_MESSAGE;
break; break;
case InstallationState::START_CONTAINER: case InstallerState::kStartContainer:
message_id = IDS_CROSTINI_INSTALLER_START_CONTAINER_MESSAGE; message_id = IDS_CROSTINI_INSTALLER_START_CONTAINER_MESSAGE;
break; break;
case InstallationState::FETCH_SSH_KEYS: case InstallerState::kFetchSshKeys:
message_id = IDS_CROSTINI_INSTALLER_FETCH_SSH_KEYS_MESSAGE; message_id = IDS_CROSTINI_INSTALLER_FETCH_SSH_KEYS_MESSAGE;
break; break;
case InstallationState::MOUNT_CONTAINER: case InstallerState::kMountContainer:
message_id = IDS_CROSTINI_INSTALLER_MOUNT_CONTAINER_MESSAGE; message_id = IDS_CROSTINI_INSTALLER_MOUNT_CONTAINER_MESSAGE;
break; break;
default: default:
......
...@@ -43,10 +43,6 @@ class CrostiniInstallerView : public views::DialogDelegateView, ...@@ -43,10 +43,6 @@ class CrostiniInstallerView : public views::DialogDelegateView,
void LinkClicked(views::Link* source, int event_flags) override; void LinkClicked(views::Link* source, int event_flags) override;
private: private:
using InstallationState =
crostini::CrostiniInstallerUIDelegate::InstallationState;
using Error = crostini::CrostiniInstallerUIDelegate::Error;
enum class State { enum class State {
PROMPT, PROMPT,
INSTALLING, INSTALLING,
...@@ -61,14 +57,14 @@ class CrostiniInstallerView : public views::DialogDelegateView, ...@@ -61,14 +57,14 @@ class CrostiniInstallerView : public views::DialogDelegateView,
crostini::CrostiniInstallerUIDelegate* delegate); crostini::CrostiniInstallerUIDelegate* delegate);
~CrostiniInstallerView() override; ~CrostiniInstallerView() override;
void OnProgressUpdate(InstallationState installing_state, void OnProgressUpdate(crostini::mojom::InstallerState installing_state,
double progress_fraction); double progress_fraction);
void OnInstallFinished(Error error); void OnInstallFinished(crostini::mojom::InstallerError error);
void OnCanceled(); void OnCanceled();
void SetMessageLabel(); void SetMessageLabel();
State state_ = State::PROMPT; State state_ = State::PROMPT;
InstallationState installing_state_; crostini::mojom::InstallerState installing_state_;
Profile* profile_; Profile* profile_;
crostini::CrostiniInstallerUIDelegate* delegate_; crostini::CrostiniInstallerUIDelegate* delegate_;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/chromeos/crostini/crostini_installer_types.mojom.h"
#include "chrome/browser/ui/views/crostini/crostini_installer_view.h" #include "chrome/browser/ui/views/crostini/crostini_installer_view.h"
#include "base/bind.h" #include "base/bind.h"
...@@ -22,9 +23,8 @@ ...@@ -22,9 +23,8 @@
#include "ui/base/ui_base_types.h" #include "ui/base/ui_base_types.h"
#include "ui/views/window/dialog_client_view.h" #include "ui/views/window/dialog_client_view.h"
using Error = crostini::CrostiniInstallerUIDelegate::Error; using crostini::mojom::InstallerError;
using InstallationState = using crostini::mojom::InstallerState;
crostini::CrostiniInstallerUIDelegate::InstallationState;
class CrostiniInstallerViewBrowserTest : public CrostiniDialogBrowserTest { class CrostiniInstallerViewBrowserTest : public CrostiniDialogBrowserTest {
public: public:
...@@ -82,11 +82,9 @@ IN_PROC_BROWSER_TEST_F(CrostiniInstallerViewBrowserTest, InstallFlow) { ...@@ -82,11 +82,9 @@ IN_PROC_BROWSER_TEST_F(CrostiniInstallerViewBrowserTest, InstallFlow) {
<< "Install() should be called"; << "Install() should be called";
EXPECT_TRUE(fake_delegate_.result_callback_); EXPECT_TRUE(fake_delegate_.result_callback_);
fake_delegate_.progress_callback_.Run(InstallationState::CREATE_CONTAINER, fake_delegate_.progress_callback_.Run(InstallerState::kCreateContainer, 0.4);
0.4); fake_delegate_.progress_callback_.Run(InstallerState::kMountContainer, 0.8);
fake_delegate_.progress_callback_.Run(InstallationState::MOUNT_CONTAINER, std::move(fake_delegate_.result_callback_).Run(InstallerError::kNone);
0.8);
std::move(fake_delegate_.result_callback_).Run(Error::NONE);
// This allow the dialog to be destructed. // This allow the dialog to be destructed.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -104,7 +102,7 @@ IN_PROC_BROWSER_TEST_F(CrostiniInstallerViewBrowserTest, ErrorThenCancel) { ...@@ -104,7 +102,7 @@ IN_PROC_BROWSER_TEST_F(CrostiniInstallerViewBrowserTest, ErrorThenCancel) {
ASSERT_TRUE(fake_delegate_.result_callback_); ASSERT_TRUE(fake_delegate_.result_callback_);
std::move(fake_delegate_.result_callback_) std::move(fake_delegate_.result_callback_)
.Run(Error::ERROR_CREATING_DISK_IMAGE); .Run(InstallerError::kErrorCreatingDiskImage);
EXPECT_FALSE(ActiveView()->GetWidget()->IsClosed()); EXPECT_FALSE(ActiveView()->GetWidget()->IsClosed());
EXPECT_TRUE(HasEnabledAcceptButton()); EXPECT_TRUE(HasEnabledAcceptButton());
...@@ -129,7 +127,7 @@ IN_PROC_BROWSER_TEST_F(CrostiniInstallerViewBrowserTest, ErrorThenRetry) { ...@@ -129,7 +127,7 @@ IN_PROC_BROWSER_TEST_F(CrostiniInstallerViewBrowserTest, ErrorThenRetry) {
ASSERT_TRUE(fake_delegate_.result_callback_); ASSERT_TRUE(fake_delegate_.result_callback_);
std::move(fake_delegate_.result_callback_) std::move(fake_delegate_.result_callback_)
.Run(Error::ERROR_CREATING_DISK_IMAGE); .Run(InstallerError::kErrorCreatingDiskImage);
EXPECT_FALSE(ActiveView()->GetWidget()->IsClosed()); EXPECT_FALSE(ActiveView()->GetWidget()->IsClosed());
EXPECT_TRUE(HasEnabledAcceptButton()); EXPECT_TRUE(HasEnabledAcceptButton());
...@@ -140,7 +138,7 @@ IN_PROC_BROWSER_TEST_F(CrostiniInstallerViewBrowserTest, ErrorThenRetry) { ...@@ -140,7 +138,7 @@ IN_PROC_BROWSER_TEST_F(CrostiniInstallerViewBrowserTest, ErrorThenRetry) {
EXPECT_TRUE(fake_delegate_.result_callback_) EXPECT_TRUE(fake_delegate_.result_callback_)
<< "Install() should be called again"; << "Install() should be called again";
std::move(fake_delegate_.result_callback_).Run(Error::NONE); std::move(fake_delegate_.result_callback_).Run(InstallerError::kNone);
// This allow the dialog to be destructed. // This allow the dialog to be destructed.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
......
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