Commit 87c8ba39 authored by Fergus Dall's avatar Fergus Dall Committed by Commit Bot

Add a pref to store the list of crostini containers

This is needed because at the current time we have no way to get such a
list, and we arguably shouldn't be trying to handle containers we didn't
set up anyway. The pref is a list of dictionaries, with values for
"vm_name" and "container_name". By default, the pref will be set to
[{vm_name: termina, container_name: penguin}] to handle existing users.

Change-Id: I69437fc3e7675da9058d9f83436edc82c5dc91db
Reviewed-on: https://chromium-review.googlesource.com/c/1429320
Commit-Queue: Fergus Dall <sidereal@google.com>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#626994}
parent 9aa57055
...@@ -4,6 +4,11 @@ ...@@ -4,6 +4,11 @@
#include "chrome/browser/chromeos/crostini/crostini_pref_names.h" #include "chrome/browser/chromeos/crostini/crostini_pref_names.h"
#include <memory>
#include <utility>
#include "base/values.h"
#include "chrome/browser/chromeos/crostini/crostini_util.h"
#include "components/prefs/pref_registry_simple.h" #include "components/prefs/pref_registry_simple.h"
namespace crostini { namespace crostini {
...@@ -19,6 +24,7 @@ const char kCrostiniSharedPaths[] = "crostini.shared_paths"; ...@@ -19,6 +24,7 @@ const char kCrostiniSharedPaths[] = "crostini.shared_paths";
// List of USB devices with their system guid, a name/description and their // List of USB devices with their system guid, a name/description and their
// enabled state for use with Crostini. // enabled state for use with Crostini.
const char kCrostiniSharedUsbDevices[] = "crostini.shared_usb_devices"; const char kCrostiniSharedUsbDevices[] = "crostini.shared_usb_devices";
const char kCrostiniContainers[] = "crostini.containers";
// A boolean preference representing a user level enterprise policy to enable // A boolean preference representing a user level enterprise policy to enable
// Crostini use. // Crostini use.
...@@ -41,6 +47,22 @@ void RegisterProfilePrefs(PrefRegistrySimple* registry) { ...@@ -41,6 +47,22 @@ void RegisterProfilePrefs(PrefRegistrySimple* registry) {
registry->RegisterDictionaryPref(kCrostiniRegistry); registry->RegisterDictionaryPref(kCrostiniRegistry);
registry->RegisterListPref(kCrostiniSharedPaths); registry->RegisterListPref(kCrostiniSharedPaths);
registry->RegisterListPref(kCrostiniSharedUsbDevices); registry->RegisterListPref(kCrostiniSharedUsbDevices);
// Set a default value for crostini.containers to ensure that we track the
// default container even if its creation predates this preference. This
// preference should not be accessed unless crostini is installed
// (i.e. kCrostiniEnabled is true).
base::Value default_container(base::Value::Type::DICTIONARY);
default_container.SetKey("vm_name", base::Value(kCrostiniDefaultVmName));
default_container.SetKey("container_name",
base::Value(kCrostiniDefaultContainerName));
auto default_containers_list =
std::make_unique<base::Value>(base::Value::Type::LIST);
default_containers_list->GetList().push_back(std::move(default_container));
registry->RegisterListPref(kCrostiniContainers,
std::move(default_containers_list));
registry->RegisterBooleanPref(crostini::prefs::kReportCrostiniUsageEnabled, registry->RegisterBooleanPref(crostini::prefs::kReportCrostiniUsageEnabled,
false); false);
registry->RegisterStringPref(kCrostiniLastLaunchVersion, std::string()); registry->RegisterStringPref(kCrostiniLastLaunchVersion, std::string());
......
...@@ -15,6 +15,7 @@ extern const char kCrostiniMimeTypes[]; ...@@ -15,6 +15,7 @@ extern const char kCrostiniMimeTypes[];
extern const char kCrostiniRegistry[]; extern const char kCrostiniRegistry[];
extern const char kCrostiniSharedPaths[]; extern const char kCrostiniSharedPaths[];
extern const char kCrostiniSharedUsbDevices[]; extern const char kCrostiniSharedUsbDevices[];
extern const char kCrostiniContainers[];
extern const char kUserCrostiniAllowedByPolicy[]; extern const char kUserCrostiniAllowedByPolicy[];
......
...@@ -372,6 +372,8 @@ const PrefsUtil::TypedPrefMap& PrefsUtil::GetWhitelistedKeys() { ...@@ -372,6 +372,8 @@ const PrefsUtil::TypedPrefMap& PrefsUtil::GetWhitelistedKeys() {
settings_api::PrefType::PREF_TYPE_LIST; settings_api::PrefType::PREF_TYPE_LIST;
(*s_whitelist)[crostini::prefs::kCrostiniSharedUsbDevices] = (*s_whitelist)[crostini::prefs::kCrostiniSharedUsbDevices] =
settings_api::PrefType::PREF_TYPE_LIST; settings_api::PrefType::PREF_TYPE_LIST;
(*s_whitelist)[crostini::prefs::kCrostiniContainers] =
settings_api::PrefType::PREF_TYPE_LIST;
// Android Apps. // Android Apps.
(*s_whitelist)[arc::prefs::kArcEnabled] = (*s_whitelist)[arc::prefs::kArcEnabled] =
......
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