Commit c82e1379 authored by yoshiki@chromium.org's avatar yoshiki@chromium.org

Files.app: don't refresh metadata when unnecessary

r276293 had introduced the force refresh but it did refresh even when unnecessary. This patch make it refresh metadata 
only when necessary.

BUG=386939
TEST=manually tested

Review URL: https://codereview.chromium.org/347973002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278726 0039d316-1c4b-4281-b951-d872f2087c98
parent 4cd72855
......@@ -546,8 +546,11 @@ DirectoryContents.prototype.getDirectoryEntry = function() {
/**
* Start directory scan/search operation. Either 'scan-completed' or
* 'scan-failed' event will be fired upon completion.
*
* @param {boolean} refresh True to refrech metadata, or false to use cached
* one.
*/
DirectoryContents.prototype.scan = function() {
DirectoryContents.prototype.scan = function(refresh) {
/**
* Invoked when the scanning is completed successfully.
* @this {DirectoryContents}
......@@ -569,7 +572,7 @@ DirectoryContents.prototype.scan = function() {
// 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.scanner_.scan(this.onNewEntries_.bind(this, refresh),
completionCallback.bind(this),
errorCallback.bind(this));
};
......@@ -648,10 +651,13 @@ DirectoryContents.prototype.onScanError_ = function() {
/**
* Called when some chunk of entries are read by scanner.
*
* @param {boolean} refresh True to refresh metadata, or false to use cached
* one.
* @param {Array.<Entry>} entries The list of the scanned entries.
* @private
*/
DirectoryContents.prototype.onNewEntries_ = function(entries) {
DirectoryContents.prototype.onNewEntries_ = function(refresh, entries) {
if (this.scanCancelled_)
return;
......@@ -689,7 +695,7 @@ DirectoryContents.prototype.onNewEntries_ = function(entries) {
var chunk = entriesFiltered.slice(i, i + MAX_CHUNK_SIZE);
prefetchMetadataQueue.run(function(chunk, callbackInner) {
this.prefetchMetadata(chunk, function() {
this.prefetchMetadata(chunk, refresh, function() {
if (!prefetchMetadataQueue.isCancelled()) {
if (this.scanCancelled_)
prefetchMetadataQueue.cancel();
......@@ -712,10 +718,17 @@ DirectoryContents.prototype.onNewEntries_ = function(entries) {
/**
* @param {Array.<Entry>} entries Files.
* @param {boolean} refresh True to refresh metadata, or false to use cached
* one.
* @param {function(Object)} callback Callback on done.
*/
DirectoryContents.prototype.prefetchMetadata = function(entries, callback) {
this.context_.metadataCache.getLatest(entries, 'filesystem|drive', callback);
DirectoryContents.prototype.prefetchMetadata =
function(entries, refresh, callback) {
var TYPES = 'filesystem|drive';
if (refresh)
this.context_.metadataCache.getLatest(entries, TYPES, callback);
else
this.context_.metadataCache.get(entries, TYPES, callback);
};
/**
......
......@@ -170,7 +170,7 @@ DirectoryModel.prototype.onWatcherDirectoryChanged_ = function() {
// Clear the metadata cache since something in this directory has changed.
var directoryEntry = this.getCurrentDirEntry();
this.rescanSoon();
this.rescanSoon(true);
};
/**
......@@ -178,7 +178,7 @@ DirectoryModel.prototype.onWatcherDirectoryChanged_ = function() {
* @private
*/
DirectoryModel.prototype.onFilterChanged_ = function() {
this.rescanSoon();
this.rescanSoon(false);
};
/**
......@@ -252,17 +252,21 @@ DirectoryModel.prototype.setLeadEntry_ = function(value) {
/**
* Schedule rescan with short delay.
* @param {boolean} refresh True to refrech metadata, or false to use cached
* one.
*/
DirectoryModel.prototype.rescanSoon = function() {
this.scheduleRescan(SHORT_RESCAN_INTERVAL);
DirectoryModel.prototype.rescanSoon = function(refresh) {
this.scheduleRescan(SHORT_RESCAN_INTERVAL, refresh);
};
/**
* Schedule rescan with delay. Designed to handle directory change
* notification.
* @param {boolean} refresh True to refrech metadata, or false to use cached
* one.
*/
DirectoryModel.prototype.rescanLater = function() {
this.scheduleRescan(SIMULTANEOUS_RESCAN_INTERVAL);
DirectoryModel.prototype.rescanLater = function(refresh) {
this.scheduleRescan(SIMULTANEOUS_RESCAN_INTERVAL, refresh);
};
/**
......@@ -270,8 +274,10 @@ DirectoryModel.prototype.rescanLater = function() {
* nothing. File operation may cause a few notifications what should cause
* a single refresh.
* @param {number} delay Delay in ms after which the rescan will be performed.
* @param {boolean} refresh True to refrech metadata, or false to use cached
* one.
*/
DirectoryModel.prototype.scheduleRescan = function(delay) {
DirectoryModel.prototype.scheduleRescan = function(delay, refresh) {
if (this.rescanTime_) {
if (this.rescanTime_ <= Date.now() + delay)
return;
......@@ -284,7 +290,7 @@ DirectoryModel.prototype.scheduleRescan = function(delay) {
this.rescanTimeoutId_ = setTimeout(function() {
this.rescanTimeoutId_ = null;
if (sequence === this.changeDirectorySequence_)
this.rescan();
this.rescan(refresh);
}.bind(this), delay);
};
......@@ -307,8 +313,11 @@ DirectoryModel.prototype.clearRescanTimeout_ = function() {
* preserving the select element etc.
*
* This should be to scan the contents of current directory (or search).
*
* @param {boolean} refresh True to refrech metadata, or false to use cached
* one.
*/
DirectoryModel.prototype.rescan = function() {
DirectoryModel.prototype.rescan = function(refresh) {
this.clearRescanTimeout_();
if (this.runningScan_) {
this.pendingRescan_ = true;
......@@ -328,6 +337,7 @@ DirectoryModel.prototype.rescan = function() {
}).bind(this);
this.scan_(dirContents,
refresh,
successCallback, function() {}, function() {}, function() {});
};
......@@ -405,7 +415,7 @@ DirectoryModel.prototype.clearAndScan_ = function(newDirContents,
cr.dispatchSimpleEvent(this, 'scan-started');
var fileList = this.getFileList();
fileList.splice(0, fileList.length);
this.scan_(this.currentDirContents_,
this.scan_(this.currentDirContents_, false,
onDone, onFailed, onUpdated, onCancelled);
};
......@@ -415,6 +425,8 @@ DirectoryModel.prototype.clearAndScan_ = function(newDirContents,
*
* @param {DirectoryContents} dirContents DirectoryContents instance on which
* the scan will be run.
* @param {boolean} refresh True to refrech metadata, or false to use cached
* one.
* @param {function()} successCallback Callback on success.
* @param {function()} failureCallback Callback on failure.
* @param {function()} updatedCallback Callback on update. Only on the last
......@@ -424,6 +436,7 @@ DirectoryModel.prototype.clearAndScan_ = function(newDirContents,
*/
DirectoryModel.prototype.scan_ = function(
dirContents,
refresh,
successCallback, failureCallback, updatedCallback, cancelledCallback) {
var self = this;
......@@ -434,7 +447,7 @@ DirectoryModel.prototype.scan_ = function(
*/
var maybeRunPendingRescan = function() {
if (this.pendingRescan_) {
this.rescanSoon();
this.rescanSoon(refresh);
this.pendingRescan_ = false;
return true;
}
......@@ -469,7 +482,7 @@ DirectoryModel.prototype.scan_ = function(
return;
if (this.scanFailures_ <= 1)
this.rescanLater();
this.rescanLater(refresh);
}.bind(this);
this.runningScan_ = dirContents;
......@@ -478,7 +491,7 @@ DirectoryModel.prototype.scan_ = function(
dirContents.addEventListener('scan-updated', updatedCallback);
dirContents.addEventListener('scan-failed', onFailure);
dirContents.addEventListener('scan-cancelled', cancelledCallback);
dirContents.scan();
dirContents.scan(refresh);
};
/**
......@@ -537,14 +550,13 @@ DirectoryModel.prototype.onEntryChanged = function(kind, entry) {
switch (kind) {
case util.EntryChangedKind.CREATED:
// Refresh the cache.
this.metadataCache_.clear([entry], '*');
entry.getParent(function(parentEntry) {
if (!util.isSameEntry(this.getCurrentDirEntry(), parentEntry)) {
// Do nothing if current directory changed during async operations.
return;
}
this.currentDirContents_.prefetchMetadata([entry], function() {
// Refresh the cache.
this.currentDirContents_.prefetchMetadata([entry], true, function() {
if (!util.isSameEntry(this.getCurrentDirEntry(), parentEntry)) {
// Do nothing if current directory changed during async operations.
return;
......@@ -601,7 +613,7 @@ DirectoryModel.prototype.findIndexByEntry_ = function(entry) {
*/
DirectoryModel.prototype.onRenameEntry = function(
oldEntry, newEntry, opt_callback) {
this.currentDirContents_.prefetchMetadata([newEntry], function() {
this.currentDirContents_.prefetchMetadata([newEntry], true, function() {
// If the current directory is the old entry, then quietly change to the
// new one.
if (util.isSameEntry(oldEntry, this.getCurrentDirEntry()))
......
......@@ -1872,7 +1872,7 @@ var BOTTOM_MARGIN_FOR_PREVIEW_PANEL_PX = 52;
if (self.hostedButton.hasAttribute('checked') ===
prefs.hostedFilesDisabled && self.isOnDrive()) {
self.directoryModel_.rescan();
self.directoryModel_.rescan(false);
}
if (!prefs.hostedFilesDisabled)
......
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