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