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

Side by Side Diff: chrome/browser/resources/downloads.html

Issue 6905049: Detect removed files and reflect the state in chrome://downloads and the download shelf (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Correct typo Created 9 years, 7 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
OLDNEW
1 <!DOCTYPE HTML> 1 <!DOCTYPE HTML>
2 <html i18n-values="dir:textdirection;"> 2 <html i18n-values="dir:textdirection;">
3 <head> 3 <head>
4 <meta charset="utf-8"> 4 <meta charset="utf-8">
5 <title i18n-content="title"></title> 5 <title i18n-content="title"></title>
6 <link rel="icon" href="../../app/theme/downloads_favicon.png"> 6 <link rel="icon" href="../../app/theme/downloads_favicon.png">
7 <style> 7 <style>
8 body { 8 body {
9 background-color: white; 9 background-color: white;
10 color: black; 10 color: black;
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 } 464 }
465 465
466 /** 466 /**
467 * The states a download can be in. These correspond to states defined in 467 * The states a download can be in. These correspond to states defined in
468 * DownloadsDOMHandler::CreateDownloadItemValue 468 * DownloadsDOMHandler::CreateDownloadItemValue
469 */ 469 */
470 Download.States = { 470 Download.States = {
471 IN_PROGRESS : "IN_PROGRESS", 471 IN_PROGRESS : "IN_PROGRESS",
472 CANCELLED : "CANCELLED", 472 CANCELLED : "CANCELLED",
473 COMPLETE : "COMPLETE", 473 COMPLETE : "COMPLETE",
474 REMOVED : "REMOVED",
474 PAUSED : "PAUSED", 475 PAUSED : "PAUSED",
475 DANGEROUS : "DANGEROUS", 476 DANGEROUS : "DANGEROUS",
476 INTERRUPTED : "INTERRUPTED", 477 INTERRUPTED : "INTERRUPTED",
477 } 478 }
478 479
479 /** 480 /**
480 * Explains why a download is in DANGEROUS state. 481 * Explains why a download is in DANGEROUS state.
481 */ 482 */
482 Download.DangerType = { 483 Download.DangerType = {
483 NOT_DANGEROUS: "NOT_DANGEROUS", 484 NOT_DANGEROUS: "NOT_DANGEROUS",
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 621
621 /** 622 /**
622 * @return {String} User-visible status update text. 623 * @return {String} User-visible status update text.
623 */ 624 */
624 Download.prototype.getStatusText_ = function() { 625 Download.prototype.getStatusText_ = function() {
625 switch (this.state_) { 626 switch (this.state_) {
626 case Download.States.IN_PROGRESS: 627 case Download.States.IN_PROGRESS:
627 return this.progressStatusText_; 628 return this.progressStatusText_;
628 case Download.States.CANCELLED: 629 case Download.States.CANCELLED:
629 return localStrings.getString('status_cancelled'); 630 return localStrings.getString('status_cancelled');
631 case Download.States.REMOVED:
632 return localStrings.getString('status_removed');
630 case Download.States.PAUSED: 633 case Download.States.PAUSED:
631 return localStrings.getString('status_paused'); 634 return localStrings.getString('status_paused');
632 case Download.States.DANGEROUS: 635 case Download.States.DANGEROUS:
633 var desc = this.dangerType_ == Download.DangerType.DANGEROUS_FILE ? 636 var desc = this.dangerType_ == Download.DangerType.DANGEROUS_FILE ?
634 'danger_file_desc' : 'danger_url_desc'; 637 'danger_file_desc' : 'danger_url_desc';
635 return localStrings.getString(desc); 638 return localStrings.getString(desc);
636 case Download.States.INTERRUPTED: 639 case Download.States.INTERRUPTED:
637 return localStrings.getString('status_interrupted'); 640 return localStrings.getString('status_interrupted');
638 case Download.States.COMPLETE: 641 case Download.States.COMPLETE:
639 return ''; 642 return '';
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 */ 707 */
705 Download.prototype.cancel_ = function() { 708 Download.prototype.cancel_ = function() {
706 chrome.send('cancel', [this.id_.toString()]); 709 chrome.send('cancel', [this.id_.toString()]);
707 return false; 710 return false;
708 } 711 }
709 712
710 /////////////////////////////////////////////////////////////////////////////// 713 ///////////////////////////////////////////////////////////////////////////////
711 // Page: 714 // Page:
712 var downloads, localStrings, resultsTimeout; 715 var downloads, localStrings, resultsTimeout;
713 716
717 /**
718 * The FIFO array that stores updates of download files to be appeared
719 * on the download page. It is guaranteed that the updates in this array
720 * are reflected to the download page in a FIFO order.
721 */
722 var fifo_results;
723
714 function load() { 724 function load() {
725 fifo_results = new Array();
715 localStrings = new LocalStrings(); 726 localStrings = new LocalStrings();
716 downloads = new Downloads(); 727 downloads = new Downloads();
717 $('term').focus(); 728 $('term').focus();
718 setSearch(''); 729 setSearch('');
719 } 730 }
720 731
721 function setSearch(searchText) { 732 function setSearch(searchText) {
733 fifo_results.length = 0;
722 downloads.clear(); 734 downloads.clear();
723 downloads.setSearchText(searchText); 735 downloads.setSearchText(searchText);
724 chrome.send('getDownloads', [searchText.toString()]); 736 chrome.send('getDownloads', [searchText.toString()]);
725 } 737 }
726 738
727 function clearAll() { 739 function clearAll() {
740 fifo_results.length = 0;
728 downloads.clear(); 741 downloads.clear();
729 downloads.setSearchText(''); 742 downloads.setSearchText('');
730 chrome.send('clearAll', []); 743 chrome.send('clearAll', []);
731 return false; 744 return false;
732 } 745 }
733 746
734 /////////////////////////////////////////////////////////////////////////////// 747 ///////////////////////////////////////////////////////////////////////////////
735 // Chrome callbacks: 748 // Chrome callbacks:
736 /** 749 /**
737 * Our history system calls this function with results from searches or when 750 * Our history system calls this function with results from searches or when
738 * downloads are added or removed. 751 * downloads are added or removed.
739 */ 752 */
740 function downloadsList(results) { 753 function downloadsList(results) {
741 if (resultsTimeout) 754 if (resultsTimeout)
742 clearTimeout(resultsTimeout); 755 clearTimeout(resultsTimeout);
743 window.console.log('results'); 756 window.console.log('results');
757 fifo_results.length = 0;
744 downloads.clear(); 758 downloads.clear();
745 downloadUpdated(results); 759 downloadUpdated(results);
746 downloads.updateSummary(); 760 downloads.updateSummary();
747 } 761 }
748 762
749 /** 763 /**
750 * When a download is updated (progress, state change), this is called. 764 * When a download is updated (progress, state change), this is called.
751 */ 765 */
752 function downloadUpdated(results) { 766 function downloadUpdated(results) {
753 // Sometimes this can get called too early. 767 // Sometimes this can get called too early.
754 if (!downloads) 768 if (!downloads)
755 return; 769 return;
756 770
771 fifo_results = fifo_results.concat(results);
772 tryDownloadUpdatedPeriodically();
773 }
774
775 /**
776 * Try to reflect as much updates as possible within 50ms.
777 * This function is scheduled again and again until all updates are reflected.
778 */
779 function tryDownloadUpdatedPeriodically() {
780 // Sometimes this can get called too early.
781 if (!downloads)
782 return;
Randy Smith (Not in Mondays) 2011/05/16 20:57:12 Do we still need this comment and the null check f
haraken1 2011/06/07 12:49:18 Done.
783
757 var start = Date.now(); 784 var start = Date.now();
758 for (var i = 0; i < results.length; i++) { 785 while (fifo_results.length) {
759 downloads.updated(results[i]); 786 var result = fifo_results.shift();
787 downloads.updated(result);
760 // Do as much as we can in 50ms. 788 // Do as much as we can in 50ms.
761 if (Date.now() - start > 50) { 789 if (Date.now() - start > 50) {
762 clearTimeout(resultsTimeout); 790 clearTimeout(resultsTimeout);
763 resultsTimeout = setTimeout(downloadUpdated, 5, results.slice(i + 1)); 791 resultsTimeout = setTimeout(tryDownloadUpdatedPeriodically, 5);
764 break; 792 break;
765 } 793 }
766 } 794 }
767 } 795 }
768 796
769 </script> 797 </script>
770 </head> 798 </head>
771 <body onload="load();" i18n-values=".style.fontFamily:fontfamily;.style.fontSize :fontsize"> 799 <body onload="load();" i18n-values=".style.fontFamily:fontfamily;.style.fontSize :fontsize">
772 <div class="header"> 800 <div class="header">
773 <a href="" onclick="setSearch(''); return false;"> 801 <a href="" onclick="setSearch(''); return false;">
(...skipping 10 matching lines...) Expand all
784 <div id="downloads-summary"> 812 <div id="downloads-summary">
785 <span id="downloads-summary-text" i18n-content="downloads">Downloads</span> 813 <span id="downloads-summary-text" i18n-content="downloads">Downloads</span>
786 <a id="clear-all" href="" onclick="clearAll();" i18n-content="clear_all">Cle ar All</a> 814 <a id="clear-all" href="" onclick="clearAll();" i18n-content="clear_all">Cle ar All</a>
787 </div> 815 </div>
788 <div id="downloads-display"></div> 816 <div id="downloads-display"></div>
789 </div> 817 </div>
790 <div class="footer"> 818 <div class="footer">
791 </div> 819 </div>
792 </body> 820 </body>
793 </html> 821 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698