Chromium Code Reviews| Index: chrome/browser/resources/file_manager/background/js/file_operation_manager.js |
| diff --git a/chrome/browser/resources/file_manager/background/js/file_operation_manager.js b/chrome/browser/resources/file_manager/background/js/file_operation_manager.js |
| index add481a520b921ae65cf9279310bc5199b989bef..22308dd68501be4de042a8ac4bd0a8926986d919 100644 |
| --- a/chrome/browser/resources/file_manager/background/js/file_operation_manager.js |
| +++ b/chrome/browser/resources/file_manager/background/js/file_operation_manager.js |
| @@ -298,7 +298,6 @@ function FileOperationManager() { |
| this.copyTasks_ = []; |
| this.deleteTasks_ = []; |
| this.taskIdCounter_ = 0; |
| - |
| this.eventRouter_ = new FileOperationManager.EventRouter(); |
| Object.seal(this); |
| @@ -1165,54 +1164,65 @@ FileOperationManager.prototype.paste = function( |
| /** |
| * Checks if the move operation is available between the given two locations. |
| + * This method uses the volume manager, which is lazily created, therefore the |
| + * result is returned asynchronously. |
| * |
| * @param {DirectoryEntry} sourceEntry An entry from the source. |
| * @param {DirectoryEntry} targetDirEntry Directory entry for the target. |
| - * @return {boolean} Whether we can move from the source to the target. |
| + * @param {function(boolean)} callback Callback with result whether the entries |
| + * can be directly moved. |
| + * @private |
| */ |
| -FileOperationManager.prototype.isMovable = function( |
| - sourceEntry, targetDirEntry) { |
| - var sourceLocationInfo = this.volumeManager_.getLocationInfo(sourceEntry); |
| - var targetDirLocationInfo = this.volumeManager_.getLocationInfo( |
| - targetDirEntry); |
| - |
| - return sourceLocationInfo && targetDirLocationInfo && |
| - sourceLocationInfo.volumeInfo === targetDirLocationInfo.volumeInfo; |
| +FileOperationManager.prototype.isMovable_ = function( |
| + sourceEntry, targetDirEntry, callback) { |
| + VolumeManager.getInstance(function(volumeManager) { |
| + var sourceLocationInfo = volumeManager.getLocationInfo(sourceEntry); |
| + var targetDirLocationInfo = volumeManager.getLocationInfo(targetDirEntry); |
| + callback( |
| + sourceLocationInfo && targetDirLocationInfo && |
| + sourceLocationInfo.volumeInfo === targetDirLocationInfo.volumeInfo); |
| + }); |
| }; |
| /** |
| - * Initiate a file copy. |
| + * Initiate a file copy. When copying files, null can be specified as source |
| + * directory. |
| * |
| * @param {DirectoryEntry} targetDirEntry Target directory. |
| * @param {Array.<Entry>} entries Entries to copy. |
| * @param {boolean} isMove In case of move. |
| - * @return {FileOperationManager.Task} Copy task. |
| * @private |
| */ |
| FileOperationManager.prototype.queueCopy_ = function( |
| targetDirEntry, entries, isMove) { |
| - // When copying files, null can be specified as source directory. |
| + var createTask = function(task) { |
| + task.taskId = this.generateTaskId_(); |
| + task.initialize(function() { |
| + this.copyTasks_.push(task); |
| + this.eventRouter_.sendProgressEvent( |
|
hirono
2014/01/15 02:29:41
Can we send the event before the async call?
It sh
mtomasz
2014/01/15 08:01:03
It seems that it is not safe. If we emit an event
|
| + 'BEGIN', task.getStatus(), task.taskId); |
| + if (this.copyTasks_.length == 1) |
|
hirono
2014/01/15 02:29:41
nit: ===
|
| + this.serviceAllTasks_(); |
| + }.bind(this)); |
| + }.bind(this); |
| + |
| var task; |
| if (isMove) { |
| - if (this.isMovable(entries[0], targetDirEntry)) { |
| - task = new FileOperationManager.MoveTask(entries, targetDirEntry); |
| - } else { |
| - task = new FileOperationManager.CopyTask(entries, targetDirEntry); |
| - task.deleteAfterCopy = true; |
| - } |
| + // When moving between different volumes, moving is implemented as a copy |
| + // and delete. This is because moving between volumes is slow, and moveTo() |
| + // is not cancellable nor provides progress feedback. |
| + this.isMovable_(entries[0], targetDirEntry, function(isMovable) { |
| + if (isMovable) { |
| + createTask(new FileOperationManager.MoveTask(entries, targetDirEntry)); |
| + } else { |
| + var task = new FileOperationManager.CopyTask(entries, targetDirEntry); |
| + task.deleteAfterCopy = true; |
| + createTask(task); |
| + } |
| + }); |
| } else { |
| - task = new FileOperationManager.CopyTask(entries, targetDirEntry); |
| + createTask(new FileOperationManager.CopyTask(entries, targetDirEntry)); |
| } |
| - |
| - task.taskId = this.generateTaskId_(); |
| - task.initialize(function() { |
| - this.copyTasks_.push(task); |
| - this.eventRouter_.sendProgressEvent('BEGIN', task.getStatus(), task.taskId); |
| - if (this.copyTasks_.length == 1) |
| - this.serviceAllTasks_(); |
| - }.bind(this)); |
| - |
| - return task; |
| }; |
| /** |