| 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 {!MetadataItem} metadataItem |
| 11 * @param {!MetadataCache} metadataCache Metadata cache instance. | 12 * @param {!MetadataCache} metadataCache Metadata cache instance. |
| 12 * @param {!MetadataModel} metadataModel File system metadata. | 13 * @param {!MetadataModel} metadataModel File system metadata. |
| 13 * @param {boolean} original Whether the entry is original or edited. | 14 * @param {boolean} original Whether the entry is original or edited. |
| 14 * @constructor | 15 * @constructor |
| 15 * @struct | 16 * @struct |
| 16 */ | 17 */ |
| 17 Gallery.Item = function( | 18 Gallery.Item = function( |
| 18 entry, locationInfo, metadata, metadataCache, metadataModel, | 19 entry, locationInfo, metadata, metadataItem, metadataCache, |
| 19 original) { | 20 metadataModel, original) { |
| 20 /** | 21 /** |
| 21 * @type {!FileEntry} | 22 * @type {!FileEntry} |
| 22 * @private | 23 * @private |
| 23 */ | 24 */ |
| 24 this.entry_ = entry; | 25 this.entry_ = entry; |
| 25 | 26 |
| 26 /** | 27 /** |
| 27 * @type {!EntryLocation} | 28 * @type {!EntryLocation} |
| 28 * @private | 29 * @private |
| 29 */ | 30 */ |
| 30 this.locationInfo_ = locationInfo; | 31 this.locationInfo_ = locationInfo; |
| 31 | 32 |
| 32 /** | 33 /** |
| 33 * @type {!Object} | 34 * @type {!Object} |
| 34 * @private | 35 * @private |
| 35 */ | 36 */ |
| 36 this.metadata_ = Object.preventExtensions(metadata); | 37 this.metadata_ = Object.preventExtensions(metadata); |
| 37 | 38 |
| 38 /** | 39 /** |
| 40 * @type {!MetadataItem} |
| 41 */ |
| 42 this.metadataItem_ = metadataItem; |
| 43 |
| 44 /** |
| 39 * @type {!MetadataCache} | 45 * @type {!MetadataCache} |
| 40 * @private | 46 * @private |
| 41 * @const | 47 * @const |
| 42 */ | 48 */ |
| 43 this.metadataCache_ = metadataCache; | 49 this.metadataCache_ = metadataCache; |
| 44 | 50 |
| 45 /** | 51 /** |
| 46 * @type {!MetadataModel} | 52 * @type {!MetadataModel} |
| 47 * @private | 53 * @private |
| 48 * @const | 54 * @const |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 Gallery.Item.prototype.getLocationInfo = function() { | 99 Gallery.Item.prototype.getLocationInfo = function() { |
| 94 return this.locationInfo_; | 100 return this.locationInfo_; |
| 95 }; | 101 }; |
| 96 | 102 |
| 97 /** | 103 /** |
| 98 * @return {!Object} Metadata. | 104 * @return {!Object} Metadata. |
| 99 */ | 105 */ |
| 100 Gallery.Item.prototype.getMetadata = function() { return this.metadata_; }; | 106 Gallery.Item.prototype.getMetadata = function() { return this.metadata_; }; |
| 101 | 107 |
| 102 /** | 108 /** |
| 103 * Obtains the latest media metadata. | 109 * @return {!MetadataItem} Metadata. |
| 104 * | |
| 105 * This is a heavy operation since it forces to load the image data to obtain | |
| 106 * the metadata. | |
| 107 * @return {!Promise} Promise to be fulfilled with fetched metadata. | |
| 108 */ | 110 */ |
| 109 Gallery.Item.prototype.getFetchedMedia = function() { | 111 Gallery.Item.prototype.getMetadataItem = function() { |
| 110 return new Promise(function(fulfill, reject) { | 112 return this.metadataItem_; |
| 111 this.metadataCache_.getLatest( | |
| 112 [this.entry_], | |
| 113 'fetchedMedia', | |
| 114 function(metadata) { | |
| 115 if (metadata[0]) | |
| 116 fulfill(metadata[0]); | |
| 117 else | |
| 118 reject('Failed to load metadata.'); | |
| 119 }); | |
| 120 }.bind(this)); | |
| 121 }; | 113 }; |
| 122 | 114 |
| 123 /** | 115 /** |
| 124 * @return {string} File name. | 116 * @return {string} File name. |
| 125 */ | 117 */ |
| 126 Gallery.Item.prototype.getFileName = function() { | 118 Gallery.Item.prototype.getFileName = function() { |
| 127 return this.entry_.name; | 119 return this.entry_.name; |
| 128 }; | 120 }; |
| 129 | 121 |
| 130 /** | 122 /** |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 return Promise.reject(str('GALLERY_FILE_EXISTS')); | 369 return Promise.reject(str('GALLERY_FILE_EXISTS')); |
| 378 }, function() { | 370 }, function() { |
| 379 return new Promise( | 371 return new Promise( |
| 380 this.entry_.moveTo.bind(this.entry_, parentDirectory, newFileName)); | 372 this.entry_.moveTo.bind(this.entry_, parentDirectory, newFileName)); |
| 381 }.bind(this)); | 373 }.bind(this)); |
| 382 }.bind(this)); | 374 }.bind(this)); |
| 383 }.bind(this)).then(function(entry) { | 375 }.bind(this)).then(function(entry) { |
| 384 this.entry_ = entry; | 376 this.entry_ = entry; |
| 385 }.bind(this)); | 377 }.bind(this)); |
| 386 }; | 378 }; |
| OLD | NEW |