summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryoshiki@chromium.org <yoshiki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-24 22:36:05 +0000
committeryoshiki@chromium.org <yoshiki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-24 22:36:05 +0000
commitfe3493e5a5e0f6d24b0b0f22b8f880da5490b80c (patch)
tree894e99b01fa59355f284b894864e0b47d4dd26df
parentda8b9aab728939c8475ec90afa76328ef29b07b3 (diff)
downloadchromium_src-fe3493e5a5e0f6d24b0b0f22b8f880da5490b80c.zip
chromium_src-fe3493e5a5e0f6d24b0b0f22b8f880da5490b80c.tar.gz
chromium_src-fe3493e5a5e0f6d24b0b0f22b8f880da5490b80c.tar.bz2
[Files.app] Reduce the number of the sorts during file list loading
Sort was invoked every after loading 50 files, but sort is heavy operation and we needed to reduce it. This patch changes the timing to do sort after loading the complete list. BUG=348886 TEST=manually tested Review URL: https://codereview.chromium.org/203413007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@259041 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/resources/file_manager/foreground/js/directory_contents.js64
1 files changed, 49 insertions, 15 deletions
diff --git a/chrome/browser/resources/file_manager/foreground/js/directory_contents.js b/chrome/browser/resources/file_manager/foreground/js/directory_contents.js
index 7c9cfa5..23581f2 100644
--- a/chrome/browser/resources/file_manager/foreground/js/directory_contents.js
+++ b/chrome/browser/resources/file_manager/foreground/js/directory_contents.js
@@ -528,12 +528,30 @@ DirectoryContents.prototype.getDirectoryEntry = function() {
* 'scan-failed' event will be fired upon completion.
*/
DirectoryContents.prototype.scan = function() {
+ /**
+ * Invoked when the scanning is completed successfully.
+ * @this {DirectoryContents}
+ */
+ function completionCallback() {
+ this.onScanFinished_();
+ this.onScanCompleted_();
+ }
+
+ /**
+ * Invoked when the scanning is finished but is not completed due to error.
+ * @this {DirectoryContents}
+ */
+ function errorCallback() {
+ this.onScanFinished_();
+ this.onScanError_();
+ }
+
// TODO(hidehiko,mtomasz): this scan method must be called at most once.
// Remove such a limitation.
this.scanner_ = this.scannerFactory_();
this.scanner_.scan(this.onNewEntries_.bind(this),
- this.onScanCompleted_.bind(this),
- this.onScanError_.bind(this));
+ completionCallback.bind(this),
+ errorCallback.bind(this));
};
/**
@@ -546,22 +564,49 @@ DirectoryContents.prototype.cancelScan = function() {
if (this.scanner_)
this.scanner_.cancel();
+ this.onScanFinished_();
+
this.prefetchMetadataQueue_.cancel();
cr.dispatchSimpleEvent(this, 'scan-cancelled');
};
/**
- * Called when the scanning by scanner_ is done.
+ * Called when the scanning by scanner_ is done, even when the scanning is
+ * succeeded or failed. This is called before completion (or error) callback.
+ *
* @private
*/
-DirectoryContents.prototype.onScanCompleted_ = function() {
+DirectoryContents.prototype.onScanFinished_ = function() {
this.scanner_ = null;
+
+ this.prefetchMetadataQueue_.run(function(callback) {
+ // TODO(yoshiki): Here we should fire the update event of changed
+ // items. Currently we have a method this.fileList_.updateIndex() to
+ // fire an event, but this method takes only 1 argument and invokes sort
+ // one by one. It is obviously time wasting. Instead, we call sort
+ // directory.
+ // In future, we should implement a good method like updateIndexes and
+ // use it here.
+ var status = this.fileList_.sortStatus;
+ if (status)
+ this.fileList_.sort(status.field, status.direction);
+
+ callback();
+ }.bind(this));
+};
+
+/**
+ * Called when the scanning by scanner_ is succeeded.
+ * @private
+ */
+DirectoryContents.prototype.onScanCompleted_ = function() {
if (this.scanCancelled_)
return;
this.prefetchMetadataQueue_.run(function(callback) {
// Call callback first, so isScanning() returns false in the event handlers.
callback();
+
cr.dispatchSimpleEvent(this, 'scan-completed');
}.bind(this));
};
@@ -571,7 +616,6 @@ DirectoryContents.prototype.onScanCompleted_ = function() {
* @private
*/
DirectoryContents.prototype.onScanError_ = function() {
- this.scanner_ = null;
if (this.scanCancelled_)
return;
@@ -614,16 +658,6 @@ DirectoryContents.prototype.onNewEntries_ = function(entries) {
return;
}
- // TODO(yoshiki): Here we should fire the update event of changed
- // items. Currently we have a method this.fileList_.updateIndex() to
- // fire an event, but this method takes only 1 argument and invokes sort
- // one by one. It is obviously time wasting. Instead, we call sort
- // directory.
- // In future, we should implement a good method like updateIndexes and
- // use it here.
- var status = this.fileList_.sortStatus;
- this.fileList_.sort(status.field, status.direction);
-
cr.dispatchSimpleEvent(this, 'scan-updated');
callback();
}.bind(this));