Commit 14e8ee71 authored by Joel Hockey's avatar Joel Hockey Committed by Commit Bot

Refactor Plugin VM move dialog

Refactor dialog into static function where it can be reused by drag and
drop.

Event type name 'failed_plugin_vm_directory_not_shared' will also be
used by CrostiniEventType.

Remove FAILED_PLUGIN_VM_TASK_EXTERNAL_DRIVE error and only use
FAILED_PLUGIN_VM_DIRECTORY_NOT_SHARED which is slightly renamed.
FilesApp can detect when entries are in MyFiles volume or not and show
the correct message of move vs copy.

Bug: 1144138
Change-Id: I14072bcc3514f598428936dcad04b0468e432de8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2557819Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Commit-Queue: Joel Hockey <joelhockey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#830856}
parent b20d589b
......@@ -135,9 +135,7 @@ auto ConvertLaunchPluginVmAppResultToTaskResult(
case plugin_vm::LaunchPluginVmAppResult::SUCCESS:
return fmp::TASK_RESULT_MESSAGE_SENT;
case plugin_vm::LaunchPluginVmAppResult::FAILED_DIRECTORY_NOT_SHARED:
return fmp::TASK_RESULT_FAILED_PLUGIN_VM_TASK_DIRECTORY_NOT_SHARED;
case plugin_vm::LaunchPluginVmAppResult::FAILED_FILE_ON_EXTERNAL_DRIVE:
return fmp::TASK_RESULT_FAILED_PLUGIN_VM_TASK_EXTERNAL_DRIVE;
return fmp::TASK_RESULT_FAILED_PLUGIN_VM_DIRECTORY_NOT_SHARED;
case plugin_vm::LaunchPluginVmAppResult::FAILED:
return fmp::TASK_RESULT_FAILED;
}
......
......@@ -184,10 +184,7 @@ void LaunchPluginVmApp(Profile* profile,
!file_manager::util::ConvertFileSystemURLToPathInsideVM(
profile, url, vm_mount, /*map_crostini_home=*/false, &file_path)) {
return std::move(callback).Run(
file_manager::util::GetMyFilesFolderForProfile(profile).IsParent(
url.path())
? LaunchPluginVmAppResult::FAILED_DIRECTORY_NOT_SHARED
: LaunchPluginVmAppResult::FAILED_FILE_ON_EXTERNAL_DRIVE,
LaunchPluginVmAppResult::FAILED_DIRECTORY_NOT_SHARED,
"Only files in shared dirs are supported. Got: " + url.DebugString());
}
// Convert slashes: '/' => '\'.
......
......@@ -27,7 +27,6 @@ enum class LaunchPluginVmAppResult {
SUCCESS,
FAILED,
FAILED_DIRECTORY_NOT_SHARED,
FAILED_FILE_ON_EXTERNAL_DRIVE,
};
using LaunchArg = absl::variant<storage::FileSystemURL, std::string>;
......
......@@ -202,7 +202,7 @@ TEST_F(PluginVmFilesTest, LaunchAppFail) {
LaunchPluginVmApp(&profile_, app_id_, {url},
base::BindOnce(capture_result, &actual_result));
task_environment_.RunUntilIdle();
EXPECT_EQ(LaunchPluginVmAppResult::FAILED_FILE_ON_EXTERNAL_DRIVE,
EXPECT_EQ(LaunchPluginVmAppResult::FAILED_DIRECTORY_NOT_SHARED,
actual_result);
}
......
......@@ -169,10 +169,8 @@ enum TaskResult {
failed,
// No URL is specified.
empty,
// The task was a |plugin_vm| task, and the file was in a unshared directory
failed_plugin_vm_task_directory_not_shared,
// The task was a |plugin_vm| task, and the file was in an external drive.
failed_plugin_vm_task_external_drive
// The task was a |plugin_vm| task, and the file was in an unshared directory
failed_plugin_vm_directory_not_shared
};
// Drive share type.
......
......@@ -181,9 +181,8 @@ chrome.fileManagerPrivate.TaskResult = {
MESSAGE_SENT: 'message_sent',
FAILED: 'failed',
EMPTY: 'empty',
FAILED_PLUGIN_VM_TASK_DIRECTORY_NOT_SHARED:
'failed_plugin_vm_task_directory_not_shared',
FAILED_PLUGIN_VM_TASK_EXTERNAL_DRIVE: 'failed_plugin_vm_task_external_drive',
FAILED_PLUGIN_VM_DIRECTORY_NOT_SHARED:
'failed_plugin_vm_directory_not_shared',
};
/** @enum {string} */
......
......@@ -481,6 +481,60 @@ class FileTasks {
location.rootType === VolumeManagerCommon.RootType.CROSTINI;
}
/**
* @param {!Entry} entry
* @param {!VolumeManager} volumeManager
* @return {boolean} True if the entry is from MyFiles.
*/
static isMyFilesEntry(entry, volumeManager) {
const location = volumeManager.getLocationInfo(entry);
return !!location &&
location.rootType === VolumeManagerCommon.RootType.DOWNLOADS;
}
/**
* @param {!Array<!Entry>} entries Selected entries to be moved or copied.
* @param {!VolumeManager} volumeManager
* @param {!FileManagerUI} ui FileManager UI to show dialog.
* @param {string} title Dialog title.
* @param {?FileTransferController} fileTransferController
* @param {!DirectoryModel} directoryModel
*/
static showPluginVmMoveDialog(
entries, volumeManager, ui, title, fileTransferController,
directoryModel) {
if (entries.length == 0) {
return;
}
const isMyFiles = FileTasks.isMyFilesEntry(entries[0], volumeManager);
const [messageId, buttonId, toMove] = isMyFiles ?
[
'UNABLE_TO_OPEN_WITH_PLUGIN_VM_DIRECTORY_NOT_SHARED_MESSAGE',
'CONFIRM_MOVE_BUTTON_LABEL',
true,
] :
[
'UNABLE_TO_OPEN_WITH_PLUGIN_VM_EXTERNAL_DRIVE_MESSAGE',
'CONFIRM_COPY_BUTTON_LABEL',
false,
];
const dialog = new FilesConfirmDialog(ui.element);
dialog.setOkLabel(strf(buttonId));
dialog.show(strf(messageId, title), async () => {
if (!fileTransferController) {
console.error('FileTransferController not set');
return;
}
const pvmDir = await FileTasks.getPvmSharedDir_(volumeManager);
fileTransferController.executePaste(new FileTransferController.PastePlan(
entries.map(e => e.toURL()), [], pvmDir,
assert(volumeManager.getLocationInfo(pvmDir)), toMove));
directoryModel.changeDirectoryEntry(pvmDir);
});
}
/**
* Executes default task.
*
......@@ -666,38 +720,10 @@ class FileTasks {
}
});
break;
case taskResult.FAILED_PLUGIN_VM_TASK_DIRECTORY_NOT_SHARED:
case taskResult.FAILED_PLUGIN_VM_TASK_EXTERNAL_DRIVE:
const [messageId, buttonId, toMove] =
result == taskResult.FAILED_PLUGIN_VM_TASK_DIRECTORY_NOT_SHARED ?
[
'UNABLE_TO_OPEN_WITH_PLUGIN_VM_DIRECTORY_NOT_SHARED_MESSAGE',
'CONFIRM_MOVE_BUTTON_LABEL',
true,
] :
[
'UNABLE_TO_OPEN_WITH_PLUGIN_VM_EXTERNAL_DRIVE_MESSAGE',
'CONFIRM_COPY_BUTTON_LABEL',
false,
];
const dialog = new FilesConfirmDialog(this.ui_.element);
dialog.setOkLabel(strf(buttonId));
dialog.show(
strf(messageId, task.title), async () => {
if (!this.fileTransferController_) {
console.error('FileTransferController not set');
return;
}
const pvmDir = await this.getPvmSharedDir_();
this.fileTransferController_.executePaste(
new FileTransferController.PastePlan(
this.entries_.map(e => e.toURL()), [], pvmDir,
assert(this.volumeManager_.getLocationInfo(pvmDir)),
toMove));
this.directoryModel_.changeDirectoryEntry(pvmDir);
});
case taskResult.FAILED_PLUGIN_VM_DIRECTORY_NOT_SHARED:
FileTasks.showPluginVmMoveDialog(
this.entries_, this.volumeManager_, this.ui_, task.title,
this.fileTransferController_, this.directoryModel_);
break;
}
};
......@@ -1280,9 +1306,12 @@ class FileTasks {
return null;
}
async getPvmSharedDir_() {
/**
* @param {!VolumeManager} volumeManager
*/
static async getPvmSharedDir_(volumeManager) {
return new Promise((resolve, reject) => {
this.volumeManager_
volumeManager
.getCurrentProfileVolumeInfo(VolumeManagerCommon.VolumeType.DOWNLOADS)
.fileSystem.root.getDirectory(
'PvmDefault', {create: false},
......
......@@ -122,8 +122,7 @@ function setUp() {
},
TaskResult: {
MESSAGE_SENT: 'test_ms_task',
FAILED_PLUGIN_VM_TASK_DIRECTORY_NOT_SHARED: 'test_fpvtdns_task',
FAILED_PLUGIN_VM_TASK_EXTERNAL_DRIVE: 'test_fpvted_task',
FAILED_PLUGIN_VM_DIRECTORY_NOT_SHARED: 'test_fpvdns_task',
},
getFileTasks: function(entries, callback) {
setTimeout(callback.bind(null, [mockTask]), 0);
......
......@@ -123,7 +123,7 @@ testcase.pluginVmDirectoryNotSharedErrorDialog = async () => {
]);
await remoteCall.waitUntilTaskExecutes(
appId, 'plugin-vm-app-id|pluginvm|open-with',
['failed_plugin_vm_task_directory_not_shared']);
['failed_plugin_vm_directory_not_shared']);
await remoteCall.waitForElement(
appId, '.cr-dialog-frame:not(#default-task-dialog):not([hidden])');
......@@ -146,7 +146,8 @@ testcase.pluginVmDirectoryNotSharedErrorDialog = async () => {
};
testcase.pluginVmFileOnExternalDriveErrorDialog = async () => {
const appId = await setupAndWaitUntilReady(RootPath.DOWNLOADS);
// Use files outside of MyFiles to show 'copy' rather than 'move'.
const appId = await setupAndWaitUntilReady(RootPath.DRIVE);
// Override the tasks so the "Open with Plugin VM App" button becomes a
// dropdown option.
......@@ -189,7 +190,7 @@ testcase.pluginVmFileOnExternalDriveErrorDialog = async () => {
]);
await remoteCall.waitUntilTaskExecutes(
appId, 'plugin-vm-app-id|pluginvm|open-with',
['failed_plugin_vm_task_external_drive']);
['failed_plugin_vm_directory_not_shared']);
await remoteCall.waitForElement(
appId, '.cr-dialog-frame:not(#default-task-dialog):not([hidden])');
......
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