Commit 2bdadb69 authored by matterchen's avatar matterchen Committed by Commit Bot

Share fonts with the GuestOS

We want the GuestOS to have access to the same fonts as ChromeOS. To
achieve this, on TerminaVM startup we will ask Seneschal to share the
fonts directory with the VM. Tremplin will then share this with the
container.

ChromeOS             VM                    Container
/usr/share/fonts --> /mnt/shared/fonts --> /mnt/chromeos/fonts

Relies-on: CL:1975215
Bug: chromium:903631
Test: Verifies it shares the font directory, test will come later
Change-Id: Idcc321e7b14ee1b4535d9a6e6cdaeb051d8cb98d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1973490
Commit-Queue: Matthew Chen <matterchen@google.com>
Reviewed-by: default avatarFergus Dall <sidereal@google.com>
Reviewed-by: default avatarJoel Hockey <joelhockey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734276}
parent 3ce59905
......@@ -2132,10 +2132,6 @@ void CrostiniManager::OnStartTerminaVm(
vm_name, base::BindOnce(&CrostiniManager::OnStartTremplin,
weak_ptr_factory_.GetWeakPtr(), vm_name,
std::move(callback)));
// Share folders from Downloads, etc with VM.
guest_os::GuestOsSharePath::GetForProfile(profile_)->SharePersistedPaths(
vm_name, base::DoNothing());
}
void CrostiniManager::OnStartTremplin(std::string vm_name,
......@@ -2145,6 +2141,14 @@ void CrostiniManager::OnStartTremplin(std::string vm_name,
<< vm_name;
UpdateVmState(vm_name, VmState::STARTED);
// Share fonts directory with the VM but don't persist as a shared path.
guest_os::GuestOsSharePath::GetForProfile(profile_)->SharePath(
vm_name, base::FilePath(file_manager::util::kSystemFontsPath),
/*persist=*/false, base::DoNothing());
// Share folders from Downloads, etc with VM.
guest_os::GuestOsSharePath::GetForProfile(profile_)->SharePersistedPaths(
vm_name, base::DoNothing());
// Run the original callback.
std::move(callback).Run(/*success=*/true);
}
......
......@@ -116,6 +116,9 @@ const base::FilePath::CharType kRemovableMediaPath[] =
const base::FilePath::CharType kAndroidFilesPath[] =
FILE_PATH_LITERAL("/run/arc/sdcard/write/emulated/0");
const base::FilePath::CharType kSystemFontsPath[] =
FILE_PATH_LITERAL("/usr/share/fonts");
base::FilePath GetDownloadsFolderForProfile(Profile* profile) {
// Check if FilesApp has a registered path already. This happens for tests.
const std::string mount_point_name =
......
......@@ -24,6 +24,9 @@ extern const base::FilePath::CharType kRemovableMediaPath[];
// Absolute path for the folder containing Android files.
extern const base::FilePath::CharType kAndroidFilesPath[];
// Absolute path for the folder containing font files.
extern const base::FilePath::CharType kSystemFontsPath[];
// Gets the absolute path for the 'Downloads' folder for the |profile|.
base::FilePath GetDownloadsFolderForProfile(Profile* profile);
......
......@@ -222,6 +222,7 @@ void GuestOsSharePath::CallSeneschalSharePath(const std::string& vm_name,
file_manager::util::GetMyFilesFolderForProfile(profile_);
base::FilePath android_files(file_manager::util::kAndroidFilesPath);
base::FilePath removable_media(file_manager::util::kRemovableMediaPath);
base::FilePath system_fonts(file_manager::util::kSystemFontsPath);
base::FilePath linux_files =
file_manager::util::GetCrostiniMountDirectory(profile_);
if (my_files == path || my_files.AppendRelativePath(path, &relative_path)) {
......@@ -292,6 +293,10 @@ void GuestOsSharePath::CallSeneschalSharePath(const std::string& vm_name,
request.set_storage_location(
vm_tools::seneschal::SharePathRequest::LINUX_FILES);
request.set_owner_id(crostini::CryptohomeIdForProfile(profile_));
} else if (path == system_fonts ||
system_fonts.AppendRelativePath(path, &relative_path)) {
allowed_path = true;
request.set_storage_location(vm_tools::seneschal::SharePathRequest::FONTS);
}
if (!allowed_path) {
......
......@@ -502,6 +502,17 @@ TEST_F(GuestOsSharePathTest, FailRemovableRoot) {
run_loop()->Run();
}
TEST_F(GuestOsSharePathTest, SuccessSystemFonts) {
SetUpVolume();
guest_os_share_path_->SharePath(
"vm-running", base::FilePath("/usr/share/fonts"), PERSIST_NO,
base::BindOnce(
&GuestOsSharePathTest::SharePathCallback, base::Unretained(this),
"vm-running", Persist::NO, SeneschalClientCalled::YES,
&vm_tools::seneschal::SharePathRequest::FONTS, "", Success::YES, ""));
run_loop()->Run();
}
TEST_F(GuestOsSharePathTest, SharePathErrorSeneschal) {
features_.InitWithFeatures({features::kCrostini}, {});
GetFakeUserManager()->LoginUser(account_id_);
......
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