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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 }; | 50 }; |
51 this.container_ = queryRequiredElement(document, '.gallery'); | 51 this.container_ = queryRequiredElement(document, '.gallery'); |
52 this.document_ = document; | 52 this.document_ = document; |
53 this.metadataCache_ = this.context_.metadataCache; | 53 this.metadataCache_ = this.context_.metadataCache; |
54 this.volumeManager_ = volumeManager; | 54 this.volumeManager_ = volumeManager; |
55 /** | 55 /** |
56 * @private {!MetadataModel} | 56 * @private {!MetadataModel} |
57 * @const | 57 * @const |
58 */ | 58 */ |
59 this.metadataModel_ = MetadataModel.create(volumeManager); | 59 this.metadataModel_ = MetadataModel.create(volumeManager); |
| 60 /** |
| 61 * @private {!ThumbnailModel} |
| 62 * @const |
| 63 */ |
| 64 this.thumbnailModel_ = new ThumbnailModel(this.metadataModel_); |
60 this.selectedEntry_ = null; | 65 this.selectedEntry_ = null; |
61 this.metadataCacheObserverId_ = null; | 66 this.metadataCacheObserverId_ = null; |
62 this.onExternallyUnmountedBound_ = this.onExternallyUnmounted_.bind(this); | 67 this.onExternallyUnmountedBound_ = this.onExternallyUnmounted_.bind(this); |
63 this.initialized_ = false; | 68 this.initialized_ = false; |
64 | 69 |
65 this.dataModel_ = new GalleryDataModel( | 70 this.dataModel_ = new GalleryDataModel( |
66 this.context_.metadataCache, | 71 this.context_.metadataCache, |
67 this.metadataModel_); | 72 this.metadataModel_); |
68 var downloadVolumeInfo = this.volumeManager_.getCurrentProfileVolumeInfo( | 73 var downloadVolumeInfo = this.volumeManager_.getCurrentProfileVolumeInfo( |
69 VolumeManagerCommon.VolumeType.DOWNLOADS); | 74 VolumeManagerCommon.VolumeType.DOWNLOADS); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 this.volumeManager_, | 161 this.volumeManager_, |
157 this.toggleMode_.bind(this, undefined)); | 162 this.toggleMode_.bind(this, undefined)); |
158 | 163 |
159 this.slideMode_ = new SlideMode(this.container_, | 164 this.slideMode_ = new SlideMode(this.container_, |
160 content, | 165 content, |
161 this.toolbar_, | 166 this.toolbar_, |
162 this.prompt_, | 167 this.prompt_, |
163 this.errorBanner_, | 168 this.errorBanner_, |
164 this.dataModel_, | 169 this.dataModel_, |
165 this.selectionModel_, | 170 this.selectionModel_, |
| 171 this.metadataModel_, |
| 172 this.thumbnailModel_, |
166 this.context_, | 173 this.context_, |
167 this.volumeManager_, | 174 this.volumeManager_, |
168 this.toggleMode_.bind(this), | 175 this.toggleMode_.bind(this), |
169 str); | 176 str); |
170 | 177 |
171 this.slideMode_.addEventListener('image-displayed', function() { | 178 this.slideMode_.addEventListener('image-displayed', function() { |
172 cr.dispatchSimpleEvent(this, 'image-displayed'); | 179 cr.dispatchSimpleEvent(this, 'image-displayed'); |
173 }.bind(this)); | 180 }.bind(this)); |
174 this.slideMode_.addEventListener('image-saved', function() { | 181 this.slideMode_.addEventListener('image-saved', function() { |
175 cr.dispatchSimpleEvent(this, 'image-saved'); | 182 cr.dispatchSimpleEvent(this, 'image-saved'); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 Gallery.MOSAIC_BACKGROUND_INIT_DELAY = 1000; | 249 Gallery.MOSAIC_BACKGROUND_INIT_DELAY = 1000; |
243 | 250 |
244 /** | 251 /** |
245 * Types of metadata Gallery uses (to query the metadata cache). | 252 * Types of metadata Gallery uses (to query the metadata cache). |
246 * @const | 253 * @const |
247 * @type {string} | 254 * @type {string} |
248 */ | 255 */ |
249 Gallery.METADATA_TYPE = 'thumbnail|filesystem|media|external'; | 256 Gallery.METADATA_TYPE = 'thumbnail|filesystem|media|external'; |
250 | 257 |
251 /** | 258 /** |
| 259 * Types of metadata Gallery uses (to query the metadata cache). |
| 260 * @const |
| 261 * @type {!Array<string>} |
| 262 */ |
| 263 Gallery.PREFETCH_PROPERTY_NAMES = ['imageWidth', 'imageHeight', 'size']; |
| 264 |
| 265 /** |
252 * Closes gallery when a volume containing the selected item is unmounted. | 266 * Closes gallery when a volume containing the selected item is unmounted. |
253 * @param {!Event} event The unmount event. | 267 * @param {!Event} event The unmount event. |
254 * @private | 268 * @private |
255 */ | 269 */ |
256 Gallery.prototype.onExternallyUnmounted_ = function(event) { | 270 Gallery.prototype.onExternallyUnmounted_ = function(event) { |
257 if (!this.selectedEntry_) | 271 if (!this.selectedEntry_) |
258 return; | 272 return; |
259 | 273 |
260 if (this.volumeManager_.getVolumeInfo(this.selectedEntry_) === | 274 if (this.volumeManager_.getVolumeInfo(this.selectedEntry_) === |
261 event.volumeInfo) { | 275 event.volumeInfo) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 * Loads the content. | 317 * Loads the content. |
304 * | 318 * |
305 * @param {!Array.<!Entry>} entries Array of entries. | 319 * @param {!Array.<!Entry>} entries Array of entries. |
306 * @param {!Array.<!Entry>} selectedEntries Array of selected entries. | 320 * @param {!Array.<!Entry>} selectedEntries Array of selected entries. |
307 * @private | 321 * @private |
308 */ | 322 */ |
309 Gallery.prototype.loadInternal_ = function(entries, selectedEntries) { | 323 Gallery.prototype.loadInternal_ = function(entries, selectedEntries) { |
310 // Obtains max chank size. | 324 // Obtains max chank size. |
311 var maxChunkSize = 20; | 325 var maxChunkSize = 20; |
312 var volumeInfo = this.volumeManager_.getVolumeInfo(entries[0]); | 326 var volumeInfo = this.volumeManager_.getVolumeInfo(entries[0]); |
313 if (volumeInfo && | 327 if (volumeInfo) { |
314 volumeInfo.volumeType === VolumeManagerCommon.VolumeType.MTP) { | 328 if (volumeInfo.volumeType === VolumeManagerCommon.VolumeType.MTP) |
315 maxChunkSize = 1; | 329 maxChunkSize = 1; |
| 330 if (volumeInfo.isReadOnly) |
| 331 this.context_.readonlyDirName = volumeInfo.label; |
316 } | 332 } |
317 if (volumeInfo.isReadOnly) | |
318 this.context_.readonlyDirName = volumeInfo.label; | |
319 | 333 |
320 // Make loading list. | 334 // Make loading list. |
321 var entrySet = {}; | 335 var entrySet = {}; |
322 for (var i = 0; i < entries.length; i++) { | 336 for (var i = 0; i < entries.length; i++) { |
323 var entry = entries[i]; | 337 var entry = entries[i]; |
324 entrySet[entry.toURL()] = { | 338 entrySet[entry.toURL()] = { |
325 entry: entry, | 339 entry: entry, |
326 selected: false, | 340 selected: false, |
327 index: i | 341 index: i |
328 }; | 342 }; |
(...skipping 25 matching lines...) Expand all Loading... |
354 } | 368 } |
355 | 369 |
356 // Load entries. | 370 // Load entries. |
357 // Use the self variable capture-by-closure because it is faster than bind. | 371 // Use the self variable capture-by-closure because it is faster than bind. |
358 var self = this; | 372 var self = this; |
359 var loadChunk = function(firstChunk) { | 373 var loadChunk = function(firstChunk) { |
360 // Extract chunk. | 374 // Extract chunk. |
361 var chunk = loadingList.splice(0, maxChunkSize); | 375 var chunk = loadingList.splice(0, maxChunkSize); |
362 if (!chunk.length) | 376 if (!chunk.length) |
363 return; | 377 return; |
364 | 378 var entries = chunk.map(function(chunkItem) { |
365 return new Promise(function(fulfill) { | 379 return chunkItem.entry; |
| 380 }); |
| 381 var oldMetadataPromise = new Promise(function(fulfill) { |
366 // Obtains metadata for chunk. | 382 // Obtains metadata for chunk. |
367 var entries = chunk.map(function(chunkItem) { | |
368 return chunkItem.entry; | |
369 }); | |
370 self.metadataCache_.get(entries, Gallery.METADATA_TYPE, fulfill); | 383 self.metadataCache_.get(entries, Gallery.METADATA_TYPE, fulfill); |
371 }).then(function(metadataList) { | 384 }).then(function(metadataList) { |
372 if (chunk.length !== metadataList.length) | 385 if (chunk.length !== metadataList.length) |
373 return Promise.reject('Failed to load metadata.'); | 386 return Promise.reject('Failed to load metadata.'); |
374 | 387 return metadataList; |
| 388 }); |
| 389 var metadataPromise = self.metadataModel_.get( |
| 390 entries, Gallery.PREFETCH_PROPERTY_NAMES); |
| 391 return Promise.all([oldMetadataPromise, metadataPromise]).then( |
| 392 function(metadataLists) { |
375 // Remove all the previous items if it's the first chunk. | 393 // Remove all the previous items if it's the first chunk. |
376 // Do it here because prevent a flicker between removing all the items | 394 // Do it here because prevent a flicker between removing all the items |
377 // and adding new ones. | 395 // and adding new ones. |
378 if (firstChunk) { | 396 if (firstChunk) { |
379 self.dataModel_.splice(0, self.dataModel_.length); | 397 self.dataModel_.splice(0, self.dataModel_.length); |
380 self.updateThumbnails_(); // Remove the caches. | 398 self.updateThumbnails_(); // Remove the caches. |
381 } | 399 } |
382 | 400 |
383 // Add items to the model. | 401 // Add items to the model. |
384 var items = []; | 402 var items = []; |
385 chunk.forEach(function(chunkItem, index) { | 403 chunk.forEach(function(chunkItem, index) { |
386 var locationInfo = self.volumeManager_.getLocationInfo(chunkItem.entry); | 404 var locationInfo = self.volumeManager_.getLocationInfo(chunkItem.entry); |
387 if (!locationInfo) // Skip the item, since gone. | 405 if (!locationInfo) // Skip the item, since gone. |
388 return; | 406 return; |
389 var clonedMetadata = MetadataCache.cloneMetadata(metadataList[index]); | 407 var clonedMetadata = |
| 408 MetadataCache.cloneMetadata(metadataLists[0][index]); |
390 items.push(new Gallery.Item( | 409 items.push(new Gallery.Item( |
391 chunkItem.entry, | 410 chunkItem.entry, |
392 locationInfo, | 411 locationInfo, |
393 clonedMetadata, | 412 clonedMetadata, |
| 413 metadataLists[1][index], |
394 self.metadataCache_, | 414 self.metadataCache_, |
395 self.metadataModel_, | 415 self.metadataModel_, |
396 /* original */ true)); | 416 /* original */ true)); |
397 }); | 417 }); |
398 self.dataModel_.push.apply(self.dataModel_, items); | 418 self.dataModel_.push.apply(self.dataModel_, items); |
399 | 419 |
400 // Apply the selection. | 420 // Apply the selection. |
401 var selectionUpdated = false; | 421 var selectionUpdated = false; |
402 for (var i = 0; i < chunk.length; i++) { | 422 for (var i = 0; i < chunk.length; i++) { |
403 if (!chunk[i].selected) | 423 if (!chunk[i].selected) |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 initializePromise.then(reload); | 998 initializePromise.then(reload); |
979 | 999 |
980 /** | 1000 /** |
981 * Enteres the debug mode. | 1001 * Enteres the debug mode. |
982 */ | 1002 */ |
983 window.debugMe = function() { | 1003 window.debugMe = function() { |
984 initializePromise.then(function() { | 1004 initializePromise.then(function() { |
985 gallery.debugMe(); | 1005 gallery.debugMe(); |
986 }); | 1006 }); |
987 }; | 1007 }; |
OLD | NEW |