Commit 5d92cb2a authored by Nicholas Verne's avatar Nicholas Verne Committed by Commit Bot

Stop accidentally reinstalling Crostini

The Linux settings subpage causes a call to crostini::disk::GetDiskInfo
This in turn causes the termina image to download, which is not what we
wanted - we just wanted to use concierge.

Bug: 1096771
Change-Id: I2970121f6f7245083f793d23d03ee8b3356d79f7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2259673
Commit-Queue: Nicholas Verne <nverne@chromium.org>
Commit-Queue: Fergus Dall <sidereal@google.com>
Reviewed-by: default avatarFergus Dall <sidereal@google.com>
Auto-Submit: Nicholas Verne <nverne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781172}
parent 6051d7a7
......@@ -13,6 +13,7 @@
#include "base/system/sys_info.h"
#include "base/task/post_task.h"
#include "base/task/thread_pool.h"
#include "chrome/browser/chromeos/crostini/crostini_features.h"
#include "chrome/browser/chromeos/crostini/crostini_manager.h"
#include "chrome/browser/chromeos/crostini/crostini_simple_types.h"
#include "chrome/browser/chromeos/crostini/crostini_types.mojom.h"
......@@ -51,6 +52,11 @@ void GetDiskInfo(OnceDiskInfoCallback callback,
Profile* profile,
std::string vm_name,
bool full_info) {
if (!CrostiniFeatures::Get()->IsEnabled(profile)) {
std::move(callback).Run(nullptr);
VLOG(1) << "Crostini not enabled. Nothing to do.";
return;
}
if (full_info) {
base::ThreadPool::PostTaskAndReplyWithResult(
FROM_HERE, {base::MayBlock()},
......@@ -65,9 +71,20 @@ void GetDiskInfo(OnceDiskInfoCallback callback,
// error conditions in |OnCrostiniSufficientlyRunning|.
constexpr int64_t kFakeAvailableDiskBytes =
kDiskHeadroomBytes + kRecommendedDiskSizeBytes;
CrostiniManager::GetForProfile(profile)->EnsureConciergeRunning(
base::BindOnce(&OnCrostiniSufficientlyRunning, std::move(callback),
profile, std::move(vm_name), kFakeAvailableDiskBytes));
CrostiniManager::GetForProfile(profile)->StartConcierge(base::BindOnce(
[](OnceDiskInfoCallback callback, Profile* profile, std::string vm_name,
bool success) {
if (!success) {
LOG(ERROR) << "Failed to start concierge";
std::move(callback).Run(nullptr);
return;
}
OnCrostiniSufficientlyRunning(
std::move(callback), profile, std::move(vm_name),
kFakeAvailableDiskBytes, CrostiniResult::SUCCESS);
},
std::move(callback), profile, std::move(vm_name)));
}
}
......@@ -94,8 +111,7 @@ void OnCrostiniSufficientlyRunning(OnceDiskInfoCallback callback,
int64_t free_space,
CrostiniResult result) {
if (result != CrostiniResult::SUCCESS) {
LOG(ERROR) << "Failed to start concierge or start VM: error "
<< static_cast<int>(result);
LOG(ERROR) << "Start VM: error " << static_cast<int>(result);
std::move(callback).Run(nullptr);
} else {
vm_tools::concierge::ListVmDisksRequest request;
......
......@@ -1740,24 +1740,6 @@ class AbortOnVmStartObserver : public CrostiniManager::RestartObserver {
base::WeakPtr<CrostiniManager> crostini_manager_;
};
// Watches the Crostini restarter until the Concierge started phase, then aborts
// the sequence.
class AbortOnConciergeStartObserver : public CrostiniManager::RestartObserver {
public:
explicit AbortOnConciergeStartObserver(
base::WeakPtr<CrostiniManager> crostini_manager)
: crostini_manager_(crostini_manager) {}
void OnConciergeStarted(bool success) override {
if (crostini_manager_) {
crostini_manager_->AbortRestartCrostini(restart_id(), base::DoNothing());
}
}
private:
base::WeakPtr<CrostiniManager> crostini_manager_;
};
} // namespace
void CrostiniManager::UpgradeContainer(const ContainerId& key,
......@@ -1856,30 +1838,6 @@ void CrostiniManager::EnsureVmRunning(const ContainerId& key,
}
}
void CrostiniManager::EnsureConciergeRunning(CrostiniResultCallback callback) {
CrostiniResultCallback inner_callback = base::BindOnce(
[](CrostiniResultCallback final_callback, CrostiniResult result) {
if (result == CrostiniResult::SUCCESS ||
result == CrostiniResult::RESTART_ABORTED) {
// RESTART_ABORTED is expected when we successfully abort after
// launching the VM, turn it into a success since that's what we were
// asked for.
std::move(final_callback).Run(CrostiniResult::SUCCESS);
} else {
std::move(final_callback).Run(result);
}
},
std::move(callback));
if (!IsVmRunning(kCrostiniDefaultVmName)) {
RestartCrostini(
ContainerId::GetDefault(), std::move(inner_callback),
new AbortOnConciergeStartObserver(weak_ptr_factory_.GetWeakPtr()));
} else {
std::move(inner_callback).Run(CrostiniResult::SUCCESS);
}
}
void CrostiniManager::CancelUpgradeContainer(const ContainerId& key,
CrostiniResultCallback callback) {
const auto& vm_name = key.vm_name;
......
......@@ -643,7 +643,6 @@ class CrostiniManager : public KeyedService,
bool ShouldPromptContainerUpgrade(const ContainerId& container_id) const;
void UpgradePromptShown(const ContainerId& container_id);
void EnsureVmRunning(const ContainerId& key, CrostiniResultCallback callback);
void EnsureConciergeRunning(CrostiniResultCallback callback);
bool IsUncleanStartup() const;
void SetUncleanStartupForTesting(bool is_unclean_startup);
void RemoveUncleanSshfsMounts();
......
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