Commit 90ed3e55 authored by Nicholas Verne's avatar Nicholas Verne Committed by Commit Bot

IsRegistered check is now async

It uses a blocking PathExists call under the hood, so cannot be called
sync on the UI thread.

The IsRegistered check now runs when MaybeUpgradeCrostini runs, which is
at user session startup time

Bug: 870117
Change-Id: I000887e2e76a0cbebfe7c12a37fe1e7d7911e22d
Reviewed-on: https://chromium-review.googlesource.com/1159936Reviewed-by: default avatarTimothy Loh <timloh@chromium.org>
Commit-Queue: Nicholas Verne <nverne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580091}
parent 25037c65
...@@ -410,17 +410,33 @@ CrostiniManager::CrostiniManager() : weak_ptr_factory_(this) { ...@@ -410,17 +410,33 @@ CrostiniManager::CrostiniManager() : weak_ptr_factory_(this) {
CrostiniManager::~CrostiniManager() {} CrostiniManager::~CrostiniManager() {}
// static
bool CrostiniManager::IsCrosTerminaInstalled() { bool CrostiniManager::IsCrosTerminaInstalled() {
// |component_manager| can be nullptr in tests. return is_cros_termina_registered_;
}
void CrostiniManager::MaybeUpgradeCrostini(Profile* profile) {
if (!IsCrostiniAllowedForProfile(profile)) {
return;
}
auto* component_manager = auto* component_manager =
g_browser_process->platform_part()->cros_component_manager(); g_browser_process->platform_part()->cros_component_manager();
return component_manager && if (!component_manager) {
component_manager->IsRegistered(imageloader::kTerminaComponentName); // |component_manager| may be nullptr in unit tests.
return;
}
base::PostTaskWithTraitsAndReplyWithResult(
FROM_HERE, {base::MayBlock()},
base::BindOnce(&component_updater::CrOSComponentManager::IsRegistered,
base::Unretained(component_manager),
imageloader::kTerminaComponentName),
base::BindOnce(&CrostiniManager::MaybeUpgradeCrostiniAfterTerminaCheck,
weak_ptr_factory_.GetWeakPtr()));
} }
void CrostiniManager::MaybeUpgradeCrostini(Profile* profile) { void CrostiniManager::MaybeUpgradeCrostiniAfterTerminaCheck(
if (!IsCrostiniAllowedForProfile(profile) || !IsCrosTerminaInstalled()) { bool is_registered) {
is_cros_termina_registered_ = is_registered;
if (!is_cros_termina_registered_) {
return; return;
} }
termina_update_check_needed_ = true; termina_update_check_needed_ = true;
...@@ -469,7 +485,7 @@ void CrostiniManager::InstallTerminaComponent(BoolCallback callback) { ...@@ -469,7 +485,7 @@ void CrostiniManager::InstallTerminaComponent(BoolCallback callback) {
DCHECK(cros_component_manager); DCHECK(cros_component_manager);
bool major_update_required = bool major_update_required =
IsCrosTerminaInstalled() && is_cros_termina_registered_ &&
cros_component_manager cros_component_manager
->GetCompatiblePath(imageloader::kTerminaComponentName) ->GetCompatiblePath(imageloader::kTerminaComponentName)
.empty(); .empty();
......
...@@ -145,7 +145,7 @@ class CrostiniManager : public chromeos::ConciergeClient::Observer, ...@@ -145,7 +145,7 @@ class CrostiniManager : public chromeos::ConciergeClient::Observer,
}; };
// Checks if the cros-termina component is installed. // Checks if the cros-termina component is installed.
static bool IsCrosTerminaInstalled(); bool IsCrosTerminaInstalled();
// Generate the URL for Crostini terminal application. // Generate the URL for Crostini terminal application.
static GURL GenerateVshInCroshUrl( static GURL GenerateVshInCroshUrl(
...@@ -427,6 +427,10 @@ class CrostiniManager : public chromeos::ConciergeClient::Observer, ...@@ -427,6 +427,10 @@ class CrostiniManager : public chromeos::ConciergeClient::Observer,
GetContainerSshKeysCallback callback, GetContainerSshKeysCallback callback,
base::Optional<vm_tools::concierge::ContainerSshKeysResponse> reply); base::Optional<vm_tools::concierge::ContainerSshKeysResponse> reply);
// Helper for CrostiniManager::MaybeUpgradeCrostini. Separated because the
// checking registration code may block.
void MaybeUpgradeCrostiniAfterTerminaCheck(bool is_registered);
// Helper for CrostiniManager::CreateDiskImage. Separated so it can be run // Helper for CrostiniManager::CreateDiskImage. Separated so it can be run
// off the main thread. // off the main thread.
void CreateDiskImageAfterSizeCheck( void CreateDiskImageAfterSizeCheck(
...@@ -435,6 +439,7 @@ class CrostiniManager : public chromeos::ConciergeClient::Observer, ...@@ -435,6 +439,7 @@ class CrostiniManager : public chromeos::ConciergeClient::Observer,
int64_t free_disk_size); int64_t free_disk_size);
bool skip_restart_for_testing_ = false; bool skip_restart_for_testing_ = false;
bool is_cros_termina_registered_ = false;
bool termina_update_check_needed_ = false; bool termina_update_check_needed_ = false;
// Pending StartContainer callbacks are keyed by <owner_id, vm_name, // Pending StartContainer callbacks are keyed by <owner_id, vm_name,
......
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