Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1915)

Unified Diff: chrome/browser/resources/file_manager/js/file_copy_manager.js

Issue 22150006: Re-implement cancellation of copyFileEntry_(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/resources/file_manager/js/util.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/file_manager/js/file_copy_manager.js
diff --git a/chrome/browser/resources/file_manager/js/file_copy_manager.js b/chrome/browser/resources/file_manager/js/file_copy_manager.js
index 1099f5d1ab00989b03a7ca6c2929b096ad54b7f3..7b2038c3526b3d69392bcdb31d1d4aac306904d9 100644
--- a/chrome/browser/resources/file_manager/js/file_copy_manager.js
+++ b/chrome/browser/resources/file_manager/js/file_copy_manager.js
@@ -889,9 +889,17 @@ FileCopyManager.prototype.processCopyEntry_ = function(
targetRelativePath,
{create: true, exclusive: true},
function(targetEntry) {
- self.copyFileEntry_(
+ self.cancelCallback_ = self.copyFileEntry_(
sourceEntry, targetEntry,
- onCopyProgress, onCopyComplete, onFilesystemError);
+ onCopyProgress,
+ function(entry, size) {
+ self.cancelCallback_ = null;
+ onCopyComplete(entry, size);
+ },
+ function(error) {
+ self.cancelCallback_ = null;
+ onFilesystemError(error);
+ });
},
util.flog('Error getting file: ' + targetRelativePath,
onFilesystemError));
@@ -991,6 +999,9 @@ FileCopyManager.prototype.processCopyEntry_ = function(
* @param {function(FileError)} errorCallback Function that will be called
* if an error is encountered. Takes error type and additional error data
* as parameters.
+ * @return {function()} Callback to cancel the current file copy operation.
+ * When the cancel is done, errorCallback will be called. The returned
+ * callback must not be called more than once.
* @private
*/
FileCopyManager.prototype.copyFileEntry_ = function(sourceEntry,
@@ -998,24 +1009,37 @@ FileCopyManager.prototype.copyFileEntry_ = function(sourceEntry,
progressCallback,
successCallback,
errorCallback) {
- if (this.maybeCancel_())
- return;
+ // Set to true when cancel is requested.
+ var cancelRequested = false;
- var self = this;
+ sourceEntry.file(function(file) {
+ if (cancelRequested) {
+ errorCallback(util.createFileError(FileError.ABORT_ERR));
+ return;
+ }
+
+ targetEntry.createWriter(function(writer) {
+ if (cancelRequested) {
+ errorCallback(util.createFileError(FileError.ABORT_ERR));
mtomasz 2013/08/06 01:39:19 Can we remove the target file on cancel? It may be
hidehiko 2013/08/06 02:14:55 I want to keep this as is, because, IIRC, many OS
mtomasz 2013/08/06 02:21:38 As far as I remember on Windows the file gets remo
mtomasz 2013/08/06 02:22:29 I meant when downloading a file in Chrome.
+ return;
+ }
- var onSourceFileFound = function(file) {
- var onWriterCreated = function(writer) {
var reportedProgress = 0;
- writer.onerror = function(progress) {
- errorCallback(writer.error);
+ writer.onerror = writer.onabort = function(progress) {
+ errorCallback(cancelRequested ?
+ util.createFileError(FileError.ABORT_ERR) :
+ writer.error);
};
writer.onprogress = function(progress) {
- if (self.maybeCancel_()) {
+ if (cancelRequested) {
// If the copy was cancelled, we should abort the operation.
+ // The errorCallback will be called by writer.onabort after the
+ // termination.
writer.abort();
return;
}
+
// |progress.loaded| will contain total amount of data copied by now.
// |progressCallback| expects data amount delta from the last progress
// update.
@@ -1024,20 +1048,31 @@ FileCopyManager.prototype.copyFileEntry_ = function(sourceEntry,
};
writer.onwrite = function() {
+ if (cancelRequested) {
+ errorCallback(util.createFileError(FileError.ABORT_ERR));
+ return;
+ }
+
sourceEntry.getMetadata(function(metadata) {
- chrome.fileBrowserPrivate.setLastModified(targetEntry.toURL(),
+ if (cancelRequested) {
+ errorCallback(util.createFileError(FileError.ABORT_ERR));
+ return;
+ }
+
+ chrome.fileBrowserPrivate.setLastModified(
+ targetEntry.toURL(),
'' + Math.round(metadata.modificationTime.getTime() / 1000));
successCallback(targetEntry, file.size - reportedProgress);
});
};
writer.write(file);
- };
+ }, errorCallback);
+ }, errorCallback);
- targetEntry.createWriter(onWriterCreated, errorCallback);
+ return function() {
+ cancelRequested = true;
};
-
- sourceEntry.file(onSourceFileFound, errorCallback);
};
/**
@@ -1196,11 +1231,7 @@ FileCopyManager.prototype.serviceZipTask_ = function(
onFilesystemError);
} else {
onFilesystemError(
- Object.create(FileError.prototype, {
- code: {
- get: function() { return FileError.INVALID_MODIFICATION_ERR; }
- }
- }));
+ util.createFileError(FileError.INVALID_MODIFICATION_ERR));
}
};
« no previous file with comments | « no previous file | chrome/browser/resources/file_manager/js/util.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698