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

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: 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 1776 matching lines...) Expand 10 before | Expand all | Expand 10 after
1787 isParentPath(event.mountPath, self.currentDirEntry_.fullPath)) { 1787 isParentPath(event.mountPath, self.currentDirEntry_.fullPath)) {
1788 self.changeDirectory(getParentPath(event.mountPath)); 1788 self.changeDirectory(getParentPath(event.mountPath));
1789 return; 1789 return;
1790 } 1790 }
1791 1791
1792 // TODO(dgozman): rescan directory, only if it contains mounted points, 1792 // TODO(dgozman): rescan directory, only if it contains mounted points,
1793 // when mounts location will be decided. 1793 // when mounts location will be decided.
1794 if (event.status == 'success' || 1794 if (event.status == 'success' ||
1795 event.status == 'error_unknown_filesystem' || 1795 event.status == 'error_unknown_filesystem' ||
1796 event.status == 'error_unsuported_filesystem') 1796 event.status == 'error_unsuported_filesystem')
1797 self.rescanDirectory_(); 1797 self.rescanDirectory_(undefined, 300);
rginda 2011/08/25 00:29:09 In js, "undefined" just happens to be a variable t
sidor 2011/08/25 01:09:58 Done.
1798 }); 1798 });
1799 }; 1799 };
1800 1800
1801 /** 1801 /**
1802 * Event handler called when some internal task should be executed. 1802 * Event handler called when some internal task should be executed.
1803 */ 1803 */
1804 FileManager.prototype.onFileTaskExecute_ = function(id, details) { 1804 FileManager.prototype.onFileTaskExecute_ = function(id, details) {
1805 var urls = details.entries.map(function(entry) { 1805 var urls = details.entries.map(function(entry) {
1806 return entry.toURL(); 1806 return entry.toURL();
1807 }); 1807 });
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after
2515 this.rescanDirectory_(function() { 2515 this.rescanDirectory_(function() {
2516 if (event.selectedEntry) 2516 if (event.selectedEntry)
2517 self.selectEntry(event.selectedEntry); 2517 self.selectEntry(event.selectedEntry);
2518 // For tests that open the dialog to empty directories, everything 2518 // For tests that open the dialog to empty directories, everything
2519 // is loaded at this point. 2519 // is loaded at this point.
2520 chrome.test.sendMessage('directory-change-complete'); 2520 chrome.test.sendMessage('directory-change-complete');
2521 }); 2521 });
2522 }; 2522 };
2523 2523
2524 /** 2524 /**
2525 * Rescan the current directory, refreshing the list. 2525 * Rescans the current directory, refreshing the list. It decreases the
2526 * probability that two such calls are pending simultaneously.
2527 *
2528 * @param {function()} opt_callback Optional function to invoke when the
2529 * rescan is complete.
2530 * @param {string} delayMS Delay during which next rescanDirectory calls
2531 * can happen.
2532 */
2533
2534 FileManager.prototype.rescanDirectory_ = function(opt_callback, delayMS) {
2535 function done(count) {
2536 // Variable count is introduced because we only want to do callbacks, that
2537 // were in the queue at the moment of rescanDirectoryNow invocation.
2538 while (count--) {
2539 var callback = this.rescanDirectory_.callbacks.shift();
rginda 2011/08/25 00:29:09 s/shift/pop/ push/pop work from the end of the ar
sidor 2011/08/25 01:09:58 Hmm.. Nope. I did it on purpose and I really think
2540 callback();
2541 }
2542 }
2543
2544 if (!this.rescanDirectory_)
2545 this.rescanDirectory_ = [];
rginda 2011/08/25 00:29:09 this.rescanDirectory_ is the function we're in. T
sidor 2011/08/25 01:09:58 Done.
2546
2547 if (!this.rescanDirectory_.callbacks)
2548 this.rescanDirectory_.callbacks = [];
2549
2550 if (opt_callback)
2551 this.rescanDirectory_.callbacks.push(opt_callback);
2552
2553 if (!delayMS)
2554 var delayMS = 100;
rginda 2011/08/25 00:29:09 No need for var here. delayMS is already declared
sidor 2011/08/25 01:09:58 That's kind of cool idiom :)
2555
2556 // Assumes rescanDirectoryNow_ takes less than 100 ms. If not there is
2557 // a possible overlap between two calls.
rginda 2011/08/25 00:29:09 I don't think this comment (or the minimum 100ms p
sidor 2011/08/25 01:09:58 No, no this is not what I mean there. Here's what
2558 if (delayMS < 100)
2559 delayMS = 100;
2560
2561 if (this.rescanDirectory_.handle)
2562 clearTimeout(this.rescanDirectory_.handle);
2563 var self = this;
2564 this.rescanDirectory_.handle = setTimeout(function () {
2565 self.rescanDirectoryNow_(done.bind(self,
rginda 2011/08/25 00:29:09 done already has access to self, there is no need
sidor 2011/08/25 01:09:58 OK, but I still need to pass and argument to the f
2566 self.rescanDirectory_.callbacks.length));
2567 }, delayMS);
2568 };
2569
2570 /**
2571 * Rescans the current directory immediately, refreshing the list. Should NOT
2572 * be used in most cases. Instead use rescanDirectory_.
2526 * 2573 *
2527 * @param {function()} opt_callback Optional function to invoke when the 2574 * @param {function()} opt_callback Optional function to invoke when the
2528 * rescan is complete. 2575 * rescan is complete.
2529 */ 2576 */
2530 FileManager.prototype.rescanDirectory_ = function(opt_callback) { 2577 FileManager.prototype.rescanDirectoryNow_ = function(opt_callback) {
2531 var self = this; 2578 var self = this;
2532 var reader; 2579 var reader;
2533 2580
2534 function onReadSome(entries) { 2581 function onReadSome(entries) {
2535 if (entries.length == 0) { 2582 if (entries.length == 0) {
2536 if (opt_callback) 2583 if (opt_callback)
2537 opt_callback(); 2584 opt_callback();
2538 return; 2585 return;
2539 } 2586 }
2540 2587
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
3147 3194
3148 if (msg) { 3195 if (msg) {
3149 console.log('no no no'); 3196 console.log('no no no');
3150 this.alert.show(msg, onAccept); 3197 this.alert.show(msg, onAccept);
3151 return false; 3198 return false;
3152 } 3199 }
3153 3200
3154 return true; 3201 return true;
3155 }; 3202 };
3156 })(); 3203 })();
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