Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Side by Side Diff: ui/file_manager/gallery/js/gallery_item.js

Issue 420743002: Gallery: Store image caches in Gallery items. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 {number}
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 */ 107 */
84 Gallery.Item.prototype.getFileName = function() { 108 Gallery.Item.prototype.getFileName = function() {
85 return this.entry_.name; 109 return this.entry_.name;
86 }; 110 };
87 111
88 /** 112 /**
89 * @return {boolean} True if this image has not been created in this session. 113 * @return {boolean} True if this image has not been created in this session.
90 */ 114 */
91 Gallery.Item.prototype.isOriginal = function() { return this.original_; }; 115 Gallery.Item.prototype.isOriginal = function() { return this.original_; };
92 116
117 /**
118 * Obtains the last accessed date.
119 * @return {number} Last accessed date.
120 */
121 Gallery.Item.prototype.getLastAccessedDate = function() {
122 return this.lastAccessed_;
123 };
124
125 /**
126 * Updates the last accessed date.
127 */
128 Gallery.Item.prototype.touch = function() {
129 return this.lastAccessed_ = Date.now();
mtomasz 2014/07/28 10:07:43 nit: Do we need to return?
hirono 2014/07/28 10:31:29 Done.
130 };
131
132
93 // TODO: Localize? 133 // TODO: Localize?
94 /** 134 /**
95 * @type {string} Suffix for a edited copy file name. 135 * @type {string} Suffix for a edited copy file name.
96 */ 136 */
97 Gallery.Item.COPY_SIGNATURE = ' - Edited'; 137 Gallery.Item.COPY_SIGNATURE = ' - Edited';
98 138
99 /** 139 /**
100 * Regular expression to match '... - Edited'. 140 * Regular expression to match '... - Edited'.
101 * @type {RegExp} 141 * @type {RegExp}
102 */ 142 */
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 return Promise.reject(str('GALLERY_FILE_EXISTS')); 320 return Promise.reject(str('GALLERY_FILE_EXISTS'));
281 }, function() { 321 }, function() {
282 return new Promise( 322 return new Promise(
283 this.entry_.moveTo.bind(this.entry_, parentDirectory, newFileName)); 323 this.entry_.moveTo.bind(this.entry_, parentDirectory, newFileName));
284 }.bind(this)); 324 }.bind(this));
285 }.bind(this)); 325 }.bind(this));
286 }.bind(this)).then(function(entry) { 326 }.bind(this)).then(function(entry) {
287 this.entry_ = entry; 327 this.entry_ = entry;
288 }.bind(this)); 328 }.bind(this));
289 }; 329 };
OLDNEW
« no previous file with comments | « ui/file_manager/gallery/js/gallery.js ('k') | ui/file_manager/gallery/js/image_editor/image_view.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698