Commit 2203429f authored by hirono@chromium.org's avatar hirono@chromium.org

Files.app: Fix nits in FileOperationManager.

 * Assign correct entry for entry-change event.
 * Assign totalBytes to processedBytes at the end of zipping.
 * Determine if entries are movable or not by comparing file system.

BUG=None
TEST=manually

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

Cr-Commit-Position: refs/heads/master@{#289291}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289291 0039d316-1c4b-4281-b951-d872f2087c98
parent 41e6c810
...@@ -237,11 +237,6 @@ function testCopy(callback) { ...@@ -237,11 +237,6 @@ function testCopy(callback) {
assertEquals(0, lastEvent.status.numRemainingItems); assertEquals(0, lastEvent.status.numRemainingItems);
assertEquals(10, lastEvent.status.processedBytes); assertEquals(10, lastEvent.status.processedBytes);
assertEquals(10, lastEvent.status.totalBytes); assertEquals(10, lastEvent.status.totalBytes);
assertTrue(events.some(function(event) {
return event.type === 'entry-changed' &&
event.entry === targetEntry;
}));
}), callback); }), callback);
fileOperationManager.paste(sourceEntries, targetEntry, false); fileOperationManager.paste(sourceEntries, targetEntry, false);
......
...@@ -241,10 +241,16 @@ fileOperationUtil.copyTo = function( ...@@ -241,10 +241,16 @@ fileOperationUtil.copyTo = function(
case 'end_copy_entry': case 'end_copy_entry':
// TODO(mtomasz): Convert URL to Entry in custom bindings. // TODO(mtomasz): Convert URL to Entry in custom bindings.
util.URLsToEntries( (source.isFile ? parent.getFile : parent.getDirectory).call(
[status.destinationUrl], function(destinationEntries) { parent,
entryChangedCallback(status.sourceUrl, newName,
destinationEntries[0] || null); null,
function(entry) {
entryChangedCallback(status.sourceUrl, entry);
callback();
},
function() {
entryChangedCallback(status.sourceUrl, null);
callback(); callback();
}); });
break; break;
...@@ -1039,9 +1045,10 @@ FileOperationManager.ZipTask.prototype.run = function( ...@@ -1039,9 +1045,10 @@ FileOperationManager.ZipTask.prototype.run = function(
this.zipBaseDirEntry, this.zipBaseDirEntry,
destPath, destPath,
function(entry) { function(entry) {
this.processedBytes = this.totalBytes;
entryChangedCallback(util.EntryChangedKind.CREATED, entry); entryChangedCallback(util.EntryChangedKind.CREATED, entry);
successCallback(); successCallback();
}, }.bind(this),
function(error) { function(error) {
errorCallback(new FileOperationManager.Error( errorCallback(new FileOperationManager.Error(
util.FileOperationErrorType.FILESYSTEM_ERROR, error)); util.FileOperationErrorType.FILESYSTEM_ERROR, error));
...@@ -1156,7 +1163,6 @@ FileOperationManager.prototype.paste = function( ...@@ -1156,7 +1163,6 @@ FileOperationManager.prototype.paste = function(
if (isMove) { if (isMove) {
for (var index = 0; index < sourceEntries.length; index++) { for (var index = 0; index < sourceEntries.length; index++) {
var sourceEntry = sourceEntries[index];
resolveGroup.run(function(sourceEntry, callback) { resolveGroup.run(function(sourceEntry, callback) {
sourceEntry.getParent(function(inParentEntry) { sourceEntry.getParent(function(inParentEntry) {
if (!util.isSameEntry(inParentEntry, targetEntry)) if (!util.isSameEntry(inParentEntry, targetEntry))
...@@ -1169,7 +1175,7 @@ FileOperationManager.prototype.paste = function( ...@@ -1169,7 +1175,7 @@ FileOperationManager.prototype.paste = function(
filteredEntries.push(sourceEntry); filteredEntries.push(sourceEntry);
callback(); callback();
}); });
}.bind(this, sourceEntry)); }.bind(this, sourceEntries[index]));
} }
} else { } else {
// Always copy all of the files. // Always copy all of the files.
...@@ -1185,28 +1191,6 @@ FileOperationManager.prototype.paste = function( ...@@ -1185,28 +1191,6 @@ FileOperationManager.prototype.paste = function(
}.bind(this)); }.bind(this));
}; };
/**
* 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.
* @param {function(boolean)} callback Callback with result whether the entries
* can be directly moved.
* @private
*/
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. When copying files, null can be specified as source * Initiate a file copy. When copying files, null can be specified as source
* directory. * directory.
...@@ -1218,34 +1202,28 @@ FileOperationManager.prototype.isMovable_ = function( ...@@ -1218,34 +1202,28 @@ FileOperationManager.prototype.isMovable_ = function(
*/ */
FileOperationManager.prototype.queueCopy_ = function( FileOperationManager.prototype.queueCopy_ = function(
targetDirEntry, entries, isMove) { targetDirEntry, entries, isMove) {
var createTask = function(task) {
task.taskId = this.generateTaskId_();
this.eventRouter_.sendProgressEvent(
'BEGIN', task.getStatus(), task.taskId);
task.initialize(function() {
this.copyTasks_.push(task);
if (this.copyTasks_.length === 1)
this.serviceAllTasks_();
}.bind(this));
}.bind(this);
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
// and delete. This is because moving between volumes is slow, and moveTo() // and delete. This is because moving between volumes is slow, and moveTo()
// is not cancellable nor provides progress feedback. // is not cancellable nor provides progress feedback.
this.isMovable_(entries[0], targetDirEntry, function(isMovable) { if (util.isSameFileSystem(entries[0].filesystem,
if (isMovable) { targetDirEntry.filesystem)) {
createTask(new FileOperationManager.MoveTask(entries, targetDirEntry)); task = new FileOperationManager.MoveTask(entries, targetDirEntry);
} else { } else {
createTask( task = new FileOperationManager.CopyTask(entries, targetDirEntry, true);
new FileOperationManager.CopyTask(entries, targetDirEntry, true)); }
}
});
} else { } else {
createTask( task = new FileOperationManager.CopyTask(entries, targetDirEntry, false);
new FileOperationManager.CopyTask(entries, targetDirEntry, false));
} }
task.taskId = this.generateTaskId_();
this.eventRouter_.sendProgressEvent('BEGIN', task.getStatus(), task.taskId);
task.initialize(function() {
this.copyTasks_.push(task);
if (this.copyTasks_.length === 1)
this.serviceAllTasks_();
}.bind(this));
}; };
/** /**
......
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