Chromium Code Reviews| 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 * Overrided metadata worker's path. | 6 * Overrided metadata worker's path. |
| 7 * @type {string} | 7 * @type {string} |
| 8 */ | 8 */ |
| 9 ContentProvider.WORKER_SCRIPT = '/js/metadata_worker.js'; | 9 ContentProvider.WORKER_SCRIPT = '/js/metadata_worker.js'; |
| 10 ContentMetadataProvider.WORKER_SCRIPT = '/js/metadata_worker.js'; | 10 ContentMetadataProvider.WORKER_SCRIPT = '/js/metadata_worker.js'; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 /** | 60 /** |
| 61 * @private {!ThumbnailModel} | 61 * @private {!ThumbnailModel} |
| 62 * @const | 62 * @const |
| 63 */ | 63 */ |
| 64 this.thumbnailModel_ = new ThumbnailModel(this.metadataModel_); | 64 this.thumbnailModel_ = new ThumbnailModel(this.metadataModel_); |
| 65 this.selectedEntry_ = null; | 65 this.selectedEntry_ = null; |
| 66 this.metadataCacheObserverId_ = null; | 66 this.metadataCacheObserverId_ = null; |
| 67 this.onExternallyUnmountedBound_ = this.onExternallyUnmounted_.bind(this); | 67 this.onExternallyUnmountedBound_ = this.onExternallyUnmounted_.bind(this); |
| 68 this.initialized_ = false; | 68 this.initialized_ = false; |
| 69 | 69 |
| 70 this.dataModel_ = new GalleryDataModel( | 70 this.dataModel_ = new GalleryDataModel(this.metadataModel_); |
| 71 this.context_.metadataCache, | |
| 72 this.metadataModel_); | |
| 73 var downloadVolumeInfo = this.volumeManager_.getCurrentProfileVolumeInfo( | 71 var downloadVolumeInfo = this.volumeManager_.getCurrentProfileVolumeInfo( |
| 74 VolumeManagerCommon.VolumeType.DOWNLOADS); | 72 VolumeManagerCommon.VolumeType.DOWNLOADS); |
| 75 downloadVolumeInfo.resolveDisplayRoot().then(function(entry) { | 73 downloadVolumeInfo.resolveDisplayRoot().then(function(entry) { |
| 76 this.dataModel_.fallbackSaveDirectory = entry; | 74 this.dataModel_.fallbackSaveDirectory = entry; |
| 77 }.bind(this)).catch(function(error) { | 75 }.bind(this)).catch(function(error) { |
| 78 console.error( | 76 console.error( |
| 79 'Failed to obtain the fallback directory: ' + (error.stack || error)); | 77 'Failed to obtain the fallback directory: ' + (error.stack || error)); |
| 80 }); | 78 }); |
| 81 this.selectionModel_ = new cr.ui.ListSelectionModel(); | 79 this.selectionModel_ = new cr.ui.ListSelectionModel(); |
| 82 | 80 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 * @const | 251 * @const |
| 254 * @type {string} | 252 * @type {string} |
| 255 */ | 253 */ |
| 256 Gallery.METADATA_TYPE = 'thumbnail|filesystem|media|external'; | 254 Gallery.METADATA_TYPE = 'thumbnail|filesystem|media|external'; |
| 257 | 255 |
| 258 /** | 256 /** |
| 259 * Types of metadata Gallery uses (to query the metadata cache). | 257 * Types of metadata Gallery uses (to query the metadata cache). |
| 260 * @const | 258 * @const |
| 261 * @type {!Array<string>} | 259 * @type {!Array<string>} |
| 262 */ | 260 */ |
| 263 Gallery.PREFETCH_PROPERTY_NAMES = ['imageWidth', 'imageHeight', 'size']; | 261 Gallery.PREFETCH_PROPERTY_NAMES = |
| 262 ['imageWidth', 'imageHeight', 'size', 'present']; | |
|
mtomasz
2015/03/04 09:29:59
nit: Why present is added?
nit: Is size used?
| |
| 264 | 263 |
| 265 /** | 264 /** |
| 266 * Closes gallery when a volume containing the selected item is unmounted. | 265 * Closes gallery when a volume containing the selected item is unmounted. |
| 267 * @param {!Event} event The unmount event. | 266 * @param {!Event} event The unmount event. |
| 268 * @private | 267 * @private |
| 269 */ | 268 */ |
| 270 Gallery.prototype.onExternallyUnmounted_ = function(event) { | 269 Gallery.prototype.onExternallyUnmounted_ = function(event) { |
| 271 if (!this.selectedEntry_) | 270 if (!this.selectedEntry_) |
| 272 return; | 271 return; |
| 273 | 272 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 363 }); | 362 }); |
| 364 | 363 |
| 365 if (loadingList.length === 0) { | 364 if (loadingList.length === 0) { |
| 366 this.dataModel_.splice(0, this.dataModel_.length); | 365 this.dataModel_.splice(0, this.dataModel_.length); |
| 367 return; | 366 return; |
| 368 } | 367 } |
| 369 | 368 |
| 370 // Load entries. | 369 // Load entries. |
| 371 // Use the self variable capture-by-closure because it is faster than bind. | 370 // Use the self variable capture-by-closure because it is faster than bind. |
| 372 var self = this; | 371 var self = this; |
| 372 var thumbnailModel = new ThumbnailModel(this.metadataModel_); | |
| 373 var loadChunk = function(firstChunk) { | 373 var loadChunk = function(firstChunk) { |
| 374 // Extract chunk. | 374 // Extract chunk. |
| 375 var chunk = loadingList.splice(0, maxChunkSize); | 375 var chunk = loadingList.splice(0, maxChunkSize); |
| 376 if (!chunk.length) | 376 if (!chunk.length) |
| 377 return; | 377 return; |
| 378 var entries = chunk.map(function(chunkItem) { | 378 var entries = chunk.map(function(chunkItem) { |
| 379 return chunkItem.entry; | 379 return chunkItem.entry; |
| 380 }); | 380 }); |
| 381 var oldMetadataPromise = new Promise(function(fulfill) { | |
| 382 // Obtains metadata for chunk. | |
| 383 self.metadataCache_.get(entries, Gallery.METADATA_TYPE, fulfill); | |
| 384 }).then(function(metadataList) { | |
| 385 if (chunk.length !== metadataList.length) | |
| 386 return Promise.reject('Failed to load metadata.'); | |
| 387 return metadataList; | |
| 388 }); | |
| 389 var metadataPromise = self.metadataModel_.get( | 381 var metadataPromise = self.metadataModel_.get( |
| 390 entries, Gallery.PREFETCH_PROPERTY_NAMES); | 382 entries, Gallery.PREFETCH_PROPERTY_NAMES); |
| 391 return Promise.all([oldMetadataPromise, metadataPromise]).then( | 383 var thumbnailPromise = thumbnailModel.get(entries); |
| 384 return Promise.all([metadataPromise, thumbnailPromise]).then( | |
| 392 function(metadataLists) { | 385 function(metadataLists) { |
| 393 // Remove all the previous items if it's the first chunk. | 386 // Remove all the previous items if it's the first chunk. |
| 394 // Do it here because prevent a flicker between removing all the items | 387 // Do it here because prevent a flicker between removing all the items |
| 395 // and adding new ones. | 388 // and adding new ones. |
| 396 if (firstChunk) { | 389 if (firstChunk) { |
| 397 self.dataModel_.splice(0, self.dataModel_.length); | 390 self.dataModel_.splice(0, self.dataModel_.length); |
| 398 self.updateThumbnails_(); // Remove the caches. | 391 self.updateThumbnails_(); // Remove the caches. |
| 399 } | 392 } |
| 400 | 393 |
| 401 // Add items to the model. | 394 // Add items to the model. |
| 402 var items = []; | 395 var items = []; |
| 403 chunk.forEach(function(chunkItem, index) { | 396 chunk.forEach(function(chunkItem, index) { |
| 404 var locationInfo = self.volumeManager_.getLocationInfo(chunkItem.entry); | 397 var locationInfo = self.volumeManager_.getLocationInfo(chunkItem.entry); |
| 405 if (!locationInfo) // Skip the item, since gone. | 398 if (!locationInfo) // Skip the item, since gone. |
| 406 return; | 399 return; |
| 407 var clonedMetadata = | |
| 408 MetadataCache.cloneMetadata(metadataLists[0][index]); | |
| 409 items.push(new Gallery.Item( | 400 items.push(new Gallery.Item( |
| 410 chunkItem.entry, | 401 chunkItem.entry, |
| 411 locationInfo, | 402 locationInfo, |
| 412 clonedMetadata, | 403 metadataLists[0][index], |
| 413 metadataLists[1][index], | 404 metadataLists[1][index], |
| 414 self.metadataCache_, | |
| 415 self.metadataModel_, | |
| 416 /* original */ true)); | 405 /* original */ true)); |
| 417 }); | 406 }); |
| 418 self.dataModel_.push.apply(self.dataModel_, items); | 407 self.dataModel_.push.apply(self.dataModel_, items); |
| 419 | 408 |
| 420 // Apply the selection. | 409 // Apply the selection. |
| 421 var selectionUpdated = false; | 410 var selectionUpdated = false; |
| 422 for (var i = 0; i < chunk.length; i++) { | 411 for (var i = 0; i < chunk.length; i++) { |
| 423 if (!chunk[i].selected) | 412 if (!chunk[i].selected) |
| 424 continue; | 413 continue; |
| 425 var index = self.dataModel_.indexOf(items[i]); | 414 var index = self.dataModel_.indexOf(items[i]); |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 834 */ | 823 */ |
| 835 Gallery.prototype.onFilenameEditBlur_ = function(event) { | 824 Gallery.prototype.onFilenameEditBlur_ = function(event) { |
| 836 var item = this.getSingleSelectedItem(); | 825 var item = this.getSingleSelectedItem(); |
| 837 if (item) { | 826 if (item) { |
| 838 var oldEntry = item.getEntry(); | 827 var oldEntry = item.getEntry(); |
| 839 | 828 |
| 840 item.rename(this.filenameEdit_.value).then(function() { | 829 item.rename(this.filenameEdit_.value).then(function() { |
| 841 var event = new Event('content'); | 830 var event = new Event('content'); |
| 842 event.item = item; | 831 event.item = item; |
| 843 event.oldEntry = oldEntry; | 832 event.oldEntry = oldEntry; |
| 844 event.metadata = null; // Metadata unchanged. | 833 event.thumbnailChanged = false; |
| 845 this.dataModel_.dispatchEvent(event); | 834 this.dataModel_.dispatchEvent(event); |
| 846 }.bind(this), function(error) { | 835 }.bind(this), function(error) { |
| 847 if (error === 'NOT_CHANGED') | 836 if (error === 'NOT_CHANGED') |
| 848 return Promise.resolve(); | 837 return Promise.resolve(); |
| 849 this.filenameEdit_.value = | 838 this.filenameEdit_.value = |
| 850 ImageUtil.getDisplayNameFromName(item.getEntry().name); | 839 ImageUtil.getDisplayNameFromName(item.getEntry().name); |
| 851 this.filenameEdit_.focus(); | 840 this.filenameEdit_.focus(); |
| 852 if (typeof error === 'string') | 841 if (typeof error === 'string') |
| 853 this.prompt_.showStringAt('center', error, 5000); | 842 this.prompt_.showStringAt('center', error, 5000); |
| 854 else | 843 else |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 998 initializePromise.then(reload); | 987 initializePromise.then(reload); |
| 999 | 988 |
| 1000 /** | 989 /** |
| 1001 * Enteres the debug mode. | 990 * Enteres the debug mode. |
| 1002 */ | 991 */ |
| 1003 window.debugMe = function() { | 992 window.debugMe = function() { |
| 1004 initializePromise.then(function() { | 993 initializePromise.then(function() { |
| 1005 gallery.debugMe(); | 994 gallery.debugMe(); |
| 1006 }); | 995 }); |
| 1007 }; | 996 }; |
| OLD | NEW |