Commit 5efdaf2d authored by François Degros's avatar François Degros Committed by Commit Bot

Files app: Fix presubmit errors in file_operation_manager.js

Replaced var with const / let.
Simplified filterSameDirectoryEntry using async / await.
Fixed comments that didn't match the code.

BUG=778674
TEST=autoninja -C out/release ui/file_manager:closure_compile
TEST=testing/xvfb.py out/release/browser_tests --gtest_filter="*/FilesApp*" --test-launcher-jobs=8

Change-Id: I73a2c2e980ef21b61e3b9513e72327d275249a9e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2211587Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Commit-Queue: François Degros <fdegros@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771660}
parent d0a196f2
...@@ -110,7 +110,7 @@ class FileOperationManagerImpl { ...@@ -110,7 +110,7 @@ class FileOperationManagerImpl {
* @return {Object} Status object with optional volume information. * @return {Object} Status object with optional volume information.
*/ */
getTaskStatus(task) { getTaskStatus(task) {
let status = task.getStatus(); const status = task.getStatus();
// If there's no target directory name, use the volume name for UI display. // If there's no target directory name, use the volume name for UI display.
if (status['targetDirEntryName'] === '' && task.targetDirEntry) { if (status['targetDirEntryName'] === '' && task.targetDirEntry) {
const entry = /** {Entry} */ (task.targetDirEntry); const entry = /** {Entry} */ (task.targetDirEntry);
...@@ -129,7 +129,7 @@ class FileOperationManagerImpl { ...@@ -129,7 +129,7 @@ class FileOperationManagerImpl {
let task = null; let task = null;
// If the task is not on progress, remove it immediately. // If the task is not on progress, remove it immediately.
for (var i = 0; i < this.pendingCopyTasks_.length; i++) { for (let i = 0; i < this.pendingCopyTasks_.length; i++) {
task = this.pendingCopyTasks_[i]; task = this.pendingCopyTasks_[i];
if (task.taskId !== taskId) { if (task.taskId !== taskId) {
continue; continue;
...@@ -148,7 +148,7 @@ class FileOperationManagerImpl { ...@@ -148,7 +148,7 @@ class FileOperationManagerImpl {
} }
} }
for (var i = 0; i < this.deleteTasks_.length; i++) { for (let i = 0; i < this.deleteTasks_.length; i++) {
task = this.deleteTasks_[i]; task = this.deleteTasks_[i];
if (task.taskId !== taskId) { if (task.taskId !== taskId) {
continue; continue;
...@@ -171,26 +171,16 @@ class FileOperationManagerImpl { ...@@ -171,26 +171,16 @@ class FileOperationManagerImpl {
* target directory. * target directory.
* @param {boolean} isMove True if the operation is "move", otherwise (i.e. * @param {boolean} isMove True if the operation is "move", otherwise (i.e.
* if the operation is "copy") false. * if the operation is "copy") false.
* @return {Promise} Promise fulfilled with the filtered entry. This is not * @return {!Promise<Array<Entry>>} Promise fulfilled with the filtered entry.
* rejected. * This is not rejected.
*/ */
filterSameDirectoryEntry(sourceEntries, targetEntry, isMove) { async filterSameDirectoryEntry(sourceEntries, targetEntry, isMove) {
if (!isMove) { if (!isMove) {
return Promise.resolve(sourceEntries); return sourceEntries;
} }
// Utility function to concat arrays.
const compactArrays = arrays => {
return arrays.filter(element => {
return !!element;
});
};
// Call processEntry for each item of entries.
const processEntries = entries => {
const promises = entries.map(processFileOrDirectoryEntries);
return Promise.all(promises).then(compactArrays);
};
// Check all file entries and keeps only those need sharing operation. // Check all file entries and keeps only those need sharing operation.
var processFileOrDirectoryEntries = entry => { const processEntry = entry => {
return new Promise(resolve => { return new Promise(resolve => {
entry.getParent( entry.getParent(
inParentEntry => { inParentEntry => {
...@@ -206,7 +196,12 @@ class FileOperationManagerImpl { ...@@ -206,7 +196,12 @@ class FileOperationManagerImpl {
}); });
}); });
}; };
return processEntries(sourceEntries);
// Call processEntry for each item of sourceEntries.
const result = await Promise.all(sourceEntries.map(processEntry));
// Remove null entries.
return result.filter(entry => !!entry);
} }
/** /**
......
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