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

Unified Diff: chrome/browser/resources/file_manager/background/js/file_operation_manager.js

Issue 152513002: Files.app: Fix the number of remaining files and processed bytes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed a test. Created 6 years, 10 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
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 16bd4a0ef2821259f78013adb011948ac72a0f0a..00258fc94384ac4f0f84c89c4223d512a28f8f1e 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
@@ -412,6 +412,13 @@ FileOperationManager.Task = function(
this.processedBytes = 0;
/**
+ * Index of the progressing entry in sourceEntries.
+ * @type {number}
+ * @private
+ */
+ this.processingSourceIndex_ = 0;
+
+ /**
* Set to true when cancel is requested.
* @private {boolean}
*/
@@ -439,15 +446,6 @@ FileOperationManager.Task.prototype.initialize = function(callback) {
};
/**
- * Updates copy progress status for the entry.
- *
- * @param {number} size Number of bytes that has been copied since last update.
- */
-FileOperationManager.Task.prototype.updateFileCopyProgress = function(size) {
- this.completedBytes += size;
-};
-
-/**
* Requests cancellation of this task.
* When the cancellation is done, it is notified via callbacks of run().
*/
@@ -480,44 +478,33 @@ FileOperationManager.Task.prototype.run = function(
* @return {object} Status object.
*/
FileOperationManager.Task.prototype.getStatus = function() {
- var numRemainingItems = this.countRemainingItems();
+ var processingEntry = this.sourceEntries[this.processingSourceIndex_];
return {
operationType: this.operationType,
- numRemainingItems: numRemainingItems,
+ numRemainingItems: this.sourceEntries.length - this.processingSourceIndex_,
totalBytes: this.totalBytes,
processedBytes: this.processedBytes,
- processingEntry: this.getSingleEntry()
+ processingEntryName: processingEntry ? processingEntry.name : ''
};
};
/**
- * Counts the number of remaining items.
- * @return {number} Number of remaining items.
- */
-FileOperationManager.Task.prototype.countRemainingItems = function() {
- var count = 0;
- for (var i = 0; i < this.processingEntries.length; i++) {
- for (var entryURL in this.processingEntries[i]) {
- count++;
- }
- }
- return count;
-};
-
-/**
- * Obtains the single processing entry. If there are multiple processing
- * entries, it returns null.
- * @return {Entry} First entry.
+ * Obtains the number of total processed bytes.
+ * @return {number} Number of total processed bytes.
+ * @private
*/
-FileOperationManager.Task.prototype.getSingleEntry = function() {
- if (this.countRemainingItems() !== 1)
- return null;
- for (var i = 0; i < this.processingEntries.length; i++) {
+FileOperationManager.Task.prototype.calcProcessedBytes_ = function() {
+ var bytes = 0;
+ for (var i = 0; i < this.processingSourceIndex_ + 1; i++) {
var entryMap = this.processingEntries[i];
- for (var name in entryMap)
- return entryMap[name];
+ if (!entryMap)
+ break;
+ for (var name in entryMap) {
+ bytes += i < this.processingSourceIndex_ ?
+ entryMap[name].size : entryMap[name].processedBytes;
+ }
}
- return null;
+ return bytes;
};
/**
@@ -653,12 +640,10 @@ FileOperationManager.CopyTask.prototype.run = function(
var sourceEntryURL = sourceEntry.toURL();
var processedEntry =
this.processingEntries[index][sourceEntryURL];
- if (processedEntry) {
- this.processedBytes +=
- processedEntry.size - processedEntry.processedBytes;
- progressCallback();
- delete this.processingEntries[index][sourceEntryURL];
- }
+
+ // Update current source index.
+ this.processingSourceIndex_ = index + 1;
+ this.processedBytes = this.calcProcessedBytes_();
// The destination entry may be null, if the copied file got
// deleted just after copying.
@@ -814,9 +799,9 @@ FileOperationManager.MoveTask.prototype.run = function(
FileOperationManager.MoveTask.processEntry_(
entry, this.targetDirEntry, entryChangedCallback,
function() {
- // Erase the processing entry.
- this.processingEntries[index] = {};
- this.processedBytes++;
+ // Update current source index.
+ this.processingSourceIndex_ = index + 1;
+ this.processedBytes = this.calcProcessedBytes_();
callback();
}.bind(this),
errorCallback);

Powered by Google App Engine
This is Rietveld 408576698