Bug 423790: Back off of safebrowsing updates for 4xx errors. r=tony, blocking-firefox3=beltzner
authordcamp@mozilla.com
Wed, 19 Mar 2008 18:55:56 -0700
changeset 13352 631f90312ecd4e827e06d892e0dec265ba994400
parent 13351 b4a0dc4db376ca22f74c173c3ab5a8924a640540
child 13353 5a35cd55fbd579478edd4a04abfc87cb60a727af
push idunknown
push userunknown
push dateunknown
reviewerstony
bugs423790
milestone1.9b5pre
Bug 423790: Back off of safebrowsing updates for 4xx errors. r=tony, blocking-firefox3=beltzner
toolkit/components/url-classifier/content/listmanager.js
toolkit/components/url-classifier/content/request-backoff.js
--- a/toolkit/components/url-classifier/content/listmanager.js
+++ b/toolkit/components/url-classifier/content/listmanager.js
@@ -462,16 +462,19 @@ PROT_ListManager.prototype.updateSuccess
   G_Debug(this, "update success: " + waitForUpdate);
   if (waitForUpdate) {
     var delay = parseInt(waitForUpdate, 10);
     // As long as the delay is something sane (5 minutes or more), update
     // our delay time for requesting updates
     if (delay >= (5 * 60) && this.updateChecker_)
       this.updateChecker_.setDelay(delay * 1000);
   }
+
+  // Let the backoff object know that we completed successfully.
+  this.requestBackoff_.noteServerResponse(200);
 }
 
 /**
  * Callback function if the update request succeeded.
  * @param result String The error code of the failure
  */
 PROT_ListManager.prototype.updateError_ = function(result) {
   G_Debug(this, "update error: " + result);
@@ -487,19 +490,21 @@ PROT_ListManager.prototype.downloadError
   // If status is empty, then we assume that we got an NS_CONNECTION_REFUSED
   // error.  In this case, we treat this is a http 500 error.
   if (!status) {
     status = 500;
   }
   status = parseInt(status, 10);
   this.requestBackoff_.noteServerResponse(status);
 
-  // Try again in a minute
-  this.currentUpdateChecker_ =
-    new G_Alarm(BindToObject(this.checkForUpdates, this), 60000);
+  if (this.requestBackoff_.isErrorStatus(status)) {
+    // Try again in a minute
+    this.currentUpdateChecker_ =
+      new G_Alarm(BindToObject(this.checkForUpdates, this), 60000);
+  }
 }
 
 /**
  * Called when either the update process or a gethash request signals
  * that the server requested a rekey.
  */
 PROT_ListManager.prototype.rekey_ = function() {
   G_Debug(this, "rekey requested");
--- a/toolkit/components/url-classifier/content/request-backoff.js
+++ b/toolkit/components/url-classifier/content/request-backoff.js
@@ -85,17 +85,17 @@ RequestBackoff.prototype.reset = functio
 RequestBackoff.prototype.canMakeRequest = function() {
   return Date.now() > this.nextRequestTime_;
 }
 
 /**
  * Notify this object of the last server response.  If it's an error,
  */
 RequestBackoff.prototype.noteServerResponse = function(status) {
-  if (this.isErrorStatus_(status)) {
+  if (this.isErrorStatus(status)) {
     var now = Date.now();
     this.errorTimes_.push(now);
 
     // We only care about keeping track of MAX_ERRORS
     if (this.errorTimes_.length > this.MAX_ERRORS_)
       this.errorTimes_.shift();
 
     // See if we hit the backoff case
@@ -115,22 +115,22 @@ RequestBackoff.prototype.noteServerRespo
     // of backoff state.
     this.errorTimeout_ = 0;
     this.nextRequestTime_ = 0;
     this.backoffTriggered_ = false;
   }
 }
 
 /**
- * We consider 302, 303, 307, and 5xx http responses to be errors.
+ * We consider 302, 303, 307, 4xx, and 5xx http responses to be errors.
  * @param status Number http status
  * @return Boolean true if we consider this http status an error
  */
-RequestBackoff.prototype.isErrorStatus_ = function(status) {
-  return ((500 <= status && status <= 599) ||
+RequestBackoff.prototype.isErrorStatus = function(status) {
+  return ((400 <= status && status <= 599) ||
           HTTP_FOUND == status ||
           HTTP_SEE_OTHER == status ||
           HTTP_TEMPORARY_REDIRECT == status);
 }
 
 #ifdef 0
 // Some unittests (e.g., paste into JS shell)
 var jslib = Cc["@mozilla.org/url-classifier/jslib;1"].