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

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

Issue 9379023: Tweaks for improving file manager performance (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix comment typo Created 8 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 | 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 // Setting the src of an img to an empty string can crash the browser, so we 5 // Setting the src of an img to an empty string can crash the browser, so we
6 // use an empty 1x1 gif instead. 6 // use an empty 1x1 gif instead.
7 const EMPTY_IMAGE_URI = 'data:image/gif;base64,' 7 const EMPTY_IMAGE_URI = 'data:image/gif;base64,'
8 + 'R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D'; 8 + 'R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D';
9 9
10 /** 10 /**
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 }; 473 };
474 } 474 }
475 475
476 // Optional list of file types. 476 // Optional list of file types.
477 this.fileTypes_ = this.params_.typeList; 477 this.fileTypes_ = this.params_.typeList;
478 478
479 this.showCheckboxes_ = 479 this.showCheckboxes_ =
480 (this.dialogType_ == FileManager.DialogType.FULL_PAGE || 480 (this.dialogType_ == FileManager.DialogType.FULL_PAGE ||
481 this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE); 481 this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE);
482 482
483 this.table_.list.startBatchUpdates(); 483 this.table_.startBatchUpdates();
484 this.grid_.startBatchUpdates(); 484 this.grid_.startBatchUpdates();
485 485
486 this.initFileList_(); 486 this.initFileList_();
487 this.initDialogs_(); 487 this.initDialogs_();
488 488
489 this.copyManager_ = new FileCopyManager(); 489 this.copyManager_ = new FileCopyManager();
490 this.copyManager_.addEventListener('copy-progress', 490 this.copyManager_.addEventListener('copy-progress',
491 this.onCopyProgress_.bind(this)); 491 this.onCopyProgress_.bind(this));
492 492
493 window.addEventListener('popstate', this.onPopState_.bind(this)); 493 window.addEventListener('popstate', this.onPopState_.bind(this));
(...skipping 19 matching lines...) Expand all
513 // The list of archives requested to mount. We will show contents once 513 // The list of archives requested to mount. We will show contents once
514 // archive is mounted, but only for mounts from within this filebrowser tab. 514 // archive is mounted, but only for mounts from within this filebrowser tab.
515 this.mountRequests_ = []; 515 this.mountRequests_ = [];
516 this.unmountRequests_ = []; 516 this.unmountRequests_ = [];
517 chrome.fileBrowserPrivate.onMountCompleted.addListener( 517 chrome.fileBrowserPrivate.onMountCompleted.addListener(
518 this.onMountCompleted_.bind(this)); 518 this.onMountCompleted_.bind(this));
519 519
520 chrome.fileBrowserPrivate.onFileChanged.addListener( 520 chrome.fileBrowserPrivate.onFileChanged.addListener(
521 this.onFileChanged_.bind(this)); 521 this.onFileChanged_.bind(this));
522 522
523 var self = this;
524
525 // The list of callbacks to be invoked during the directory rescan after 523 // The list of callbacks to be invoked during the directory rescan after
526 // all paste tasks are complete. 524 // all paste tasks are complete.
527 this.pasteSuccessCallbacks_ = []; 525 this.pasteSuccessCallbacks_ = [];
528 526
529 this.setupCurrentDirectory_(); 527 this.setupCurrentDirectory_();
530 528
531 this.summarizeSelection_(); 529 this.summarizeSelection_();
532 530
533 var sortField = 'cachedMtime_'; 531 var sortField = 'cachedMtime_';
534 var sortDirection = 'desc'; 532 var sortDirection = 'desc';
535 if (FileManager.DialogType.isModal(this.dialogType_)) { 533 if (FileManager.DialogType.isModal(this.dialogType_)) {
536 sortField = 534 sortField =
537 window.localStorage['sort-field-' + this.dialogType_] || 535 window.localStorage['sort-field-' + this.dialogType_] ||
538 sortField; 536 sortField;
539 sortDirection = 537 sortDirection =
540 window.localStorage['sort-direction-' + this.dialogType_] || 538 window.localStorage['sort-direction-' + this.dialogType_] ||
541 sortDirection; 539 sortDirection;
542 } 540 }
543 this.directoryModel_.fileList.sort(sortField, sortDirection); 541 this.directoryModel_.fileList.sort(sortField, sortDirection);
544 542
545 this.refocus(); 543 this.refocus();
546 544
547 this.createMetadataProvider_(); 545 this.createMetadataProvider_();
548 546
549 this.table_.list.endBatchUpdates(); 547 this.table_.endBatchUpdates();
550 this.grid_.endBatchUpdates(); 548 this.grid_.endBatchUpdates();
551 549
552 metrics.recordInterval('Load.DOM'); 550 metrics.recordInterval('Load.DOM');
553 metrics.recordInterval('Load.Total'); 551 metrics.recordInterval('Load.Total');
554 }; 552 };
555 553
556 /** 554 /**
557 * One-time initialization of commands. 555 * One-time initialization of commands.
558 */ 556 */
559 FileManager.prototype.initCommands_ = function() { 557 FileManager.prototype.initCommands_ = function() {
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 746
749 var self = this; 747 var self = this;
750 this.rootsList_.itemConstructor = function(entry) { 748 this.rootsList_.itemConstructor = function(entry) {
751 return self.renderRoot_(entry); 749 return self.renderRoot_(entry);
752 }; 750 };
753 751
754 this.rootsList_.selectionModel = this.directoryModel_.rootsListSelection; 752 this.rootsList_.selectionModel = this.directoryModel_.rootsListSelection;
755 753
756 // TODO(dgozman): add "Add a drive" item. 754 // TODO(dgozman): add "Add a drive" item.
757 this.rootsList_.dataModel = this.directoryModel_.rootsList; 755 this.rootsList_.dataModel = this.directoryModel_.rootsList;
758 this.directoryModel_.updateRoots(); 756 this.directoryModel_.updateRoots(function() {
757 self.rootsList_.endBatchUpdates();
arv (Not doing code reviews) 2012/02/28 20:26:32 this.directoryModel_.updateRoots(function() { se
Rick Byers 2012/02/28 20:35:00 Done.
758 });
759 }; 759 };
760 760
761 /** 761 /**
762 * Get the icon type for a given Entry. 762 * Get the icon type for a given Entry.
763 * 763 *
764 * @param {Entry} entry An Entry subclass (FileEntry or DirectoryEntry). 764 * @param {Entry} entry An Entry subclass (FileEntry or DirectoryEntry).
765 * @return {string} 765 * @return {string}
766 */ 766 */
767 FileManager.prototype.getIconType = function(entry) { 767 FileManager.prototype.getIconType = function(entry) {
768 if (!('cachedIconType_' in entry)) 768 if (!('cachedIconType_' in entry))
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
1377 1377
1378 /** 1378 /**
1379 * Restores current directory and may be a selected item after page load (or 1379 * Restores current directory and may be a selected item after page load (or
1380 * reload) or popping a state (after click on back/forward). If location.hash 1380 * reload) or popping a state (after click on back/forward). If location.hash
1381 * is present it means that the user has navigated somewhere and that place 1381 * is present it means that the user has navigated somewhere and that place
1382 * will be restored. defaultPath primarily is used with save/open dialogs. 1382 * will be restored. defaultPath primarily is used with save/open dialogs.
1383 * Default path may also contain a file name. Freshly opened file manager 1383 * Default path may also contain a file name. Freshly opened file manager
1384 * window has neither. 1384 * window has neither.
1385 */ 1385 */
1386 FileManager.prototype.setupCurrentDirectory_ = function() { 1386 FileManager.prototype.setupCurrentDirectory_ = function() {
1387 // Avoid a bunch of intermediate list redraws while the data model is
1388 // cleared and updated.
1389 this.table_.startBatchUpdates();
1390 var onLoaded = function() {
arv (Not doing code reviews) 2012/02/28 20:26:32 or var onLoaded = this.table_.endBatchUpdates.bin
Rick Byers 2012/02/28 20:35:00 Done.
1391 this.table_.endBatchUpdates();
1392 }.bind(this);
1393
1387 if (location.hash) { 1394 if (location.hash) {
1388 // Location hash has the highest priority. 1395 // Location hash has the highest priority.
1389 var path = decodeURI(location.hash.substr(1)); 1396 var path = decodeURI(location.hash.substr(1));
1390 this.directoryModel_.setupPath(path); 1397 this.directoryModel_.setupPath(path, onLoaded);
1391 return; 1398 return;
1392 } else if (this.params_.defaultPath) { 1399 } else if (this.params_.defaultPath) {
1393 var pathResolvedCallback; 1400 var pathResolvedCallback;
1394 if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { 1401 if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) {
1395 pathResolvedCallback = function(basePath, leafName) { 1402 pathResolvedCallback = function(basePath, leafName) {
1396 this.filenameInput_.value = leafName; 1403 this.filenameInput_.value = leafName;
1397 this.selectDefaultPathInFilenameInput_(); 1404 this.selectDefaultPathInFilenameInput_();
1398 }.bind(this); 1405 }.bind(this);
1399 } 1406 }
1400 this.directoryModel_.setupPath(this.params_.defaultPath, 1407 this.directoryModel_.setupPath(this.params_.defaultPath,
1408 onLoaded,
1401 pathResolvedCallback); 1409 pathResolvedCallback);
1402 } else { 1410 } else {
1403 this.directoryModel_.setupDefaultPath(); 1411 this.directoryModel_.setupDefaultPath(onLoaded);
1404 } 1412 }
1405 }; 1413 };
1406 1414
1407 /** 1415 /**
1408 * Tweak the UI to become a particular kind of dialog, as determined by the 1416 * Tweak the UI to become a particular kind of dialog, as determined by the
1409 * dialog type parameter passed to the constructor. 1417 * dialog type parameter passed to the constructor.
1410 */ 1418 */
1411 FileManager.prototype.initDialogType_ = function() { 1419 FileManager.prototype.initDialogType_ = function() {
1412 var defaultTitle; 1420 var defaultTitle;
1413 var okLabel = str('OPEN_LABEL'); 1421 var okLabel = str('OPEN_LABEL');
(...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after
2272 }; 2280 };
2273 2281
2274 /** 2282 /**
2275 * Event handler called when some volume was mounted or unmouted. 2283 * Event handler called when some volume was mounted or unmouted.
2276 */ 2284 */
2277 FileManager.prototype.onMountCompleted_ = function(event) { 2285 FileManager.prototype.onMountCompleted_ = function(event) {
2278 var self = this; 2286 var self = this;
2279 chrome.fileBrowserPrivate.getMountPoints(function(mountPoints) { 2287 chrome.fileBrowserPrivate.getMountPoints(function(mountPoints) {
2280 self.mountPoints_ = mountPoints; 2288 self.mountPoints_ = mountPoints;
2281 self.updateVolumeMetadata_(); 2289 self.updateVolumeMetadata_();
2282 var changeDirectoryTo = null; 2290 var changeDirectoryCallback = null;
2283 2291
2284 if (event.eventType == 'mount') { 2292 if (event.eventType == 'mount') {
2285 // Mount request finished - remove it. 2293 // Mount request finished - remove it.
2286 var index = self.mountRequests_.indexOf(event.sourceUrl); 2294 var index = self.mountRequests_.indexOf(event.sourceUrl);
2287 if (index != -1) { 2295 if (index != -1) {
2288 self.mountRequests_.splice(index, 1); 2296 self.mountRequests_.splice(index, 1);
2289 // Go to mounted directory, if request was initiated from this tab. 2297 // Go to mounted directory, if request was initiated from this tab.
2290 if (event.status == 'success') 2298 if (event.status == 'success')
2291 changeDirectoryTo = event.mountPath; 2299 changeDirectoryTo = event.mountPath;
2292 } 2300 }
(...skipping 23 matching lines...) Expand all
2316 if (event.eventType == 'unmount' && event.status == 'success' && 2324 if (event.eventType == 'unmount' && event.status == 'success' &&
2317 event.mountPath == self.directoryModel_.rootPath) { 2325 event.mountPath == self.directoryModel_.rootPath) {
2318 if (self.params_.mountTriggered) { 2326 if (self.params_.mountTriggered) {
2319 // window.close() sometimes doesn't work. 2327 // window.close() sometimes doesn't work.
2320 chrome.tabs.getCurrent(function(tab){ 2328 chrome.tabs.getCurrent(function(tab){
2321 chrome.tabs.remove(tab.id); 2329 chrome.tabs.remove(tab.id);
2322 }); 2330 });
2323 return; 2331 return;
2324 } 2332 }
2325 // Current durectory just unmounted. Move to the 'Downloads'. 2333 // Current durectory just unmounted. Move to the 'Downloads'.
2326 changeDirectoryTo = '/' + DirectoryModel.DOWNLOADS_DIRECTORY; 2334 changeDirectoryCallback = function() {
2335 self.directoryModel_.changeDirectory(
2336 '/' + DirectoryModel.DOWNLOADS_DIRECTORY);
2337 };
2327 } 2338 }
2328 2339
2329 // Even if something failed root list should be rescanned. 2340 // Even if something failed root list should be rescanned.
2330 // Failed mounts can "give" us new devices which might be formatted, 2341 // Failed mounts can "give" us new devices which might be formatted,
2331 // so we have to refresh root list then. 2342 // so we have to refresh root list then.
2332 self.directoryModel_.updateRoots(changeDirectoryTo); 2343 self.directoryModel_.updateRoots(changeDirectoryCallback);
2333 }); 2344 });
2334 }; 2345 };
2335 2346
2336 /** 2347 /**
2337 * Event handler called when some internal task should be executed. 2348 * Event handler called when some internal task should be executed.
2338 */ 2349 */
2339 FileManager.prototype.onFileTaskExecute_ = function(id, details) { 2350 FileManager.prototype.onFileTaskExecute_ = function(id, details) {
2340 var urls = details.urls; 2351 var urls = details.urls;
2341 if (id == 'play') { 2352 if (id == 'play') {
2342 var position = 0; 2353 var position = 0;
(...skipping 1475 matching lines...) Expand 10 before | Expand all | Expand 10 after
3818 }); 3829 });
3819 }, onError); 3830 }, onError);
3820 3831
3821 function onError(err) { 3832 function onError(err) {
3822 console.log('Error while checking free space: ' + err); 3833 console.log('Error while checking free space: ' + err);
3823 setTimeout(doCheck, 1000 * 60); 3834 setTimeout(doCheck, 1000 * 60);
3824 } 3835 }
3825 } 3836 }
3826 } 3837 }
3827 })(); 3838 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698