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

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

Issue 7715023: Debouncing of function rescanning directory in File Manager (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: iteration 4 Created 9 years, 4 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 | no next file » | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 var g_slideshow_data = null; 10 var g_slideshow_data = null;
(...skipping 1777 matching lines...) Expand 10 before | Expand all | Expand 10 after
1788 isParentPath(event.mountPath, self.currentDirEntry_.fullPath)) { 1788 isParentPath(event.mountPath, self.currentDirEntry_.fullPath)) {
1789 self.changeDirectory(getParentPath(event.mountPath)); 1789 self.changeDirectory(getParentPath(event.mountPath));
1790 return; 1790 return;
1791 } 1791 }
1792 1792
1793 // TODO(dgozman): rescan directory, only if it contains mounted points, 1793 // TODO(dgozman): rescan directory, only if it contains mounted points,
1794 // when mounts location will be decided. 1794 // when mounts location will be decided.
1795 if (event.status == 'success' || 1795 if (event.status == 'success' ||
1796 event.status == 'error_unknown_filesystem' || 1796 event.status == 'error_unknown_filesystem' ||
1797 event.status == 'error_unsuported_filesystem') 1797 event.status == 'error_unsuported_filesystem')
1798 self.rescanDirectory_(); 1798 self.rescanDirectory_(null, 300);
1799 }); 1799 });
1800 }; 1800 };
1801 1801
1802 /** 1802 /**
1803 * Event handler called when some internal task should be executed. 1803 * Event handler called when some internal task should be executed.
1804 */ 1804 */
1805 FileManager.prototype.onFileTaskExecute_ = function(id, details) { 1805 FileManager.prototype.onFileTaskExecute_ = function(id, details) {
1806 var urls = details.entries.map(function(entry) { 1806 var urls = details.entries.map(function(entry) {
1807 return entry.toURL(); 1807 return entry.toURL();
1808 }); 1808 });
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after
2516 this.rescanDirectory_(function() { 2516 this.rescanDirectory_(function() {
2517 if (event.selectedEntry) 2517 if (event.selectedEntry)
2518 self.selectEntry(event.selectedEntry); 2518 self.selectEntry(event.selectedEntry);
2519 // For tests that open the dialog to empty directories, everything 2519 // For tests that open the dialog to empty directories, everything
2520 // is loaded at this point. 2520 // is loaded at this point.
2521 chrome.test.sendMessage('directory-change-complete'); 2521 chrome.test.sendMessage('directory-change-complete');
2522 }); 2522 });
2523 }; 2523 };
2524 2524
2525 /** 2525 /**
2526 * Rescan the current directory, refreshing the list. 2526 * Rescans the current directory, refreshing the list. It decreases the
2527 * probability that two such calls are pending simultaneously.
2528 *
2529 * @param {function()} opt_callback Optional function to invoke when the
2530 * rescan is complete.
2531 * @param {string} delayMS Delay during which next rescanDirectory calls
2532 * can happen.
2533 */
2534
2535 FileManager.prototype.rescanDirectory_ = function(opt_callback, delayMS) {
2536 var self = this;
2537 function done(count) {
2538 // Variable count is introduced because we only want to do callbacks, that
2539 // were in the queue at the moment of rescanDirectoryNow invocation.
2540 while (count--) {
2541 var callback = self.rescanDirectory_.callbacks.shift();
2542 callback();
2543 }
2544 }
2545
2546 // callbacks is a queue of callbacks that need to be called after rescaning
2547 // directory is done. We push callback to the end and pop form the front.
2548 // When we get to actually call rescanDirectoryNow_ we need to remember how
2549 // many callbacks were in a queue at the time, not to call callbacks that
2550 // arrived in the middle of execution (they may depend on rescaning being
2551 // done after they called rescanDirectory_).
2552 if (!this.rescanDirectory_.callbacks)
2553 this.rescanDirectory_.callbacks = [];
2554
2555 if (opt_callback)
2556 this.rescanDirectory_.callbacks.push(opt_callback);
2557
2558 delayMS = delayMS || 100;
2559
2560 // Assumes rescanDirectoryNow_ takes less than 100 ms. If not there is
2561 // a possible overlap between two calls.
2562 if (delayMS < 100)
2563 delayMS = 100;
2564
2565 if (this.rescanDirectory_.handle)
2566 clearTimeout(this.rescanDirectory_.handle);
2567 var currentQueueLength = self.rescanDirectory_.callbacks.length;
2568 this.rescanDirectory_.handle = setTimeout(function () {
2569 self.rescanDirectoryNow_(function() {
2570 done(currentQueueLength);
2571 });
2572 }, delayMS);
2573 };
2574
2575 /**
2576 * Rescans the current directory immediately, refreshing the list. Should NOT
2577 * be used in most cases. Instead use rescanDirectory_.
2527 * 2578 *
2528 * @param {function()} opt_callback Optional function to invoke when the 2579 * @param {function()} opt_callback Optional function to invoke when the
2529 * rescan is complete. 2580 * rescan is complete.
2530 */ 2581 */
2531 FileManager.prototype.rescanDirectory_ = function(opt_callback) { 2582 FileManager.prototype.rescanDirectoryNow_ = function(opt_callback) {
2532 var self = this; 2583 var self = this;
2533 var reader; 2584 var reader;
2534 2585
2535 function onReadSome(entries) { 2586 function onReadSome(entries) {
2536 if (entries.length == 0) { 2587 if (entries.length == 0) {
2537 if (opt_callback) 2588 if (opt_callback)
2538 opt_callback(); 2589 opt_callback();
2539 return; 2590 return;
2540 } 2591 }
2541 2592
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
3148 3199
3149 if (msg) { 3200 if (msg) {
3150 console.log('no no no'); 3201 console.log('no no no');
3151 this.alert.show(msg, onAccept); 3202 this.alert.show(msg, onAccept);
3152 return false; 3203 return false;
3153 } 3204 }
3154 3205
3155 return true; 3206 return true;
3156 }; 3207 };
3157 })(); 3208 })();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698