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

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

Issue 971173002: Gallery: Start to use new metadata model in Gallery. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
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 /** 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
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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 }; 221 };
230 222
231 /** 223 /**
232 * Writes the new item content to either the existing or a new file. 224 * Writes the new item content to either the existing or a new file.
233 * 225 *
234 * @param {!VolumeManager} volumeManager Volume manager instance. 226 * @param {!VolumeManager} volumeManager Volume manager instance.
235 * @param {DirectoryEntry} fallbackDir Fallback directory in case the current 227 * @param {DirectoryEntry} fallbackDir Fallback directory in case the current
236 * directory is read only. 228 * directory is read only.
237 * @param {boolean} overwrite Whether to overwrite the image to the item or not. 229 * @param {boolean} overwrite Whether to overwrite the image to the item or not.
238 * @param {!HTMLCanvasElement} canvas Source canvas. 230 * @param {!HTMLCanvasElement} canvas Source canvas.
239 * @param {function(boolean)=} opt_callback Callback accepting true for success. 231 * @param {function(boolean)} callback Callback accepting true for success.
240 */ 232 */
241 Gallery.Item.prototype.saveToFile = function( 233 Gallery.Item.prototype.saveToFile = function(
242 volumeManager, fallbackDir, overwrite, canvas, opt_callback) { 234 volumeManager, fallbackDir, overwrite, canvas, callback) {
243 ImageUtil.metrics.startInterval(ImageUtil.getMetricName('SaveTime')); 235 ImageUtil.metrics.startInterval(ImageUtil.getMetricName('SaveTime'));
244 236
245 var name = this.getFileName(); 237 var name = this.getFileName();
246 238
247 var onSuccess = function(entry) { 239 var onSuccess = function(entry) {
248 var locationInfo = volumeManager.getLocationInfo(entry); 240 var locationInfo = volumeManager.getLocationInfo(entry);
249 if (!locationInfo) { 241 if (!locationInfo) {
250 // Reuse old location info if it fails to obtain location info. 242 // Reuse old location info if it fails to obtain location info.
251 locationInfo = this.locationInfo_; 243 locationInfo = this.locationInfo_;
252 } 244 }
253 ImageUtil.metrics.recordEnum(ImageUtil.getMetricName('SaveResult'), 1, 2); 245 ImageUtil.metrics.recordEnum(ImageUtil.getMetricName('SaveResult'), 1, 2);
254 ImageUtil.metrics.recordInterval(ImageUtil.getMetricName('SaveTime')); 246 ImageUtil.metrics.recordInterval(ImageUtil.getMetricName('SaveTime'));
255 247
256 this.entry_ = entry; 248 this.entry_ = entry;
257 this.locationInfo_ = locationInfo; 249 this.locationInfo_ = locationInfo;
258 250
259 // Updates the metadata. 251 // Updates the metadata.
260 this.metadataCache_.clear([this.entry_], '*'); 252 this.metadataCache_.clear([this.entry_], '*');
261 this.metadataCache_.getLatest( 253 var oldMetadataPromise = new Promise(function(fulfill, reject) {
262 [this.entry_], 254 this.metadataCache_.getLatest(
263 Gallery.METADATA_TYPE, 255 [this.entry_],
264 function(metadataList) { 256 Gallery.METADATA_TYPE,
265 if (metadataList.length === 1) { 257 function(metadataList) {
266 this.metadata_ = metadataList[0]; 258 if (metadataList.length === 1) {
267 if (opt_callback) 259 this.metadata_ = metadataList[0];
268 opt_callback(true); 260 fulfill();
269 } else { 261 } else {
270 if (opt_callback) 262 reject();
271 opt_callback(false); 263 }
272 } 264 }.bind(this));
265 }.bind(this));
266 this.metadataModel_.notifyEntriesChanged([this.entry_]);
267 var newMetadataPromise = this.metadataModel_.get(
268 [entry], Gallery.PREFETCH_PROPERTY_NAMES).then(
269 function(metadataItems) {
270 console.log(metadataItems);
yawano 2015/03/04 05:20:45 Is this console output intentionally included in t
hirono 2015/03/04 05:32:45 Done.
271 this.metadataItem = metadataItems[0];
yawano 2015/03/04 05:20:45 this.metadataItem_?
hirono 2015/03/04 05:32:45 Done.
273 }.bind(this)); 272 }.bind(this));
274 this.metadataModel_.notifyEntriesChanged([this.entry_]); 273 if (callback) {
274 Promise.all([oldMetadataPromise, newMetadataPromise]).then(
275 callback.bind(null, true),
276 callback.bind(null, false));
277 }
275 }.bind(this); 278 }.bind(this);
276 279
277 var onError = function(error) { 280 var onError = function(error) {
278 console.error('Error saving from gallery', name, error); 281 console.error('Error saving from gallery', name, error);
279 ImageUtil.metrics.recordEnum(ImageUtil.getMetricName('SaveResult'), 0, 2); 282 ImageUtil.metrics.recordEnum(ImageUtil.getMetricName('SaveResult'), 0, 2);
280 if (opt_callback) 283 if (callback)
281 opt_callback(false); 284 callback(false);
282 }; 285 };
283 286
284 var doSave = function(newFile, fileEntry) { 287 var doSave = function(newFile, fileEntry) {
285 var metadataPromise = this.metadataModel_.get( 288 var metadataPromise = this.metadataModel_.get(
286 [fileEntry], 289 [fileEntry],
287 ['mediaMimeType', 'contentMimeType', 'ifd', 'exifLittleEndian']); 290 ['mediaMimeType', 'contentMimeType', 'ifd', 'exifLittleEndian']);
288 metadataPromise.then(function(metadataItems) { 291 metadataPromise.then(function(metadataItems) {
289 fileEntry.createWriter(function(fileWriter) { 292 fileEntry.createWriter(function(fileWriter) {
290 var writeContent = function() { 293 var writeContent = function() {
291 fileWriter.onwriteend = onSuccess.bind(null, fileEntry); 294 fileWriter.onwriteend = onSuccess.bind(null, fileEntry);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 return Promise.reject(str('GALLERY_FILE_EXISTS')); 380 return Promise.reject(str('GALLERY_FILE_EXISTS'));
378 }, function() { 381 }, function() {
379 return new Promise( 382 return new Promise(
380 this.entry_.moveTo.bind(this.entry_, parentDirectory, newFileName)); 383 this.entry_.moveTo.bind(this.entry_, parentDirectory, newFileName));
381 }.bind(this)); 384 }.bind(this));
382 }.bind(this)); 385 }.bind(this));
383 }.bind(this)).then(function(entry) { 386 }.bind(this)).then(function(entry) {
384 this.entry_ = entry; 387 this.entry_ = entry;
385 }.bind(this)); 388 }.bind(this));
386 }; 389 };
OLDNEW
« no previous file with comments | « ui/file_manager/gallery/js/gallery_data_model.js ('k') | ui/file_manager/gallery/js/gallery_item_unittest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698