Bug 952465 - [Session Restore] Replace Components.utils.reportError with Console.jsm. r=Yoric
authorPeiyong Lin <pylaurent1314@gmail.com>
Mon, 06 Jan 2014 15:27:25 -0500
changeset 162256 c0c89e5d0cf1b8e3c15ca73c2980967f1950477f
parent 162255 841238b6a1077dbb111e8a2d2e3f845a8c057afd
child 162257 a58fd917dead962ff03314d72ab7bd2fdc380261
push idunknown
push userunknown
push dateunknown
reviewersYoric
bugs952465
milestone29.0a1
Bug 952465 - [Session Restore] Replace Components.utils.reportError with Console.jsm. r=Yoric
browser/components/sessionstore/src/SessionFile.jsm
browser/components/sessionstore/src/SessionSaver.jsm
browser/components/sessionstore/src/SessionStorage.jsm
browser/components/sessionstore/src/SessionStore.jsm
browser/components/sessionstore/src/TabState.jsm
browser/components/sessionstore/src/nsSessionStartup.js
--- a/browser/components/sessionstore/src/SessionFile.jsm
+++ b/browser/components/sessionstore/src/SessionFile.jsm
@@ -31,16 +31,18 @@ const Ci = Components.interfaces;
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/osfile.jsm");
 Cu.import("resource://gre/modules/osfile/_PromiseWorker.jsm", this);
 Cu.import("resource://gre/modules/Promise.jsm");
 Cu.import("resource://gre/modules/AsyncShutdown.jsm");
 
+XPCOMUtils.defineLazyModuleGetter(this, "console",
+  "resource://gre/modules/devtools/Console.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "TelemetryStopwatch",
   "resource://gre/modules/TelemetryStopwatch.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Task",
   "resource://gre/modules/Task.jsm");
 XPCOMUtils.defineLazyServiceGetter(this, "Telemetry",
   "@mozilla.org/base/telemetry;1", "nsITelemetry");
 
 this.SessionFile = {
@@ -97,17 +99,17 @@ const TaskUtils = {
    * @param {Promise} promise
    * @return {Promise} A promise behaving as |promise|, but with additional
    * logging in case of uncaught error.
    */
   captureErrors: function captureErrors(promise) {
     return promise.then(
       null,
       function onError(reason) {
-        Cu.reportError("Uncaught asynchronous error: " + reason + " at\n" + reason.stack);
+        console.error("Uncaught asynchronous error", reason, "at", reason.stack);
         throw reason;
       }
     );
   },
   /**
    * Spawn a new Task from a generator.
    *
    * This function behaves as |Task.spawn|, with the exception that it
@@ -174,31 +176,30 @@ let SessionFileInternal = {
         // At this point, we measure how long we stop the main thread
         TelemetryStopwatch.finish("FX_SESSION_RESTORE_WRITE_FILE_LONGEST_OP_MS", refObj);
 
         // Now wait for the result and record how long the write took
         let msg = yield promise;
         this._recordTelemetry(msg.telemetry);
       } catch (ex) {
         TelemetryStopwatch.cancel("FX_SESSION_RESTORE_WRITE_FILE_LONGEST_OP_MS", refObj);
-        Cu.reportError("Could not write session state file " + this.path
-                       + ": " + ex);
+        console.error("Could not write session state file ", this.path, ex);
       }
 
       if (isFinalWrite) {
         Services.obs.notifyObservers(null, "sessionstore-final-state-write-complete", "");
       }
     }.bind(this));
   },
 
   writeLoadStateOnceAfterStartup: function (aLoadState) {
     SessionWorker.post("writeLoadStateOnceAfterStartup", [aLoadState]).then(msg => {
       this._recordTelemetry(msg.telemetry);
       return msg;
-    }, Cu.reportError);
+    }, console.error);
   },
 
   createBackupCopy: function (ext) {
     return SessionWorker.post("createBackupCopy", [ext]);
   },
 
   removeBackupCopy: function (ext) {
     return SessionWorker.post("removeBackupCopy", [ext]);
--- a/browser/components/sessionstore/src/SessionSaver.jsm
+++ b/browser/components/sessionstore/src/SessionSaver.jsm
@@ -12,17 +12,18 @@ const Ci = Components.interfaces;
 
 Cu.import("resource://gre/modules/Timer.jsm", this);
 Cu.import("resource://gre/modules/Services.jsm", this);
 Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
 Cu.import("resource://gre/modules/TelemetryStopwatch.jsm", this);
 
 XPCOMUtils.defineLazyModuleGetter(this, "SessionStore",
   "resource:///modules/sessionstore/SessionStore.jsm");
-
+XPCOMUtils.defineLazyModuleGetter(this, "console",
+  "resource://gre/modules/devtools/Console.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "SessionFile",
   "resource:///modules/sessionstore/SessionFile.jsm");
 
 // Minimal interval between two save operations (in milliseconds).
 XPCOMUtils.defineLazyGetter(this, "gInterval", function () {
   const PREF = "browser.sessionstore.interval";
 
   // Observer that updates the cached value when the preference changes.
@@ -304,17 +305,17 @@ let SessionSaverInternal = {
     this.updateLastSaveTime();
 
     // Write (atomically) to a session file, using a tmp file. Once the session
     // file is successfully updated, save the time stamp of the last save and
     // notify the observers.
     return SessionFile.write(data).then(() => {
       this.updateLastSaveTime();
       notify(null, "sessionstore-state-write-complete");
-    }, Cu.reportError);
+    }, console.error);
   },
 
   /**
    * Notify sessionstore-state-write observer and give them a
    * chance to modify session data before we'll write it to disk.
    */
   _notifyObserversBeforeStateWrite: function (data) {
     let stateString = createSupportsString(data);
--- a/browser/components/sessionstore/src/SessionStorage.jsm
+++ b/browser/components/sessionstore/src/SessionStorage.jsm
@@ -7,16 +7,18 @@
 this.EXPORTED_SYMBOLS = ["SessionStorage"];
 
 const Cu = Components.utils;
 const Ci = Components.interfaces;
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
+XPCOMUtils.defineLazyModuleGetter(this, "console",
+  "resource://gre/modules/devtools/Console.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "PrivacyLevel",
   "resource:///modules/sessionstore/PrivacyLevel.jsm");
 
 this.SessionStorage = Object.freeze({
   /**
    * Updates all sessionStorage "super cookies"
    * @param aDocShell
    *        That tab's docshell (containing the sessionStorage)
@@ -99,17 +101,17 @@ let SessionStorageInternal = {
       // of missing documentURI will be solved in a followup bug to bug 600307.
       let storage = storageManager.createStorage(principal, "", aDocShell.usePrivateBrowsing);
 
       for (let [key, value] in Iterator(data)) {
         try {
           storage.setItem(key, value);
         } catch (e) {
           // throws e.g. for URIs that can't have sessionStorage
-          Cu.reportError(e);
+          console.error(e);
         }
       }
     }
   },
 
   /**
    * Reads an entry in the session storage data contained in a tab's history.
    * @param aURI
--- a/browser/components/sessionstore/src/SessionStore.jsm
+++ b/browser/components/sessionstore/src/SessionStore.jsm
@@ -97,16 +97,18 @@ Cu.import("resource://gre/modules/Task.j
 
 XPCOMUtils.defineLazyServiceGetter(this, "gSessionStartup",
   "@mozilla.org/browser/sessionstartup;1", "nsISessionStartup");
 XPCOMUtils.defineLazyServiceGetter(this, "gScreenManager",
   "@mozilla.org/gfx/screenmanager;1", "nsIScreenManager");
 XPCOMUtils.defineLazyServiceGetter(this, "Telemetry",
   "@mozilla.org/base/telemetry;1", "nsITelemetry");
 
+XPCOMUtils.defineLazyModuleGetter(this, "console",
+  "resource://gre/modules/devtools/Console.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "DocShellCapabilities",
   "resource:///modules/sessionstore/DocShellCapabilities.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Messenger",
   "resource:///modules/sessionstore/Messenger.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "PageStyle",
   "resource:///modules/sessionstore/PageStyle.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "RecentWindow",
   "resource:///modules/RecentWindow.jsm");
@@ -954,17 +956,17 @@ let SessionStoreInternal = {
         } else {
           let initialState = this.initSession();
           this._sessionInitialized = true;
           this.onLoad(aWindow, initialState);
 
           // Let everyone know we're done.
           this._deferredInitialized.resolve();
         }
-      }, Cu.reportError);
+      }, console.error);
     };
 
     aWindow.addEventListener("load", onload);
   },
 
   /**
    * On window close...
    * - remove event listeners from tabs
@@ -3131,17 +3133,17 @@ let SessionStoreInternal = {
     var MAX_EXPIRY = Math.pow(2, 62);
     for (let i = 0; i < aCookies.length; i++) {
       var cookie = aCookies[i];
       try {
         Services.cookies.add(cookie.host, cookie.path || "", cookie.name || "",
                              cookie.value, !!cookie.secure, !!cookie.httponly, true,
                              "expiry" in cookie ? cookie.expiry : MAX_EXPIRY);
       }
-      catch (ex) { Cu.reportError(ex); } // don't let a single cookie stop recovering
+      catch (ex) { console.error(ex); } // don't let a single cookie stop recovering
     }
   },
 
   /* ........ Disk Access .............. */
 
   /**
    * Save the current session state to disk, after a delay.
    *
--- a/browser/components/sessionstore/src/TabState.jsm
+++ b/browser/components/sessionstore/src/TabState.jsm
@@ -7,16 +7,18 @@
 this.EXPORTED_SYMBOLS = ["TabState"];
 
 const Cu = Components.utils;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
 Cu.import("resource://gre/modules/Promise.jsm", this);
 Cu.import("resource://gre/modules/Task.jsm", this);
 
+XPCOMUtils.defineLazyModuleGetter(this, "console",
+  "resource://gre/modules/devtools/Console.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Messenger",
   "resource:///modules/sessionstore/Messenger.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "PrivacyLevel",
   "resource:///modules/sessionstore/PrivacyLevel.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "TabStateCache",
   "resource:///modules/sessionstore/TabStateCache.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "TabAttributes",
   "resource:///modules/sessionstore/TabAttributes.jsm");
@@ -323,17 +325,17 @@ let TabStateInternal = {
 
     let includePrivateData = options && options.includePrivateData;
 
     let history;
     try {
       history = syncHandler.collectSessionHistory(includePrivateData);
     } catch (e) {
       // This may happen if the tab has crashed.
-      Cu.reportError(e);
+      console.error(e);
       return tabData;
     }
 
     tabData.entries = history.entries;
     if ("index" in history) {
       tabData.index = history.index;
     }
 
--- a/browser/components/sessionstore/src/nsSessionStartup.js
+++ b/browser/components/sessionstore/src/nsSessionStartup.js
@@ -38,16 +38,18 @@ const Ci = Components.interfaces;
 const Cr = Components.results;
 const Cu = Components.utils;
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/TelemetryStopwatch.jsm");
 Cu.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
 Cu.import("resource://gre/modules/Promise.jsm");
 
+XPCOMUtils.defineLazyModuleGetter(this, "console",
+  "resource://gre/modules/devtools/Console.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "SessionFile",
   "resource:///modules/sessionstore/SessionFile.jsm");
 
 const STATE_RUNNING_STR = "running";
 
 // 'browser.startup.page' preference value to resume the previous session.
 const BROWSER_STARTUP_RESUME_SESSION = 3;
 
@@ -80,17 +82,17 @@ SessionStartup.prototype = {
     if (PrivateBrowsingUtils.permanentPrivateBrowsing) {
       this._initialized = true;
       gOnceInitializedDeferred.resolve();
       return;
     }
 
     SessionFile.read().then(
       this._onSessionFileRead.bind(this),
-      Cu.reportError
+      console.error
     );
   },
 
   // Wrap a string as a nsISupports
   _createSupportsString: function ssfi_createSupportsString(aData) {
     let string = Cc["@mozilla.org/supports-string;1"]
                    .createInstance(Ci.nsISupportsString);
     string.data = aData;