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

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

Issue 9701063: Fix file manager to better handle missing roots and scan failure (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with trunk (serya beat me to getting the exception fix in) 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
« no previous file with comments | « no previous file | chrome/browser/resources/file_manager/js/file_manager.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // If directory files changes too often, don't rescan directory more than once 5 // If directory files changes too often, don't rescan directory more than once
6 // per specified interval 6 // per specified interval
7 const SIMULTANEOUS_RESCAN_INTERVAL = 1000; 7 const SIMULTANEOUS_RESCAN_INTERVAL = 1000;
8 8
9 /** 9 /**
10 * Data model of the file manager. 10 * Data model of the file manager.
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 this.selectedNames = selectedNames; 323 this.selectedNames = selectedNames;
324 this.fileListSelection_.leadIndex = leadIndex; 324 this.fileListSelection_.leadIndex = leadIndex;
325 this.leadName = leadName; 325 this.leadName = leadName;
326 this.fileListSelection_.endChange(); 326 this.fileListSelection_.endChange();
327 cr.dispatchSimpleEvent(this, 'end-update-files'); 327 cr.dispatchSimpleEvent(this, 'end-update-files');
328 }, 328 },
329 329
330 /** 330 /**
331 * Cancels waiting and scheduled rescans and starts new scan. 331 * Cancels waiting and scheduled rescans and starts new scan.
332 * 332 *
333 * @param {Function} callback Called when scan completed. 333 * If the scan completes successfully on the first attempt, the callback will
334 * be invoked and a 'scan-completed' event will be dispatched. If the scan
335 * fails for any reason, we'll periodically retry until it succeeds (and then
336 * send a 'rescan-complete' event) or is cancelled or replaced by another
337 * scan.
338 *
339 * @param {Function} callback Called if scan completes on the first attempt.
340 * Note that this will NOT be called if the scan fails but later succeeds.
334 */ 341 */
335 scan_: function(callback) { 342 scan_: function(callback) {
336 if (this.rescanTimeout_) { 343 if (this.rescanTimeout_) {
337 clearTimeout(this.rescanTimeout_); 344 clearTimeout(this.rescanTimeout_);
338 this.rescanTimeout_ = 0; 345 this.rescanTimeout_ = 0;
339 } 346 }
340 if (this.runningScan_) 347 if (this.runningScan_)
341 this.runningScan_.cancel(); 348 this.runningScan_.cancel();
342 this.pendingScan_ = null; 349 this.pendingScan_ = null;
343 350
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 }, 497 },
491 498
492 /** 499 /**
493 * Change the current directory to the directory represented by a 500 * Change the current directory to the directory represented by a
494 * DirectoryEntry. 501 * DirectoryEntry.
495 * 502 *
496 * Dispatches the 'directory-changed' event when the directory is successfully 503 * Dispatches the 'directory-changed' event when the directory is successfully
497 * changed. 504 * changed.
498 * 505 *
499 * @param {DirectoryEntry} dirEntry The absolute path to the new directory. 506 * @param {DirectoryEntry} dirEntry The absolute path to the new directory.
500 * @param {function} action Action executed when the directory loaded. 507 * @param {function} action Action executed if the directory loads
501 * By default selects the first item 508 * successfully. By default selects the first item (unless it's a save
502 * (unless it's a save dialog). 509 * dialog).
503 * @param {boolean} initial True if it comes from setupPath and 510 * @param {boolean} initial True if it comes from setupPath and
504 * false if caused by an user action. 511 * false if caused by an user action.
505 */ 512 */
506 changeDirectoryEntry_: function(dirEntry, action, initial) { 513 changeDirectoryEntry_: function(dirEntry, action, initial) {
507 var current = this.currentEntry; 514 var current = this.currentEntry;
508 this.currentDirEntry_ = dirEntry; 515 this.currentDirEntry_ = dirEntry;
509 function onRescanComplete() { 516 function onRescanComplete() {
510 action(); 517 action();
511 // For tests that open the dialog to empty directories, everything 518 // For tests that open the dialog to empty directories, everything
512 // is loaded at this point. 519 // is loaded at this point.
513 chrome.test.sendMessage('directory-change-complete'); 520 chrome.test.sendMessage('directory-change-complete');
514 } 521 }
515 this.updateRootsListSelection_(); 522 this.updateRootsListSelection_();
516 this.scan_(onRescanComplete); 523 this.scan_(onRescanComplete);
517 524
518 var e = new cr.Event('directory-changed'); 525 var e = new cr.Event('directory-changed');
519 e.previousDirEntry = this.currentEntry; 526 e.previousDirEntry = this.currentEntry;
520 e.newDirEntry = dirEntry; 527 e.newDirEntry = dirEntry;
521 e.initial = initial; 528 e.initial = initial;
522 this.dispatchEvent(e); 529 this.dispatchEvent(e);
523 }, 530 },
524 531
525 /** 532 /**
526 * Change the state of the model to reflect the specified path (either a 533 * Change the state of the model to reflect the specified path (either a
527 * file or directory). 534 * file or directory).
528 * 535 *
529 * @param {string} path The root path to use 536 * @param {string} path The root path to use
530 * @param {Function=} opt_loadedCallback Invoked when the entire directory 537 * @param {Function=} opt_loadedCallback Invoked when the entire directory
531 * has been loaded and any default file selected. 538 * has been loaded and any default file selected. If there are any
539 * errors loading the directory this will not get called (even if the
540 * directory loads OK on retry later).
532 * @param {Function=} opt_pathResolveCallback Invoked as soon as the path has 541 * @param {Function=} opt_pathResolveCallback Invoked as soon as the path has
533 * been resolved, and called with the base and leaf portions of the path 542 * been resolved, and called with the base and leaf portions of the path
534 * name, and a flag indicating if the entry exists. 543 * name, and a flag indicating if the entry exists.
535 */ 544 */
536 setupPath: function(path, opt_loadedCallback, opt_pathResolveCallback) { 545 setupPath: function(path, opt_loadedCallback, opt_pathResolveCallback) {
537 // Split the dirname from the basename. 546 // Split the dirname from the basename.
538 var ary = path.match(/^(?:(.*)\/)?([^\/]*)$/); 547 var ary = path.match(/^(?:(.*)\/)?([^\/]*)$/);
539 var autoSelect = function() { 548 var autoSelect = function() {
540 this.selectIndex(this.autoSelectIndex_); 549 this.selectIndex(this.autoSelectIndex_);
541 if (opt_loadedCallback) 550 if (opt_loadedCallback)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 var onBaseError = function(err) { 599 var onBaseError = function(err) {
591 resolveCallback(false); 600 resolveCallback(false);
592 console.log('Unexpected error resolving default base "' + 601 console.log('Unexpected error resolving default base "' +
593 baseName + '": ' + err); 602 baseName + '": ' + err);
594 if (path != '/' + DirectoryModel.DOWNLOADS_DIRECTORY) { 603 if (path != '/' + DirectoryModel.DOWNLOADS_DIRECTORY) {
595 // Can't find the provided path, let's go to default one instead. 604 // Can't find the provided path, let's go to default one instead.
596 this.setupDefaultPath(opt_loadedCallback); 605 this.setupDefaultPath(opt_loadedCallback);
597 } else { 606 } else {
598 // Well, we can't find the downloads dir. Let's just show something, 607 // Well, we can't find the downloads dir. Let's just show something,
599 // or we will get an infinite recursion. 608 // or we will get an infinite recursion.
600 this.changeDirectory('/', opt_loadedCallback, true); 609 this.changeDirectoryEntry_(this.root_, opt_loadedCallback, true);
601 } 610 }
602 }.bind(this); 611 }.bind(this);
603 612
604 var onBaseFound = function(baseDirEntry) { 613 var onBaseFound = function(baseDirEntry) {
605 if (!leafName) { 614 if (!leafName) {
606 // Default path is just a directory, cd to it and we're done. 615 // Default path is just a directory, cd to it and we're done.
607 this.changeDirectoryEntry_(baseDirEntry, autoSelect, true); 616 this.changeDirectoryEntry_(baseDirEntry, autoSelect, true);
608 return; 617 return;
609 } 618 }
610 619
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 936
928 recordMetrics_: function() { 937 recordMetrics_: function() {
929 metrics.recordInterval('DirectoryScan'); 938 metrics.recordInterval('DirectoryScan');
930 if (this.dir_.fullPath == 939 if (this.dir_.fullPath ==
931 '/' + DirectoryModel.DOWNLOADS_DIRECTORY) { 940 '/' + DirectoryModel.DOWNLOADS_DIRECTORY) {
932 metrics.recordMediumCount("DownloadsCount", this.list_.length); 941 metrics.recordMediumCount("DownloadsCount", this.list_.length);
933 } 942 }
934 } 943 }
935 }; 944 };
936 945
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/file_manager/js/file_manager.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698