Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 this.rescanDirectory_.handle = setTimeout(function () { | |
| 2568 self.rescanDirectoryNow_(done.bind(null, | |
|
rginda
2011/08/25 19:14:56
This is usually done with another nested function,
sidor
2011/08/25 23:54:17
Done.
| |
| 2569 self.rescanDirectory_.callbacks.length)); | |
| 2570 }, delayMS); | |
| 2571 }; | |
| 2572 | |
| 2573 /** | |
| 2574 * Rescans the current directory immediately, refreshing the list. Should NOT | |
| 2575 * be used in most cases. Instead use rescanDirectory_. | |
| 2527 * | 2576 * |
| 2528 * @param {function()} opt_callback Optional function to invoke when the | 2577 * @param {function()} opt_callback Optional function to invoke when the |
| 2529 * rescan is complete. | 2578 * rescan is complete. |
| 2530 */ | 2579 */ |
| 2531 FileManager.prototype.rescanDirectory_ = function(opt_callback) { | 2580 FileManager.prototype.rescanDirectoryNow_ = function(opt_callback) { |
| 2532 var self = this; | 2581 var self = this; |
| 2533 var reader; | 2582 var reader; |
| 2534 | 2583 |
| 2535 function onReadSome(entries) { | 2584 function onReadSome(entries) { |
| 2536 if (entries.length == 0) { | 2585 if (entries.length == 0) { |
| 2537 if (opt_callback) | 2586 if (opt_callback) |
| 2538 opt_callback(); | 2587 opt_callback(); |
| 2539 return; | 2588 return; |
| 2540 } | 2589 } |
| 2541 | 2590 |
| (...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3148 | 3197 |
| 3149 if (msg) { | 3198 if (msg) { |
| 3150 console.log('no no no'); | 3199 console.log('no no no'); |
| 3151 this.alert.show(msg, onAccept); | 3200 this.alert.show(msg, onAccept); |
| 3152 return false; | 3201 return false; |
| 3153 } | 3202 } |
| 3154 | 3203 |
| 3155 return true; | 3204 return true; |
| 3156 }; | 3205 }; |
| 3157 })(); | 3206 })(); |
| OLD | NEW |