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

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
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..137e5acf84697045c699be111505c002e944b91f 100644
--- a/ui/file_manager/gallery/js/gallery.js
+++ b/ui/file_manager/gallery/js/gallery.js
@@ -134,6 +134,49 @@ 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) {
+ // Updates the last accessed date.
+ if (currentSelectedItem)
+ currentSelectedItem.lastAccessed = Date.now();
+
+ // Sort the item by the last accessed date.
+ var sorted = this.slice().sort(function(a, b) {
+ return b.lastAccessed - a.lastAccessed;
+ });
+
+ // Evict caches.
+ var contentCacheCount = 2;
mtomasz 2014/07/28 05:13:01 I think the code is too complicated. contentCacheC
hirono 2014/07/28 06:50:32 Done.
+ var screenCacheCount = 5;
+ for (var i = 0; i < sorted.length; i++) {
+ if (sorted[i].contentImage) {
+ if (contentCacheCount-- <= 0) {
+ if (sorted[i].contentImage.parentNode) {
+ console.error('The content image has a parent node.');
+ } else {
+ sorted[i].contentImage.width = 0;
mtomasz 2014/07/28 05:13:01 Please add a comment, that this is needed to force
hirono 2014/07/28 06:50:32 Done.
+ sorted[i].contentImage.height = 0;
+ sorted[i].contentImage = null;
+ }
+ }
+ }
+ if (sorted[i].screenImage) {
+ if (screenCacheCount-- <= 0) {
+ if (sorted[i].screenImage.parentNode) {
+ console.error('The screen image has a parent node.');
+ } else {
+ 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 +689,7 @@ Gallery.prototype.getSingleSelectedItem = function() {
Gallery.prototype.onSelection_ = function() {
this.updateSelectionAndState_();
this.updateShareMenu_();
+ this.dataModel_.evictCache(this.getSelectedItems()[0]);
};
/**
« no previous file with comments | « no previous file | ui/file_manager/gallery/js/gallery_item.js » ('j') | ui/file_manager/gallery/js/gallery_item.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698