Commit f1b61622 authored by Joel Hockey's avatar Joel Hockey Committed by Commit Bot

Crostini: Allow any observers of RemoveCrostini

This will be used at least in tast tests where the UI is used to
uninstall crostini, but the test must wait until uninstall completes
and receives result.

Bug: 849438
Change-Id: Ia44dfa80cae957082bc1641bc5540f69b0ba3b40
Reviewed-on: https://chromium-review.googlesource.com/1236616Reviewed-by: default avatarNicholas Verne <nverne@chromium.org>
Commit-Queue: Joel Hockey <joelhockey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593056}
parent 48b9f7f3
......@@ -1109,6 +1109,11 @@ void CrostiniManager::AddShutdownContainerCallback(
std::make_tuple(vm_name, container_name), std::move(shutdown_callback));
}
void CrostiniManager::AddRemoveCrostiniCallback(
RemoveCrostiniCallback remove_callback) {
remove_crostini_callbacks_.emplace_back(std::move(remove_callback));
}
void CrostiniManager::AddInstallLinuxPackageProgressObserver(
InstallLinuxPackageProgressObserver* observer) {
install_linux_package_progress_observers_.AddObserver(observer);
......@@ -1549,12 +1554,21 @@ void CrostiniManager::OnGetContainerSshKeys(
void CrostiniManager::RemoveCrostini(std::string vm_name,
std::string container_name,
RemoveCrostiniCallback callback) {
AddRemoveCrostiniCallback(std::move(callback));
auto crostini_remover = base::MakeRefCounted<CrostiniRemover>(
profile_, std::move(vm_name), std::move(container_name),
std::move(callback));
base::BindOnce(&CrostiniManager::OnRemoveCrostini,
weak_ptr_factory_.GetWeakPtr()));
crostini_remover->RemoveCrostini();
}
void CrostiniManager::OnRemoveCrostini(ConciergeClientResult result) {
for (auto& callback : remove_crostini_callbacks_) {
std::move(callback).Run(result);
}
remove_crostini_callbacks_.clear();
}
void CrostiniManager::FinishRestart(CrostiniRestarter* restarter,
ConciergeClientResult result) {
auto key = std::make_pair(restarter->vm_name(), restarter->container_name());
......
......@@ -331,6 +331,9 @@ class CrostiniManager : public KeyedService,
std::string container_name,
ShutdownContainerCallback shutdown_callback);
// Adds a callback to receive uninstall notification.
void AddRemoveCrostiniCallback(RemoveCrostiniCallback remove_callback);
// Add/remove observers for package install progress.
void AddInstallLinuxPackageProgressObserver(
InstallLinuxPackageProgressObserver* observer);
......@@ -501,6 +504,9 @@ class CrostiniManager : public KeyedService,
void FinishRestart(CrostiniRestarter* restarter,
ConciergeClientResult result);
// Callback for CrostiniManager::RemoveCrostini.
void OnRemoveCrostini(ConciergeClientResult result);
Profile* profile_;
std::string owner_id_;
......@@ -539,6 +545,8 @@ class CrostiniManager : public KeyedService,
// Running containers as keyed by vm name.
std::multimap<std::string, std::string> running_containers_;
std::vector<RemoveCrostiniCallback> remove_crostini_callbacks_;
base::ObserverList<InstallLinuxPackageProgressObserver>::Unchecked
install_linux_package_progress_observers_;
......
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