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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 // correctly. | 127 // correctly. |
| 128 this.splice(this.indexOf(item) + 1, 0, anotherItem); | 128 this.splice(this.indexOf(item) + 1, 0, anotherItem); |
| 129 } | 129 } |
| 130 | 130 |
| 131 fulfill(); | 131 fulfill(); |
| 132 }.bind(this)); | 132 }.bind(this)); |
| 133 }.bind(this)); | 133 }.bind(this)); |
| 134 }; | 134 }; |
| 135 | 135 |
| 136 /** | 136 /** |
| 137 * Evicts image caches in the items. | |
| 138 * @param {Gallery.Item} currentSelectedItem Current selected item. | |
| 139 */ | |
| 140 GalleryDataModel.prototype.evictCache = function(currentSelectedItem) { | |
| 141 // Updates the last accessed date. | |
| 142 if (currentSelectedItem) | |
| 143 currentSelectedItem.lastAccessed = Date.now(); | |
| 144 | |
| 145 // Sort the item by the last accessed date. | |
| 146 var sorted = this.slice().sort(function(a, b) { | |
| 147 return b.lastAccessed - a.lastAccessed; | |
| 148 }); | |
| 149 | |
| 150 // Evict caches. | |
| 151 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.
| |
| 152 var screenCacheCount = 5; | |
| 153 for (var i = 0; i < sorted.length; i++) { | |
| 154 if (sorted[i].contentImage) { | |
| 155 if (contentCacheCount-- <= 0) { | |
| 156 if (sorted[i].contentImage.parentNode) { | |
| 157 console.error('The content image has a parent node.'); | |
| 158 } else { | |
| 159 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.
| |
| 160 sorted[i].contentImage.height = 0; | |
| 161 sorted[i].contentImage = null; | |
| 162 } | |
| 163 } | |
| 164 } | |
| 165 if (sorted[i].screenImage) { | |
| 166 if (screenCacheCount-- <= 0) { | |
| 167 if (sorted[i].screenImage.parentNode) { | |
| 168 console.error('The screen image has a parent node.'); | |
| 169 } else { | |
| 170 sorted[i].screenImage.width = 0; | |
| 171 sorted[i].screenImage.height = 0; | |
| 172 sorted[i].screenImage = null; | |
| 173 } | |
| 174 } | |
| 175 } | |
| 176 } | |
| 177 }; | |
| 178 | |
| 179 /** | |
| 137 * Gallery for viewing and editing image files. | 180 * Gallery for viewing and editing image files. |
| 138 * | 181 * |
| 139 * @param {!VolumeManager} volumeManager The VolumeManager instance of the | 182 * @param {!VolumeManager} volumeManager The VolumeManager instance of the |
| 140 * system. | 183 * system. |
| 141 * @constructor | 184 * @constructor |
| 142 */ | 185 */ |
| 143 function Gallery(volumeManager) { | 186 function Gallery(volumeManager) { |
| 144 this.context_ = { | 187 this.context_ = { |
| 145 appWindow: chrome.app.window.current(), | 188 appWindow: chrome.app.window.current(), |
| 146 onClose: function() { close(); }, | 189 onClose: function() { close(); }, |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 639 return items[0]; | 682 return items[0]; |
| 640 }; | 683 }; |
| 641 | 684 |
| 642 /** | 685 /** |
| 643 * Selection change event handler. | 686 * Selection change event handler. |
| 644 * @private | 687 * @private |
| 645 */ | 688 */ |
| 646 Gallery.prototype.onSelection_ = function() { | 689 Gallery.prototype.onSelection_ = function() { |
| 647 this.updateSelectionAndState_(); | 690 this.updateSelectionAndState_(); |
| 648 this.updateShareMenu_(); | 691 this.updateShareMenu_(); |
| 692 this.dataModel_.evictCache(this.getSelectedItems()[0]); | |
| 649 }; | 693 }; |
| 650 | 694 |
| 651 /** | 695 /** |
| 652 * Data model splice event handler. | 696 * Data model splice event handler. |
| 653 * @private | 697 * @private |
| 654 */ | 698 */ |
| 655 Gallery.prototype.onSplice_ = function() { | 699 Gallery.prototype.onSplice_ = function() { |
| 656 this.selectionModel_.adjustLength(this.dataModel_.length); | 700 this.selectionModel_.adjustLength(this.dataModel_.length); |
| 657 }; | 701 }; |
| 658 | 702 |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 969 window.loadTimeData.data = backgroundComponents.stringData; | 1013 window.loadTimeData.data = backgroundComponents.stringData; |
| 970 gallery = new Gallery(backgroundComponents.volumeManager); | 1014 gallery = new Gallery(backgroundComponents.volumeManager); |
| 971 }; | 1015 }; |
| 972 | 1016 |
| 973 /** | 1017 /** |
| 974 * Loads entries. | 1018 * Loads entries. |
| 975 */ | 1019 */ |
| 976 window.loadEntries = function(entries, selectedEntries) { | 1020 window.loadEntries = function(entries, selectedEntries) { |
| 977 gallery.load(entries, selectedEntries); | 1021 gallery.load(entries, selectedEntries); |
| 978 }; | 1022 }; |
| OLD | NEW |