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

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 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 }; 475 };
476 } 476 }
477 477
478 // Optional list of file types. 478 // Optional list of file types.
479 this.fileTypes_ = this.params_.typeList; 479 this.fileTypes_ = this.params_.typeList;
480 480
481 this.showCheckboxes_ = 481 this.showCheckboxes_ =
482 (this.dialogType_ == FileManager.DialogType.FULL_PAGE || 482 (this.dialogType_ == FileManager.DialogType.FULL_PAGE ||
483 this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE); 483 this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE);
484 484
485 this.table_.list.startBatchUpdates(); 485 this.table_.startBatchUpdates();
486 this.grid_.startBatchUpdates(); 486 this.grid_.startBatchUpdates();
487 487
488 this.initFileList_(); 488 this.initFileList_();
489 this.initDialogs_(); 489 this.initDialogs_();
490 490
491 this.copyManager_ = new FileCopyManager(); 491 this.copyManager_ = new FileCopyManager();
492 this.copyManager_.addEventListener('copy-progress', 492 this.copyManager_.addEventListener('copy-progress',
493 this.onCopyProgress_.bind(this)); 493 this.onCopyProgress_.bind(this));
494 494
495 window.addEventListener('popstate', this.onPopState_.bind(this)); 495 window.addEventListener('popstate', this.onPopState_.bind(this));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 sortDirection = 543 sortDirection =
544 window.localStorage['sort-direction-' + this.dialogType_] || 544 window.localStorage['sort-direction-' + this.dialogType_] ||
545 sortDirection; 545 sortDirection;
546 } 546 }
547 this.directoryModel_.fileList.sort(sortField, sortDirection); 547 this.directoryModel_.fileList.sort(sortField, sortDirection);
548 548
549 this.refocus(); 549 this.refocus();
550 550
551 this.createMetadataProvider_(); 551 this.createMetadataProvider_();
552 552
553 this.table_.list.endBatchUpdates(); 553 this.table_.endBatchUpdates();
554 this.grid_.endBatchUpdates(); 554 this.grid_.endBatchUpdates();
555 555
556 metrics.recordInterval('Load.DOM'); 556 metrics.recordInterval('Load.DOM');
557 metrics.recordInterval('Load.Total'); 557 metrics.recordInterval('Load.Total');
558 }; 558 };
559 559
560 /** 560 /**
561 * One-time initialization of commands. 561 * One-time initialization of commands.
562 */ 562 */
563 FileManager.prototype.initCommands_ = function() { 563 FileManager.prototype.initCommands_ = function() {
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 754
755 var self = this; 755 var self = this;
756 this.rootsList_.itemConstructor = function(entry) { 756 this.rootsList_.itemConstructor = function(entry) {
757 return self.renderRoot_(entry); 757 return self.renderRoot_(entry);
758 }; 758 };
759 759
760 this.rootsList_.selectionModel = this.directoryModel_.rootsListSelection; 760 this.rootsList_.selectionModel = this.directoryModel_.rootsListSelection;
761 761
762 // TODO(dgozman): add "Add a drive" item. 762 // TODO(dgozman): add "Add a drive" item.
763 this.rootsList_.dataModel = this.directoryModel_.rootsList; 763 this.rootsList_.dataModel = this.directoryModel_.rootsList;
764 this.directoryModel_.updateRoots(); 764 this.directoryModel_.updateRoots(function() {
765 self.rootsList_.endBatchUpdates();
766 });
765 }; 767 };
766 768
767 FileManager.prototype.initGData_ = function() { 769 FileManager.prototype.initGData_ = function() {
768 metrics.startInterval('Load.GData'); 770 metrics.startInterval('Load.GData');
769 // TODO(zelidrag): We should do this first time user selects this provider. 771 // TODO(zelidrag): We should do this first time user selects this provider.
770 chrome.fileBrowserPrivate.addMount('', 'gdata', {}); 772 chrome.fileBrowserPrivate.addMount('', 'gdata', {});
771 }; 773 };
772 774
773 /** 775 /**
774 * Get the icon type for a given Entry. 776 * Get the icon type for a given Entry.
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
1393 1395
1394 /** 1396 /**
1395 * Restores current directory and may be a selected item after page load (or 1397 * Restores current directory and may be a selected item after page load (or
1396 * reload) or popping a state (after click on back/forward). If location.hash 1398 * reload) or popping a state (after click on back/forward). If location.hash
1397 * is present it means that the user has navigated somewhere and that place 1399 * is present it means that the user has navigated somewhere and that place
1398 * will be restored. defaultPath primarily is used with save/open dialogs. 1400 * will be restored. defaultPath primarily is used with save/open dialogs.
1399 * Default path may also contain a file name. Freshly opened file manager 1401 * Default path may also contain a file name. Freshly opened file manager
1400 * window has neither. 1402 * window has neither.
1401 */ 1403 */
1402 FileManager.prototype.setupCurrentDirectory_ = function() { 1404 FileManager.prototype.setupCurrentDirectory_ = function() {
1405 // Avoid a bunch of intermediate list redraws while the data model is
1406 // cleared and updated. Note that it may (or may not) be desirable to draw
1407 // partial results as we get them, but today the DirectoryReader API
1408 // generally returns all entries in one chunk so even without this batching
1409 // we wouldn't have incremental updates.
1410 this.table_.startBatchUpdates();
1411 var onLoaded = this.table_.endBatchUpdates.bind(this.table_);
1412
1403 if (location.hash) { 1413 if (location.hash) {
1404 // Location hash has the highest priority. 1414 // Location hash has the highest priority.
1405 var path = decodeURI(location.hash.substr(1)); 1415 var path = decodeURI(location.hash.substr(1));
1406 1416
1407 // In the FULL_PAGE mode if the path points to a file we should invoke 1417 // In the FULL_PAGE mode if the path points to a file we should invoke
1408 // the default action after selecting it. 1418 // the default action after selecting it.
1409 if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { 1419 if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) {
1410 // To prevent the file list flickering for a moment before the action 1420 // To prevent the file list flickering for a moment before the action
1411 // is executed we hide it under a white div. 1421 // is executed we hide it under a white div.
1412 var shade = this.document_.createElement('div'); 1422 var shade = this.document_.createElement('div');
1413 shade.className = 'overlay-pane'; 1423 shade.className = 'overlay-pane';
1414 shade.style.backgroundColor = 'white'; 1424 shade.style.backgroundColor = 'white';
1415 this.document_.body.appendChild(shade); 1425 this.document_.body.appendChild(shade);
1416 function removeShade() { shade.parentNode.removeChild(shade) } 1426 function removeShade() { shade.parentNode.removeChild(shade) }
1417 1427
1428 // Keep track of whether the path is identified as an existing leaf
1429 // node. Note that onResolve is guaranteed to be called (exactly once)
1430 // before onLoadedActivateLeaf.
1431 var foundLeaf = true;
Rick Byers 2012/03/02 00:19:46 Here's where I handled the special 'onFileSelected
1418 function onResolve(baseName, leafName, exists) { 1432 function onResolve(baseName, leafName, exists) {
1419 if (!exists || leafName == '') { 1433 if (!exists || leafName == '') {
1420 // Non-existent file or a directory. Remove the shade immediately. 1434 // Non-existent file or a directory. Remove the shade immediately.
1421 removeShade(); 1435 removeShade();
1436 foundLeaf = false;
1422 } 1437 }
1423 } 1438 }
1424 1439
1425 // TODO(kaznacheev): refactor dispatchDefaultTask to accept an array 1440 // TODO(kaznacheev): refactor dispatchDefaultTask to accept an array
1426 // of urls instead of a selection. This will remove the need to wait 1441 // of urls instead of a selection. This will remove the need to wait
1427 // until the selection is done. 1442 // until the selection is done.
1428 var self = this; 1443 var self = this;
1429 function onFileSelected() { 1444 function onLoadedActivateLeaf() {
1430 self.dispatchDefaultTask_(); 1445 onLoaded();
1431 setTimeout(removeShade, 1000); 1446 if (foundLeaf) {
1447 self.dispatchDefaultTask_();
1448 setTimeout(removeShade, 1000);
1449 }
1432 } 1450 }
1433 this.directoryModel_.setupPath(path, onResolve, onFileSelected); 1451 this.directoryModel_.setupPath(path, onLoadedActivateLeaf, onResolve);
1452
1434 return; 1453 return;
1435 } 1454 }
1436 1455
1437 this.directoryModel_.setupPath(path); 1456 this.directoryModel_.setupPath(path, onLoaded);
1438 return; 1457 return;
1439 } 1458 }
1440 1459
1441 if (this.params_.defaultPath) { 1460 if (this.params_.defaultPath) {
1442 var path = this.params_.defaultPath; 1461 var path = this.params_.defaultPath;
1443 if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { 1462 if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) {
1444 this.directoryModel_.setupPath(path, function(basePath, leafName) { 1463 this.directoryModel_.setupPath(path, onLoaded,
1445 this.filenameInput_.value = leafName; 1464 function(basePath, leafName) {
1446 this.selectDefaultPathInFilenameInput_(); 1465 this.filenameInput_.value = leafName;
1447 }.bind(this)); 1466 this.selectDefaultPathInFilenameInput_();
1467 }.bind(this));
1448 return; 1468 return;
1449 } 1469 }
1450 1470
1451 this.directoryModel_.setupPath(path); 1471 this.directoryModel_.setupPath(path, onLoaded);
1452 return; 1472 return;
1453 } 1473 }
1454 1474
1455 this.directoryModel_.setupDefaultPath(); 1475 this.directoryModel_.setupDefaultPath(onLoaded);
1456 }; 1476 };
1457 1477
1458 /** 1478 /**
1459 * Tweak the UI to become a particular kind of dialog, as determined by the 1479 * Tweak the UI to become a particular kind of dialog, as determined by the
1460 * dialog type parameter passed to the constructor. 1480 * dialog type parameter passed to the constructor.
1461 */ 1481 */
1462 FileManager.prototype.initDialogType_ = function() { 1482 FileManager.prototype.initDialogType_ = function() {
1463 var defaultTitle; 1483 var defaultTitle;
1464 var okLabel = str('OPEN_LABEL'); 1484 var okLabel = str('OPEN_LABEL');
1465 1485
(...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after
2394 }); 2414 });
2395 return; 2415 return;
2396 } 2416 }
2397 // Current durectory just unmounted. Move to the 'Downloads'. 2417 // Current durectory just unmounted. Move to the 'Downloads'.
2398 changeDirectoryTo = '/' + DirectoryModel.DOWNLOADS_DIRECTORY; 2418 changeDirectoryTo = '/' + DirectoryModel.DOWNLOADS_DIRECTORY;
2399 } 2419 }
2400 2420
2401 // Even if something failed root list should be rescanned. 2421 // Even if something failed root list should be rescanned.
2402 // Failed mounts can "give" us new devices which might be formatted, 2422 // Failed mounts can "give" us new devices which might be formatted,
2403 // so we have to refresh root list then. 2423 // so we have to refresh root list then.
2404 self.directoryModel_.updateRoots(changeDirectoryTo); 2424 self.directoryModel_.updateRoots(function() {
2425 if (changeDirectoryTo) {
2426 self.directoryModel_.changeDirectory(changeDirectoryTo);
2427 }
2428 });
2405 }); 2429 });
2406 }; 2430 };
2407 2431
2408 /** 2432 /**
2409 * Event handler called when some internal task should be executed. 2433 * Event handler called when some internal task should be executed.
2410 */ 2434 */
2411 FileManager.prototype.onFileTaskExecute_ = function(id, details) { 2435 FileManager.prototype.onFileTaskExecute_ = function(id, details) {
2412 var urls = details.urls; 2436 var urls = details.urls;
2413 if (id == 'play') { 2437 if (id == 'play') {
2414 var position = 0; 2438 var position = 0;
(...skipping 1522 matching lines...) Expand 10 before | Expand all | Expand 10 after
3937 }); 3961 });
3938 }, onError); 3962 }, onError);
3939 3963
3940 function onError(err) { 3964 function onError(err) {
3941 console.log('Error while checking free space: ' + err); 3965 console.log('Error while checking free space: ' + err);
3942 setTimeout(doCheck, 1000 * 60); 3966 setTimeout(doCheck, 1000 * 60);
3943 } 3967 }
3944 } 3968 }
3945 } 3969 }
3946 })(); 3970 })();
OLDNEW
« no previous file with comments | « chrome/browser/resources/file_manager/js/directory_model.js ('k') | chrome/browser/resources/shared/js/cr/ui/table.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698