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

Unified Diff: ui/file_manager/gallery/js/gallery.js

Issue 420743002: Gallery: Store image caches in Gallery items. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | « ui/file_manager/file_manager/common/js/util.js ('k') | ui/file_manager/gallery/js/gallery_item.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/file_manager/gallery/js/gallery.js
diff --git a/ui/file_manager/gallery/js/gallery.js b/ui/file_manager/gallery/js/gallery.js
index 305def2b307b82b506aefd25ac6e265da851bb06..f8f5da84e2f96be1705604eb6e6355343b91b0aa 100644
--- a/ui/file_manager/gallery/js/gallery.js
+++ b/ui/file_manager/gallery/js/gallery.js
@@ -28,6 +28,22 @@ function GalleryDataModel() {
this.metadataCache_ = null;
}
+/**
+ * Maximum number of full size image cache.
+ * @type {number}
+ * @const
+ * @private
+ */
+GalleryDataModel.MAX_FULL_IMAGE_CACHE_ = 3;
+
+/**
+ * Maximum number of screen size image cache.
+ * @type {number}
+ * @const
+ * @private
+ */
+GalleryDataModel.MAX_SCREEN_IMAGE_CACHE_ = 5;
+
GalleryDataModel.prototype = {
__proto__: cr.ui.ArrayDataModel.prototype
};
@@ -134,6 +150,47 @@ GalleryDataModel.prototype.saveItem = function(item, canvas, overwrite) {
};
/**
+ * Evicts image caches in the items.
+ * @param {Gallery.Item} currentSelectedItem Current selected item.
+ */
+GalleryDataModel.prototype.evictCache = function(currentSelectedItem) {
+ // Sort the item by the last accessed date.
+ var sorted = this.slice().sort(function(a, b) {
+ return b.getLastAccessedDate() - a.getLastAccessedDate();
+ });
+
+ // Evict caches.
+ var contentCacheCount = 0;
+ var screenCacheCount = 0;
+ for (var i = 0; i < sorted.length; i++) {
+ if (sorted[i].contentImage) {
+ if (++contentCacheCount > GalleryDataModel.MAX_FULL_IMAGE_CACHE_) {
+ if (sorted[i].contentImage.parentNode) {
+ console.error('The content image has a parent node.');
+ } else {
+ // Force to free the buffer of the canvas by assinng zero size.
+ sorted[i].contentImage.width = 0;
+ sorted[i].contentImage.height = 0;
+ sorted[i].contentImage = null;
+ }
+ }
+ }
+ if (sorted[i].screenImage) {
+ if (++screenCacheCount > GalleryDataModel.MAX_SCREEN_IMAGE_CACHE_) {
+ if (sorted[i].screenImage.parentNode) {
+ console.error('The screen image has a parent node.');
+ } else {
+ // Force to free the buffer of the canvas by assinng zero size.
+ sorted[i].screenImage.width = 0;
+ sorted[i].screenImage.height = 0;
+ sorted[i].screenImage = null;
+ }
+ }
+ }
+ }
+};
+
+/**
* Gallery for viewing and editing image files.
*
* @param {!VolumeManager} volumeManager The VolumeManager instance of the
@@ -646,6 +703,10 @@ Gallery.prototype.getSingleSelectedItem = function() {
Gallery.prototype.onSelection_ = function() {
this.updateSelectionAndState_();
this.updateShareMenu_();
+ var currentItem = this.getSelectedItems()[0];
+ if (currentItem)
+ currentItem.touch();
+ this.dataModel_.evictCache();
};
/**
« no previous file with comments | « ui/file_manager/file_manager/common/js/util.js ('k') | ui/file_manager/gallery/js/gallery_item.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698