Commit 1fe7babf authored by serya@chromium.org's avatar serya@chromium.org

Preventing files from being resorted after load.

Scanning a directory we add files to the data model, sort them by name (if the sorting field needs async call like date) and then resort againg when data available.
To avoid flacking lets fetch the data before adding data to the model.

BUG=chromium-os:19082
TEST=None


Review URL: http://codereview.chromium.org/8774008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112691 0039d316-1c4b-4281-b951-d872f2087c98
parent 27e836ea
...@@ -1482,6 +1482,11 @@ FileManager.prototype = { ...@@ -1482,6 +1482,11 @@ FileManager.prototype = {
* go fetch data for the sort field that we may not have yet. * go fetch data for the sort field that we may not have yet.
*/ */
FileManager.prototype.prepareSort_ = function(field, callback) { FileManager.prototype.prepareSort_ = function(field, callback) {
this.prepareSortEntries_(this.dataModel_.slice(), field, callback);
};
FileManager.prototype.prepareSortEntries_ = function(entries, field,
callback) {
var cacheFunction; var cacheFunction;
if (field == 'name' || field == 'cachedMtime_') { if (field == 'name' || field == 'cachedMtime_') {
...@@ -1507,11 +1512,10 @@ FileManager.prototype = { ...@@ -1507,11 +1512,10 @@ FileManager.prototype = {
} }
} }
var dataModel = this.dataModel_; var uncachedCount = entries.length;
var uncachedCount = dataModel.length;
for (var i = uncachedCount - 1; i >= 0 ; i--) { for (var i = uncachedCount - 1; i >= 0 ; i--) {
var entry = dataModel.item(i); var entry = entries[i];
if (field in entry) { if (field in entry) {
uncachedCount--; uncachedCount--;
} else { } else {
...@@ -3212,11 +3216,13 @@ FileManager.prototype = { ...@@ -3212,11 +3216,13 @@ FileManager.prototype = {
}); });
} }
spliceArgs.unshift(0, 0); // index, deleteCount self.prefetchCacheForSorting_(spliceArgs, function() {
self.dataModel_.splice.apply(self.dataModel_, spliceArgs); spliceArgs.unshift(0, 0); // index, deleteCount
self.dataModel_.splice.apply(self.dataModel_, spliceArgs);
// Keep reading until entries.length is 0. // Keep reading until entries.length is 0.
reader.readEntries(onReadSome, onError); reader.readEntries(onReadSome, onError);
});
}; };
metrics.startInterval('DirectoryScan'); metrics.startInterval('DirectoryScan');
...@@ -3238,6 +3244,16 @@ FileManager.prototype = { ...@@ -3238,6 +3244,16 @@ FileManager.prototype = {
opt_callback(); opt_callback();
}; };
FileManager.prototype.prefetchCacheForSorting_ = function(entries, callback) {
var field = this.dataModel_.sortStatus.field;
if (field) {
this.prepareSortEntries_(entries, field, callback);
} else {
callback();
return;
}
};
FileManager.prototype.findListItem_ = function(event) { FileManager.prototype.findListItem_ = function(event) {
var node = event.srcElement; var node = event.srcElement;
while (node) { while (node) {
......
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