Chromium Code Reviews| Index: chrome/browser/resources/file_manager/js/file_selection.js |
| diff --git a/chrome/browser/resources/file_manager/js/file_selection.js b/chrome/browser/resources/file_manager/js/file_selection.js |
| index 0e439f2a070a8e162d0a968ad7d3919a5f8f618a..19c7d55972d0e6272fbaf550580eec19a317b148 100644 |
| --- a/chrome/browser/resources/file_manager/js/file_selection.js |
| +++ b/chrome/browser/resources/file_manager/js/file_selection.js |
| @@ -13,6 +13,7 @@ |
| */ |
| function FileSelection(fileManager, indexes) { |
| this.fileManager_ = fileManager; |
| + this.sequenceIndex_ = 0; |
|
satorux1
2013/04/19 07:52:18
sequenceIndex_ may sound too general as this is on
mtomasz
2013/04/19 09:13:16
Done.
|
| this.indexes = indexes; |
| this.entries = []; |
| this.urls = []; |
| @@ -23,7 +24,6 @@ function FileSelection(fileManager, indexes) { |
| this.showBytes = false; |
| this.allDriveFilesPresent = false, |
| this.iconType = null; |
| - this.cancelled_ = false; |
| this.bytesKnown = false; |
| // Synchronously compute what we can. |
| @@ -83,7 +83,8 @@ FileSelection.prototype.createTasks = function(callback) { |
| /** |
| * Computes the total size of selected files. |
| * |
| - * @param {function} callback The callback. |
| + * @param {function} callback Completion callback. Not called when cancelled, |
| + * or a new call has been invoked in the meantime. |
| */ |
| FileSelection.prototype.computeBytes = function(callback) { |
| if (this.entries.length == 0) { |
| @@ -92,26 +93,30 @@ FileSelection.prototype.computeBytes = function(callback) { |
| return; |
| } |
| - var countdown = this.entries.length; |
| + var sequenceIndex = ++this.sequenceIndex_; |
| var pendingMetadataCount = 0; |
| var maybeDone = function() { |
| - if (countdown == 0 && pendingMetadataCount == 0 && !this.cancelled_) { |
| + if (pendingMetadataCount == 0) { |
| this.bytesKnown = true; |
| callback(); |
| } |
| }.bind(this); |
| var onProps = function(filesystem) { |
|
satorux1
2013/04/19 07:52:18
The parameter looks like a misnomer. We are gettin
mtomasz
2013/04/19 09:13:16
This fetches the 'filesystem' metadata. Done.
|
| - this.bytes += filesystem.size; |
| + // Ignore if the call got cancelled, or there is another new one fired. |
| + if (sequenceIndex != this.sequenceIndex_) |
| + return; |
| + |
| + // It may happen that the metadata is not available because a file has been |
| + // deleted in the meantime. |
| + if (filesystem) |
| + this.bytes += filesystem.size; |
| pendingMetadataCount--; |
| maybeDone(); |
| }.bind(this); |
| for (var index = 0; index < this.entries.length; index++) { |
| - if (this.cancelled_) |
| - break; |
| - |
| var entry = this.entries[index]; |
| if (entry.isFile) { |
| this.showBytes |= !FileType.isHosted(entry); |
| @@ -121,10 +126,8 @@ FileSelection.prototype.computeBytes = function(callback) { |
| // Don't compute the directory size as it's expensive. |
| // crbug.com/179073. |
| this.showBytes = false; |
| - countdown = 0; |
| break; |
| } |
| - countdown--; |
| } |
| maybeDone(); |
| }; |
| @@ -135,7 +138,7 @@ FileSelection.prototype.computeBytes = function(callback) { |
| * @private |
| */ |
| FileSelection.prototype.cancelComputing_ = function() { |
| - this.cancelled_ = true; |
| + this.sequenceIndex_++; |
|
satorux1
2013/04/19 07:52:18
Maybe add some comment?
This will invalidate the
mtomasz
2013/04/19 09:13:16
Done.
|
| }; |
| /** |