Changeset 750

Show
Ignore:
Timestamp:
2008-01-18 20:14:29 (1 year ago)
Author:
MaierMan
Message:

initial implementation of the auto-retry backend

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/chrome/content/dta/manager.js

    r749 r750  
    3636 * 
    3737 * ***** END LICENSE BLOCK ***** */ 
     38  
     39const NS_ERROR_MODULE_NETWORK = 0x804B0000; 
     40const NS_ERROR_BINDING_ABORTED = NS_ERROR_MODULE_NETWORK + 2; 
     41const NS_ERROR_UNKNOWN_HOST = NS_ERROR_MODULE_NETWORK + 30; 
     42const NS_ERROR_CONNECTION_REFUSED = NS_ERROR_MODULE_NETWORK + 13; 
     43const NS_ERROR_NET_TIMEOUT = NS_ERROR_MODULE_NETWORK + 14; 
     44const NS_ERROR_NET_RESET = NS_ERROR_MODULE_NETWORK + 20; 
    3845 
    3946const Cc = Components.classes; 
     
    229236                try { 
    230237                        this.refresh(); 
    231                  
     238                         
     239                        if (Prefs.autoRetryInterval) { 
     240                                for (let d in Tree.all) { 
     241                                        d.autoRetry(); 
     242                                } 
     243                        } 
     244                                         
    232245                        this._running.forEach( 
    233246                                function(i) { 
     
    237250                                                if (d.resumable) { 
    238251                                                        d.pause(); 
     252                                                        d.markAutoRetry(); 
    239253                                                        d.status = _("timeout"); 
    240254                                                } 
     
    925939        set conflicts(nv) { 
    926940                if (typeof(nv) != 'number') { 
    927                         return
     941                        return this._conflicts
    928942                } 
    929943                this._conflicts = nv; 
     
    10671081        _status : '', 
    10681082        get status() { 
    1069                 return this._status
     1083                return this._status + (this._autoRetryTime ? ' *' : '')
    10701084        }, 
    10711085        set status(nv) { 
     
    11031117        }, 
    11041118 
    1105         retry: function QI_retry() { 
     1119        safeRetry: function QI_safeRetry() { 
    11061120                // reset flags 
    11071121                this.totalSize = this.partialSize = 0; 
     
    14291443        }, 
    14301444        sessionConnections: 0, 
     1445        _autoRetries: 0, 
     1446        _autoRetryTime: 0, 
     1447        markAutoRetry: function QI_markRetry() { 
     1448                if (!Prefs.autoRetryInterval || Prefs.maxAutoRetries <= this._autoRetries) { 
     1449                         return; 
     1450                } 
     1451                this._autoRetryTime = Utils.getTimestamp(); 
     1452                Debug.logString("marked auto-retry: " + d); 
     1453        }, 
     1454        autoRetry: function QI_autoRetry() { 
     1455                if (!this._autoRetryTime || Utils.getTimestamp() - (Prefs.autoRetryInterval * 1000) < this._autoRetryTime) { 
     1456                        return; 
     1457                } 
     1458 
     1459                this._autoRetryTime = 0; 
     1460                ++this._autoRetries; 
     1461                this.queue(); 
     1462                Debug.logString("Requeued due to auto-retry: " + d);             
     1463        }, 
     1464        queue: function QI_queue() { 
     1465                this.state = QUEUED; 
     1466                this.status = _("inqueue"); 
     1467        }, 
    14311468        resumeDownload: function QI_resumeDownload() { 
    14321469                Debug.logString("resumeDownload: " + this); 
     
    14371474                                if (c1.complete && c2.complete) { 
    14381475                                        c1.merge(c2); 
    1439                                         d.chunks.splice(i + 1, 1); 
     1476                                        d.splice(i + 1, 1); 
    14401477                                } 
    14411478                        } 
     
    18131850                        Debug.logString("cancel"); 
    18141851                        if (!aReason) { 
    1815                                 aReason = 0x804b0002; // NS_BINDING_ABORTED; 
     1852                                aReason = NS_ERROR_BINDING_ABORTED; 
    18161853                        } 
    18171854                        this._chan.cancel(aReason); 
     
    19902027                                        Debug.log("we got temp failure!", code); 
    19912028                                        d.pause(); 
     2029                                        d.markAutoRetry(); 
    19922030                                        d.status = code >= 500 ? _('temperror') : _('autherror'); 
    19932031                                } 
     
    20112049                if (code != 206 && !this.isInfoGetter) { 
    20122050                        Debug.log(d + ": Server returned a " + aChannel.responseStatus + " response instead of 206", this.isInfoGetter); 
    2013                         Debug.log(c, this.url.url); 
    20142051                         
    20152052                        d.resumable = false; 
     
    20242061                                d.cancel(); 
    20252062                                d.resumable = false; 
    2026                                 d.retry(); 
     2063                                d.safeRetry(); 
    20272064                                return false; 
    20282065                        } 
     
    20382075                        d.cancel(); 
    20392076                        d.resumable = false; 
    2040                         d.retry(); 
     2077                        d.safeRetry(); 
    20412078                        return false; 
    20422079                } 
     
    21012138                                Debug.log(d + ": Server error or disconnection", "(type 1)"); 
    21022139                                d.status = _("servererror"); 
     2140                                d.markAutoRetry(); 
    21032141                                d.pause(); 
    21042142                        } 
     
    22472285                } 
    22482286 
     2287                if (aStatusCode == NS_ERROR_BINDING_ABORTED) { 
     2288                        return; 
     2289                } 
     2290                 
     2291                if (-1 != [ 
     2292                        NS_ERROR_CONNECTION_REFUSED, 
     2293                        NS_ERROR_UNKNOWN_HOST, 
     2294                        NS_ERROR_NET_TIMEOUT, 
     2295                        NS_ERROR_NET_RESET 
     2296                ].indexOf(aStatusCode)) { 
     2297                        Debug.log(d + ": Server error or disconnection", "(type 3)"); 
     2298                        d.pause(); 
     2299                        d.status = _("servererror"); 
     2300                        d.markAutoRetry();                               
     2301                        return; 
     2302                }                
     2303 
    22492304                // routine for normal chunk 
    22502305                Debug.logString(d + ": Chunk " + c.start + "-" + c.end + " finished."); 
    2251  
     2306                 
    22522307                // rude way to determine disconnection: if connection is closed before download is started we assume a server error/disconnection 
    22532308                if (c.starter && !shouldFinish && d.is(RUNNING)) { 
    22542309                        if (!d.urlManager.markBad(this.url)) { 
    22552310                                Debug.log(d + ": Server error or disconnection", "(type 2)"); 
     2311                                d.pause(); 
    22562312                                d.status = _("servererror"); 
    2257                                 d.pause(); 
     2313                                d.markAutoRetry();                              
    22582314                                return; 
    22592315                        } 
     
    22612317                                Debug.log("caught bad server", d.toString()); 
    22622318                                d.cancel(); 
    2263                                 d.retry(); 
     2319                                d.safeRetry(); 
    22642320                                return; 
    22652321                        } 
     
    22742330                        if (d.resumable) { 
    22752331                                d.pause(); 
     2332                                d.markAutoRetry(); 
    22762333                                d.status = _('errmismatchtitle'); 
    22772334                        } 
     
    22882345                        d.resumeDownload(); 
    22892346                } 
    2290                 SessionManager.save(d); 
     2347                //SessionManager.save(d); 
    22912348        }, 
    22922349 
  • trunk/chrome/content/dta/manager/prefs.js

    r740 r750  
    5353                ['alertingSystem', 'alertbox', (SYSTEMSLASH == '\\') ? 1 : 0], 
    5454                ['finishEvent', ''], 
    55                 ['showTooltip', true] 
     55                ['showTooltip', true], 
     56                ['maxAutoRetries', 10], 
     57                ['autoRetryInterval', 0] 
    5658        ], 
    5759 
  • trunk/chrome/content/dta/manager/tree.js

    r740 r750  
    378378                        function(d) { 
    379379                                if (d.is(PAUSED, CANCELED)) { 
    380                                         d.state = QUEUED; 
    381                                         d.status = _("inqueue"); 
     380                                        d.queue(); 
    382381                                } 
    383382                                return true; 
  • trunk/chrome/content/dta/manager/verificator.js

    r740 r750  
    103103                        var act = DTA_confirm(_('verifyerrortitle'), _('verifyerrortext'), _('retry'), _('delete'), _('keep')); 
    104104                        switch (act) { 
    105                                 case 0: this._delete(); this.download.retry(); return; 
     105                                case 0: this._delete(); this.download.safeRetry(); return; 
    106106                                case 1: this._delete(); this.download.cancel(); return; 
    107107                        } 
  • trunk/defaults/preferences/dta.js

    r545 r750  
    6464pref("extensions.dta.lastalltabs", false); 
    6565pref("extensions.dta.rememberoneclick", false); 
     66pref("extensions.dta.autoretryinterval", 0); 
     67pref("extensions.dta.maxautoretries", 10); 
    6668 
    6769// Seamonkey specific