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 * Object representing an image item (a photo). | 8 * Object representing an image item (a photo). |
9 * | 9 * |
10 * @param {FileEntry} entry Image entry. | 10 * @param {FileEntry} entry Image entry. |
11 * @param {function():Promise} fethcedMediaProvider Function to provide the | 11 * @param {function():Promise} fethcedMediaProvider Function to provide the |
12 * fetchedMedia metadata. | 12 * fetchedMedia metadata. |
13 * @constructor | 13 * @constructor |
14 */ | 14 */ |
15 Gallery.Item = function(entry, metadata, metadataCache, original) { | 15 Gallery.Item = function(entry, metadata, metadataCache, original) { |
16 /** | 16 /** |
17 * @type {FileEntry} | 17 * @type {FileEntry} |
18 * @private | 18 * @private |
19 */ | 19 */ |
20 this.entry_ = entry; | 20 this.entry_ = entry; |
21 | 21 |
22 /** | 22 /** |
23 * @type {Object} | 23 * @type {Object} |
24 * @private | 24 * @private |
25 */ | 25 */ |
26 this.metadata_ = Object.freeze(metadata); | 26 this.metadata_ = Object.freeze(metadata); |
27 | 27 |
28 /** | 28 /** |
29 * @type {MetadataCache} | 29 * @type {MetadataCache} |
| 30 * @private |
30 */ | 31 */ |
31 this.metadataCache_ = metadataCache; | 32 this.metadataCache_ = metadataCache; |
32 | 33 |
33 /** | 34 /** |
| 35 * The content cache is used for prefetching the next image when going through |
| 36 * the images sequentially. The real life photos can be large (18Mpix = 72Mb |
| 37 * pixel array) so we want only the minimum amount of caching. |
| 38 * @type {Canvas} |
| 39 */ |
| 40 this.screenImage = null; |
| 41 |
| 42 /** |
| 43 * We reuse previously generated screen-scale images so that going back to a |
| 44 * recently loaded image looks instant even if the image is not in the content |
| 45 * cache any more. Screen-scale images are small (~1Mpix) so we can afford to |
| 46 * cache more of them. |
| 47 * @type {Canvas} |
| 48 */ |
| 49 this.contentImage = null; |
| 50 |
| 51 /** |
| 52 * Last accessed date to be used for selecting items whose cache are evicted. |
| 53 * @type {Date} |
| 54 */ |
| 55 this.lastAccessed = Date.now(); |
| 56 |
| 57 /** |
34 * @type {boolean} | 58 * @type {boolean} |
35 * @private | 59 * @private |
36 */ | 60 */ |
37 this.original_ = original; | 61 this.original_ = original; |
38 | 62 |
39 Object.seal(this); | 63 Object.seal(this); |
40 }; | 64 }; |
41 | 65 |
42 /** | 66 /** |
43 * @return {FileEntry} Image entry. | 67 * @return {FileEntry} Image entry. |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 return Promise.reject(str('GALLERY_FILE_EXISTS')); | 304 return Promise.reject(str('GALLERY_FILE_EXISTS')); |
281 }, function() { | 305 }, function() { |
282 return new Promise( | 306 return new Promise( |
283 this.entry_.moveTo.bind(this.entry_, parentDirectory, newFileName)); | 307 this.entry_.moveTo.bind(this.entry_, parentDirectory, newFileName)); |
284 }.bind(this)); | 308 }.bind(this)); |
285 }.bind(this)); | 309 }.bind(this)); |
286 }.bind(this)).then(function(entry) { | 310 }.bind(this)).then(function(entry) { |
287 this.entry_ = entry; | 311 this.entry_ = entry; |
288 }.bind(this)); | 312 }.bind(this)); |
289 }; | 313 }; |
OLD | NEW |