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

Side by Side Diff: ui/file_manager/gallery/js/gallery.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: Rebased. 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 * 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
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
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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 * Loads the content. 310 * Loads the content.
304 * 311 *
305 * @param {!Array.<!Entry>} entries Array of entries. 312 * @param {!Array.<!Entry>} entries Array of entries.
306 * @param {!Array.<!Entry>} selectedEntries Array of selected entries. 313 * @param {!Array.<!Entry>} selectedEntries Array of selected entries.
307 * @private 314 * @private
308 */ 315 */
309 Gallery.prototype.loadInternal_ = function(entries, selectedEntries) { 316 Gallery.prototype.loadInternal_ = function(entries, selectedEntries) {
310 // Obtains max chank size. 317 // Obtains max chank size.
311 var maxChunkSize = 20; 318 var maxChunkSize = 20;
312 var volumeInfo = this.volumeManager_.getVolumeInfo(entries[0]); 319 var volumeInfo = this.volumeManager_.getVolumeInfo(entries[0]);
313 if (volumeInfo && 320 if (volumeInfo) {
314 volumeInfo.volumeType === VolumeManagerCommon.VolumeType.MTP) { 321 if (volumeInfo.volumeType === VolumeManagerCommon.VolumeType.MTP)
315 maxChunkSize = 1; 322 maxChunkSize = 1;
323 if (volumeInfo.isReadOnly)
324 this.context_.readonlyDirName = volumeInfo.label;
316 } 325 }
317 if (volumeInfo.isReadOnly)
318 this.context_.readonlyDirName = volumeInfo.label;
319 326
320 // Make loading list. 327 // Make loading list.
321 var entrySet = {}; 328 var entrySet = {};
322 for (var i = 0; i < entries.length; i++) { 329 for (var i = 0; i < entries.length; i++) {
323 var entry = entries[i]; 330 var entry = entries[i];
324 entrySet[entry.toURL()] = { 331 entrySet[entry.toURL()] = {
325 entry: entry, 332 entry: entry,
326 selected: false, 333 selected: false,
327 index: i 334 index: i
328 }; 335 };
(...skipping 25 matching lines...) Expand all
354 } 361 }
355 362
356 // Load entries. 363 // Load entries.
357 // Use the self variable capture-by-closure because it is faster than bind. 364 // Use the self variable capture-by-closure because it is faster than bind.
358 var self = this; 365 var self = this;
359 var loadChunk = function(firstChunk) { 366 var loadChunk = function(firstChunk) {
360 // Extract chunk. 367 // Extract chunk.
361 var chunk = loadingList.splice(0, maxChunkSize); 368 var chunk = loadingList.splice(0, maxChunkSize);
362 if (!chunk.length) 369 if (!chunk.length)
363 return; 370 return;
364 371 var entries = chunk.map(function(chunkItem) {
365 return new Promise(function(fulfill) { 372 return chunkItem.entry;
373 });
374 var oldMetadataPromise = new Promise(function(fulfill) {
366 // Obtains metadata for chunk. 375 // 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); 376 self.metadataCache_.get(entries, Gallery.METADATA_TYPE, fulfill);
371 }).then(function(metadataList) { 377 }).then(function(metadataList) {
372 if (chunk.length !== metadataList.length) 378 if (chunk.length !== metadataList.length)
373 return Promise.reject('Failed to load metadata.'); 379 return Promise.reject('Failed to load metadata.');
374 380 return metadataList;
381 });
382 var metadataPromise = self.metadataModel_.get(
383 entries, ['imageWidth', 'imageHeight', 'size']);
384 return Promise.all([oldMetadataPromise, metadataPromise]).then(
385 function(metadataList) {
yawano 2015/03/03 04:14:50 very small nit: We uses metadataList in this funct
hirono 2015/03/04 05:07:04 Done.
375 // Remove all the previous items if it's the first chunk. 386 // Remove all the previous items if it's the first chunk.
376 // 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
377 // and adding new ones. 388 // and adding new ones.
378 if (firstChunk) { 389 if (firstChunk) {
379 self.dataModel_.splice(0, self.dataModel_.length); 390 self.dataModel_.splice(0, self.dataModel_.length);
380 self.updateThumbnails_(); // Remove the caches. 391 self.updateThumbnails_(); // Remove the caches.
381 } 392 }
382 393
383 // Add items to the model. 394 // Add items to the model.
384 var items = []; 395 var items = [];
385 chunk.forEach(function(chunkItem, index) { 396 chunk.forEach(function(chunkItem, index) {
386 var locationInfo = self.volumeManager_.getLocationInfo(chunkItem.entry); 397 var locationInfo = self.volumeManager_.getLocationInfo(chunkItem.entry);
387 if (!locationInfo) // Skip the item, since gone. 398 if (!locationInfo) // Skip the item, since gone.
388 return; 399 return;
389 var clonedMetadata = MetadataCache.cloneMetadata(metadataList[index]); 400 var clonedMetadata =
401 MetadataCache.cloneMetadata(metadataList[0][index]);
390 items.push(new Gallery.Item( 402 items.push(new Gallery.Item(
391 chunkItem.entry, 403 chunkItem.entry,
392 locationInfo, 404 locationInfo,
393 clonedMetadata, 405 clonedMetadata,
406 metadataList[1][index],
394 self.metadataCache_, 407 self.metadataCache_,
395 self.metadataModel_, 408 self.metadataModel_,
396 /* original */ true)); 409 /* original */ true));
397 }); 410 });
398 self.dataModel_.push.apply(self.dataModel_, items); 411 self.dataModel_.push.apply(self.dataModel_, items);
399 412
400 // Apply the selection. 413 // Apply the selection.
401 var selectionUpdated = false; 414 var selectionUpdated = false;
402 for (var i = 0; i < chunk.length; i++) { 415 for (var i = 0; i < chunk.length; i++) {
403 if (!chunk[i].selected) 416 if (!chunk[i].selected)
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 initializePromise.then(reload); 991 initializePromise.then(reload);
979 992
980 /** 993 /**
981 * Enteres the debug mode. 994 * Enteres the debug mode.
982 */ 995 */
983 window.debugMe = function() { 996 window.debugMe = function() {
984 initializePromise.then(function() { 997 initializePromise.then(function() {
985 gallery.debugMe(); 998 gallery.debugMe();
986 }); 999 });
987 }; 1000 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698