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

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

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: Reflect the "Removed" status to the download shelf Created 9 years, 6 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 // 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 /////////////////////////////////////////////////////////////////////////////// 5 ///////////////////////////////////////////////////////////////////////////////
6 // Helper functions 6 // Helper functions
7 function $(o) {return document.getElementById(o);} 7 function $(o) {return document.getElementById(o);}
8 8
9 /** 9 /**
10 * Sets the display style of a node. 10 * Sets the display style of a node.
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 } 285 }
286 286
287 /** 287 /**
288 * The states a download can be in. These correspond to states defined in 288 * The states a download can be in. These correspond to states defined in
289 * DownloadsDOMHandler::CreateDownloadItemValue 289 * DownloadsDOMHandler::CreateDownloadItemValue
290 */ 290 */
291 Download.States = { 291 Download.States = {
292 IN_PROGRESS : "IN_PROGRESS", 292 IN_PROGRESS : "IN_PROGRESS",
293 CANCELLED : "CANCELLED", 293 CANCELLED : "CANCELLED",
294 COMPLETE : "COMPLETE", 294 COMPLETE : "COMPLETE",
295 REMOVED : "REMOVED",
hendrickson_a 2011/06/07 15:38:52 I don't like this mismatch between the states in D
Randy Smith (Not in Mondays) 2011/06/07 18:51:10 I'm sorry if this was covered earlier and the stat
haraken1 2011/06/08 05:11:49 I got it. I removed REMOVED state from Download.St
295 PAUSED : "PAUSED", 296 PAUSED : "PAUSED",
296 DANGEROUS : "DANGEROUS", 297 DANGEROUS : "DANGEROUS",
297 INTERRUPTED : "INTERRUPTED", 298 INTERRUPTED : "INTERRUPTED",
298 } 299 }
299 300
300 /** 301 /**
301 * Explains why a download is in DANGEROUS state. 302 * Explains why a download is in DANGEROUS state.
302 */ 303 */
303 Download.DangerType = { 304 Download.DangerType = {
304 NOT_DANGEROUS: "NOT_DANGEROUS", 305 NOT_DANGEROUS: "NOT_DANGEROUS",
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 442
442 /** 443 /**
443 * @return {String} User-visible status update text. 444 * @return {String} User-visible status update text.
444 */ 445 */
445 Download.prototype.getStatusText_ = function() { 446 Download.prototype.getStatusText_ = function() {
446 switch (this.state_) { 447 switch (this.state_) {
447 case Download.States.IN_PROGRESS: 448 case Download.States.IN_PROGRESS:
448 return this.progressStatusText_; 449 return this.progressStatusText_;
449 case Download.States.CANCELLED: 450 case Download.States.CANCELLED:
450 return localStrings.getString('status_cancelled'); 451 return localStrings.getString('status_cancelled');
452 case Download.States.REMOVED:
453 return localStrings.getString('status_removed');
451 case Download.States.PAUSED: 454 case Download.States.PAUSED:
452 return localStrings.getString('status_paused'); 455 return localStrings.getString('status_paused');
453 case Download.States.DANGEROUS: 456 case Download.States.DANGEROUS:
454 var desc = this.dangerType_ == Download.DangerType.DANGEROUS_FILE ? 457 var desc = this.dangerType_ == Download.DangerType.DANGEROUS_FILE ?
455 'danger_file_desc' : 'danger_url_desc'; 458 'danger_file_desc' : 'danger_url_desc';
456 return localStrings.getString(desc); 459 return localStrings.getString(desc);
457 case Download.States.INTERRUPTED: 460 case Download.States.INTERRUPTED:
458 return localStrings.getString('status_interrupted'); 461 return localStrings.getString('status_interrupted');
459 case Download.States.COMPLETE: 462 case Download.States.COMPLETE:
460 return ''; 463 return '';
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 */ 528 */
526 Download.prototype.cancel_ = function() { 529 Download.prototype.cancel_ = function() {
527 chrome.send('cancel', [this.id_.toString()]); 530 chrome.send('cancel', [this.id_.toString()]);
528 return false; 531 return false;
529 } 532 }
530 533
531 /////////////////////////////////////////////////////////////////////////////// 534 ///////////////////////////////////////////////////////////////////////////////
532 // Page: 535 // Page:
533 var downloads, localStrings, resultsTimeout; 536 var downloads, localStrings, resultsTimeout;
534 537
538 /**
539 * The FIFO array that stores updates of download files to be appeared
540 * on the download page. It is guaranteed that the updates in this array
541 * are reflected to the download page in a FIFO order.
542 */
543 var fifo_results;
544
535 function load() { 545 function load() {
546 fifo_results = new Array();
536 localStrings = new LocalStrings(); 547 localStrings = new LocalStrings();
537 downloads = new Downloads(); 548 downloads = new Downloads();
538 $('term').focus(); 549 $('term').focus();
539 setSearch(''); 550 setSearch('');
540 } 551 }
541 552
542 function setSearch(searchText) { 553 function setSearch(searchText) {
554 fifo_results.length = 0;
543 downloads.clear(); 555 downloads.clear();
544 downloads.setSearchText(searchText); 556 downloads.setSearchText(searchText);
545 chrome.send('getDownloads', [searchText.toString()]); 557 chrome.send('getDownloads', [searchText.toString()]);
546 } 558 }
547 559
548 function clearAll() { 560 function clearAll() {
561 fifo_results.length = 0;
549 downloads.clear(); 562 downloads.clear();
550 downloads.setSearchText(''); 563 downloads.setSearchText('');
551 chrome.send('clearAll', []); 564 chrome.send('clearAll', []);
552 return false; 565 return false;
553 } 566 }
554 567
555 /////////////////////////////////////////////////////////////////////////////// 568 ///////////////////////////////////////////////////////////////////////////////
556 // Chrome callbacks: 569 // Chrome callbacks:
557 /** 570 /**
558 * Our history system calls this function with results from searches or when 571 * Our history system calls this function with results from searches or when
559 * downloads are added or removed. 572 * downloads are added or removed.
560 */ 573 */
561 function downloadsList(results) { 574 function downloadsList(results) {
562 if (resultsTimeout) 575 if (resultsTimeout)
563 clearTimeout(resultsTimeout); 576 clearTimeout(resultsTimeout);
564 window.console.log('results'); 577 window.console.log('results');
578 fifo_results.length = 0;
565 downloads.clear(); 579 downloads.clear();
566 downloadUpdated(results); 580 downloadUpdated(results);
567 downloads.updateSummary(); 581 downloads.updateSummary();
568 } 582 }
569 583
570 /** 584 /**
571 * When a download is updated (progress, state change), this is called. 585 * When a download is updated (progress, state change), this is called.
572 */ 586 */
573 function downloadUpdated(results) { 587 function downloadUpdated(results) {
574 // Sometimes this can get called too early. 588 // Sometimes this can get called too early.
575 if (!downloads) 589 if (!downloads)
576 return; 590 return;
577 591
592 fifo_results = fifo_results.concat(results);
593 tryDownloadUpdatedPeriodically();
594 }
595
596 /**
597 * Try to reflect as much updates as possible within 50ms.
598 * This function is scheduled again and again until all updates are reflected.
599 */
600 function tryDownloadUpdatedPeriodically() {
578 var start = Date.now(); 601 var start = Date.now();
579 for (var i = 0; i < results.length; i++) { 602 while (fifo_results.length) {
580 downloads.updated(results[i]); 603 var result = fifo_results.shift();
604 downloads.updated(result);
581 // Do as much as we can in 50ms. 605 // Do as much as we can in 50ms.
582 if (Date.now() - start > 50) { 606 if (Date.now() - start > 50) {
583 clearTimeout(resultsTimeout); 607 clearTimeout(resultsTimeout);
584 resultsTimeout = setTimeout(downloadUpdated, 5, results.slice(i + 1)); 608 resultsTimeout = setTimeout(tryDownloadUpdatedPeriodically, 5);
585 break; 609 break;
586 } 610 }
587 } 611 }
588 } 612 }
589 613
590 // Add handlers to HTML elements. 614 // Add handlers to HTML elements.
591 document.body.onload = load; 615 document.body.onload = load;
592 $('clear-all').onclick = function () { clearAll(''); }; 616 $('clear-all').onclick = function () { clearAll(''); };
593 $('search-link').onclick = function () { 617 $('search-link').onclick = function () {
594 setSearch(''); 618 setSearch('');
595 return false; 619 return false;
596 }; 620 };
597 $('search-form').onsubmit = function () { 621 $('search-form').onsubmit = function () {
598 setSearch(this.term.value); 622 setSearch(this.term.value);
599 return false; 623 return false;
600 }; 624 };
601 625
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698