Chromium Code Reviews| 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..5b0058fb608618829e2e3a2e878ecba08021bd2c 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. |
| * |
| @@ -799,6 +835,8 @@ fileOperationUtil.CopyTask.prototype.run = function( |
| this.processedBytes += size - processedEntry.processedBytes; |
| processedEntry.processedBytes = size; |
| + this.numRemainingItems--; |
|
fukino
2017/06/26 07:34:09
IIRC, progress callback can be called multiple tim
tetsui
2017/06/26 08:55:42
Done.
|
| + |
| // Updates progress bar in limited frequency so that intervals between |
| // updates have at least 200ms. |
| this.updateProgressRateLimiter_.run(); |
| @@ -807,6 +845,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 +882,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 +892,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 +1044,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); |