Bug 745342 - Use more lazy services from Services.jsm [r=dietrich]
authorPaul O’Shannessy <paul@oshannessy.com>
Mon, 16 Apr 2012 14:26:10 -0700
changeset 95097 a84bdeb378f6303335351dbf31ee020d29e8ec65
parent 95096 26439e0c36792be23e913711ff4eb10b09f2f303
child 95098 cfcd178b2f5fff1d81445c63fac335f2ec940530
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdietrich
bugs745342
milestone14.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 745342 - Use more lazy services from Services.jsm [r=dietrich]
browser/components/sessionstore/src/nsSessionStore.js
--- a/browser/components/sessionstore/src/nsSessionStore.js
+++ b/browser/components/sessionstore/src/nsSessionStore.js
@@ -135,38 +135,31 @@ Cu.import("resource://gre/modules/Teleme
 
 XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
                                   "resource://gre/modules/NetUtil.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "ScratchpadManager",
                                   "resource:///modules/devtools/scratchpad-manager.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "XPathGenerator",
                                   "resource:///modules/sessionstore/XPathGenerator.jsm");
 
-XPCOMUtils.defineLazyServiceGetter(this, "CookieSvc",
-  "@mozilla.org/cookiemanager;1", "nsICookieManager2");
-
 #ifdef MOZ_CRASHREPORTER
 XPCOMUtils.defineLazyServiceGetter(this, "CrashReporter",
   "@mozilla.org/xre/app-info;1", "nsICrashReporter");
 #endif
 
-XPCOMUtils.defineLazyServiceGetter(this, "SecuritySvc",
-  "@mozilla.org/scriptsecuritymanager;1", "nsIScriptSecurityManager");
-
 function debug(aMsg) {
   aMsg = ("SessionStore: " + aMsg).replace(/\S{80}/g, "$&\n");
   Services.console.logStringMessage(aMsg);
 }
 
 /* :::::::: The Service ::::::::::::::: */
 
 function SessionStoreService() {
   XPCOMUtils.defineLazyGetter(this, "_prefBranch", function () {
-    return Cc["@mozilla.org/preferences-service;1"].
-           getService(Ci.nsIPrefService).getBranch("browser.");
+    return Services.prefs.getBranch("browser.");
   });
 
   // minimal interval between two save operations (in milliseconds)
   XPCOMUtils.defineLazyGetter(this, "_interval", function () {
     // used often, so caching/observing instead of fetching on-demand
     this._prefBranch.addObserver("sessionstore.interval", this, true);
     return this._prefBranch.getIntPref("sessionstore.interval");
   });
@@ -2128,17 +2121,17 @@ SessionStoreService.prototype = {
       }
       catch (ex) { /* this throws for host-less URIs (such as about: or jar:) */ }
       if (storageData[domain] ||
           !(aFullData || this._checkPrivacyLevel(uri.schemeIs("https"), aIsPinned)))
         continue;
 
       let storage, storageItemCount = 0;
       try {
-        var principal = SecuritySvc.getCodebasePrincipal(uri);
+        var principal = Services.scriptSecurityManager.getCodebasePrincipal(uri);
 
         // Using getSessionStorageForPrincipal instead of getSessionStorageForURI
         // just to be able to pass aCreate = false, that avoids creation of the
         // sessionStorage object for the page earlier than the page really
         // requires it. It was causing problems while accessing a storage when
         // a page later changed its domain.
         storage = aDocShell.getSessionStorageForPrincipal(principal, "", false);
         if (storage)
@@ -2502,17 +2495,17 @@ SessionStoreService.prototype = {
     for (let [id, window] in Iterator(aWindows)) {
       window.cookies = [];
       let internalWindow = this._internalWindows[id];
       if (!internalWindow.hosts)
         return;
       for (var [host, isPinned] in Iterator(internalWindow.hosts)) {
         let list;
         try {
-          list = CookieSvc.getCookiesFromHost(host);
+          list = Services.cookies.getCookiesFromHost(host);
         }
         catch (ex) {
           debug("getCookiesFromHost failed. Host: " + host);
         }
         while (list && list.hasMoreElements()) {
           var cookie = list.getNext().QueryInterface(Ci.nsICookie2);
           // window._hosts will only have hosts with the right privacy rules,
           // so there is no need to do anything special with this call to
@@ -3698,19 +3691,19 @@ SessionStoreService.prototype = {
    *        Array of cookie objects
    */
   restoreCookies: function sss_restoreCookies(aCookies) {
     // MAX_EXPIRY should be 2^63-1, but JavaScript can't handle that precision
     var MAX_EXPIRY = Math.pow(2, 62);
     for (let i = 0; i < aCookies.length; i++) {
       var cookie = aCookies[i];
       try {
-        CookieSvc.add(cookie.host, cookie.path || "", cookie.name || "",
-                      cookie.value, !!cookie.secure, !!cookie.httponly, true,
-                      "expiry" in cookie ? cookie.expiry : MAX_EXPIRY);
+        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
     }
   },
 
 /* ........ Disk Access .............. */
 
   /**