Chromium Code Reviews| 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 // Updates the last accessed date. | |
| 158 if (currentSelectedItem) | |
| 159 currentSelectedItem.lastAccessed = Date.now(); | |
|
mtomasz
2014/07/28 07:51:21
I think updating lastAccessed time shouldn't be re
hirono
2014/07/28 09:10:33
How about adding touch method and calling it when
mtomasz
2014/07/28 09:14:00
SGTM!
hirono
2014/07/28 09:27:21
Thanks! Done.
| |
| 160 | |
| 161 // Sort the item by the last accessed date. | |
| 162 var sorted = this.slice().sort(function(a, b) { | |
| 163 return b.lastAccessed - a.lastAccessed; | |
| 164 }); | |
| 165 | |
| 166 // Evict caches. | |
| 167 var contentCacheCount = 0; | |
| 168 var screenCacheCount = 0; | |
| 169 for (var i = 0; i < sorted.length; i++) { | |
| 170 if (sorted[i].contentImage) { | |
| 171 if (++contentCacheCount > GalleryDataModel.MAX_FULL_IMAGE_CACHE_) { | |
| 172 if (sorted[i].contentImage.parentNode) { | |
| 173 console.error('The content image has a parent node.'); | |
| 174 } else { | |
| 175 // Force to free the buffer of the canvas by assinng zero size. | |
| 176 sorted[i].contentImage.width = 0; | |
| 177 sorted[i].contentImage.height = 0; | |
| 178 sorted[i].contentImage = null; | |
| 179 } | |
| 180 } | |
| 181 } | |
| 182 if (sorted[i].screenImage) { | |
| 183 if (++screenCacheCount > GalleryDataModel.MAX_SCREEN_IMAGE_CACHE_) { | |
| 184 if (sorted[i].screenImage.parentNode) { | |
| 185 console.error('The screen image has a parent node.'); | |
| 186 } else { | |
| 187 // Force to free the buffer of the canvas by assinng zero size. | |
| 188 sorted[i].screenImage.width = 0; | |
| 189 sorted[i].screenImage.height = 0; | |
| 190 sorted[i].screenImage = null; | |
| 191 } | |
| 192 } | |
| 193 } | |
| 194 } | |
| 195 }; | |
| 196 | |
| 197 /** | |
| 137 * Gallery for viewing and editing image files. | 198 * Gallery for viewing and editing image files. |
| 138 * | 199 * |
| 139 * @param {!VolumeManager} volumeManager The VolumeManager instance of the | 200 * @param {!VolumeManager} volumeManager The VolumeManager instance of the |
| 140 * system. | 201 * system. |
| 141 * @constructor | 202 * @constructor |
| 142 */ | 203 */ |
| 143 function Gallery(volumeManager) { | 204 function Gallery(volumeManager) { |
| 144 this.context_ = { | 205 this.context_ = { |
| 145 appWindow: chrome.app.window.current(), | 206 appWindow: chrome.app.window.current(), |
| 146 onClose: function() { close(); }, | 207 onClose: function() { close(); }, |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 639 return items[0]; | 700 return items[0]; |
| 640 }; | 701 }; |
| 641 | 702 |
| 642 /** | 703 /** |
| 643 * Selection change event handler. | 704 * Selection change event handler. |
| 644 * @private | 705 * @private |
| 645 */ | 706 */ |
| 646 Gallery.prototype.onSelection_ = function() { | 707 Gallery.prototype.onSelection_ = function() { |
| 647 this.updateSelectionAndState_(); | 708 this.updateSelectionAndState_(); |
| 648 this.updateShareMenu_(); | 709 this.updateShareMenu_(); |
| 710 this.dataModel_.evictCache(this.getSelectedItems()[0]); | |
| 649 }; | 711 }; |
| 650 | 712 |
| 651 /** | 713 /** |
| 652 * Data model splice event handler. | 714 * Data model splice event handler. |
| 653 * @private | 715 * @private |
| 654 */ | 716 */ |
| 655 Gallery.prototype.onSplice_ = function() { | 717 Gallery.prototype.onSplice_ = function() { |
| 656 this.selectionModel_.adjustLength(this.dataModel_.length); | 718 this.selectionModel_.adjustLength(this.dataModel_.length); |
| 657 }; | 719 }; |
| 658 | 720 |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 969 window.loadTimeData.data = backgroundComponents.stringData; | 1031 window.loadTimeData.data = backgroundComponents.stringData; |
| 970 gallery = new Gallery(backgroundComponents.volumeManager); | 1032 gallery = new Gallery(backgroundComponents.volumeManager); |
| 971 }; | 1033 }; |
| 972 | 1034 |
| 973 /** | 1035 /** |
| 974 * Loads entries. | 1036 * Loads entries. |
| 975 */ | 1037 */ |
| 976 window.loadEntries = function(entries, selectedEntries) { | 1038 window.loadEntries = function(entries, selectedEntries) { |
| 977 gallery.load(entries, selectedEntries); | 1039 gallery.load(entries, selectedEntries); |
| 978 }; | 1040 }; |
| OLD | NEW |