Commit fe9b1a17 authored by iseki's avatar iseki Committed by Commit bot

Add notification before getMultiProfileShareEntries_.

* getMultiProfileShareEntries_ is very slow.

BUG=409711
TEST=manually
1.Copy the large directory in the drive of user A.
2.Paste the A's large directory into the drive of user B.
3.Confirm notification is displayed.

Review URL: https://codereview.chromium.org/571343002

Cr-Commit-Position: refs/heads/master@{#295235}
parent 1e6ba5a2
......@@ -1184,9 +1184,12 @@ FileOperationManager.prototype.requestTaskCancel = function(taskId) {
* directory.
* @param {boolean} isMove True if the operation is "move", otherwise (i.e.
* if the operation is "copy") false.
* @param {string=} opt_taskId If the corresponding item has already created
* at another places, we need to specify the ID of the item. If the
* item is not created, FileOperationManager generates new ID.
*/
FileOperationManager.prototype.paste = function(
sourceEntries, targetEntry, isMove) {
sourceEntries, targetEntry, isMove, opt_taskId) {
// Do nothing if sourceEntries is empty.
if (sourceEntries.length === 0)
return;
......@@ -1220,7 +1223,7 @@ FileOperationManager.prototype.paste = function(
if (filteredEntries.length === 0)
return;
this.queueCopy_(targetEntry, filteredEntries, isMove);
this.queueCopy_(targetEntry, filteredEntries, isMove, opt_taskId);
}.bind(this));
};
......@@ -1231,10 +1234,13 @@ FileOperationManager.prototype.paste = function(
* @param {DirectoryEntry} targetDirEntry Target directory.
* @param {Array.<Entry>} entries Entries to copy.
* @param {boolean} isMove In case of move.
* @param {string=} opt_taskId If the corresponding item has already created
* at another places, we need to specify the ID of the item. If the
* item is not created, FileOperationManager generates new ID.
* @private
*/
FileOperationManager.prototype.queueCopy_ = function(
targetDirEntry, entries, isMove) {
targetDirEntry, entries, isMove, opt_taskId) {
var task;
if (isMove) {
// When moving between different volumes, moving is implemented as a copy
......@@ -1250,7 +1256,7 @@ FileOperationManager.prototype.queueCopy_ = function(
task = new FileOperationManager.CopyTask(entries, targetDirEntry, false);
}
task.taskId = this.generateTaskId_();
task.taskId = opt_taskId || this.generateTaskId();
this.eventRouter_.sendProgressEvent('BEGIN', task.getStatus(), task.taskId);
task.initialize(function() {
this.copyTasks_.push(task);
......@@ -1327,7 +1333,7 @@ FileOperationManager.prototype.deleteEntries = function(entries) {
// TODO(hirono): Make FileOperationManager.DeleteTask.
var task = Object.seal({
entries: entries,
taskId: this.generateTaskId_(),
taskId: this.generateTaskId(),
entrySize: {},
totalBytes: 0,
processedBytes: 0,
......@@ -1438,7 +1444,7 @@ FileOperationManager.prototype.zipSelection = function(
dirEntry, selectionEntries) {
var zipTask = new FileOperationManager.ZipTask(
selectionEntries, dirEntry, dirEntry);
zipTask.taskId = this.generateTaskId_(this.copyTasks_);
zipTask.taskId = this.generateTaskId(this.copyTasks_);
zipTask.zip = true;
this.eventRouter_.sendProgressEvent('BEGIN',
zipTask.getStatus(),
......@@ -1454,8 +1460,7 @@ FileOperationManager.prototype.zipSelection = function(
* Generates new task ID.
*
* @return {string} New task ID.
* @private
*/
FileOperationManager.prototype.generateTaskId_ = function() {
FileOperationManager.prototype.generateTaskId = function() {
return 'file-operation-' + this.taskIdCounter_++;
};
......@@ -959,12 +959,14 @@ var BOTTOM_MARGIN_FOR_PREVIEW_PANEL_PX = 52;
'entries-changed', this.onEntriesChangedBound_);
var controller = this.fileTransferController_ =
new FileTransferController(this.document_,
this.fileOperationManager_,
this.metadataCache_,
this.directoryModel_,
this.volumeManager_,
this.ui_.multiProfileShareDialog);
new FileTransferController(
this.document_,
this.fileOperationManager_,
this.metadataCache_,
this.directoryModel_,
this.volumeManager_,
this.ui_.multiProfileShareDialog,
this.backgroundPage_.background.progressCenter);
controller.attachDragSource(this.table_.list);
controller.attachFileListDropTarget(this.table_.list);
controller.attachDragSource(this.grid_);
......@@ -2829,9 +2831,20 @@ var BOTTOM_MARGIN_FOR_PREVIEW_PANEL_PX = 52;
this.directoryModel_.dispose();
if (this.volumeManager_)
this.volumeManager_.dispose();
if (this.progressCenterPanel_)
for (var i = 0;
i < this.fileTransferController_.pendingTaskId.length;
i++) {
var taskId = this.fileTransferController_.pendingTaskId[i];
var item =
this.backgroundPage_.background.progressCenter.getItemById(taskId);
item.message = '';
item.state = ProgressItemState.CANCELED;
this.backgroundPage_.background.progressCenter.updateItem(item);
}
if (this.progressCenterPanel_) {
this.backgroundPage_.background.progressCenter.removePanel(
this.progressCenterPanel_);
}
if (this.fileOperationManager_) {
if (this.onCopyProgressBound_) {
this.fileOperationManager_.removeEventListener(
......
......@@ -21,6 +21,7 @@ var DRAG_AND_DROP_GLOBAL_DATA = '__drag_and_drop_global_data';
* @param {VolumeManagerWrapper} volumeManager Volume manager instance.
* @param {MultiProfileShareDialog} multiProfileShareDialog Share dialog to be
* used to share files from another profile.
* @param {ProgressCenter} progressCenter To notify starting copy operation.
* @constructor
*/
function FileTransferController(doc,
......@@ -28,13 +29,15 @@ function FileTransferController(doc,
metadataCache,
directoryModel,
volumeManager,
multiProfileShareDialog) {
multiProfileShareDialog,
progressCenter) {
this.document_ = doc;
this.fileOperationManager_ = fileOperationManager;
this.metadataCache_ = metadataCache;
this.directoryModel_ = directoryModel;
this.volumeManager_ = volumeManager;
this.multiProfileShareDialog_ = multiProfileShareDialog;
this.progressCenter_ = progressCenter;
this.directoryModel_.getFileList().addEventListener(
'change', function(event) {
......@@ -46,6 +49,12 @@ function FileTransferController(doc,
this.directoryModel_.getFileListSelection().addEventListener('change',
this.onSelectionChanged_.bind(this));
/**
* The array of pending task ID.
* @type {Array.<string>}
*/
this.pendingTaskIds = [];
/**
* Promise to be fulfilled with the thumbnail image of selected file in drag
* operation. Used if only one element is selected.
......@@ -75,6 +84,13 @@ function FileTransferController(doc,
* @private
*/
this.touching_ = false;
/**
* Task ID counter.
* @type {number}
* @private
*/
this.taskIdCounter_ = 0;
}
/**
......@@ -333,11 +349,21 @@ FileTransferController.prototype = {
opt_destinationEntry || this.currentDirectoryContentEntry;
var entries;
var failureUrls;
var taskId = this.fileOperationManager_.generateTaskId();
util.URLsToEntries(sourceURLs).
then(function(result) {
this.pendingTaskIds.push(taskId);
entries = result.entries;
failureUrls = result.failureUrls;
var item = new ProgressCenterItem();
item.id = taskId;
item.type = ProgressItemType.COPY;
if (result.entries.length === 1)
item.message = strf('COPY_FILE_NAME', result.entries[0].name);
else
item.message = strf('COPY_ITEMS_REMAINING', result.entries.length);
this.progressCenter_.updateItem(item);
// Check if cross share is needed or not.
return this.getMultiProfileShareEntries_(entries);
}.bind(this)).
......@@ -369,7 +395,8 @@ FileTransferController.prototype = {
then(function() {
// Start the pasting operation.
this.fileOperationManager_.paste(
entries, destinationEntry, toMove);
entries, destinationEntry, toMove, taskId);
this.pendingTaskIds.splice(this.pendingTaskIds.indexOf(taskId), 1);
// Publish events for failureUrls.
for (var i = 0; i < failureUrls.length; i++) {
......
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