Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Unified Diff: chrome/browser/resources/file_manager/foreground/js/metadata/metadata_cache.js

Issue 132683004: [Files.app] Change sort timing during metadata fetch (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/resources/file_manager/foreground/js/file_manager.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/file_manager/foreground/js/metadata/metadata_cache.js
diff --git a/chrome/browser/resources/file_manager/foreground/js/metadata/metadata_cache.js b/chrome/browser/resources/file_manager/foreground/js/metadata/metadata_cache.js
index bc724dab4bf0755e2c5f9bbeb70b1dcd8a371970..51f2bad71f93ae364fbc72da26b502fc5a16ce31 100644
--- a/chrome/browser/resources/file_manager/foreground/js/metadata/metadata_cache.js
+++ b/chrome/browser/resources/file_manager/foreground/js/metadata/metadata_cache.js
@@ -76,6 +76,8 @@ function MetadataCache() {
this.batchCount_ = 0;
this.totalCount_ = 0;
+ this.currentCacheSize_ = 0;
+
/**
* Time of first get query of the current batch. Items updated later than this
* will not be evicted.
@@ -103,9 +105,9 @@ MetadataCache.CHILDREN = 1;
MetadataCache.DESCENDANTS = 2;
/**
- * Minimum number of items in cache to start eviction.
+ * Margin of the cache size. This amount of caches may be kept in addition.
*/
-MetadataCache.EVICTION_NUMBER = 1000;
+MetadataCache.EVICTION_THRESHOLD_MARGIN = 500;
/**
* @param {VolumeManagerWrapper} volumeManager Volume manager instance.
@@ -159,6 +161,28 @@ MetadataCache.prototype.isInitialized = function() {
};
/**
+ * Sets the size of cache. The actual cache size may be larger than the given
+ * value.
+ * @param {number} size The cache size to be set.
+ */
+MetadataCache.prototype.setCacheSize = function(size) {
+ this.currentCacheSize_ = size;
+
+ if (this.totalCount_ > this.currentEvictionThreshold_())
+ this.evict_();
+};
+
+/**
+ * Returns the current threshold to evict caches. When the number of caches
+ * exceeds this, the cache should be evicted.
+ * @return {number} Threshold to evict caches.
+ * @private
+ */
+MetadataCache.prototype.currentEvictionThreshold_ = function() {
+ return this.currentCacheSize_ * 2 + MetadataCache.EVICTION_THRESHOLD_MARGIN;
+};
+
+/**
* Fetches the metadata, puts it in the cache, and passes to callback.
* If required metadata is already in the cache, does not fetch it again.
* @param {Entry|Array.<Entry>} entries The list of entries. May be just a
@@ -458,7 +482,7 @@ MetadataCache.prototype.startBatchUpdates = function() {
MetadataCache.prototype.endBatchUpdates = function() {
this.batchCount_--;
if (this.batchCount_ !== 0) return;
- if (this.totalCount_ > MetadataCache.EVICTION_NUMBER)
+ if (this.totalCount_ > this.currentEvictionThreshold_())
this.evict_();
for (var index = 0; index < this.observers_.length; index++) {
var observer = this.observers_[index];
@@ -513,7 +537,7 @@ MetadataCache.prototype.evict_ = function() {
var toRemove = [];
// We leave only a half of items, so we will not call evict_ soon again.
- var desiredCount = Math.round(MetadataCache.EVICTION_NUMBER / 2);
+ var desiredCount = this.currentEvictionThreshold_();
var removeCount = this.totalCount_ - desiredCount;
for (var url in this.cache_) {
if (this.cache_.hasOwnProperty(url) &&
« no previous file with comments | « chrome/browser/resources/file_manager/foreground/js/file_manager.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698