Commit 04a1bb6d authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Chromium LUCI CQ

Files app: Generate JS module for //u/f/f/b/j/task_queue.m.js

Generate JS modules for:
//ui/file_manager/externs/background/task_queue.js
//ui/file_manager/file_manager/background/js/task_queue.js

Because Closure doesn't deal well importing the same namespace from
different files, I started splitting the "importer" namespace so each
file will have its own namespace.  Files in the "externs" directory will
have the suffix "Interface" on their namespace.  I'll use this logic for
all files related to "importer" namespace.

The "importer" namespace will remain for the file "importer_common.js"

Move the `UpdateType` our of the TaskQueue namespace to remove the
reference of importer.TaskQueue from importer_common.js because it was
causing a circular dependency between externs/b/task_queue.js and
importer_common.js.

Bug: 1133186
Change-Id: I53af2ceb7f75e463702fdfbb3f2c4758f1fbc540
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2592578
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Commit-Queue: Jeremie Boulic <jboulic@chromium.org>
Reviewed-by: default avatarJeremie Boulic <jboulic@chromium.org>
Auto-Submit: Luciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837920}
parent c97414e9
...@@ -72,6 +72,14 @@ js_library("progress_center.m") { ...@@ -72,6 +72,14 @@ js_library("progress_center.m") {
extra_deps = [ ":modulize" ] extra_deps = [ ":modulize" ]
} }
js_library("task_queue.m") {
sources =
[ "$root_gen_dir/ui/file_manager/externs/background/task_queue.m.js" ]
deps = [ "//ui/file_manager/file_manager/common/js:importer_common.m" ]
extra_deps = [ ":modulize" ]
}
js_modulizer("modulize") { js_modulizer("modulize") {
input_files = [ input_files = [
"background_base.js", "background_base.js",
...@@ -79,5 +87,6 @@ js_modulizer("modulize") { ...@@ -79,5 +87,6 @@ js_modulizer("modulize") {
"drive_sync_handler.js", "drive_sync_handler.js",
"file_operation_manager.js", "file_operation_manager.js",
"progress_center.js", "progress_center.js",
"task_queue.js",
] ]
} }
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
// Namespace // Namespace
// eslint-disable-next-line no-var
var importer = importer || {}; var importer = importer || {};
/* /*
...@@ -34,7 +35,7 @@ importer.MediaImportHandler = class extends importer.ImportRunner { ...@@ -34,7 +35,7 @@ importer.MediaImportHandler = class extends importer.ImportRunner {
* the FileOperationManager (and thus *spawns* an associated * the FileOperationManager (and thus *spawns* an associated
* FileOperationManager.CopyTask) but this is a temporary state of affairs. * FileOperationManager.CopyTask) but this is a temporary state of affairs.
* *
* @extends {importer.TaskQueue.BaseTask} * @extends {taskQueueInterfaces.BaseTask}
* @interface * @interface
*/ */
importer.MediaImportHandler.ImportTask = class { importer.MediaImportHandler.ImportTask = class {
......
...@@ -2,22 +2,28 @@ ...@@ -2,22 +2,28 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// Namespace
var importer = importer || {};
/** /**
* import.TaskQueue. * @fileoverview
* @interface * @suppress {uselessCode, externsValidation} Temporary suppress because of the
* line exporting.
*/ */
importer.TaskQueue = class {
// clang-format off
// #import {importer} from '../../file_manager/common/js/importer_common.m.js';
// clang-format on
const taskQueueInterfaces = {};
/** @interface */
taskQueueInterfaces.TaskQueue = class {
/** /**
* @param {!importer.TaskQueue.Task} task * @param {!taskQueueInterfaces.Task} task
*/ */
queueTask(task) {} queueTask(task) {}
/** /**
* Sets a callback to be triggered when a task updates. * Sets a callback to be triggered when a task updates.
* @param {function(string, !importer.TaskQueue.Task)} callback * @param {function(string, !taskQueueInterfaces.Task)} callback
*/ */
addUpdateCallback(callback) {} addUpdateCallback(callback) {}
...@@ -41,14 +47,14 @@ importer.TaskQueue = class { ...@@ -41,14 +47,14 @@ importer.TaskQueue = class {
* Interface for any Task that is to run on the TaskQueue. * Interface for any Task that is to run on the TaskQueue.
* @interface * @interface
*/ */
importer.TaskQueue.Task = class { taskQueueInterfaces.Task = class {
constructor() {} constructor() {}
/** /**
* Sets the TaskQueue that will own this task. The TaskQueue must call this * Sets the TaskQueue that will own this task. The TaskQueue must call this
* prior to enqueuing a Task. * prior to enqueuing a Task.
* @param {!importer.TaskQueue.Task.Observer} observer A callback that * @param {!taskQueueInterfaces.Task.Observer} observer A callback
* will be triggered each time the task has a status update. * that will be triggered each time the task has a status update.
*/ */
addObserver(observer) {} addObserver(observer) {}
...@@ -62,23 +68,25 @@ importer.TaskQueue.Task = class { ...@@ -62,23 +68,25 @@ importer.TaskQueue.Task = class {
* Base class for importer tasks. * Base class for importer tasks.
* @interface * @interface
*/ */
importer.TaskQueue.BaseTask = class extends importer.TaskQueue.Task { taskQueueInterfaces.BaseTask = class extends taskQueueInterfaces.Task {
/** /**
* @param {string} taskId * @param {string} taskId
*/ */
constructor(taskId) {} constructor(taskId) {
super();
}
/** @return {string} The task ID. */ /** @return {string} The task ID. */
get taskId() {} get taskId() {}
/** /**
* @return {!Promise<!importer.TaskQueue.UpdateType>} Resolves when task * @return {!Promise<!importer.UpdateType>} Resolves when task
* is complete, or cancelled, rejects on error. * is complete, or cancelled, rejects on error.
*/ */
get whenFinished() {} get whenFinished() {}
/** /**
* @param {importer.TaskQueue.UpdateType} updateType * @param {importer.UpdateType} updateType
* @param {Object=} opt_data * @param {Object=} opt_data
* @protected * @protected
*/ */
...@@ -89,9 +97,12 @@ importer.TaskQueue.BaseTask = class extends importer.TaskQueue.Task { ...@@ -89,9 +97,12 @@ importer.TaskQueue.BaseTask = class extends importer.TaskQueue.Task {
* A callback that is triggered whenever an update is reported on the observed * A callback that is triggered whenever an update is reported on the observed
* task. The first argument is a string specifying the type of the update. * task. The first argument is a string specifying the type of the update.
* Standard values used by all tasks are enumerated in * Standard values used by all tasks are enumerated in
* importer.TaskQueue.UpdateType, but child classes may add supplementary update * importer.UpdateType, but child classes may add supplementary update
* types of their own. The second argument is an Object containing * types of their own. The second argument is an Object containing
* supplementary information pertaining to the update. * supplementary information pertaining to the update.
* @typedef {function(!importer.TaskQueue.UpdateType, Object=)} * @typedef {function(!importer.UpdateType, Object=)}
*/ */
importer.TaskQueue.Task.Observer; taskQueueInterfaces.Task.Observer;
// eslint-disable-next-line semi,no-extra-semi
/* #export */ {taskQueueInterfaces};
...@@ -84,6 +84,7 @@ js_type_check("closure_compile_jsmodules") { ...@@ -84,6 +84,7 @@ js_type_check("closure_compile_jsmodules") {
":mock_file_operation_manager.m", ":mock_file_operation_manager.m",
":mock_progress_center.m", ":mock_progress_center.m",
":mount_metrics.m", ":mount_metrics.m",
":task_queue.m",
":test_util_base.m", ":test_util_base.m",
":volume_info_impl.m", ":volume_info_impl.m",
":volume_info_list_impl.m", ":volume_info_list_impl.m",
...@@ -91,6 +92,12 @@ js_type_check("closure_compile_jsmodules") { ...@@ -91,6 +92,12 @@ js_type_check("closure_compile_jsmodules") {
":volume_manager_impl.m", ":volume_manager_impl.m",
":volume_manager_util.m", ":volume_manager_util.m",
] ]
closure_flags = strict_error_checking_closure_args + [
"js_module_root=./gen/ui",
"js_module_root=../../ui",
"hide_warnings_for=third_party/",
]
} }
js_type_check("test_support_modules_type_check") { js_type_check("test_support_modules_type_check") {
...@@ -725,6 +732,18 @@ js_unittest("task_queue_unittest") { ...@@ -725,6 +732,18 @@ js_unittest("task_queue_unittest") {
externs_list = [ "//ui/file_manager/externs/background/task_queue.js" ] externs_list = [ "//ui/file_manager/externs/background/task_queue.js" ]
} }
js_library("task_queue.m") {
sources = [
"$root_gen_dir/ui/file_manager/file_manager/background/js/task_queue.m.js",
]
deps = [
"//ui/file_manager/externs/background:task_queue.m",
"//ui/file_manager/file_manager/common/js:importer_common.m",
]
extra_deps = [ ":modulize" ]
}
js_library("test_util_base") { js_library("test_util_base") {
} }
...@@ -930,6 +949,7 @@ js_modulizer("modulize") { ...@@ -930,6 +949,7 @@ js_modulizer("modulize") {
"mock_file_operation_manager.js", "mock_file_operation_manager.js",
"mock_progress_center.js", "mock_progress_center.js",
"mount_metrics.js", "mount_metrics.js",
"task_queue.js",
] ]
namespace_rewrites = cr_namespace_rewrites namespace_rewrites = cr_namespace_rewrites
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
// Namespace // Namespace
var importer = importer || {}; window.importer = window.importer || {};
/** /**
* @enum {string} * @enum {string}
......
...@@ -30,8 +30,8 @@ importer.MediaImportHandlerImpl = class { ...@@ -30,8 +30,8 @@ importer.MediaImportHandlerImpl = class {
/** @private {!importer.HistoryLoader} */ /** @private {!importer.HistoryLoader} */
this.historyLoader_ = historyLoader; this.historyLoader_ = historyLoader;
/** @private {!importer.TaskQueue} */ /** @private {!taskQueueInterfaces.TaskQueue} */
this.queue_ = new importer.TaskQueueImpl(); this.queue_ = new taskQueue.TaskQueueImpl();
// Prevent the system from sleeping while imports are active. // Prevent the system from sleeping while imports are active.
this.queue_.setActiveCallback(() => { this.queue_.setActiveCallback(() => {
...@@ -104,8 +104,6 @@ importer.MediaImportHandlerImpl = class { ...@@ -104,8 +104,6 @@ importer.MediaImportHandlerImpl = class {
* @private * @private
*/ */
onTaskProgress_(task, updateType) { onTaskProgress_(task, updateType) {
const UpdateType = importer.TaskQueue.UpdateType;
let item = this.progressCenter_.getItemById(task.taskId); let item = this.progressCenter_.getItemById(task.taskId);
if (!item) { if (!item) {
item = new ProgressCenterItem(); item = new ProgressCenterItem();
...@@ -120,7 +118,7 @@ importer.MediaImportHandlerImpl = class { ...@@ -120,7 +118,7 @@ importer.MediaImportHandlerImpl = class {
} }
switch (updateType) { switch (updateType) {
case UpdateType.PROGRESS: case importer.UpdateType.PROGRESS:
item.message = item.message =
strf('CLOUD_IMPORT_ITEMS_REMAINING', task.remainingFilesCount); strf('CLOUD_IMPORT_ITEMS_REMAINING', task.remainingFilesCount);
item.progressValue = task.processedBytes; item.progressValue = task.processedBytes;
...@@ -131,7 +129,7 @@ importer.MediaImportHandlerImpl = class { ...@@ -131,7 +129,7 @@ importer.MediaImportHandlerImpl = class {
item.remainingTime = this.speedometer_.getRemainingTime(); item.remainingTime = this.speedometer_.getRemainingTime();
break; break;
case UpdateType.COMPLETE: case importer.UpdateType.COMPLETE:
// Remove the event handler that gets attached for retries. // Remove the event handler that gets attached for retries.
this.driveSyncHandler_.removeEventListener( this.driveSyncHandler_.removeEventListener(
this.driveSyncHandler_.getCompletedEventName(), this.driveSyncHandler_.getCompletedEventName(),
...@@ -166,7 +164,7 @@ importer.MediaImportHandlerImpl = class { ...@@ -166,7 +164,7 @@ importer.MediaImportHandlerImpl = class {
break; break;
case UpdateType.CANCELED: case importer.UpdateType.CANCELED:
item.message = ''; item.message = '';
item.state = ProgressItemState.CANCELED; item.state = ProgressItemState.CANCELED;
break; break;
...@@ -203,7 +201,7 @@ importer.MediaImportHandlerImpl = class { ...@@ -203,7 +201,7 @@ importer.MediaImportHandlerImpl = class {
* @implements {importer.MediaImportHandler.ImportTask} * @implements {importer.MediaImportHandler.ImportTask}
*/ */
importer.MediaImportHandler.ImportTaskImpl = importer.MediaImportHandler.ImportTaskImpl =
class extends importer.TaskQueue.BaseTaskImpl { class extends taskQueue.BaseTaskImpl {
/** /**
* @param {string} taskId * @param {string} taskId
* @param {!importer.HistoryLoader} historyLoader * @param {!importer.HistoryLoader} historyLoader
...@@ -331,7 +329,7 @@ importer.MediaImportHandler.ImportTaskImpl = ...@@ -331,7 +329,7 @@ importer.MediaImportHandler.ImportTaskImpl =
requestCancel() { requestCancel() {
this.canceled_ = true; this.canceled_ = true;
setTimeout(() => { setTimeout(() => {
this.notify(importer.TaskQueue.UpdateType.CANCELED); this.notify(importer.UpdateType.CANCELED);
this.sendImportStats_(); this.sendImportStats_();
}); });
if (this.cancelCallback_) { if (this.cancelCallback_) {
...@@ -459,7 +457,7 @@ importer.MediaImportHandler.ImportTaskImpl = ...@@ -459,7 +457,7 @@ importer.MediaImportHandler.ImportTaskImpl =
this.processedBytes_ -= currentBytes; this.processedBytes_ -= currentBytes;
this.processedBytes_ += processedBytes; this.processedBytes_ += processedBytes;
currentBytes = processedBytes; currentBytes = processedBytes;
this.notify(importer.TaskQueue.UpdateType.PROGRESS); this.notify(importer.UpdateType.PROGRESS);
}; };
/** /**
...@@ -473,12 +471,12 @@ importer.MediaImportHandler.ImportTaskImpl = ...@@ -473,12 +471,12 @@ importer.MediaImportHandler.ImportTaskImpl =
this.processedBytes_ += entry.size; this.processedBytes_ += entry.size;
destinationEntry.size = entry.size; destinationEntry.size = entry.size;
this.notify( this.notify(
/** @type {importer.TaskQueue.UpdateType} */ /** @type {importer.UpdateType} */
(importer.MediaImportHandler.ImportTask.UpdateType.ENTRY_CHANGED), { (importer.MediaImportHandler.ImportTask.UpdateType.ENTRY_CHANGED), {
sourceUrl: sourceUrl, sourceUrl: sourceUrl,
destination: destinationEntry, destination: destinationEntry,
}); });
this.notify(importer.TaskQueue.UpdateType.PROGRESS); this.notify(importer.UpdateType.PROGRESS);
}; };
/** /**
...@@ -488,7 +486,7 @@ importer.MediaImportHandler.ImportTaskImpl = ...@@ -488,7 +486,7 @@ importer.MediaImportHandler.ImportTaskImpl =
const onComplete = destinationEntry => { const onComplete = destinationEntry => {
this.cancelCallback_ = null; this.cancelCallback_ = null;
this.markAsCopied_(entry, /** @type {!FileEntry} */ (destinationEntry)); this.markAsCopied_(entry, /** @type {!FileEntry} */ (destinationEntry));
this.notify(importer.TaskQueue.UpdateType.PROGRESS); this.notify(importer.UpdateType.PROGRESS);
resolver.resolve(destinationEntry); resolver.resolve(destinationEntry);
}; };
...@@ -498,11 +496,11 @@ importer.MediaImportHandler.ImportTaskImpl = ...@@ -498,11 +496,11 @@ importer.MediaImportHandler.ImportTaskImpl =
if (error.name === util.FileError.ABORT_ERR) { if (error.name === util.FileError.ABORT_ERR) {
// Task cancellations result in the error callback being triggered with // Task cancellations result in the error callback being triggered with
// an ABORT_ERR, but we want to ignore these errors. // an ABORT_ERR, but we want to ignore these errors.
this.notify(importer.TaskQueue.UpdateType.PROGRESS); this.notify(importer.UpdateType.PROGRESS);
resolver.resolve(null); resolver.resolve(null);
} else { } else {
this.errorCount_++; this.errorCount_++;
this.notify(importer.TaskQueue.UpdateType.ERROR); this.notify(importer.UpdateType.ERROR);
resolver.reject(error); resolver.reject(error);
} }
}; };
...@@ -555,7 +553,7 @@ importer.MediaImportHandler.ImportTaskImpl = ...@@ -555,7 +553,7 @@ importer.MediaImportHandler.ImportTaskImpl =
/** @private */ /** @private */
onSuccess_() { onSuccess_() {
this.notify(importer.TaskQueue.UpdateType.COMPLETE); this.notify(importer.UpdateType.COMPLETE);
} }
/** /**
......
...@@ -122,16 +122,16 @@ function testImportMedia(callback) { ...@@ -122,16 +122,16 @@ function testImportMedia(callback) {
const whenImportDone = new Promise((resolve, reject) => { const whenImportDone = new Promise((resolve, reject) => {
importTask.addObserver( importTask.addObserver(
/** /**
* @param {!importer.TaskQueue.UpdateType} updateType * @param {!importer.UpdateType} updateType
* @param {Object=} opt_task * @param {Object=} opt_task
*/ */
(updateType, opt_task) => { (updateType, opt_task) => {
switch (updateType) { switch (updateType) {
case importer.TaskQueue.UpdateType.COMPLETE: case importer.UpdateType.COMPLETE:
resolve(); resolve();
break; break;
case importer.TaskQueue.UpdateType.ERROR: case importer.UpdateType.ERROR:
reject(new Error(importer.TaskQueue.UpdateType.ERROR)); reject(new Error(importer.UpdateType.ERROR));
break; break;
} }
}); });
...@@ -182,16 +182,16 @@ function testImportMedia_skipAndMarkDuplicatedFiles(callback) { ...@@ -182,16 +182,16 @@ function testImportMedia_skipAndMarkDuplicatedFiles(callback) {
const whenImportDone = new Promise((resolve, reject) => { const whenImportDone = new Promise((resolve, reject) => {
importTask.addObserver( importTask.addObserver(
/** /**
* @param {!importer.TaskQueue.UpdateType} updateType * @param {!importer.UpdateType} updateType
* @param {Object=} opt_task * @param {Object=} opt_task
*/ */
(updateType, opt_task) => { (updateType, opt_task) => {
switch (updateType) { switch (updateType) {
case importer.TaskQueue.UpdateType.COMPLETE: case importer.UpdateType.COMPLETE:
resolve(); resolve();
break; break;
case importer.TaskQueue.UpdateType.ERROR: case importer.UpdateType.ERROR:
reject(new Error(importer.TaskQueue.UpdateType.ERROR)); reject(new Error(importer.UpdateType.ERROR));
break; break;
} }
}); });
...@@ -236,16 +236,16 @@ function testImportMedia_EmploysEncodedUrls(callback) { ...@@ -236,16 +236,16 @@ function testImportMedia_EmploysEncodedUrls(callback) {
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
importTask.addObserver( importTask.addObserver(
/** /**
* @param {!importer.TaskQueue.UpdateType} updateType * @param {!importer.UpdateType} updateType
* @param {Object=} opt_task * @param {Object=} opt_task
*/ */
(updateType, opt_task) => { (updateType, opt_task) => {
switch (updateType) { switch (updateType) {
case importer.TaskQueue.UpdateType.COMPLETE: case importer.UpdateType.COMPLETE:
resolve(/** @type {!MockDirectoryEntry} */ resolve(/** @type {!MockDirectoryEntry} */
(destinationFileSystem.root).getAllChildren()); (destinationFileSystem.root).getAllChildren());
break; break;
case importer.TaskQueue.UpdateType.ERROR: case importer.UpdateType.ERROR:
reject('Task failed :('); reject('Task failed :(');
break; break;
} }
...@@ -284,16 +284,16 @@ function testImportMediaWithDuplicateFilenames(callback) { ...@@ -284,16 +284,16 @@ function testImportMediaWithDuplicateFilenames(callback) {
const whenImportDone = new Promise((resolve, reject) => { const whenImportDone = new Promise((resolve, reject) => {
importTask.addObserver( importTask.addObserver(
/** /**
* @param {!importer.TaskQueue.UpdateType} updateType * @param {!importer.UpdateType} updateType
* @param {Object=} opt_task * @param {Object=} opt_task
*/ */
(updateType, opt_task) => { (updateType, opt_task) => {
switch (updateType) { switch (updateType) {
case importer.TaskQueue.UpdateType.COMPLETE: case importer.UpdateType.COMPLETE:
resolve(); resolve();
break; break;
case importer.TaskQueue.UpdateType.ERROR: case importer.UpdateType.ERROR:
reject(new Error(importer.TaskQueue.UpdateType.ERROR)); reject(new Error(importer.UpdateType.ERROR));
break; break;
} }
}); });
...@@ -332,18 +332,18 @@ function testKeepAwakeDuringImport(callback) { ...@@ -332,18 +332,18 @@ function testKeepAwakeDuringImport(callback) {
const whenImportDone = new Promise((resolve, reject) => { const whenImportDone = new Promise((resolve, reject) => {
importTask.addObserver( importTask.addObserver(
/** /**
* @param {!importer.TaskQueue.UpdateType} updateType * @param {!importer.UpdateType} updateType
* @param {Object=} opt_task * @param {Object=} opt_task
*/ */
(updateType, opt_task) => { (updateType, opt_task) => {
// Assert that keepAwake is set while the task is active. // Assert that keepAwake is set while the task is active.
assertTrue(mockChrome.power.requestKeepAwakeStatus); assertTrue(mockChrome.power.requestKeepAwakeStatus);
switch (updateType) { switch (updateType) {
case importer.TaskQueue.UpdateType.COMPLETE: case importer.UpdateType.COMPLETE:
resolve(); resolve();
break; break;
case importer.TaskQueue.UpdateType.ERROR: case importer.UpdateType.ERROR:
reject(new Error(importer.TaskQueue.UpdateType.ERROR)); reject(new Error(importer.UpdateType.ERROR));
break; break;
} }
}); });
...@@ -385,16 +385,16 @@ function testUpdatesHistoryAfterImport(callback) { ...@@ -385,16 +385,16 @@ function testUpdatesHistoryAfterImport(callback) {
const whenImportDone = new Promise((resolve, reject) => { const whenImportDone = new Promise((resolve, reject) => {
importTask.addObserver( importTask.addObserver(
/** /**
* @param {!importer.TaskQueue.UpdateType} updateType * @param {!importer.UpdateType} updateType
* @param {Object=} opt_task * @param {Object=} opt_task
*/ */
(updateType, opt_task) => { (updateType, opt_task) => {
switch (updateType) { switch (updateType) {
case importer.TaskQueue.UpdateType.COMPLETE: case importer.UpdateType.COMPLETE:
resolve(); resolve();
break; break;
case importer.TaskQueue.UpdateType.ERROR: case importer.UpdateType.ERROR:
reject(new Error(importer.TaskQueue.UpdateType.ERROR)); reject(new Error(importer.UpdateType.ERROR));
break; break;
} }
}); });
...@@ -442,11 +442,11 @@ function testImportCancellation(callback) { ...@@ -442,11 +442,11 @@ function testImportCancellation(callback) {
const whenImportCancelled = new Promise((resolve, reject) => { const whenImportCancelled = new Promise((resolve, reject) => {
importTask.addObserver( importTask.addObserver(
/** /**
* @param {!importer.TaskQueue.UpdateType} updateType * @param {!importer.UpdateType} updateType
* @param {Object=} opt_task * @param {Object=} opt_task
*/ */
(updateType, opt_task) => { (updateType, opt_task) => {
if (updateType === importer.TaskQueue.UpdateType.CANCELED) { if (updateType === importer.UpdateType.CANCELED) {
resolve(); resolve();
} }
}); });
...@@ -503,11 +503,11 @@ function testImportWithErrors(callback) { ...@@ -503,11 +503,11 @@ function testImportWithErrors(callback) {
const whenImportDone = new Promise((resolve, reject) => { const whenImportDone = new Promise((resolve, reject) => {
importTask.addObserver( importTask.addObserver(
/** /**
* @param {!importer.TaskQueue.UpdateType} updateType * @param {!importer.UpdateType} updateType
* @param {Object=} opt_task * @param {Object=} opt_task
*/ */
(updateType, opt_task) => { (updateType, opt_task) => {
if (updateType === importer.TaskQueue.UpdateType.COMPLETE) { if (updateType === importer.UpdateType.COMPLETE) {
resolve(); resolve();
} }
}); });
...@@ -546,7 +546,7 @@ function testImportWithErrors(callback) { ...@@ -546,7 +546,7 @@ function testImportWithErrors(callback) {
* @return {!Array<!Entry>} * @return {!Array<!Entry>}
*/ */
function setupFileSystem(fileNames) { function setupFileSystem(fileNames) {
let fileSystem = new MockFileSystem('fake-media-volume'); const fileSystem = new MockFileSystem('fake-media-volume');
fileSystem.populate(fileNames); fileSystem.populate(fileNames);
return fileNames.map((name) => fileSystem.entries[name]); return fileNames.map((name) => fileSystem.entries[name]);
} }
......
...@@ -2,13 +2,21 @@ ...@@ -2,13 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// Namespace /**
var importer = importer || {}; * @fileoverview
* @suppress {uselessCode} Temporary suppress because of the line exporting.
*/
importer.TaskQueue = importer.TaskQueue || {}; // clang-format off
// #import {importer} from '../../common/js/importer_common.m.js';
// #import {taskQueueInterfaces} from '../../../externs/background/task_queue.m.js';
// clang-format on
// Namespace
const taskQueue = {};
/** /**
* A queue of tasks. Tasks (subclasses of TaskQueue.Task) can be pushed onto * A queue of tasks. Tasks (subclasses of Task) can be pushed onto
* the queue. The queue becomes active whenever it is not empty, and it will * the queue. The queue becomes active whenever it is not empty, and it will
* begin executing tasks one at a time. The tasks are executed in a separate * begin executing tasks one at a time. The tasks are executed in a separate
* asynchronous context. As each task runs, it can send update notifications * asynchronous context. As each task runs, it can send update notifications
...@@ -17,14 +25,16 @@ importer.TaskQueue = importer.TaskQueue || {}; ...@@ -17,14 +25,16 @@ importer.TaskQueue = importer.TaskQueue || {};
* be triggered whenever the queue transitions between the active and idle * be triggered whenever the queue transitions between the active and idle
* states. * states.
* *
* @implements {importer.TaskQueue} * @implements {taskQueueInterfaces.TaskQueue}
*/ */
importer.TaskQueueImpl = class { taskQueue.TaskQueueImpl = class {
constructor() { constructor() {
/** @private {!Array<!importer.TaskQueue.Task>} */ /** @private {!Array<!taskQueueInterfaces.Task>} */
this.tasks_ = []; this.tasks_ = [];
/** @private {!Array<!function(string, !importer.TaskQueue.Task)>} */ /**
* @private {!Array<!function(string, !taskQueueInterfaces.Task)>}
*/
this.updateCallbacks_ = []; this.updateCallbacks_ = [];
/** @private {?function()} */ /** @private {?function()} */
...@@ -38,7 +48,7 @@ importer.TaskQueueImpl = class { ...@@ -38,7 +48,7 @@ importer.TaskQueueImpl = class {
} }
/** /**
* @param {!importer.TaskQueue.Task} task * @param {!taskQueueInterfaces.Task} task
*/ */
queueTask(task) { queueTask(task) {
// The Tasks that are pushed onto the queue aren't required to be inherently // The Tasks that are pushed onto the queue aren't required to be inherently
...@@ -55,7 +65,7 @@ importer.TaskQueueImpl = class { ...@@ -55,7 +65,7 @@ importer.TaskQueueImpl = class {
/** /**
* Sets a callback to be triggered when a task updates. * Sets a callback to be triggered when a task updates.
* @param {function(string, !importer.TaskQueue.Task)} callback * @param {function(string, !taskQueueInterfaces.Task)} callback
*/ */
addUpdateCallback(callback) { addUpdateCallback(callback) {
this.updateCallbacks_.push(callback); this.updateCallbacks_.push(callback);
...@@ -83,8 +93,8 @@ importer.TaskQueueImpl = class { ...@@ -83,8 +93,8 @@ importer.TaskQueueImpl = class {
/** /**
* Sends out notifications when a task updates. This is meant to be called by * Sends out notifications when a task updates. This is meant to be called by
* the running tasks owned by this queue. * the running tasks owned by this queue.
* @param {!importer.TaskQueue.Task} task * @param {!taskQueueInterfaces.Task} task
* @param {!importer.TaskQueue.UpdateType} updateType * @param {!importer.UpdateType} updateType
* @private * @private
*/ */
onTaskUpdate_(task, updateType) { onTaskUpdate_(task, updateType) {
...@@ -94,9 +104,8 @@ importer.TaskQueueImpl = class { ...@@ -94,9 +104,8 @@ importer.TaskQueueImpl = class {
}); });
// If the task update is a terminal one, move on to the next task. // If the task update is a terminal one, move on to the next task.
const UpdateType = importer.TaskQueue.UpdateType; if (updateType === importer.UpdateType.COMPLETE ||
if (updateType === UpdateType.COMPLETE || updateType === importer.UpdateType.CANCELED) {
updateType === UpdateType.CANCELED) {
// Assumption: the currently running task is at the head of the queue. // Assumption: the currently running task is at the head of the queue.
console.assert( console.assert(
this.tasks_[0] === task, this.tasks_[0] === task,
...@@ -139,9 +148,9 @@ importer.TaskQueueImpl = class { ...@@ -139,9 +148,9 @@ importer.TaskQueueImpl = class {
/** /**
* Base class for importer tasks. * Base class for importer tasks.
* @implements {importer.TaskQueue.Task} * @implements {taskQueueInterfaces.Task}
*/ */
importer.TaskQueue.BaseTaskImpl = class { taskQueue.BaseTaskImpl = class {
/** /**
* @param {string} taskId * @param {string} taskId
*/ */
...@@ -149,10 +158,10 @@ importer.TaskQueue.BaseTaskImpl = class { ...@@ -149,10 +158,10 @@ importer.TaskQueue.BaseTaskImpl = class {
/** @protected {string} */ /** @protected {string} */
this.taskId_ = taskId; this.taskId_ = taskId;
/** @private {!Array<!importer.TaskQueue.Task.Observer>} */ /** @private {!Array<!taskQueueInterfaces.Task.Observer>} */
this.observers_ = []; this.observers_ = [];
/** @private {!importer.Resolver<!importer.TaskQueue.UpdateType>} */ /** @private {!importer.Resolver<!importer.UpdateType>} */
this.finishedResolver_ = new importer.Resolver(); this.finishedResolver_ = new importer.Resolver();
} }
/** @return {string} The task ID. */ /** @return {string} The task ID. */
...@@ -161,7 +170,7 @@ importer.TaskQueue.BaseTaskImpl = class { ...@@ -161,7 +170,7 @@ importer.TaskQueue.BaseTaskImpl = class {
} }
/** /**
* @return {!Promise<!importer.TaskQueue.UpdateType>} Resolves when task * @return {!Promise<!importer.UpdateType>} Resolves when task
* is complete, or cancelled, rejects on error. * is complete, or cancelled, rejects on error.
*/ */
get whenFinished() { get whenFinished() {
...@@ -177,14 +186,14 @@ importer.TaskQueue.BaseTaskImpl = class { ...@@ -177,14 +186,14 @@ importer.TaskQueue.BaseTaskImpl = class {
run() {} run() {}
/** /**
* @param {importer.TaskQueue.UpdateType} updateType * @param {importer.UpdateType} updateType
* @param {Object=} opt_data * @param {Object=} opt_data
* @protected * @protected
*/ */
notify(updateType, opt_data) { notify(updateType, opt_data) {
switch (updateType) { switch (updateType) {
case importer.TaskQueue.UpdateType.CANCELED: case importer.UpdateType.CANCELED:
case importer.TaskQueue.UpdateType.COMPLETE: case importer.UpdateType.COMPLETE:
this.finishedResolver_.resolve(updateType); this.finishedResolver_.resolve(updateType);
} }
...@@ -193,3 +202,6 @@ importer.TaskQueue.BaseTaskImpl = class { ...@@ -193,3 +202,6 @@ importer.TaskQueue.BaseTaskImpl = class {
}); });
} }
}; };
// eslint-disable-next-line semi,no-extra-semi
/* #export */ {taskQueue};
...@@ -2,19 +2,19 @@ ...@@ -2,19 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
/** @type {!importer.TaskQueue} */ /** @type {!taskQueueInterfaces.TaskQueue} */
let queue; let queue;
/** @type {!Object<importer.TaskQueue.UpdateType, number>} */ /** @type {!Object<importer.UpdateType, number>} */
const updates = {}; const updates = {};
function setUp() { function setUp() {
queue = new importer.TaskQueueImpl(); queue = new taskQueue.TaskQueueImpl();
// Set up a callback to log updates from running tasks. // Set up a callback to log updates from running tasks.
for (const updateType in importer.TaskQueue.UpdateType) { for (const updateType in importer.UpdateType) {
// Reset counts for all update types. // Reset counts for all update types.
updates[importer.TaskQueue.UpdateType[updateType]] = 0; updates[importer.UpdateType[updateType]] = 0;
} }
// Counts the number of updates of each type that have been received. // Counts the number of updates of each type that have been received.
...@@ -27,7 +27,7 @@ function setUp() { ...@@ -27,7 +27,7 @@ function setUp() {
/** /**
* A Task subclass for testing. * A Task subclass for testing.
*/ */
class TestTask extends importer.TaskQueue.BaseTaskImpl { class TestTask extends taskQueue.BaseTaskImpl {
/** /**
* @param {string} taskId * @param {string} taskId
*/ */
...@@ -55,22 +55,22 @@ class TestTask extends importer.TaskQueue.BaseTaskImpl { ...@@ -55,22 +55,22 @@ class TestTask extends importer.TaskQueue.BaseTaskImpl {
/** Sends a quick error notification. */ /** Sends a quick error notification. */
notifyError() { notifyError() {
this.notify(importer.TaskQueue.UpdateType.ERROR); this.notify(importer.UpdateType.ERROR);
} }
/** Sends a quick completion notification. */ /** Sends a quick completion notification. */
notifyComplete() { notifyComplete() {
this.notify(importer.TaskQueue.UpdateType.COMPLETE); this.notify(importer.UpdateType.COMPLETE);
} }
/** Sends a quick cancelled notification. */ /** Sends a quick cancelled notification. */
notifyCanceled() { notifyCanceled() {
this.notify(importer.TaskQueue.UpdateType.CANCELED); this.notify(importer.UpdateType.CANCELED);
} }
/** Sends a quick progress notification. */ /** Sends a quick progress notification. */
notifyProgress() { notifyProgress() {
this.notify(importer.TaskQueue.UpdateType.PROGRESS); this.notify(importer.UpdateType.PROGRESS);
} }
/** @return {!Promise} A promise that settles once #run is called. */ /** @return {!Promise} A promise that settles once #run is called. */
...@@ -165,7 +165,7 @@ function testProgressUpdate(callback) { ...@@ -165,7 +165,7 @@ function testProgressUpdate(callback) {
const whenDone = new Promise(resolve => { const whenDone = new Promise(resolve => {
queue.setIdleCallback(() => { queue.setIdleCallback(() => {
// Verify that progress was recorded. // Verify that progress was recorded.
assertEquals(1, updates[importer.TaskQueue.UpdateType.PROGRESS]); assertEquals(1, updates[importer.UpdateType.PROGRESS]);
resolve(); resolve();
}); });
}); });
...@@ -189,7 +189,7 @@ function testSuccessUpdate(callback) { ...@@ -189,7 +189,7 @@ function testSuccessUpdate(callback) {
const whenDone = new Promise(resolve => { const whenDone = new Promise(resolve => {
queue.setIdleCallback(() => { queue.setIdleCallback(() => {
// Verify that the done callback was called. // Verify that the done callback was called.
assertEquals(1, updates[importer.TaskQueue.UpdateType.COMPLETE]); assertEquals(1, updates[importer.UpdateType.COMPLETE]);
resolve(); resolve();
}); });
}); });
...@@ -214,7 +214,7 @@ function testErrorUpdate(callback) { ...@@ -214,7 +214,7 @@ function testErrorUpdate(callback) {
const whenDone = new Promise(resolve => { const whenDone = new Promise(resolve => {
queue.setIdleCallback(() => { queue.setIdleCallback(() => {
// Verify that the done callback was called. // Verify that the done callback was called.
assertEquals(1, updates[importer.TaskQueue.UpdateType.ERROR]); assertEquals(1, updates[importer.UpdateType.ERROR]);
resolve(); resolve();
}); });
}); });
......
...@@ -56,6 +56,12 @@ js_type_check("closure_compile_jsmodules") { ...@@ -56,6 +56,12 @@ js_type_check("closure_compile_jsmodules") {
":trash.m", ":trash.m",
":util.m", ":util.m",
] ]
closure_flags = strict_error_checking_closure_args + [
"js_module_root=./gen/ui",
"js_module_root=../../ui",
"hide_warnings_for=third_party/",
]
} }
js_type_check("test_support_type_check") { js_type_check("test_support_type_check") {
...@@ -214,6 +220,7 @@ js_library("test_importer_common.m") { ...@@ -214,6 +220,7 @@ js_library("test_importer_common.m") {
js_unittest("importer_common_unittest.m") { js_unittest("importer_common_unittest.m") {
deps = [ deps = [
":importer_common.m",
":mock_entry.m", ":mock_entry.m",
":test_importer_common.m", ":test_importer_common.m",
"//chrome/test/data/webui:chai_assert", "//chrome/test/data/webui:chai_assert",
......
...@@ -19,12 +19,10 @@ ...@@ -19,12 +19,10 @@
// eslint-disable-next-line no-var // eslint-disable-next-line no-var
var importer = importer || {}; var importer = importer || {};
importer.TaskQueue = importer.TaskQueue || {};
/** /**
* @enum {string} * @enum {string}
*/ */
importer.TaskQueue.UpdateType = { importer.UpdateType = {
PROGRESS: 'PROGRESS', PROGRESS: 'PROGRESS',
COMPLETE: 'COMPLETE', COMPLETE: 'COMPLETE',
ERROR: 'ERROR', ERROR: 'ERROR',
......
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