| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Called from the main frame when unloading. | 8 * Called from the main frame when unloading. |
| 9 * @param {boolean=} opt_exiting True if the app is exiting. | 9 * @param {boolean=} opt_exiting True if the app is exiting. |
| 10 */ | 10 */ |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * Data model for gallery. | 21 * Data model for gallery. |
| 22 * | 22 * |
| 23 * @constructor | 23 * @constructor |
| 24 * @extends {cr.ui.ArrayDataModel} | 24 * @extends {cr.ui.ArrayDataModel} |
| 25 */ | 25 */ |
| 26 function GalleryDataModel() { | 26 function GalleryDataModel() { |
| 27 cr.ui.ArrayDataModel.call(this, []); | 27 cr.ui.ArrayDataModel.call(this, []); |
| 28 this.metadataCache_ = null; | 28 this.metadataCache_ = null; |
| 29 } | 29 } |
| 30 | 30 |
| 31 /** |
| 32 * Maximum number of full size image cache. |
| 33 * @type {number} |
| 34 * @const |
| 35 * @private |
| 36 */ |
| 37 GalleryDataModel.MAX_FULL_IMAGE_CACHE_ = 3; |
| 38 |
| 39 /** |
| 40 * Maximum number of screen size image cache. |
| 41 * @type {number} |
| 42 * @const |
| 43 * @private |
| 44 */ |
| 45 GalleryDataModel.MAX_SCREEN_IMAGE_CACHE_ = 5; |
| 46 |
| 31 GalleryDataModel.prototype = { | 47 GalleryDataModel.prototype = { |
| 32 __proto__: cr.ui.ArrayDataModel.prototype | 48 __proto__: cr.ui.ArrayDataModel.prototype |
| 33 }; | 49 }; |
| 34 | 50 |
| 35 /** | 51 /** |
| 36 * Initializes the data model. | 52 * Initializes the data model. |
| 37 * | 53 * |
| 38 * @param {MetadataCache} metadataCache Metadata cache. | 54 * @param {MetadataCache} metadataCache Metadata cache. |
| 39 * @param {Array.<FileEntry>} entries Image entries. | 55 * @param {Array.<FileEntry>} entries Image entries. |
| 40 * @return {Promise} Promise to be fulfilled with after initialization. | 56 * @return {Promise} Promise to be fulfilled with after initialization. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 // correctly. | 143 // correctly. |
| 128 this.splice(this.indexOf(item) + 1, 0, anotherItem); | 144 this.splice(this.indexOf(item) + 1, 0, anotherItem); |
| 129 } | 145 } |
| 130 | 146 |
| 131 fulfill(); | 147 fulfill(); |
| 132 }.bind(this)); | 148 }.bind(this)); |
| 133 }.bind(this)); | 149 }.bind(this)); |
| 134 }; | 150 }; |
| 135 | 151 |
| 136 /** | 152 /** |
| 153 * Evicts image caches in the items. |
| 154 * @param {Gallery.Item} currentSelectedItem Current selected item. |
| 155 */ |
| 156 GalleryDataModel.prototype.evictCache = function(currentSelectedItem) { |
| 157 // Sort the item by the last accessed date. |
| 158 var sorted = this.slice().sort(function(a, b) { |
| 159 return b.getLastAccessedDate() - a.getLastAccessedDate(); |
| 160 }); |
| 161 |
| 162 // Evict caches. |
| 163 var contentCacheCount = 0; |
| 164 var screenCacheCount = 0; |
| 165 for (var i = 0; i < sorted.length; i++) { |
| 166 if (sorted[i].contentImage) { |
| 167 if (++contentCacheCount > GalleryDataModel.MAX_FULL_IMAGE_CACHE_) { |
| 168 if (sorted[i].contentImage.parentNode) { |
| 169 console.error('The content image has a parent node.'); |
| 170 } else { |
| 171 // Force to free the buffer of the canvas by assinng zero size. |
| 172 sorted[i].contentImage.width = 0; |
| 173 sorted[i].contentImage.height = 0; |
| 174 sorted[i].contentImage = null; |
| 175 } |
| 176 } |
| 177 } |
| 178 if (sorted[i].screenImage) { |
| 179 if (++screenCacheCount > GalleryDataModel.MAX_SCREEN_IMAGE_CACHE_) { |
| 180 if (sorted[i].screenImage.parentNode) { |
| 181 console.error('The screen image has a parent node.'); |
| 182 } else { |
| 183 // Force to free the buffer of the canvas by assinng zero size. |
| 184 sorted[i].screenImage.width = 0; |
| 185 sorted[i].screenImage.height = 0; |
| 186 sorted[i].screenImage = null; |
| 187 } |
| 188 } |
| 189 } |
| 190 } |
| 191 }; |
| 192 |
| 193 /** |
| 137 * Gallery for viewing and editing image files. | 194 * Gallery for viewing and editing image files. |
| 138 * | 195 * |
| 139 * @param {!VolumeManager} volumeManager The VolumeManager instance of the | 196 * @param {!VolumeManager} volumeManager The VolumeManager instance of the |
| 140 * system. | 197 * system. |
| 141 * @constructor | 198 * @constructor |
| 142 */ | 199 */ |
| 143 function Gallery(volumeManager) { | 200 function Gallery(volumeManager) { |
| 144 this.context_ = { | 201 this.context_ = { |
| 145 appWindow: chrome.app.window.current(), | 202 appWindow: chrome.app.window.current(), |
| 146 onClose: function() { close(); }, | 203 onClose: function() { close(); }, |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 return items[0]; | 696 return items[0]; |
| 640 }; | 697 }; |
| 641 | 698 |
| 642 /** | 699 /** |
| 643 * Selection change event handler. | 700 * Selection change event handler. |
| 644 * @private | 701 * @private |
| 645 */ | 702 */ |
| 646 Gallery.prototype.onSelection_ = function() { | 703 Gallery.prototype.onSelection_ = function() { |
| 647 this.updateSelectionAndState_(); | 704 this.updateSelectionAndState_(); |
| 648 this.updateShareMenu_(); | 705 this.updateShareMenu_(); |
| 706 var currentItem = this.getSelectedItems()[0]; |
| 707 if (currentItem) |
| 708 currentItem.touch(); |
| 709 this.dataModel_.evictCache(); |
| 649 }; | 710 }; |
| 650 | 711 |
| 651 /** | 712 /** |
| 652 * Data model splice event handler. | 713 * Data model splice event handler. |
| 653 * @private | 714 * @private |
| 654 */ | 715 */ |
| 655 Gallery.prototype.onSplice_ = function() { | 716 Gallery.prototype.onSplice_ = function() { |
| 656 this.selectionModel_.adjustLength(this.dataModel_.length); | 717 this.selectionModel_.adjustLength(this.dataModel_.length); |
| 657 }; | 718 }; |
| 658 | 719 |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 969 window.loadTimeData.data = backgroundComponents.stringData; | 1030 window.loadTimeData.data = backgroundComponents.stringData; |
| 970 gallery = new Gallery(backgroundComponents.volumeManager); | 1031 gallery = new Gallery(backgroundComponents.volumeManager); |
| 971 }; | 1032 }; |
| 972 | 1033 |
| 973 /** | 1034 /** |
| 974 * Loads entries. | 1035 * Loads entries. |
| 975 */ | 1036 */ |
| 976 window.loadEntries = function(entries, selectedEntries) { | 1037 window.loadEntries = function(entries, selectedEntries) { |
| 977 gallery.load(entries, selectedEntries); | 1038 gallery.load(entries, selectedEntries); |
| 978 }; | 1039 }; |
| OLD | NEW |