Skip to content

Commit

Permalink
Suport MyFiles for crostini path sharing
Browse files Browse the repository at this point in the history
Bug: 878324
Change-Id: I09976b84a4016d687c505f0808d92d57ab87ee7c
Reviewed-on: https://chromium-review.googlesource.com/c/1312138
Commit-Queue: Joel Hockey <joelhockey@chromium.org>
Reviewed-by: Nicholas Verne <nverne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606262}
  • Loading branch information
Joel Hockey authored and Commit Bot committed Nov 8, 2018
1 parent ee2630a commit c4453e2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
19 changes: 12 additions & 7 deletions chrome/browser/chromeos/crostini/crostini_share_path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,24 @@ void CallSeneschalSharePath(
vm_tools::seneschal::SharePathRequest request;
base::FilePath drivefs_path;
base::FilePath relative_path;
drive::DriveIntegrationService* integration_service =
drive::DriveIntegrationServiceFactory::GetForProfile(profile);
drive::DriveIntegrationService* integration_service = nullptr;
if (base::FeatureList::IsEnabled(chromeos::features::kDriveFs)) {
integration_service =
drive::DriveIntegrationServiceFactory::GetForProfile(profile);
}
base::FilePath drivefs_mount_point_path;
base::FilePath drivefs_mount_name;

// Allow download directory and subdirs.
// Allow MyFiles|Downloads directory and subdirs.
bool allowed_path = false;
base::FilePath downloads =
file_manager::util::GetDownloadsFolderForProfile(profile);
if (downloads == path || downloads.AppendRelativePath(path, &relative_path)) {
base::FilePath my_files =
file_manager::util::GetMyFilesFolderForProfile(profile);
if (my_files == path || my_files.AppendRelativePath(path, &relative_path)) {
allowed_path = true;
request.set_storage_location(
vm_tools::seneschal::SharePathRequest::DOWNLOADS);
base::FeatureList::IsEnabled(chromeos::features::kMyFilesVolume)
? vm_tools::seneschal::SharePathRequest::MY_FILES
: vm_tools::seneschal::SharePathRequest::DOWNLOADS);
request.set_owner_id(crostini::CryptohomeIdForProfile(profile));
} else if (base::FeatureList::IsEnabled(chromeos::features::kDriveFs) &&
integration_service &&
Expand Down
31 changes: 30 additions & 1 deletion chrome/browser/chromeos/crostini/crostini_share_path_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ class CrostiniSharePathTest : public testing::Test {
chromeos::switches::kCrostiniFiles);

// Setup for DriveFS.
features_.InitAndEnableFeature(chromeos::features::kDriveFs);
user_manager.AddUser(AccountId::FromUserEmailGaiaId(
profile()->GetProfileUserName(), "12345"));
profile()->GetPrefs()->SetString(drive::prefs::kDriveFsProfileSalt, "a");
Expand Down Expand Up @@ -167,6 +166,19 @@ TEST_F(CrostiniSharePathTest, SuccessDownloadsRoot) {
run_loop()->Run();
}

TEST_F(CrostiniSharePathTest, SuccessMyFilesRoot) {
features_.InitAndEnableFeature(chromeos::features::kMyFilesVolume);
base::FilePath my_files =
file_manager::util::GetMyFilesFolderForProfile(profile());
SharePath(profile(), "vm-running", my_files, PERSIST_NO,
base::BindOnce(&CrostiniSharePathTest::SharePathCallback,
base::Unretained(this), Persist::NO,
SeneschalClientCalled::YES,
&vm_tools::seneschal::SharePathRequest::MY_FILES, "",
Success::YES, "", run_loop()->QuitClosure()));
run_loop()->Run();
}

TEST_F(CrostiniSharePathTest, SuccessNoPersist) {
SharePath(profile(), "vm-running", share_path_, PERSIST_NO,
base::BindOnce(
Expand All @@ -189,6 +201,7 @@ TEST_F(CrostiniSharePathTest, SuccessPersist) {
}

TEST_F(CrostiniSharePathTest, SuccessDriveFsMyDrive) {
features_.InitAndEnableFeature(chromeos::features::kDriveFs);
SharePath(profile(), "vm-running", drivefs_.Append("root").Append("my"),
PERSIST_NO,
base::BindOnce(
Expand All @@ -199,7 +212,19 @@ TEST_F(CrostiniSharePathTest, SuccessDriveFsMyDrive) {
run_loop()->Run();
}

TEST_F(CrostiniSharePathTest, FailureDriveFsDisabled) {
features_.InitAndDisableFeature(chromeos::features::kDriveFs);
SharePath(
profile(), "vm-running", drivefs_.Append("root").Append("my"), PERSIST_NO,
base::BindOnce(&CrostiniSharePathTest::SharePathCallback,
base::Unretained(this), Persist::NO,
SeneschalClientCalled::NO, nullptr, "my", Success::NO,
"Path is not allowed", run_loop()->QuitClosure()));
run_loop()->Run();
}

TEST_F(CrostiniSharePathTest, SuccessDriveFsMyDriveRoot) {
features_.InitAndEnableFeature(chromeos::features::kDriveFs);
SharePath(profile(), "vm-running", drivefs_.Append("root"), PERSIST_NO,
base::BindOnce(
&CrostiniSharePathTest::SharePathCallback,
Expand All @@ -210,6 +235,7 @@ TEST_F(CrostiniSharePathTest, SuccessDriveFsMyDriveRoot) {
}

TEST_F(CrostiniSharePathTest, FailDriveFsRoot) {
features_.InitAndEnableFeature(chromeos::features::kDriveFs);
SharePath(profile(), "vm-running", drivefs_, PERSIST_NO,
base::BindOnce(&CrostiniSharePathTest::SharePathCallback,
base::Unretained(this), Persist::NO,
Expand All @@ -219,6 +245,7 @@ TEST_F(CrostiniSharePathTest, FailDriveFsRoot) {
}

TEST_F(CrostiniSharePathTest, SuccessDriveFsTeamDrives) {
features_.InitAndEnableFeature(chromeos::features::kDriveFs);
SharePath(profile(), "vm-running",
drivefs_.Append("team_drives").Append("team"), PERSIST_NO,
base::BindOnce(
Expand All @@ -230,6 +257,7 @@ TEST_F(CrostiniSharePathTest, SuccessDriveFsTeamDrives) {
}

TEST_F(CrostiniSharePathTest, SuccessDriveFsComputers) {
features_.InitAndEnableFeature(chromeos::features::kDriveFs);
SharePath(profile(), "vm-running", drivefs_.Append("Computers").Append("pc"),
PERSIST_NO,
base::BindOnce(
Expand All @@ -241,6 +269,7 @@ TEST_F(CrostiniSharePathTest, SuccessDriveFsComputers) {
}

TEST_F(CrostiniSharePathTest, FailDriveFsTrash) {
features_.InitAndEnableFeature(chromeos::features::kDriveFs);
SharePath(profile(), "vm-running",
drivefs_.Append(".Trash").Append("in-the-trash"), PERSIST_NO,
base::BindOnce(&CrostiniSharePathTest::SharePathCallback,
Expand Down

0 comments on commit c4453e2

Please sign in to comment.