Index: ui/file_manager/file_manager/background/js/file_operation_util.js |
diff --git a/ui/file_manager/file_manager/background/js/file_operation_util.js b/ui/file_manager/file_manager/background/js/file_operation_util.js |
index 73bb7268651baf18e607a82adb79fbd255e18461..467cf30b4a2df5ae3f14f4da9936198d665fc891 100644 |
--- a/ui/file_manager/file_manager/background/js/file_operation_util.js |
+++ b/ui/file_manager/file_manager/background/js/file_operation_util.js |
@@ -549,6 +549,12 @@ fileOperationUtil.Task = function( |
*/ |
this.processedBytes = 0; |
+ /** |
+ * Total number of remaining items. Updated periodically. |
+ * @type {number} |
+ */ |
+ this.numRemainingItems = this.sourceEntries.length; |
+ |
/** |
* Index of the progressing entry in sourceEntries. |
* @private {number} |
@@ -612,14 +618,14 @@ fileOperationUtil.Task.prototype.run = function( |
/** |
* Get states of the task. |
- * TOOD(hirono): Removes this method and sets a task to progress events. |
+ * TODO(hirono): Removes this method and sets a task to progress events. |
* @return {Object} Status object. |
*/ |
fileOperationUtil.Task.prototype.getStatus = function() { |
var processingEntry = this.sourceEntries[this.processingSourceIndex_]; |
return { |
operationType: this.operationType, |
- numRemainingItems: this.sourceEntries.length - this.processingSourceIndex_, |
+ numRemainingItems: this.numRemainingItems, |
totalBytes: this.totalBytes, |
processedBytes: this.processedBytes, |
processingEntryName: processingEntry ? processingEntry.name : '' |
@@ -645,6 +651,36 @@ fileOperationUtil.Task.prototype.calcProcessedBytes_ = function() { |
return bytes; |
}; |
+/** |
+ * Obtains the number of remaining items. |
+ * @return {number} Number of remaining items. |
+ * @private |
+ */ |
+fileOperationUtil.Task.prototype.calcNumRemainingItems_ = function() { |
+ var numRemainingItems = 0; |
+ |
+ var resolvedEntryMap; |
+ if (this.processingEntries && this.processingEntries.length > 0) |
+ resolvedEntryMap = this.processingEntries[this.processingSourceIndex_]; |
+ |
+ if (resolvedEntryMap) { |
+ for (var key in resolvedEntryMap) { |
+ if (resolvedEntryMap.hasOwnProperty(key) && |
+ resolvedEntryMap[key].processedBytes === 0) { |
+ numRemainingItems++; |
+ } |
+ } |
+ for (var i = this.processingSourceIndex_ + 1; |
+ i < this.processingEntries.length; i++) { |
+ numRemainingItems += Object.keys(this.processingEntries[i] || {}).length; |
+ } |
+ } else { |
+ numRemainingItems = this.sourceEntries.length - this.processingSourceIndex_; |
+ } |
+ |
+ return numRemainingItems; |
+}; |
+ |
/** |
* Task to copy entries. |
* |
@@ -794,11 +830,24 @@ fileOperationUtil.CopyTask.prototype.run = function( |
if (!processedEntry) |
return; |
+ var alreadyCompleted = |
+ processedEntry.processedBytes === processedEntry.size; |
+ |
// Accumulates newly processed bytes. |
var size = opt_size !== undefined ? opt_size : processedEntry.size; |
this.processedBytes += size - processedEntry.processedBytes; |
processedEntry.processedBytes = size; |
+ // updateProgress can be called multiple times for a single file copy, and |
+ // it might not be called for a small file. |
+ // The following prevents multiple call for a single file to decrement |
+ // numRemainingItems multiple times. |
+ // For small files, it will be decremented by next calcNumRemainingItems_(). |
+ if (!alreadyCompleted && |
+ processedEntry.processedBytes === processedEntry.size) { |
+ this.numRemainingItems--; |
+ } |
+ |
// Updates progress bar in limited frequency so that intervals between |
// updates have at least 200ms. |
this.updateProgressRateLimiter_.run(); |
@@ -807,6 +856,8 @@ fileOperationUtil.CopyTask.prototype.run = function( |
this.updateProgressRateLimiter_ = new AsyncUtil.RateLimiter(progressCallback); |
+ this.numRemainingItems = this.calcNumRemainingItems_(); |
+ |
// Number of consecutive errors. Increases while failing and resets to zero |
// when one of them succeeds. |
var errorCount = 0; |
@@ -842,6 +893,7 @@ fileOperationUtil.CopyTask.prototype.run = function( |
// Update current source index and processing bytes. |
this.processingSourceIndex_ = index + 1; |
this.processedBytes = this.calcProcessedBytes_(); |
+ this.numRemainingItems = this.calcNumRemainingItems_(); |
errorCount = 0; |
callback(); |
}.bind(this), |
@@ -851,6 +903,7 @@ fileOperationUtil.CopyTask.prototype.run = function( |
// Update current source index and processing bytes. |
this.processingSourceIndex_ = index + 1; |
this.processedBytes = this.calcProcessedBytes_(); |
+ this.numRemainingItems = this.calcNumRemainingItems_(); |
errorCount++; |
lastError = error; |
if (errorCount < |
@@ -1002,6 +1055,7 @@ fileOperationUtil.MoveTask.prototype.run = function( |
// Update current source index. |
this.processingSourceIndex_ = index + 1; |
this.processedBytes = this.calcProcessedBytes_(); |
+ this.numRemainingItems = this.calcNumRemainingItems_(); |
callback(); |
}.bind(this), |
errorCallback); |