Commit 447ae27d authored by Fergus Dall's avatar Fergus Dall Committed by Commit Bot

Update crostini.containers when creating and destroying LXD containers

Change-Id: If1ce2c1dc88929cce71f60f3980521f8209e8078
Reviewed-on: https://chromium-review.googlesource.com/c/1429300
Commit-Queue: Fergus Dall <sidereal@google.com>
Reviewed-by: default avatarNicholas Verne <nverne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#626995}
parent 87c8ba39
...@@ -1935,6 +1935,8 @@ void CrostiniManager::OnLxdContainerCreated( ...@@ -1935,6 +1935,8 @@ void CrostiniManager::OnLxdContainerCreated(
break; break;
case vm_tools::cicerone::LxdContainerCreatedSignal::CREATED: case vm_tools::cicerone::LxdContainerCreatedSignal::CREATED:
result = CrostiniResult::SUCCESS; result = CrostiniResult::SUCCESS;
AddNewLxdContainerToPrefs(profile_, signal.vm_name(),
signal.container_name());
break; break;
case vm_tools::cicerone::LxdContainerCreatedSignal::DOWNLOAD_TIMED_OUT: case vm_tools::cicerone::LxdContainerCreatedSignal::DOWNLOAD_TIMED_OUT:
result = CrostiniResult::CONTAINER_DOWNLOAD_TIMED_OUT; result = CrostiniResult::CONTAINER_DOWNLOAD_TIMED_OUT;
......
...@@ -101,6 +101,8 @@ void CrostiniRemover::StopConciergeFinished(bool is_successful) { ...@@ -101,6 +101,8 @@ void CrostiniRemover::StopConciergeFinished(bool is_successful) {
CrostiniManager::GetForProfile(profile_)->UninstallTerminaComponent()) { CrostiniManager::GetForProfile(profile_)->UninstallTerminaComponent()) {
profile_->GetPrefs()->SetBoolean(prefs::kCrostiniEnabled, false); profile_->GetPrefs()->SetBoolean(prefs::kCrostiniEnabled, false);
profile_->GetPrefs()->ClearPref(prefs::kCrostiniLastDiskSize); profile_->GetPrefs()->ClearPref(prefs::kCrostiniLastDiskSize);
profile_->GetPrefs()->Set(prefs::kCrostiniContainers,
base::Value(base::Value::Type::LIST));
} }
std::move(callback_).Run(CrostiniResult::SUCCESS); std::move(callback_).Run(CrostiniResult::SUCCESS);
} }
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "chrome/browser/chromeos/crostini/crostini_util.h" #include "chrome/browser/chromeos/crostini/crostini_util.h"
#include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/feature_list.h" #include "base/feature_list.h"
...@@ -408,4 +410,17 @@ bool IsUnaffiliatedCrostiniAllowedByPolicy() { ...@@ -408,4 +410,17 @@ bool IsUnaffiliatedCrostiniAllowedByPolicy() {
return true; return true;
} }
void AddNewLxdContainerToPrefs(Profile* profile,
std::string vm_name,
std::string container_name) {
auto* pref_service = profile->GetPrefs();
base::Value new_container(base::Value::Type::DICTIONARY);
new_container.SetKey("vm_name", base::Value(vm_name));
new_container.SetKey("container_name", base::Value(container_name));
ListPrefUpdate updater(pref_service, crostini::prefs::kCrostiniContainers);
updater->GetList().emplace_back(std::move(new_container));
}
} // namespace crostini } // namespace crostini
...@@ -139,6 +139,11 @@ constexpr char kCrostiniDefaultImageAlias[] = "debian/stretch"; ...@@ -139,6 +139,11 @@ constexpr char kCrostiniDefaultImageAlias[] = "debian/stretch";
// policy. // policy.
bool IsUnaffiliatedCrostiniAllowedByPolicy(); bool IsUnaffiliatedCrostiniAllowedByPolicy();
// Add a newly created LXD container to the kCrostiniContainers pref
void AddNewLxdContainerToPrefs(Profile* profile,
std::string vm_name,
std::string container_name);
} // namespace crostini } // namespace crostini
#endif // CHROME_BROWSER_CHROMEOS_CROSTINI_CROSTINI_UTIL_H_ #endif // CHROME_BROWSER_CHROMEOS_CROSTINI_CROSTINI_UTIL_H_
...@@ -149,6 +149,13 @@ bool CrostiniInstallerView::Accept() { ...@@ -149,6 +149,13 @@ bool CrostiniInstallerView::Accept() {
UpdateState(State::INSTALL_START); UpdateState(State::INSTALL_START);
profile_->GetPrefs()->SetBoolean(crostini::prefs::kCrostiniEnabled, true); profile_->GetPrefs()->SetBoolean(crostini::prefs::kCrostiniEnabled, true);
// The default value of kCrostiniContainers is set to migrate existing
// crostini users who don't have the pref set. If crostini is being installed,
// then we know the user must not actually have any containers yet, so we set
// this pref to the empty list.
profile_->GetPrefs()->Set(crostini::prefs::kCrostiniContainers,
base::Value(base::Value::Type::LIST));
progress_bar_->SetVisible(true); progress_bar_->SetVisible(true);
// |learn_more_link_| should only be present in State::PROMPT. // |learn_more_link_| should only be present in State::PROMPT.
......
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