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 /** | 5 /** |
6 * Object representing an image item (a photo). | 6 * Object representing an image item (a photo). |
7 * | 7 * |
8 * @param {!FileEntry} entry Image entry. | 8 * @param {!FileEntry} entry Image entry. |
9 * @param {!EntryLocation} locationInfo Entry location information. | 9 * @param {!EntryLocation} locationInfo Entry location information. |
10 * @param {!Object} metadata Metadata for the entry. | 10 * @param {!Object} metadata Metadata for the entry. |
11 * @param {!MetadataCache} metadataCache Metadata cache instance. | 11 * @param {!MetadataCache} metadataCache Metadata cache instance. |
12 * @param {!FileSystemMetadata} fileSystemMetadata File system metadata. | 12 * @param {!MetadataModel} metadataModel File system metadata. |
13 * @param {boolean} original Whether the entry is original or edited. | 13 * @param {boolean} original Whether the entry is original or edited. |
14 * @constructor | 14 * @constructor |
15 * @struct | 15 * @struct |
16 */ | 16 */ |
17 Gallery.Item = function( | 17 Gallery.Item = function( |
18 entry, locationInfo, metadata, metadataCache, fileSystemMetadata, | 18 entry, locationInfo, metadata, metadataCache, metadataModel, |
19 original) { | 19 original) { |
20 /** | 20 /** |
21 * @type {!FileEntry} | 21 * @type {!FileEntry} |
22 * @private | 22 * @private |
23 */ | 23 */ |
24 this.entry_ = entry; | 24 this.entry_ = entry; |
25 | 25 |
26 /** | 26 /** |
27 * @type {!EntryLocation} | 27 * @type {!EntryLocation} |
28 * @private | 28 * @private |
29 */ | 29 */ |
30 this.locationInfo_ = locationInfo; | 30 this.locationInfo_ = locationInfo; |
31 | 31 |
32 /** | 32 /** |
33 * @type {!Object} | 33 * @type {!Object} |
34 * @private | 34 * @private |
35 */ | 35 */ |
36 this.metadata_ = Object.preventExtensions(metadata); | 36 this.metadata_ = Object.preventExtensions(metadata); |
37 | 37 |
38 /** | 38 /** |
39 * @type {!MetadataCache} | 39 * @type {!MetadataCache} |
40 * @private | 40 * @private |
41 * @const | 41 * @const |
42 */ | 42 */ |
43 this.metadataCache_ = metadataCache; | 43 this.metadataCache_ = metadataCache; |
44 | 44 |
45 /** | 45 /** |
46 * @type {!FileSystemMetadata} | 46 * @type {!MetadataModel} |
47 * @private | 47 * @private |
48 * @const | 48 * @const |
49 */ | 49 */ |
50 this.fileSystemMetadata_ = fileSystemMetadata; | 50 this.metadataModel_ = metadataModel; |
51 | 51 |
52 // TODO(yawano): Change this.contentImage and this.screenImage to private | 52 // TODO(yawano): Change this.contentImage and this.screenImage to private |
53 // fields and provide utility methods for them (e.g. revokeFullImageCache). | 53 // fields and provide utility methods for them (e.g. revokeFullImageCache). |
54 /** | 54 /** |
55 * The content cache is used for prefetching the next image when going through | 55 * The content cache is used for prefetching the next image when going through |
56 * the images sequentially. The real life photos can be large (18Mpix = 72Mb | 56 * the images sequentially. The real life photos can be large (18Mpix = 72Mb |
57 * pixel array) so we want only the minimum amount of caching. | 57 * pixel array) so we want only the minimum amount of caching. |
58 * @type {(HTMLCanvasElement|HTMLImageElement)} | 58 * @type {(HTMLCanvasElement|HTMLImageElement)} |
59 */ | 59 */ |
60 this.contentImage = null; | 60 this.contentImage = null; |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 function(metadataList) { | 264 function(metadataList) { |
265 if (metadataList.length === 1) { | 265 if (metadataList.length === 1) { |
266 this.metadata_ = metadataList[0]; | 266 this.metadata_ = metadataList[0]; |
267 if (opt_callback) | 267 if (opt_callback) |
268 opt_callback(true); | 268 opt_callback(true); |
269 } else { | 269 } else { |
270 if (opt_callback) | 270 if (opt_callback) |
271 opt_callback(false); | 271 opt_callback(false); |
272 } | 272 } |
273 }.bind(this)); | 273 }.bind(this)); |
274 this.fileSystemMetadata_.notifyEntriesChanged([this.entry_]); | 274 this.metadataModel_.notifyEntriesChanged([this.entry_]); |
275 }.bind(this); | 275 }.bind(this); |
276 | 276 |
277 var onError = function(error) { | 277 var onError = function(error) { |
278 console.error('Error saving from gallery', name, error); | 278 console.error('Error saving from gallery', name, error); |
279 ImageUtil.metrics.recordEnum(ImageUtil.getMetricName('SaveResult'), 0, 2); | 279 ImageUtil.metrics.recordEnum(ImageUtil.getMetricName('SaveResult'), 0, 2); |
280 if (opt_callback) | 280 if (opt_callback) |
281 opt_callback(false); | 281 opt_callback(false); |
282 }; | 282 }; |
283 | 283 |
284 var doSave = function(newFile, fileEntry) { | 284 var doSave = function(newFile, fileEntry) { |
285 var metadataPromise = this.fileSystemMetadata_.get( | 285 var metadataPromise = this.metadataModel_.get( |
286 [fileEntry], | 286 [fileEntry], |
287 ['mediaMimeType', 'contentMimeType', 'ifd', 'exifLittleEndian']); | 287 ['mediaMimeType', 'contentMimeType', 'ifd', 'exifLittleEndian']); |
288 metadataPromise.then(function(metadataItems) { | 288 metadataPromise.then(function(metadataItems) { |
289 fileEntry.createWriter(function(fileWriter) { | 289 fileEntry.createWriter(function(fileWriter) { |
290 var writeContent = function() { | 290 var writeContent = function() { |
291 fileWriter.onwriteend = onSuccess.bind(null, fileEntry); | 291 fileWriter.onwriteend = onSuccess.bind(null, fileEntry); |
292 var metadataItem = metadataItems[0]; | 292 var metadataItem = metadataItems[0]; |
293 metadataItem.modificationTime = new Date(); | 293 metadataItem.modificationTime = new Date(); |
294 var metadataEncoder = ImageEncoder.encodeMetadata( | 294 var metadataEncoder = ImageEncoder.encodeMetadata( |
295 metadataItem, canvas, /* quality for thumbnail*/ 0.8); | 295 metadataItem, canvas, /* quality for thumbnail*/ 0.8); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 return Promise.reject(str('GALLERY_FILE_EXISTS')); | 377 return Promise.reject(str('GALLERY_FILE_EXISTS')); |
378 }, function() { | 378 }, function() { |
379 return new Promise( | 379 return new Promise( |
380 this.entry_.moveTo.bind(this.entry_, parentDirectory, newFileName)); | 380 this.entry_.moveTo.bind(this.entry_, parentDirectory, newFileName)); |
381 }.bind(this)); | 381 }.bind(this)); |
382 }.bind(this)); | 382 }.bind(this)); |
383 }.bind(this)).then(function(entry) { | 383 }.bind(this)).then(function(entry) { |
384 this.entry_ = entry; | 384 this.entry_ = entry; |
385 }.bind(this)); | 385 }.bind(this)); |
386 }; | 386 }; |
OLD | NEW |