Commit b4dab60e authored by Jérémie Boulic's avatar Jérémie Boulic Committed by Chromium LUCI CQ

[Files app] Generate modules for file_operation_util.js and dependencies

Module generation for the following JS files in //ui/file_manager/:
- file_manager/common/js/trash.js
- file_manager/background/js/file_operation_util.js
- file_manager/common/js/file_operation_progress_event.js

//u/f/externs/file_operation_progress_event.js moved to
//u/f/file_manager/common/js/file_operation_common.js.

Converting:
- fileOperationUtil.Error => FileOperationError
- fileOperationUtil.EventRouter.EventType =>
  FileOperationProgressEvent.EventType

This breaks the circular dependency where fileOperationUtil used types
from file_operation_progress_event.js, which used types from
fileOperationUtil.

Bug: 1133186
Change-Id: I8d7270cb037907388086a5b8c0fb2da35b65b070
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2576994Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Commit-Queue: Jeremie Boulic <jboulic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835073}
parent 743d53d0
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
class FileOperationProgressEvent extends Event {
constructor() {
/** @type {fileOperationUtil.EventRouter.EventType} */
this.reason;
/** @type {(fileOperationUtil.Error|undefined)} */
this.error;
/** @public {string} */
this.taskId;
/** @public {?Array<!Entry>} */
this.entries;
/** @public {?Object} */
this.status;
/** @public {number} */
this.totalBytes;
/** @public {number} */
this.processedBytes;
/** @public {?Array<!FilesAppEntry>} */
this.trashedEntries;
}
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
const fileOperationUtil = {};
/** @constructor */
fileOperationUtil.Error = function() {};
/** @constructor */
fileOperationUtil.EventRouter = function() {};
/** @enum {string} */
fileOperationUtil.EventRouter.EventType = {};
......@@ -77,6 +77,7 @@ js_type_check("closure_compile_jsmodules") {
":app_windows.m",
":background_base.m",
":entry_location_impl.m",
":file_operation_util.m",
":metadata_proxy.m",
":test_util_base.m",
":volume_info_impl.m",
......@@ -122,7 +123,6 @@ js_library("closure_compile_externs") {
"//ui/file_manager/externs/background/progress_center.js",
"//ui/file_manager/externs/background_window.js",
"//ui/file_manager/externs/css_rule.js",
"//ui/file_manager/externs/file_operation_progress_event.js",
"//ui/file_manager/externs/launcher_search_provider.js",
"//ui/file_manager/externs/platform.js",
"//ui/file_manager/externs/progress_center_panel.js",
......@@ -362,6 +362,7 @@ js_library("file_operation_manager") {
":file_operation_util",
":trash",
":volume_manager_factory",
"//ui/file_manager/file_manager/common/js:file_operation_common",
"//ui/webui/resources/js:cr",
"//ui/webui/resources/js/cr:event_target",
]
......@@ -383,11 +384,25 @@ js_library("file_operation_util") {
deps = [
":metadata_proxy",
"//ui/file_manager/file_manager/common/js:async_util",
"//ui/file_manager/file_manager/common/js:file_operation_common",
"//ui/file_manager/file_manager/common/js:trash",
"//ui/file_manager/file_manager/common/js:util",
]
externs_list =
[ "//ui/file_manager/externs/file_operation_progress_event.js" ]
}
js_library("file_operation_util.m") {
sources = [ "$root_gen_dir/ui/file_manager/file_manager/background/js/file_operation_util.m.js" ]
deps = [
":metadata_proxy.m",
"//ui/file_manager/file_manager/common/js:async_util.m",
"//ui/file_manager/file_manager/common/js:file_operation_common.m",
"//ui/file_manager/file_manager/common/js:trash.m",
"//ui/file_manager/file_manager/common/js:util.m",
"//ui/webui/resources/js:assert.m",
"//ui/webui/resources/js/cr:event_target.m",
]
extra_deps = [ ":modulize" ]
}
js_library("metadata_proxy") {
......@@ -828,6 +843,7 @@ js_modulizer("modulize") {
"volume_manager_factory.js",
"volume_manager_impl.js",
"volume_manager_util.js",
"file_operation_util.js",
]
namespace_rewrites = cr_namespace_rewrites
......
......@@ -11,6 +11,7 @@
// <include src="../../common/js/progress_center_common.js">
// <include src="../../common/js/importer_common.js">
// <include src="../../common/js/trash.js">
// <include src="../../common/js/file_operation_common.js">
// <include src="metadata_proxy.js">
// <include src="crostini.js">
// <include src="device_handler.js">
......
......@@ -51,7 +51,7 @@ class FileOperationHandler {
* @private
*/
onCopyProgress_(event) {
const EventType = fileOperationUtil.EventRouter.EventType;
const EventType = FileOperationProgressEvent.EventType;
event = /** @type {FileOperationProgressEvent} */ (event);
// Update progress center.
......@@ -129,7 +129,7 @@ class FileOperationHandler {
* @private
*/
onDeleteProgress_(event) {
const EventType = fileOperationUtil.EventRouter.EventType;
const EventType = FileOperationProgressEvent.EventType;
event = /** @type {FileOperationProgressEvent} */ (event);
// Update progress center.
......@@ -224,7 +224,7 @@ class FileOperationHandler {
* @private
*/
static getMessage_(event) {
if (event.reason === fileOperationUtil.EventRouter.EventType.ERROR) {
if (event.reason === FileOperationProgressEvent.EventType.ERROR) {
switch (event.error.code) {
case util.FileOperationErrorType.TARGET_EXISTS:
let name = event.error.data.name;
......
......@@ -79,7 +79,7 @@ function testCopySuccess() {
fileOperationManager.dispatchEvent(
/** @type {!Event} */ (Object.assign(new Event('copy-progress'), {
taskId: 'TASK_ID',
reason: fileOperationUtil.EventRouter.EventType.BEGIN,
reason: FileOperationProgressEvent.EventType.BEGIN,
status: {
operationType: 'COPY',
numRemainingItems: 1,
......@@ -102,7 +102,7 @@ function testCopySuccess() {
fileOperationManager.dispatchEvent(
/** @type {!Event} */ (Object.assign(new Event('copy-progress'), {
taskId: 'TASK_ID',
reason: fileOperationUtil.EventRouter.EventType.SUCCESS,
reason: FileOperationProgressEvent.EventType.SUCCESS,
status: {
operationType: 'COPY',
},
......@@ -126,7 +126,7 @@ function testCopyCancel() {
fileOperationManager.dispatchEvent(
/** @type {!Event} */ (Object.assign(new Event('copy-progress'), {
taskId: 'TASK_ID',
reason: fileOperationUtil.EventRouter.EventType.BEGIN,
reason: FileOperationProgressEvent.EventType.BEGIN,
status: {
operationType: 'COPY',
numRemainingItems: 1,
......@@ -148,7 +148,7 @@ function testCopyCancel() {
fileOperationManager.cancelEvent =
/** @type {!Event} */ (Object.assign(new Event('copy-progress'), {
taskId: 'TASK_ID',
reason: fileOperationUtil.EventRouter.EventType.CANCELED,
reason: FileOperationProgressEvent.EventType.CANCELED,
status: {
operationType: 'COPY',
},
......@@ -175,7 +175,7 @@ function testCopyTargetExistsError() {
fileOperationManager.dispatchEvent(
/** @type {!Event} */ (Object.assign(new Event('copy-progress'), {
taskId: 'TASK_ID',
reason: fileOperationUtil.EventRouter.EventType.ERROR,
reason: FileOperationProgressEvent.EventType.ERROR,
status: {
operationType: 'COPY',
},
......@@ -204,7 +204,7 @@ function testCopyFileSystemError() {
fileOperationManager.dispatchEvent(
/** @type {!Event} */ (Object.assign(new Event('copy-progress'), {
taskId: 'TASK_ID',
reason: fileOperationUtil.EventRouter.EventType.ERROR,
reason: FileOperationProgressEvent.EventType.ERROR,
status: {
operationType: 'COPY',
},
......@@ -233,7 +233,7 @@ function testCopyUnexpectedError() {
fileOperationManager.dispatchEvent(
/** @type {!Event} */ (Object.assign(new Event('copy-progress'), {
taskId: 'TASK_ID',
reason: fileOperationUtil.EventRouter.EventType.ERROR,
reason: FileOperationProgressEvent.EventType.ERROR,
status: {
operationType: 'COPY',
},
......
......@@ -143,7 +143,7 @@ class FileOperationManagerImpl {
}
task.requestCancel();
this.eventRouter_.sendProgressEvent(
fileOperationUtil.EventRouter.EventType.CANCELED,
FileOperationProgressEvent.EventType.CANCELED,
this.getTaskStatus(task), task.taskId);
this.pendingCopyTasks_.splice(i, 1);
}
......@@ -164,7 +164,7 @@ class FileOperationManagerImpl {
// If the task is not on progress, remove it immediately.
if (i !== 0) {
this.eventRouter_.sendDeleteEvent(
fileOperationUtil.EventRouter.EventType.CANCELED, task);
FileOperationProgressEvent.EventType.CANCELED, task);
this.deleteTasks_.splice(i, 1);
}
}
......@@ -273,7 +273,7 @@ class FileOperationManagerImpl {
}
this.eventRouter_.sendProgressEvent(
fileOperationUtil.EventRouter.EventType.BEGIN, this.getTaskStatus(task),
FileOperationProgressEvent.EventType.BEGIN, this.getTaskStatus(task),
task.taskId);
task.initialize(() => {
......@@ -320,9 +320,9 @@ class FileOperationManagerImpl {
/** @type {!DirectoryEntry} */ (task.targetDirEntry));
if (volumeInfo === null) {
this.eventRouter_.sendProgressEvent(
fileOperationUtil.EventRouter.EventType.ERROR,
FileOperationProgressEvent.EventType.ERROR,
this.getTaskStatus(task), task.taskId,
new fileOperationUtil.Error(
new FileOperationError(
util.FileOperationErrorType.FILESYSTEM_ERROR,
util.createDOMError(util.FileError.NOT_FOUND_ERR)));
......@@ -347,7 +347,7 @@ class FileOperationManagerImpl {
const onTaskProgress = function(task) {
this.eventRouter_.sendProgressEvent(
fileOperationUtil.EventRouter.EventType.PROGRESS,
FileOperationProgressEvent.EventType.PROGRESS,
this.getTaskStatus(task), task.taskId);
}.bind(this, nextTask);
......@@ -362,8 +362,8 @@ class FileOperationManagerImpl {
delete this.runningCopyTasks_[volumeId];
const reason = err.data.name === util.FileError.ABORT_ERR ?
fileOperationUtil.EventRouter.EventType.CANCELED :
fileOperationUtil.EventRouter.EventType.ERROR;
FileOperationProgressEvent.EventType.CANCELED :
FileOperationProgressEvent.EventType.ERROR;
this.eventRouter_.sendProgressEvent(
reason, this.getTaskStatus(task), task.taskId, err);
this.serviceAllTasks_();
......@@ -374,7 +374,7 @@ class FileOperationManagerImpl {
delete this.runningCopyTasks_[volumeId];
this.eventRouter_.sendProgressEvent(
fileOperationUtil.EventRouter.EventType.SUCCESS,
FileOperationProgressEvent.EventType.SUCCESS,
this.getTaskStatus(task), task.taskId);
this.serviceAllTasks_();
}.bind(this, nextTaskVolumeId);
......@@ -383,7 +383,7 @@ class FileOperationManagerImpl {
this.runningCopyTasks_[nextTaskVolumeId] = nextTask;
this.eventRouter_.sendProgressEvent(
fileOperationUtil.EventRouter.EventType.PROGRESS,
FileOperationProgressEvent.EventType.PROGRESS,
this.getTaskStatus(nextTask), nextTask.taskId);
nextTask.run(onEntryChanged, onTaskProgress, onTaskSuccess, onTaskError);
}
......@@ -452,7 +452,7 @@ class FileOperationManagerImpl {
group.run(() => {
this.deleteTasks_.push(task);
this.eventRouter_.sendDeleteEvent(
fileOperationUtil.EventRouter.EventType.BEGIN, task);
FileOperationProgressEvent.EventType.BEGIN, task);
if (this.deleteTasks_.length === 1) {
this.serviceAllDeleteTasks_();
}
......@@ -502,7 +502,7 @@ class FileOperationManagerImpl {
return;
}
this.eventRouter_.sendDeleteEvent(
fileOperationUtil.EventRouter.EventType.PROGRESS, task);
FileOperationProgressEvent.EventType.PROGRESS, task);
// Operation will be either delete, or restore.
let operation;
......@@ -546,7 +546,7 @@ class FileOperationManagerImpl {
// Send an event and finish the async steps.
queue.run(inCallback => {
const EventType = fileOperationUtil.EventRouter.EventType;
const EventType = FileOperationProgressEvent.EventType;
let reason;
if (error) {
reason = EventType.ERROR;
......@@ -557,7 +557,7 @@ class FileOperationManagerImpl {
}
this.eventRouter_.sendDeleteEvent(
reason, task,
new fileOperationUtil.Error(
new FileOperationError(
util.FileOperationErrorType.FILESYSTEM_ERROR, error));
inCallback();
callback();
......@@ -584,8 +584,8 @@ class FileOperationManagerImpl {
const zipTask = new fileOperationUtil.ZipTask(
this.generateTaskId(), selectionEntries, dirEntry, dirEntry);
this.eventRouter_.sendProgressEvent(
fileOperationUtil.EventRouter.EventType.BEGIN,
this.getTaskStatus(zipTask), zipTask.taskId);
FileOperationProgressEvent.EventType.BEGIN, this.getTaskStatus(zipTask),
zipTask.taskId);
zipTask.initialize(() => {
this.pendingCopyTasks_.push(zipTask);
this.serviceAllTasks_();
......
......@@ -25,6 +25,7 @@ group("closure_compile") {
js_type_check("closure_compile_module") {
deps = [
":async_util",
":file_operation_common",
":file_type",
":files_app_entry_types",
":importer_common",
......@@ -43,12 +44,14 @@ js_type_check("closure_compile_jsmodules") {
uses_js_modules = true
deps = [
":async_util.m",
":file_operation_common.m",
":file_type.m",
":files_app_entry_types.m",
":lru_cache.m",
":metrics.m",
":metrics_base.m",
":mock_entry.m",
":trash.m",
":util.m",
]
}
......@@ -129,6 +132,21 @@ js_unittest("file_type_unittest.m") {
]
}
js_library("file_operation_common") {
deps = [ ":util" ]
externs_list = [ "//ui/file_manager/externs/files_app_entry_interfaces.js" ]
}
js_library("file_operation_common.m") {
sources = [ "$root_gen_dir/ui/file_manager/file_manager/common/js/file_operation_common.m.js" ]
deps = [
":util.m",
"//ui/file_manager/externs:files_app_entry_interfaces.m",
]
extra_deps = [ ":modulize" ]
}
# These importer files actually belong here. Nothing outside the Files app uses
# them, so restrict visibility. TODO(tapted): Simplify visibility when
# everything else moves to //ui/file_manager/base.
......@@ -244,6 +262,21 @@ js_library("trash") {
]
}
js_library("trash.m") {
sources =
[ "$root_gen_dir/ui/file_manager/file_manager/common/js/trash.m.js" ]
deps = [
":files_app_entry_types.m",
":util.m",
"//ui/file_manager/base/js:volume_manager_types.m",
"//ui/file_manager/externs:files_app_entry_interfaces.m",
"//ui/file_manager/externs:volume_manager.m",
"//ui/webui/resources/js:assert.m",
]
extra_deps = [ ":modulize" ]
}
js_library("unittest_util") {
testonly = true
......@@ -342,11 +375,13 @@ js_modulizer("modulize") {
"async_util.js",
"file_type.js",
"files_app_entry_types.js",
"file_operation_common.js",
"lru_cache.js",
"metrics.js",
"metrics_base.js",
"mock_entry.js",
"util.js",
"trash.js",
]
namespace_rewrites = cr_namespace_rewrites
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// clang-format off
// #import {util} from '../../common/js/util.m.js';
// #import {FilesAppEntry} from '../../../externs/files_app_entry_interfaces.m.js'
// clang-format on
/* #export */ class FileOperationProgressEvent extends Event {
/** @param {string} eventName */
constructor(eventName) {
super(eventName);
/** @type {FileOperationProgressEvent.EventType} */
this.reason;
/** @type {(FileOperationError|undefined)} */
this.error;
/** @public {string} */
this.taskId;
/** @public {?Array<!Entry>} */
this.entries;
/** @public {?Object} */
this.status;
/** @public {number} */
this.totalBytes;
/** @public {number} */
this.processedBytes;
/** @public {?Array<!FilesAppEntry>} */
this.trashedEntries;
}
}
/**
* Types of events emitted by the EventRouter.
* @enum {string}
*/
FileOperationProgressEvent.EventType = {
BEGIN: 'BEGIN',
CANCELED: 'CANCELED',
ERROR: 'ERROR',
PROGRESS: 'PROGRESS',
SUCCESS: 'SUCCESS'
};
/**
* Error class used to report problems with a copy operation.
* If the code is UNEXPECTED_SOURCE_FILE, data should be a path of the file.
* If the code is TARGET_EXISTS, data should be the existing Entry.
* If the code is FILESYSTEM_ERROR, data should be the FileError.
*/
/* #export */ class FileOperationError {
/**
* @param {util.FileOperationErrorType} code Error type.
* @param {string|Entry|DOMError} data Additional data.
*/
constructor(code, data) {
this.code = code;
this.data = data;
}
}
......@@ -19,10 +19,19 @@
* TrashEntry combines both files for display.
*/
// clang-format off
// #import {VolumeManager} from '../../../externs/volume_manager.m.js';
// #import {FilesAppEntry} from '../../../externs/files_app_entry_interfaces.m.js';
// #import {assert} from 'chrome://resources/js/assert.m.js';
// #import {util} from './util.m.js';
// #import {FakeEntryImpl, CombinedReaders} from './files_app_entry_types.m.js';
// #import {VolumeManagerCommon} from '../../../base/js/volume_manager_types.m.js';
// clang-format on
/**
* Configuration for where Trash is stored in a volume.
*/
class TrashConfig {
/* #export */ class TrashConfig {
/**
* @param {VolumeManagerCommon.VolumeType} volumeType
* @param {string} topDir Top directory of volume. Must end with a slash to
......@@ -65,7 +74,7 @@ TrashConfig.CONFIG = [
/**
* Wrapper for /.Trash/files and /.Trash/info directories.
*/
class TrashDirs {
/* #export */ class TrashDirs {
/**
* @param {!DirectoryEntry} files /.Trash/files directory entry.
* @param {!DirectoryEntry} info /.Trash/info directory entry.
......@@ -122,7 +131,7 @@ class TrashDirs {
*
* @implements {FilesAppEntry}
*/
class TrashEntry {
/* #export */ class TrashEntry {
/**
* @param {string} name Name of the file deleted.
* @param {!Date} deletionDate DeletionDate of deleted file from infoEntry.
......@@ -179,9 +188,7 @@ class TrashEntry {
}
/** @override Entry */
getParent() {
return null;
}
getParent() {}
/**
* Remove filesEntry first, then remove infoEntry. Overrides Entry.
......@@ -456,7 +463,7 @@ class TrashDirectoryReader {
* Root Trash entry sits inside "My files". It shows the combined entries of
* trashes defined in TrashConfig.
*/
class TrashRootEntry extends FakeEntryImpl {
/* #export */ class TrashRootEntry extends FakeEntryImpl {
/**
* @param {!VolumeManager} volumeManager
*/
......
......@@ -415,6 +415,7 @@ js_library("file_manager_commands") {
":task_controller",
"ui:directory_tree",
"ui:file_manager_ui",
"//ui/file_manager/file_manager/common/js:file_operation_common",
"//ui/file_manager/file_manager/common/js:progress_center_common",
"//ui/webui/resources/cr_elements/cr_input:cr_input",
]
......@@ -422,8 +423,6 @@ js_library("file_manager_commands") {
"//ui/file_manager/externs/background/file_operation_manager.js",
"//ui/file_manager/externs/background/progress_center.js",
"//ui/file_manager/externs/command_handler_deps.js",
"//ui/file_manager/externs/file_operation_progress_event.js",
"//ui/file_manager/externs/file_operation_util.js",
]
}
......
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