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

Files.app: Let DirectoryContents controls metadata cache size by relative value

Previously, DirectoryContents controlled the size of metadata cache by absolute value. But multiple of instances of DirectoryContents might be created at same time and it might set wrong cache size. 

This patch lets DirectoryContents controls metadata cache size by relative value, instead of absolute value, and solves that problem.

BUG=373629
TEST=manually

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275771 0039d316-1c4b-4281-b951-d872f2087c98
parent 3c6980fa
...@@ -455,6 +455,8 @@ function DirectoryContents(context, ...@@ -455,6 +455,8 @@ function DirectoryContents(context,
this.scanner_ = null; this.scanner_ = null;
this.processNewEntriesQueue_ = new AsyncUtil.Queue(); this.processNewEntriesQueue_ = new AsyncUtil.Queue();
this.scanCancelled_ = false; this.scanCancelled_ = false;
this.lastSpaceInMetadataCache_ = 0;
} }
/** /**
...@@ -474,6 +476,24 @@ DirectoryContents.prototype.clone = function() { ...@@ -474,6 +476,24 @@ DirectoryContents.prototype.clone = function() {
this.scannerFactory_); this.scannerFactory_);
}; };
/**
* Disposes the reserved metadata cache.
*/
DirectoryContents.prototype.dispose = function() {
this.context_.metadataCache.resizeBy(-this.lastSpaceInMetadataCache_);
};
/**
* Make a space for current directory size in the metadata cache.
*
* @param {number} size The cache size to be set.
* @private
*/
DirectoryContents.prototype.makeSpaceInMetadataCache_ = function(size) {
this.context_.metadataCache.resizeBy(size - this.lastSpaceInMetadataCache_);
this.lastSpaceInMetadataCache_ = size;
};
/** /**
* Use a given fileList instead of the fileList from the context. * Use a given fileList instead of the fileList from the context.
* @param {Array|cr.ui.ArrayDataModel} fileList The new file list. * @param {Array|cr.ui.ArrayDataModel} fileList The new file list.
...@@ -483,7 +503,7 @@ DirectoryContents.prototype.setFileList = function(fileList) { ...@@ -483,7 +503,7 @@ DirectoryContents.prototype.setFileList = function(fileList) {
this.fileList_ = fileList; this.fileList_ = fileList;
else else
this.fileList_ = new cr.ui.ArrayDataModel(fileList); this.fileList_ = new cr.ui.ArrayDataModel(fileList);
this.context_.metadataCache.setCacheSize(this.fileList_.length); this.makeSpaceInMetadataCache_(this.fileList_.length);
}; };
/** /**
...@@ -497,7 +517,7 @@ DirectoryContents.prototype.replaceContextFileList = function() { ...@@ -497,7 +517,7 @@ DirectoryContents.prototype.replaceContextFileList = function() {
spliceArgs.unshift(0, fileList.length); spliceArgs.unshift(0, fileList.length);
fileList.splice.apply(fileList, spliceArgs); fileList.splice.apply(fileList, spliceArgs);
this.fileList_ = fileList; this.fileList_ = fileList;
this.context_.metadataCache.setCacheSize(this.fileList_.length); this.makeSpaceInMetadataCache_(this.fileList_.length);
} }
}; };
...@@ -650,7 +670,7 @@ DirectoryContents.prototype.onNewEntries_ = function(entries) { ...@@ -650,7 +670,7 @@ DirectoryContents.prototype.onNewEntries_ = function(entries) {
this.fileList_.push.apply(this.fileList_, entriesFiltered); this.fileList_.push.apply(this.fileList_, entriesFiltered);
cr.dispatchSimpleEvent(this, 'scan-updated'); cr.dispatchSimpleEvent(this, 'scan-updated');
this.context_.metadataCache.setCacheSize(this.fileList_.length); this.makeSpaceInMetadataCache_(this.fileList_.length);
this.processNewEntriesQueue_.run(function(callbackOuter) { this.processNewEntriesQueue_.run(function(callbackOuter) {
// Because the prefetchMetadata can be slow, throttling by splitting entries // Because the prefetchMetadata can be slow, throttling by splitting entries
......
...@@ -497,6 +497,7 @@ DirectoryModel.prototype.replaceDirectoryContents_ = function(dirContents) { ...@@ -497,6 +497,7 @@ DirectoryModel.prototype.replaceDirectoryContents_ = function(dirContents) {
var leadIndex = this.fileListSelection_.leadIndex; var leadIndex = this.fileListSelection_.leadIndex;
var leadEntry = this.getLeadEntry_(); var leadEntry = this.getLeadEntry_();
this.currentDirContents_.dispose();
this.currentDirContents_ = dirContents; this.currentDirContents_ = dirContents;
dirContents.replaceContextFileList(); dirContents.replaceContextFileList();
......
...@@ -163,12 +163,15 @@ MetadataCache.prototype.isInitialized = function() { ...@@ -163,12 +163,15 @@ MetadataCache.prototype.isInitialized = function() {
}; };
/** /**
* Sets the size of cache. The actual cache size may be larger than the given * Changes the size of cache by delta value. The actual cache size may be larger
* value. * than the given value.
* @param {number} size The cache size to be set. *
* @param {number} delta The delta size to be changed the cache size by.
*/ */
MetadataCache.prototype.setCacheSize = function(size) { MetadataCache.prototype.resizeBy = function(delta) {
this.currentCacheSize_ = size; this.currentCacheSize_ += delta;
if (this.currentCacheSize_ < 0)
this.currentCacheSize_ = 0;
if (this.totalCount_ > this.currentEvictionThreshold_()) if (this.totalCount_ > this.currentEvictionThreshold_())
this.evict_(); this.evict_();
......
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