Commit 3cba6ce1 authored by tetsui's avatar tetsui Committed by Commit bot

Reuse File objects in FileTransferController.

FileEntry.file is slow operation internally queries file metadata.
However, FileTransferController calls FileEntry.file for all the
selected files each time CHANGE_THROTTLED event is fired.
CHANGE_THROTTLED is fired every time a file is copied
during multi file copy.
In some slow storage devices which do not support parallel requests
such as MTP connected ones, this severely slows down file copy.

BUG=712121
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:closure_compilation

Review-Url: https://codereview.chromium.org/2843683002
Cr-Commit-Position: refs/heads/master@{#467270}
parent dc1b7c2d
......@@ -1261,20 +1261,30 @@ FileTransferController.prototype.simulateCommand_ = function(command, handler) {
*/
FileTransferController.prototype.onFileSelectionChanged_ = function() {
this.preloadedThumbnailImagePromise_ = null;
this.selectedAsyncData_ = {};
};
/**
* @private
*/
FileTransferController.prototype.onFileSelectionChangedThrottled_ = function() {
// Remove file objects that are no longer in the selection.
var asyncData = {};
var entries = this.selectionHandler_.selection.entries;
var asyncData = this.selectedAsyncData_;
for (var i = 0; i < entries.length; i++) {
var entryUrl = entries[i].toURL();
if (entryUrl in this.selectedAsyncData_) {
asyncData[entryUrl] = this.selectedAsyncData_[entryUrl];
}
}
this.selectedAsyncData_ = asyncData;
var fileEntries = [];
for (var i = 0; i < entries.length; i++) {
if (entries[i].isFile)
fileEntries.push(entries[i]);
asyncData[entries[i].toURL()] = {externalFileUrl: '', file: null};
if (!(entries[i].toURL() in asyncData)) {
asyncData[entries[i].toURL()] = {externalFileUrl: '', file: null};
}
}
var containsDirectory = this.selectionHandler_.selection.directoryCount > 0;
......@@ -1285,9 +1295,11 @@ FileTransferController.prototype.onFileSelectionChangedThrottled_ = function() {
if (!containsDirectory) {
for (var i = 0; i < fileEntries.length; i++) {
(function(fileEntry) {
fileEntry.file(function(file) {
asyncData[fileEntry.toURL()].file = file;
});
if (!(asyncData[fileEntry.toURL()].file)) {
fileEntry.file(function(file) {
asyncData[fileEntry.toURL()].file = file;
});
}
})(fileEntries[i]);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment