Bug 1203347 - Increase Safe Browsing debug logging around gethash (JS). r=gcp
authorFrancois Marier <francois@mozilla.com>
Mon, 14 Sep 2015 18:04:02 -0700
changeset 296809 07a0d26e2b7d4facf83474b0ee7a66e5b5685861
parent 296808 095bcf27e08100415ccda86a341633a49d46905a
child 296810 f3994cb9aa507a754f90e78d9e5e8e6ae91bd75c
push id962
push userjlund@mozilla.com
push dateFri, 04 Dec 2015 23:28:54 +0000
treeherdermozilla-release@23a2d286e80f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgcp
bugs1203347
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1203347 - Increase Safe Browsing debug logging around gethash (JS). r=gcp
toolkit/components/url-classifier/nsUrlClassifierHashCompleter.js
--- a/toolkit/components/url-classifier/nsUrlClassifierHashCompleter.js
+++ b/toolkit/components/url-classifier/nsUrlClassifierHashCompleter.js
@@ -23,16 +23,33 @@ const PARTIAL_LENGTH = 4;
 
 const BACKOFF_ERRORS = 2;
 const BACKOFF_INTERVAL = 30 * 60 * 1000;
 const BACKOFF_MAX = 8 * 60 * 60 * 1000;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 
+// Log only if browser.safebrowsing.debug is true
+function log(...stuff) {
+  let logging = null;
+  try {
+    logging = Services.prefs.getBoolPref("browser.safebrowsing.debug");
+  } catch(e) {
+    return;
+  }
+  if (!logging) {
+    return;
+  }
+
+  var d = new Date();
+  let msg = "hashcompleter: " + d.toTimeString() + ": " + stuff.join(" ");
+  dump(msg + "\n");
+}
+
 function HashCompleter() {
   // The current HashCompleterRequest in flight. Once it is started, it is set
   // to null. It may be used by multiple calls to |complete| in succession to
   // avoid creating multiple requests to the same gethash URL.
   this._currentRequest = null;
   // A map of gethashUrls to HashCompleterRequests that haven't yet begun.
   this._pendingRequests = {};
 
@@ -270,16 +287,17 @@ HashCompleterRequest.prototype = {
       prefixes[i] = prefixes[j];
       prefixes[j] = temp;
     }
 
     let body;
     body = PARTIAL_LENGTH + ":" + (PARTIAL_LENGTH * prefixes.length) +
            "\n" + prefixes.join("");
 
+    log('Requesting completions for ' + prefixes.length + ' ' + PARTIAL_LENGTH + '-byte prefixes: ' + body);
     return body;
   },
 
   // Sets the request body of this._channel.
   addRequestBody: function HCR_addRequestBody(aBody) {
     let inputStream = Cc["@mozilla.org/io/string-input-stream;1"].
                       createInstance(Ci.nsIStringInputStream);
 
@@ -294,16 +312,17 @@ HashCompleterRequest.prototype = {
 
   // Parses the response body and eventually adds items to the |responses| array
   // for elements of |this._requests|.
   handleResponse: function HCR_handleResponse() {
     if (this._response == "") {
       return;
     }
 
+    log('Response: ' + this._response);
     let start = 0;
 
     let length = this._response.length;
     while (start != length) {
       start = this.handleTable(start);
     }
   },
 
@@ -323,16 +342,17 @@ HashCompleterRequest.prototype = {
     if (entries.length != 3) {
       throw errorWithStack();
     }
 
     let list = entries[0];
     let addChunk = parseInt(entries[1]);
     let dataLength = parseInt(entries[2]);
 
+    log('Response includes add chunks for ' + list + ': ' + addChunk);
     if (dataLength % COMPLETE_LENGTH != 0 ||
         dataLength == 0 ||
         dataLength > body.length - (newlineIndex + 1)) {
       throw errorWithStack();
     }
 
     let data = body.substr(newlineIndex + 1, dataLength);
     for (let i = 0; i < (dataLength / COMPLETE_LENGTH); i++) {
@@ -409,16 +429,17 @@ HashCompleterRequest.prototype = {
     if (Components.isSuccessCode(aStatusCode)) {
       let channel = aRequest.QueryInterface(Ci.nsIHttpChannel);
       let success = channel.requestSucceeded;
       httpStatus = channel.responseStatus;
       if (!success) {
         aStatusCode = Cr.NS_ERROR_ABORT;
       }
     }
+    log('Received a ' + httpStatus + ' status code from the gethash server.');
 
     let success = Components.isSuccessCode(aStatusCode);
     // Notify the RequestBackoff once a response is received.
     this._completer.finishRequest(this.gethashUrl, httpStatus);
 
     if (success) {
       try {
         this.handleResponse();