B2G/gecko/browser/components/downloads/src/DownloadsCommon.jsm
/**
   * Computes aggregate values based on the current state of downloads.
   */
Computes aggregate values based on the current state of downloads.
Computes aggregate values based on the current state of downloads .
function DID_refreshProperties()
  {
    let numActive = 0;
    let numPaused = 0;
    let numScanning = 0;
    let totalSize = 0;
    let totalTransferred = 0;
    let rawTimeLeft = -1;
    if (this._itemCount > 0) {
      let downloads = Services.downloads.activeDownloads;
      while (downloads.hasMoreElements()) {
        let download = downloads.getNext().QueryInterface(Ci.nsIDownload);
        numActive++;
        switch (download.state) {
          case nsIDM.DOWNLOAD_PAUSED:
            numPaused++;
            break;
          case nsIDM.DOWNLOAD_SCANNING:
            numScanning++;
            break;
          case nsIDM.DOWNLOAD_DOWNLOADING:
            if (download.size > 0 && download.speed > 0) {
              let sizeLeft = download.size - download.amountTransferred;
              rawTimeLeft = Math.max(rawTimeLeft, sizeLeft / download.speed);
            }
            break;
        }
        if (download.size > 0) {
          totalSize += download.size;
          totalTransferred += download.amountTransferred;
        }
      }
    }
    this._hasDownloads = (this._itemCount > 0);
    if (numActive == 0 || totalSize == 0 || numActive == numScanning) {
      this._percentComplete = -1;
    } else {
      this._percentComplete = (totalTransferred / totalSize) * 100;
    }
    this._paused = numActive > 0 && numActive == numPaused;
    if (rawTimeLeft == -1) {
      this._lastRawTimeLeft = -1;
      this._lastTimeLeft = -1;
      this._counter = "";
    } else {
      if (this._lastRawTimeLeft != rawTimeLeft) {
        this._lastRawTimeLeft = rawTimeLeft;
        this._updateTimeLeft(rawTimeLeft);
      }
      this._counter = DownloadsCommon.formatTimeLeft(this._lastTimeLeft);
    }
  }
function DID_refreshProperties ( ) { let numActive = 0 ; let numPaused = 0 ; let numScanning = 0 ; let totalSize = 0 ; let totalTransferred = 0 ; let rawTimeLeft = - 1 ; if ( this . _itemCount > 0 ) { let downloads = Services . downloads . activeDownloads ; while ( downloads . hasMoreElements ( ) ) { let download = downloads . getNext ( ) . QueryInterface ( Ci . nsIDownload ) ; numActive ++ ; switch ( download . state ) { case nsIDM . DOWNLOAD_PAUSED : numPaused ++ ; break ; case nsIDM . DOWNLOAD_SCANNING : numScanning ++ ; break ; case nsIDM . DOWNLOAD_DOWNLOADING : if ( download . size > 0 && download . speed > 0 ) { let sizeLeft = download . size - download . amountTransferred ; rawTimeLeft = Math . max ( rawTimeLeft , sizeLeft / download . speed ) ; } break ; } if ( download . size > 0 ) { totalSize += download . size ; totalTransferred += download . amountTransferred ; } } } this . _hasDownloads = ( this . _itemCount > 0 ) ; if ( numActive == 0 || totalSize == 0 || numActive == numScanning ) { this . _percentComplete = - 1 ; } else { this . _percentComplete = ( totalTransferred / totalSize ) * 100 ; } this . _paused = numActive > 0 && numActive == numPaused ; if ( rawTimeLeft == - 1 ) { this . _lastRawTimeLeft = - 1 ; this . _lastTimeLeft = - 1 ; this . _counter = "" ; } else { if ( this . _lastRawTimeLeft != rawTimeLeft ) { this . _lastRawTimeLeft = rawTimeLeft ; this . _updateTimeLeft ( rawTimeLeft ) ; } this . _counter = DownloadsCommon . formatTimeLeft ( this . _lastTimeLeft ) ; } }
Computes aggregate values based on the current state of downloads.
Computes aggregate values based on the current state of downloads .
// If no download has been loaded, don't use the methods of the Download // Manager service, so that it is not initialized unnecessarily. // Only add to total values if we actually know the download size. // Determine if the indicator should be shown or get attention. // Don't display the current progress. // Display the current progress. // If all downloads are paused, show the progress indicator as paused. // Display the estimated time left, if present. // There are no downloads with a known time left. // Compute the new time left only if state actually changed.