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

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: 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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 this.fileList_.splice.apply(this.fileList_, spliceArgs); 321 this.fileList_.splice.apply(this.fileList_, spliceArgs);
322 322
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. If the scan
rginda 2012/03/15 17:42:09 I had been following python documentation guidelin
Rick Byers 2012/03/15 19:13:32 Thanks, Done. I agree that's better.
332 * completes successfully on the first attempt, the callback will be invoked
333 * and a 'scan-completed' event will be dispatched. If the scan fails for
334 * any reason, we'll periodically retry until it succeeds (and then send a
335 * 'rescan-complete' event) or is cancelled or replaced by another scan.
332 * 336 *
333 * @param {Function} callback Called when scan completed. 337 * @param {Function} callback Called if scan completes on the first attempt.
338 * Note that this will NOT be called if the scan fails but later succeeds.
334 */ 339 */
335 scan_: function(callback) { 340 scan_: function(callback) {
336 if (this.rescanTimeout_) { 341 if (this.rescanTimeout_) {
337 clearTimeout(this.rescanTimeout_); 342 clearTimeout(this.rescanTimeout_);
338 this.rescanTimeout_ = 0; 343 this.rescanTimeout_ = 0;
339 } 344 }
340 if (this.runningScan_) 345 if (this.runningScan_)
341 this.runningScan_.cancel(); 346 this.runningScan_.cancel();
342 this.pendingScan_ = null; 347 this.pendingScan_ = null;
343 348
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 }, 495 },
491 496
492 /** 497 /**
493 * Change the current directory to the directory represented by a 498 * Change the current directory to the directory represented by a
494 * DirectoryEntry. 499 * DirectoryEntry.
495 * 500 *
496 * Dispatches the 'directory-changed' event when the directory is successfully 501 * Dispatches the 'directory-changed' event when the directory is successfully
497 * changed. 502 * changed.
498 * 503 *
499 * @param {DirectoryEntry} dirEntry The absolute path to the new directory. 504 * @param {DirectoryEntry} dirEntry The absolute path to the new directory.
500 * @param {function} action Action executed when the directory loaded. 505 * @param {function} action Action executed if the directory loads
501 * By default selects the first item 506 * successfully. By default selects the first item (unless it's a save
502 * (unless it's a save dialog). 507 * dialog).
503 * @param {boolean} initial True if it comes from setupPath and 508 * @param {boolean} initial True if it comes from setupPath and
504 * false if caused by an user action. 509 * false if caused by an user action.
505 */ 510 */
506 changeDirectoryEntry_: function(dirEntry, action, initial) { 511 changeDirectoryEntry_: function(dirEntry, action, initial) {
507 var current = this.currentEntry; 512 var current = this.currentEntry;
508 this.currentDirEntry_ = dirEntry; 513 this.currentDirEntry_ = dirEntry;
509 function onRescanComplete() { 514 function onRescanComplete() {
510 action(); 515 action();
511 // For tests that open the dialog to empty directories, everything 516 // For tests that open the dialog to empty directories, everything
512 // is loaded at this point. 517 // is loaded at this point.
513 chrome.test.sendMessage('directory-change-complete'); 518 chrome.test.sendMessage('directory-change-complete');
514 } 519 }
515 this.updateRootsListSelection_(); 520 this.updateRootsListSelection_();
516 this.scan_(onRescanComplete); 521 this.scan_(onRescanComplete);
517 522
518 var e = new cr.Event('directory-changed'); 523 var e = new cr.Event('directory-changed');
519 e.previousDirEntry = this.currentEntry; 524 e.previousDirEntry = this.currentEntry;
520 e.newDirEntry = dirEntry; 525 e.newDirEntry = dirEntry;
521 e.initial = initial; 526 e.initial = initial;
522 this.dispatchEvent(e); 527 this.dispatchEvent(e);
523 }, 528 },
524 529
525 /** 530 /**
526 * Change the state of the model to reflect the specified path (either a 531 * Change the state of the model to reflect the specified path (either a
527 * file or directory). 532 * file or directory).
528 * 533 *
529 * @param {string} path The root path to use 534 * @param {string} path The root path to use
530 * @param {Function=} opt_loadedCallback Invoked when the entire directory 535 * @param {Function=} opt_loadedCallback Invoked when the entire directory
531 * has been loaded and any default file selected. 536 * has been loaded and any default file selected. If there are any
537 * errors loading the directory this will not get called (even if the
538 * directory loads OK on retry later).
532 * @param {Function=} opt_pathResolveCallback Invoked as soon as the path has 539 * @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 540 * been resolved, and called with the base and leaf portions of the path
534 * name, and a flag indicating if the entry exists. 541 * name, and a flag indicating if the entry exists.
535 */ 542 */
536 setupPath: function(path, opt_loadedCallback, opt_pathResolveCallback) { 543 setupPath: function(path, opt_loadedCallback, opt_pathResolveCallback) {
537 // Split the dirname from the basename. 544 // Split the dirname from the basename.
538 var ary = path.match(/^(?:(.*)\/)?([^\/]*)$/); 545 var ary = path.match(/^(?:(.*)\/)?([^\/]*)$/);
539 var autoSelect = function() { 546 var autoSelect = function() {
540 this.selectIndex(this.autoSelectIndex_); 547 this.selectIndex(this.autoSelectIndex_);
541 if (opt_loadedCallback) 548 if (opt_loadedCallback)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 var onBaseError = function(err) { 597 var onBaseError = function(err) {
591 resolveCallback(false); 598 resolveCallback(false);
592 console.log('Unexpected error resolving default base "' + 599 console.log('Unexpected error resolving default base "' +
593 baseName + '": ' + err); 600 baseName + '": ' + err);
594 if (path != '/' + DirectoryModel.DOWNLOADS_DIRECTORY) { 601 if (path != '/' + DirectoryModel.DOWNLOADS_DIRECTORY) {
595 // Can't find the provided path, let's go to default one instead. 602 // Can't find the provided path, let's go to default one instead.
596 this.setupDefaultPath(opt_loadedCallback); 603 this.setupDefaultPath(opt_loadedCallback);
597 } else { 604 } else {
598 // Well, we can't find the downloads dir. Let's just show something, 605 // Well, we can't find the downloads dir. Let's just show something,
599 // or we will get an infinite recursion. 606 // or we will get an infinite recursion.
600 this.changeDirectory('/', opt_loadedCallback, true); 607 this.changeDirectoryEntry_(this.root_, opt_loadedCallback, true);
601 } 608 }
602 }.bind(this); 609 }.bind(this);
603 610
604 var onBaseFound = function(baseDirEntry) { 611 var onBaseFound = function(baseDirEntry) {
605 if (!leafName) { 612 if (!leafName) {
606 // Default path is just a directory, cd to it and we're done. 613 // Default path is just a directory, cd to it and we're done.
607 this.changeDirectoryEntry_(baseDirEntry, autoSelect, true); 614 this.changeDirectoryEntry_(baseDirEntry, autoSelect, true);
608 return; 615 return;
609 } 616 }
610 617
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 934
928 recordMetrics_: function() { 935 recordMetrics_: function() {
929 metrics.recordInterval('DirectoryScan'); 936 metrics.recordInterval('DirectoryScan');
930 if (this.dir_.fullPath == 937 if (this.dir_.fullPath ==
931 '/' + DirectoryModel.DOWNLOADS_DIRECTORY) { 938 '/' + DirectoryModel.DOWNLOADS_DIRECTORY) {
932 metrics.recordMediumCount("DownloadsCount", this.list_.length); 939 metrics.recordMediumCount("DownloadsCount", this.list_.length);
933 } 940 }
934 } 941 }
935 }; 942 };
936 943
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