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

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

Issue 2678723002: Compile several targets in Gallery in gyp v2. (Closed)
Patch Set: Rebased. Created 3 years, 10 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 {MetadataItem} metadataItem 10 * @param {MetadataItem} metadataItem
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 this.lastAccessed_ = Date.now(); 53 this.lastAccessed_ = Date.now();
54 54
55 /** 55 /**
56 * @type {boolean} 56 * @type {boolean}
57 * @private 57 * @private
58 */ 58 */
59 this.original_ = original; 59 this.original_ = original;
60 }; 60 };
61 61
62 /** 62 /**
63 * Types of metadata Gallery uses (to query the metadata cache).
64 * @const
65 * @type {!Array<string>}
66 */
67 GalleryItem.PREFETCH_PROPERTY_NAMES =
68 ['imageWidth', 'imageHeight', 'imageRotation', 'size', 'present'];
69
70 /**
63 * @return {!FileEntry} Image entry. 71 * @return {!FileEntry} Image entry.
64 */ 72 */
65 GalleryItem.prototype.getEntry = function() { return this.entry_; }; 73 GalleryItem.prototype.getEntry = function() { return this.entry_; };
66 74
67 /** 75 /**
68 * @return {!EntryLocation} Entry location information. 76 * @return {!EntryLocation} Entry location information.
69 */ 77 */
70 GalleryItem.prototype.getLocationInfo = function() { 78 GalleryItem.prototype.getLocationInfo = function() {
71 return this.locationInfo_; 79 return this.locationInfo_;
72 }; 80 };
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 * @param {!VolumeManagerWrapper} volumeManager Volume manager instance. 262 * @param {!VolumeManagerWrapper} volumeManager Volume manager instance.
255 * @param {!MetadataModel} metadataModel 263 * @param {!MetadataModel} metadataModel
256 * @param {!DirectoryEntry} fallbackDir Fallback directory in case the current 264 * @param {!DirectoryEntry} fallbackDir Fallback directory in case the current
257 * directory is read only. 265 * directory is read only.
258 * @param {!HTMLCanvasElement} canvas Source canvas. 266 * @param {!HTMLCanvasElement} canvas Source canvas.
259 * @param {boolean} overwrite Set true to overwrite original if it's possible. 267 * @param {boolean} overwrite Set true to overwrite original if it's possible.
260 * @param {function(boolean)} callback Callback accepting true for success. 268 * @param {function(boolean)} callback Callback accepting true for success.
261 */ 269 */
262 GalleryItem.prototype.saveToFile = function( 270 GalleryItem.prototype.saveToFile = function(
263 volumeManager, metadataModel, fallbackDir, canvas, overwrite, callback) { 271 volumeManager, metadataModel, fallbackDir, canvas, overwrite, callback) {
264 ImageUtil.metrics.startInterval(ImageUtil.getMetricName('SaveTime')); 272 metrics.startInterval(ImageUtil.getMetricName('SaveTime'));
265 var saveResultRecorded = false; 273 var saveResultRecorded = false;
266 274
267 Promise.all([this.getEntryToWrite_(overwrite, fallbackDir, volumeManager), 275 Promise.all([this.getEntryToWrite_(overwrite, fallbackDir, volumeManager),
268 this.getBlobForSave_(canvas, metadataModel)]).then(function(results) { 276 this.getBlobForSave_(canvas, metadataModel)]).then(function(results) {
269 // Write content to the entry. 277 // Write content to the entry.
270 var fileEntry = results[0]; 278 var fileEntry = results[0];
271 var blob = results[1]; 279 var blob = results[1];
272 280
273 // Create writer. 281 // Create writer.
274 return new Promise(function(resolve, reject) { 282 return new Promise(function(resolve, reject) {
(...skipping 22 matching lines...) Expand all
297 305
298 return Promise.reject(error); 306 return Promise.reject(error);
299 }); 307 });
300 }.bind(this)).then(function() { 308 }.bind(this)).then(function() {
301 var locationInfo = volumeManager.getLocationInfo(fileEntry); 309 var locationInfo = volumeManager.getLocationInfo(fileEntry);
302 if (!locationInfo) { 310 if (!locationInfo) {
303 // Reuse old location info if it fails to obtain location info. 311 // Reuse old location info if it fails to obtain location info.
304 locationInfo = this.locationInfo_; 312 locationInfo = this.locationInfo_;
305 } 313 }
306 314
307 ImageUtil.metrics.recordEnum(ImageUtil.getMetricName('SaveResult'), 1, 2); 315 metrics.recordEnum(ImageUtil.getMetricName('SaveResult'), 1, 2);
308 saveResultRecorded = true; 316 saveResultRecorded = true;
309 ImageUtil.metrics.recordInterval(ImageUtil.getMetricName('SaveTime')); 317 metrics.recordInterval(ImageUtil.getMetricName('SaveTime'));
310 318
311 this.entry_ = fileEntry; 319 this.entry_ = fileEntry;
312 this.locationInfo_ = locationInfo; 320 this.locationInfo_ = locationInfo;
313 321
314 // Updates the metadata. 322 // Updates the metadata.
315 metadataModel.notifyEntriesChanged([this.entry_]); 323 metadataModel.notifyEntriesChanged([this.entry_]);
316 Promise.all([ 324 Promise.all([
317 metadataModel.get([this.entry_], Gallery.PREFETCH_PROPERTY_NAMES), 325 metadataModel.get([this.entry_], GalleryItem.PREFETCH_PROPERTY_NAMES),
318 new ThumbnailModel(metadataModel).get([this.entry_]) 326 new ThumbnailModel(metadataModel).get([this.entry_])
319 ]).then(function(metadataLists) { 327 ]).then(function(metadataLists) {
320 this.metadataItem_ = metadataLists[0][0]; 328 this.metadataItem_ = metadataLists[0][0];
321 this.thumbnailMetadataItem_ = metadataLists[1][0]; 329 this.thumbnailMetadataItem_ = metadataLists[1][0];
322 callback(true); 330 callback(true);
323 }.bind(this), function() { 331 }.bind(this), function() {
324 callback(false); 332 callback(false);
325 }); 333 });
326 }.bind(this)); 334 }.bind(this));
327 }.bind(this)).catch(function(error) { 335 }.bind(this)).catch(function(error) {
328 console.error('Error saving from gallery', this.entry_.name, error); 336 console.error('Error saving from gallery', this.entry_.name, error);
329 337
330 if (!saveResultRecorded) 338 if (!saveResultRecorded)
331 ImageUtil.metrics.recordEnum(ImageUtil.getMetricName('SaveResult'), 0, 2); 339 metrics.recordEnum(ImageUtil.getMetricName('SaveResult'), 0, 2);
332 340
333 callback(false); 341 callback(false);
334 }.bind(this)); 342 }.bind(this));
335 }; 343 };
336 344
337 /** 345 /**
338 * Returns file entry to write. 346 * Returns file entry to write.
339 * @param {boolean} overwrite True to overwrite original file. 347 * @param {boolean} overwrite True to overwrite original file.
340 * @param {!DirectoryEntry} fallbackDirectory Directory to fallback if current 348 * @param {!DirectoryEntry} fallbackDirectory Directory to fallback if current
341 * directory is not writable. 349 * directory is not writable.
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 */ 465 */
458 GalleryItem.prototype.requireLongRenderingTime = function() { 466 GalleryItem.prototype.requireLongRenderingTime = function() {
459 // Check for undefined values. 467 // Check for undefined values.
460 if (!this.metadataItem_ || 468 if (!this.metadataItem_ ||
461 !this.metadataItem_.imageHeight || !this.metadataItem_.imageWidth) 469 !this.metadataItem_.imageHeight || !this.metadataItem_.imageWidth)
462 return false; 470 return false;
463 var numPixels = this.metadataItem_.imageHeight * 471 var numPixels = this.metadataItem_.imageHeight *
464 this.metadataItem_.imageWidth; 472 this.metadataItem_.imageWidth;
465 return numPixels > GalleryItem.HEAVY_RENDERING_THRESHOLD_PIXELS; 473 return numPixels > GalleryItem.HEAVY_RENDERING_THRESHOLD_PIXELS;
466 }; 474 };
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