Bug 1073047 - Add Firefox Account logging to MozLoopService. r=jaws
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Thu, 25 Sep 2014 09:00:51 -0700
changeset 218100 4471ec778e7c6899e5c97290e1971f4ca5db7cc1
parent 218099 cb0ec049ccd1e1c5c8763e89667ebaca61168f29
child 218101 3e7ef7666582db9eff82182207c56bbb9e6272e3
push idunknown
push userunknown
push dateunknown
reviewersjaws
bugs1073047
milestone34.0a2
Bug 1073047 - Add Firefox Account logging to MozLoopService. r=jaws
browser/components/loop/MozLoopService.jsm
--- a/browser/components/loop/MozLoopService.jsm
+++ b/browser/components/loop/MozLoopService.jsm
@@ -320,16 +320,17 @@ let MozLoopServiceInternal = {
    * @param {Boolean} aFlag
    */
   set doNotDisturb(aFlag) {
     Services.prefs.setBoolPref("loop.do_not_disturb", Boolean(aFlag));
     this.notifyStatusChanged();
   },
 
   notifyStatusChanged: function(aReason = null) {
+    log.debug("notifyStatusChanged with reason:", aReason);
     Services.obs.notifyObservers(null, "loop-status-changed", aReason);
   },
 
   /**
    * @param {String} errorType a key to identify the type of error. Only one
    *                           error of a type will be saved at a time.
    * @param {Object} error     an object describing the error in the format from Hawk errors
    */
@@ -451,16 +452,17 @@ let MozLoopServiceInternal = {
    * @return true on success or no token, false on failure.
    */
   storeSessionToken: function(sessionType, headers) {
     let sessionToken = headers["hawk-session-token"];
     if (sessionToken) {
       // XXX should do more validation here
       if (sessionToken.length === 64) {
         Services.prefs.setCharPref(this.getSessionTokenPrefName(sessionType), sessionToken);
+        log.debug("Stored a hawk session token for sessionType", sessionType);
       } else {
         // XXX Bubble the precise details up to the UI somehow (bug 1013248).
         log.warn("Loop server sent an invalid session token");
         gRegisteredDeferred.reject("session-token-wrong-size");
         gRegisteredDeferred = null;
         return false;
       }
     }
@@ -474,16 +476,17 @@ let MozLoopServiceInternal = {
    * This should normally be used after unregistering with the server so it can
    * clean up session state first.
    *
    * @param {LOOP_SESSION_TYPE} sessionType The type of session to use for the request.
    *                                        One of the LOOP_SESSION_TYPE members.
    */
   clearSessionToken: function(sessionType) {
     Services.prefs.clearUserPref(this.getSessionTokenPrefName(sessionType));
+    log.debug("Cleared hawk session token for sessionType", sessionType);
   },
 
   /**
    * Callback from MozLoopPushHandler - The push server has been registered
    * and has given us a push url.
    *
    * @param {String} pushUrl The push url given by the push server.
    */
@@ -521,16 +524,17 @@ let MozLoopServiceInternal = {
     return this.hawkRequest(sessionType, "/registration", "POST", { simplePushURL: pushUrl})
       .then((response) => {
         // If this failed we got an invalid token. storeSessionToken rejects
         // the gRegisteredDeferred promise for us, so here we just need to
         // early return.
         if (!this.storeSessionToken(sessionType, response.headers))
           return;
 
+        log.debug("Successfully registered with server for sessionType", sessionType);
         this.clearError("registration");
       }, (error) => {
         // There's other errors than invalid auth token, but we should only do the reset
         // as a last resort.
         if (error.code === 401 && error.errno === INVALID_AUTH_TOKEN) {
           if (this.urlExpiryTimeIsInFuture()) {
             // XXX Should this be reported to the user is a visible manner?
             Cu.reportError("Loop session token is invalid, all previously "
@@ -562,16 +566,17 @@ let MozLoopServiceInternal = {
    * @param {String} pushURL The push URL previously given by the push server.
    *                         This may not be necessary to unregister in the future.
    * @return {Promise} resolving when the unregistration request finishes
    */
   unregisterFromLoopServer: function(sessionType, pushURL) {
     let unregisterURL = "/registration?simplePushURL=" + encodeURIComponent(pushURL);
     return this.hawkRequest(sessionType, unregisterURL, "DELETE")
       .then(() => {
+        log.debug("Successfully unregistered from server for sessionType", sessionType);
         MozLoopServiceInternal.clearSessionToken(sessionType);
       },
       error => {
         // Always clear the registration token regardless of whether the server acknowledges the logout.
         MozLoopServiceInternal.clearSessionToken(sessionType);
         if (error.code === 401 && error.errno === INVALID_AUTH_TOKEN) {
           // Authorization failed, invalid token. This is fine since it may mean we already logged out.
           return;
@@ -1297,16 +1302,17 @@ this.MozLoopService = {
   /**
    * Start the FxA login flow using the OAuth client and params from the Loop server.
    *
    * The caller should be prepared to handle rejections related to network, server or login errors.
    *
    * @return {Promise} that resolves when the FxA login flow is complete.
    */
   logInToFxA: function() {
+    log.debug("logInToFxA with gFxAOAuthTokenData:", !!gFxAOAuthTokenData);
     if (gFxAOAuthTokenData) {
       return Promise.resolve(gFxAOAuthTokenData);
     }
 
     return MozLoopServiceInternal.promiseFxAOAuthAuthorization().then(response => {
       return MozLoopServiceInternal.promiseFxAOAuthToken(response.code, response.state);
     }).then(tokenData => {
       gFxAOAuthTokenData = tokenData;
@@ -1344,16 +1350,17 @@ this.MozLoopService = {
   /**
    * Logs the user out from FxA.
    *
    * Gracefully handles if the user is already logged out.
    *
    * @return {Promise} that resolves when the FxA logout flow is complete.
    */
   logOutFromFxA: Task.async(function*() {
+    log.debug("logOutFromFxA");
     yield MozLoopServiceInternal.unregisterFromLoopServer(LOOP_SESSION_TYPE.FXA,
                                                           gPushHandler.pushUrl);
 
     gFxAOAuthTokenData = null;
     gFxAOAuthProfile = null;
 
     // Reset the client since the initial promiseFxAOAuthParameters() call is
     // what creates a new session.