Chromium Code Reviews| 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]); |
| }; |
| /** |