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

Side by Side Diff: chrome/browser/resources/file_manager/js/file_manager.js

Issue 10384155: [filemanager] Content metadata moved to the cache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Handling content metadata for not-present gdata files. Created 8 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 * FileManager constructor. 6 * FileManager constructor.
7 * 7 *
8 * FileManager objects encapsulate the functionality of the file selector 8 * FileManager objects encapsulate the functionality of the file selector
9 * dialogs, as well as the full screen file manager application (though the 9 * dialogs, as well as the full screen file manager application (though the
10 * latter is not yet implemented). 10 * latter is not yet implemented).
(...skipping 16 matching lines...) Expand all
27 this.butterTimer_ = null; 27 this.butterTimer_ = null;
28 this.currentButter_ = null; 28 this.currentButter_ = null;
29 this.butterLastShowTime_ = 0; 29 this.butterLastShowTime_ = 0;
30 30
31 this.watchedDirectoryUrl_ = null; 31 this.watchedDirectoryUrl_ = null;
32 this.filesystemObserverId_ = null; 32 this.filesystemObserverId_ = null;
33 this.gdataObserverId_ = null; 33 this.gdataObserverId_ = null;
34 34
35 this.commands_ = {}; 35 this.commands_ = {};
36 36
37 this.thumbnailUrlCache_ = {};
38
39 this.document_ = dialogDom.ownerDocument; 37 this.document_ = dialogDom.ownerDocument;
40 this.dialogType_ = this.params_.type || FileManager.DialogType.FULL_PAGE; 38 this.dialogType_ = this.params_.type || FileManager.DialogType.FULL_PAGE;
41 39
42 metrics.recordEnum('Create', this.dialogType_, 40 metrics.recordEnum('Create', this.dialogType_,
43 [FileManager.DialogType.SELECT_FOLDER, 41 [FileManager.DialogType.SELECT_FOLDER,
44 FileManager.DialogType.SELECT_SAVEAS_FILE, 42 FileManager.DialogType.SELECT_SAVEAS_FILE,
45 FileManager.DialogType.SELECT_OPEN_FILE, 43 FileManager.DialogType.SELECT_OPEN_FILE,
46 FileManager.DialogType.SELECT_OPEN_MULTI_FILE, 44 FileManager.DialogType.SELECT_OPEN_MULTI_FILE,
47 FileManager.DialogType.FULL_PAGE]); 45 FileManager.DialogType.FULL_PAGE]);
48 46
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 }; 308 };
311 309
312 /** 310 /**
313 * Continue initializing the file manager after resolving roots. 311 * Continue initializing the file manager after resolving roots.
314 */ 312 */
315 FileManager.prototype.init_ = function() { 313 FileManager.prototype.init_ = function() {
316 metrics.startInterval('Load.DOM'); 314 metrics.startInterval('Load.DOM');
317 this.initCommands_(); 315 this.initCommands_();
318 316
319 this.metadataCache_ = MetadataCache.createFull(); 317 this.metadataCache_ = MetadataCache.createFull();
318 // PyAuto tests monitor this state by polling this variable
319 this.__defineGetter__('workerInitialized_', function() {
320 return this.metadataCache_.isInitialized();
321 }.bind(this));
320 322
321 this.shortDateFormatter_ = 323 this.shortDateFormatter_ =
322 this.locale_.createDateTimeFormat({'dateType': 'medium'}); 324 this.locale_.createDateTimeFormat({'dateType': 'medium'});
323 325
324 this.collator_ = this.locale_.createCollator({ 326 this.collator_ = this.locale_.createCollator({
325 'numeric': true, 'ignoreCase': true, 'ignoreAccents': true}); 327 'numeric': true, 'ignoreCase': true, 'ignoreAccents': true});
326 328
327 // Optional list of file types. 329 // Optional list of file types.
328 this.fileTypes_ = this.params_.typeList; 330 this.fileTypes_ = this.params_.typeList;
329 331
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 'modificationTime'; 412 'modificationTime';
411 var sortDirection = 413 var sortDirection =
412 window.localStorage['sort-direction-' + this.dialogType_] || 'desc'; 414 window.localStorage['sort-direction-' + this.dialogType_] || 'desc';
413 this.directoryModel_.sortFileList(sortField, sortDirection); 415 this.directoryModel_.sortFileList(sortField, sortDirection);
414 416
415 this.refocus(); 417 this.refocus();
416 418
417 this.metadataProvider_ = 419 this.metadataProvider_ =
418 new MetadataProvider(this.filesystem_.root.toURL()); 420 new MetadataProvider(this.filesystem_.root.toURL());
419 421
420 // PyAuto tests monitor this state by polling this variable
421 this.__defineGetter__('workerInitialized_', function() {
422 return self.getMetadataProvider().isInitialized();
423 });
424
425 if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) 422 if (this.dialogType_ == FileManager.DialogType.FULL_PAGE)
426 this.initDataTransferOperations_(); 423 this.initDataTransferOperations_();
427 424
428 this.table_.endBatchUpdates(); 425 this.table_.endBatchUpdates();
429 this.grid_.endBatchUpdates(); 426 this.grid_.endBatchUpdates();
430 427
431 metrics.recordInterval('Load.DOM'); 428 metrics.recordInterval('Load.DOM');
432 metrics.recordInterval('Load.Total'); 429 metrics.recordInterval('Load.Total');
433 }; 430 };
434 431
(...skipping 1232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1667 * @return {HTMLDivElement} Thumbnal box. 1664 * @return {HTMLDivElement} Thumbnal box.
1668 */ 1665 */
1669 FileManager.prototype.renderThumbnailBox_ = function(entry, fill, 1666 FileManager.prototype.renderThumbnailBox_ = function(entry, fill,
1670 opt_imageLoadCallback) { 1667 opt_imageLoadCallback) {
1671 var box = this.document_.createElement('div'); 1668 var box = this.document_.createElement('div');
1672 box.className = 'img-container'; 1669 box.className = 'img-container';
1673 var img = this.document_.createElement('img'); 1670 var img = this.document_.createElement('img');
1674 var self = this; 1671 var self = this;
1675 1672
1676 function onThumbnailURL(iconType, url, transform) { 1673 function onThumbnailURL(iconType, url, transform) {
1677 self.thumbnailUrlCache_[entry.fullPath] = {
1678 iconType: iconType,
1679 url: url,
1680 transform: transform
1681 };
1682 img.onload = function() { 1674 img.onload = function() {
1683 self.centerImage_(img.style, img.width, img.height, fill); 1675 self.centerImage_(img.style, img.width, img.height, fill);
1684 if (opt_imageLoadCallback) 1676 if (opt_imageLoadCallback)
1685 opt_imageLoadCallback(img, transform); 1677 opt_imageLoadCallback(img, transform);
1686 box.appendChild(img); 1678 box.appendChild(img);
1687 }; 1679 };
1688 img.onerror = function() { 1680 img.onerror = function() {
1689 // Use the default icon if we could not fetch the correct one. 1681 // Use the default icon if we could not fetch the correct one.
1690 img.src = FileType.getPreviewArt(iconType); 1682 img.src = FileType.getPreviewArt(iconType);
1691 transform = null; 1683 transform = null;
1692 util.applyTransform(box, transform); 1684 util.applyTransform(box, transform);
1693 }; 1685 };
1694 img.src = url; 1686 img.src = url;
1695 util.applyTransform(box, transform); 1687 util.applyTransform(box, transform);
1696 } 1688 }
1697 1689
1698 // TODO(dgozman): move to new metadata cache. 1690 this.getThumbnailURL(entry, onThumbnailURL);
1699 var cached = this.thumbnailUrlCache_[entry.fullPath];
1700 if (cached)
1701 onThumbnailURL(cached.iconType, cached.url, cached.transform);
1702 else
1703 this.getThumbnailURL(entry, onThumbnailURL);
1704 1691
1705 return box; 1692 return box;
1706 }; 1693 };
1707 1694
1708 FileManager.prototype.decorateThumbnail_ = function(li, entry) { 1695 FileManager.prototype.decorateThumbnail_ = function(li, entry) {
1709 li.className = 'thumbnail-item'; 1696 li.className = 'thumbnail-item';
1710 1697
1711 if (this.showCheckboxes_) 1698 if (this.showCheckboxes_)
1712 li.appendChild(this.renderSelectionCheckbox_(entry)); 1699 li.appendChild(this.renderSelectionCheckbox_(entry));
1713 1700
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
2352 '/' + DirectoryModel.GDATA_DIRECTORY; 2339 '/' + DirectoryModel.GDATA_DIRECTORY;
2353 }; 2340 };
2354 2341
2355 FileManager.prototype.isStartingOnGData_ = function() { 2342 FileManager.prototype.isStartingOnGData_ = function() {
2356 var path = this.getPathFromUrlOrParams_(); 2343 var path = this.getPathFromUrlOrParams_();
2357 return path && 2344 return path &&
2358 FileManager.isGDataEnabled() && 2345 FileManager.isGDataEnabled() &&
2359 DirectoryModel.getRootType(path) == DirectoryModel.RootType.GDATA; 2346 DirectoryModel.getRootType(path) == DirectoryModel.RootType.GDATA;
2360 }; 2347 };
2361 2348
2362 FileManager.prototype.getMetadataProvider = function() {
2363 return this.metadataProvider_;
2364 };
2365
2366 /** 2349 /**
2367 * Callback called when tasks for selected files are determined. 2350 * Callback called when tasks for selected files are determined.
2368 * @param {Object} selection Selection is passed here, since this.selection 2351 * @param {Object} selection Selection is passed here, since this.selection
2369 * can change before tasks were found, and we should be accurate. 2352 * can change before tasks were found, and we should be accurate.
2370 * @param {Array.<Task>} tasksList The tasks list. 2353 * @param {Array.<Task>} tasksList The tasks list.
2371 */ 2354 */
2372 FileManager.prototype.onTasksFound_ = function(selection, tasksList) { 2355 FileManager.prototype.onTasksFound_ = function(selection, tasksList) {
2373 this.taskItems_.clear(); 2356 this.taskItems_.clear();
2374 2357
2375 var defaultTask = null; 2358 var defaultTask = null;
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
2884 var context = { 2867 var context = {
2885 // We show the root label in readonly warning (e.g. archive name). 2868 // We show the root label in readonly warning (e.g. archive name).
2886 readonlyDirName: 2869 readonlyDirName:
2887 readonly ? 2870 readonly ?
2888 (self.isOnGData() ? 2871 (self.isOnGData() ?
2889 self.getRootLabel_( 2872 self.getRootLabel_(
2890 DirectoryModel.getRootPath(currentDir.fullPath)) : 2873 DirectoryModel.getRootPath(currentDir.fullPath)) :
2891 self.directoryModel_.getRootName()) : 2874 self.directoryModel_.getRootName()) :
2892 null, 2875 null,
2893 saveDirEntry: readonly ? downloadsDir : currentDir, 2876 saveDirEntry: readonly ? downloadsDir : currentDir,
2894 metadataProvider: self.getMetadataProvider(), 2877 metadataProvider: self.metadataProvider_,
2895 getShareActions: self.getShareActions_.bind(self), 2878 getShareActions: self.getShareActions_.bind(self),
2896 onNameChange: function(name) { 2879 onNameChange: function(name) {
2897 self.document_.title = gallerySelection = name; 2880 self.document_.title = gallerySelection = name;
2898 self.updateLocation_(true /*replace*/, dirPath + '/' + name); 2881 self.updateLocation_(true /*replace*/, dirPath + '/' + name);
2899 }, 2882 },
2900 onClose: function() { 2883 onClose: function() {
2901 if (singleSelection) 2884 if (singleSelection)
2902 self.directoryModel_.selectEntry(gallerySelection); 2885 self.directoryModel_.selectEntry(gallerySelection);
2903 history.back(1); 2886 history.back(1);
2904 }, 2887 },
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
3049 currentWidth = Math.min(currentWidth, 3032 currentWidth = Math.min(currentWidth,
3050 containerWidth - pathWidth - collapsedWidth); 3033 containerWidth - pathWidth - collapsedWidth);
3051 bc.lastChild.style.width = (currentWidth - lastCrumbSeparatorWidth) + 'px'; 3034 bc.lastChild.style.width = (currentWidth - lastCrumbSeparatorWidth) + 'px';
3052 }; 3035 };
3053 3036
3054 FileManager.prototype.getThumbnailURL = function(entry, callback) { 3037 FileManager.prototype.getThumbnailURL = function(entry, callback) {
3055 if (!entry) 3038 if (!entry)
3056 return; 3039 return;
3057 3040
3058 var iconType = FileType.getIcon(entry); 3041 var iconType = FileType.getIcon(entry);
3042 var metadataCache = this.metadataCache_;
3059 3043
3060 function returnStockIcon() { 3044 function returnStockIcon() {
3061 callback(iconType, FileType.getPreviewArt(iconType)); 3045 callback(iconType, FileType.getPreviewArt(iconType), '');
3062 } 3046 }
3063 3047
3064 var self = this; 3048 function tryUsingImageUrl() {
3065 this.getMetadataProvider().fetch(entry.toURL(), function(metadata) { 3049 metadataCache.get(entry, 'filesystem|media', function(metadata) {
3066 if (metadata.thumbnailURL) { 3050 if (FileType.canUseImageUrlForPreview(
3067 callback(iconType, metadata.thumbnailURL, 3051 metadata.media.width,
3068 metadata.thumbnailTransform); 3052 metadata.media.height,
3053 metadata.filesystem.size)) {
3054 callback(iconType, entry.toURL(), metadata.media.imageTransform);
3055 } else {
3056 returnStockIcon();
3057 }
3058 });
3059 }
3060
3061 metadataCache.get(entry, 'thumbnail', function(thumbnail) {
3062 if (thumbnail) {
3063 callback(iconType, thumbnail.url, thumbnail.transform);
3069 } else if (iconType == 'image') { 3064 } else if (iconType == 'image') {
3070 self.metadataCache_.get(entry, 'filesystem', function(filesystem) { 3065 tryUsingImageUrl();
3071 if (FileType.canUseImageUrlForPreview(metadata, filesystem.size)) {
3072 callback(iconType, entry.toURL(), metadata.imageTransform);
3073 } else {
3074 returnStockIcon();
3075 }
3076 });
3077 } else { 3066 } else {
3078 returnStockIcon(); 3067 returnStockIcon();
3079 } 3068 }
3080 }); 3069 });
3081 }; 3070 };
3082 3071
3083 FileManager.prototype.focusCurrentList_ = function() { 3072 FileManager.prototype.focusCurrentList_ = function() {
3084 if (this.listType_ == FileManager.ListType.DETAIL) 3073 if (this.listType_ == FileManager.ListType.DETAIL)
3085 this.table_.focus(); 3074 this.table_.focus();
3086 else // this.listType_ == FileManager.ListType.THUMBNAIL) 3075 else // this.listType_ == FileManager.ListType.THUMBNAIL)
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
3253 if (this.selection && 3242 if (this.selection &&
3254 this.selection.totalCount == 1 && 3243 this.selection.totalCount == 1 &&
3255 this.selection.entries[0].isFile && 3244 this.selection.entries[0].isFile &&
3256 this.filenameInput_.value != this.selection.entries[0].name) { 3245 this.filenameInput_.value != this.selection.entries[0].name) {
3257 this.filenameInput_.value = this.selection.entries[0].name; 3246 this.filenameInput_.value = this.selection.entries[0].name;
3258 } 3247 }
3259 } 3248 }
3260 3249
3261 this.updateOkButton_(); 3250 this.updateOkButton_();
3262 3251
3263 var newThumbnailUrlCache = {};
3264 if (this.selection) {
3265 var entries = this.selection.entries;
3266 for (var i = 0; i < entries.length; i++) {
3267 var path = entries[i].fullPath;
3268 if (path in this.thumbnailUrlCache_)
3269 newThumbnailUrlCache[path] = this.thumbnailUrlCache_[path];
3270 }
3271 }
3272 this.thumbnailUrlCache_ = newThumbnailUrlCache;
3273
3274 setTimeout(this.onSelectionChangeComplete_.bind(this, event), 0); 3252 setTimeout(this.onSelectionChangeComplete_.bind(this, event), 0);
3275 }; 3253 };
3276 3254
3277 /** 3255 /**
3278 * Handle selection change related tasks that won't run properly during 3256 * Handle selection change related tasks that won't run properly during
3279 * the actual selection change event. 3257 * the actual selection change event.
3280 */ 3258 */
3281 FileManager.prototype.onSelectionChangeComplete_ = function(event) { 3259 FileManager.prototype.onSelectionChangeComplete_ = function(event) {
3282 // Inform tests it's OK to click buttons now. 3260 // Inform tests it's OK to click buttons now.
3283 chrome.test.sendMessage('selection-change-complete'); 3261 chrome.test.sendMessage('selection-change-complete');
(...skipping 1198 matching lines...) Expand 10 before | Expand all | Expand 10 after
4482 4460
4483 this.directoryModel_.addEventListener('scan-completed', maybeShowBanner); 4461 this.directoryModel_.addEventListener('scan-completed', maybeShowBanner);
4484 this.directoryModel_.addEventListener('rescan-completed', maybeShowBanner); 4462 this.directoryModel_.addEventListener('rescan-completed', maybeShowBanner);
4485 4463
4486 var style = this.document_.createElement('link'); 4464 var style = this.document_.createElement('link');
4487 style.rel = 'stylesheet'; 4465 style.rel = 'stylesheet';
4488 style.href = 'css/gdrive_welcome.css'; 4466 style.href = 'css/gdrive_welcome.css';
4489 this.document_.head.appendChild(style); 4467 this.document_.head.appendChild(style);
4490 }; 4468 };
4491 })(); 4469 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698