Bug 1470324 - Clean up some unused code in EnterprisePoliciesContent.js. r=kmag draft
authorFelipe Gomes <felipc@gmail.com>
Fri, 27 Jul 2018 14:51:12 -0300
changeset 823643 ba21f04cca8614d9dd4b34f4e093ece0e3153502
parent 823642 042e1c7efbeb02c7e7928419445aba15f972b746
push id117746
push userfelipc@gmail.com
push dateFri, 27 Jul 2018 17:51:50 +0000
reviewerskmag
bugs1470324
milestone63.0a1
Bug 1470324 - Clean up some unused code in EnterprisePoliciesContent.js. r=kmag There was some unused code in this file which was wasting memory. This patch also avoids some more policies from being sent to the content process as they are not really needed there MozReview-Commit-ID: C4FzesWMQi0
browser/base/content/test/performance/browser_startup_content.js
browser/components/enterprisepolicies/EnterprisePolicies.js
browser/components/enterprisepolicies/EnterprisePoliciesContent.js
browser/components/enterprisepolicies/Policies.jsm
browser/components/enterprisepolicies/tests/browser/browser_policies_getActivePolicies.js
--- a/browser/base/content/test/performance/browser_startup_content.js
+++ b/browser/base/content/test/performance/browser_startup_content.js
@@ -15,17 +15,16 @@
 "use strict";
 
 /* Set this to true only for debugging purpose; it makes the output noisy. */
 const kDumpAllStacks = false;
 
 const whitelist = {
   components: new Set([
     "ContentProcessSingleton.js",
-    "EnterprisePoliciesContent.js", // bug 1470324
     "extension-process-script.js",
   ]),
   modules: new Set([
     // From the test harness
     "chrome://mochikit/content/ShutdownLeaksCollector.jsm",
     "resource://specialpowers/MockColorPicker.jsm",
     "resource://specialpowers/MockFilePicker.jsm",
     "resource://specialpowers/MockPermissionPrompt.jsm",
--- a/browser/components/enterprisepolicies/EnterprisePolicies.js
+++ b/browser/components/enterprisepolicies/EnterprisePolicies.js
@@ -38,48 +38,29 @@ XPCOMUtils.defineLazyGetter(this, "log",
     prefix: "Enterprise Policies",
     // tip: set maxLogLevel to "debug" and use log.debug() to create detailed
     // messages during development. See LOG_LEVELS in Console.jsm for details.
     maxLogLevel: "error",
     maxLogLevelPref: PREF_LOGLEVEL,
   });
 });
 
-// ==== Start XPCOM Boilerplate ==== \\
-
-// Factory object
-const EnterprisePoliciesFactory = {
-  _instance: null,
-  createInstance: function BGSF_createInstance(outer, iid) {
-    if (outer != null)
-      throw Cr.NS_ERROR_NO_AGGREGATION;
-    return this._instance == null ?
-      this._instance = new EnterprisePoliciesManager() : this._instance;
-  }
-};
-
-// ==== End XPCOM Boilerplate ==== //
-
-// Constructor
 function EnterprisePoliciesManager() {
   Services.obs.addObserver(this, "profile-after-change", true);
   Services.obs.addObserver(this, "final-ui-startup", true);
   Services.obs.addObserver(this, "sessionstore-windows-restored", true);
   Services.obs.addObserver(this, "EnterprisePolicies:Restart", true);
 }
 
 EnterprisePoliciesManager.prototype = {
-  // for XPCOM
-  classID:          Components.ID("{ea4e1414-779b-458b-9d1f-d18e8efbc145}"),
+  classID:        Components.ID("{ea4e1414-779b-458b-9d1f-d18e8efbc145}"),
   QueryInterface: ChromeUtils.generateQI([Ci.nsIObserver,
                                           Ci.nsISupportsWeakReference,
                                           Ci.nsIEnterprisePolicies]),
-
-  // redefine the default factory for XPCOMUtils
-  _xpcom_factory: EnterprisePoliciesFactory,
+  _xpcom_factory: XPCOMUtils.generateSingletonFactory(EnterprisePoliciesManager),
 
   _initialize() {
     let provider = this._chooseProvider();
 
     if (!provider) {
       this.status = Ci.nsIEnterprisePolicies.INACTIVE;
       return;
     }
--- a/browser/components/enterprisepolicies/EnterprisePoliciesContent.js
+++ b/browser/components/enterprisepolicies/EnterprisePoliciesContent.js
@@ -1,66 +1,27 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
-const PREF_LOGLEVEL           = "browser.policies.loglevel";
-
-XPCOMUtils.defineLazyGetter(this, "log", () => {
-  let { ConsoleAPI } = ChromeUtils.import("resource://gre/modules/Console.jsm", {});
-  return new ConsoleAPI({
-    prefix: "Enterprise Policies Child",
-    // tip: set maxLogLevel to "debug" and use log.debug() to create detailed
-    // messages during development. See LOG_LEVELS in Console.jsm for details.
-    maxLogLevel: "error",
-    maxLogLevelPref: PREF_LOGLEVEL,
-  });
-});
-
-
-// ==== Start XPCOM Boilerplate ==== \\
-
-// Factory object
-const EnterprisePoliciesFactory = {
-  _instance: null,
-  createInstance: function BGSF_createInstance(outer, iid) {
-    if (outer != null)
-      throw Cr.NS_ERROR_NO_AGGREGATION;
-    return this._instance == null ?
-      this._instance = new EnterprisePoliciesManagerContent() : this._instance;
-  }
-};
-
-// ==== End XPCOM Boilerplate ==== //
-
-
 function EnterprisePoliciesManagerContent() {
 }
 
 EnterprisePoliciesManagerContent.prototype = {
-  // for XPCOM
-  classID:          Components.ID("{dc6358f8-d167-4566-bf5b-4350b5e6a7a2}"),
+  classID:        Components.ID("{dc6358f8-d167-4566-bf5b-4350b5e6a7a2}"),
   QueryInterface: ChromeUtils.generateQI([Ci.nsIEnterprisePolicies]),
-
-  // redefine the default factory for XPCOMUtils
-  _xpcom_factory: EnterprisePoliciesFactory,
-
+  _xpcom_factory: XPCOMUtils.generateSingletonFactory(EnterprisePoliciesManagerContent),
 
   get status() {
     return Services.cpmm.sharedData.get("EnterprisePolicies:Status") ||
            Ci.nsIEnterprisePolicies.INACTIVE;
   },
 
   isAllowed(feature) {
     let disallowedFeatures = Services.cpmm.sharedData.get("EnterprisePolicies:DisallowedFeatures");
     return !(disallowedFeatures && disallowedFeatures.has(feature));
   },
-
-  getActivePolicies() {
-    throw Cr.NS_ERROR_NOT_AVAILABLE;
-  }
 };
 
-var components = [EnterprisePoliciesManagerContent];
-this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components);
+this.NSGetFactory = XPCOMUtils.generateNSGetFactory([EnterprisePoliciesManagerContent]);
--- a/browser/components/enterprisepolicies/Policies.jsm
+++ b/browser/components/enterprisepolicies/Policies.jsm
@@ -96,34 +96,34 @@ var Policies = {
         blockAboutPage(manager, "about:addons", true);
       }
     }
   },
 
   "BlockAboutConfig": {
     onBeforeUIStartup(manager, param) {
       if (param) {
-        blockAboutPage(manager, "about:config", true);
+        blockAboutPage(manager, "about:config");
         setAndLockPref("devtools.chrome.enabled", false);
       }
     }
   },
 
   "BlockAboutProfiles": {
     onBeforeUIStartup(manager, param) {
       if (param) {
-        blockAboutPage(manager, "about:profiles", true);
+        blockAboutPage(manager, "about:profiles");
       }
     }
   },
 
   "BlockAboutSupport": {
     onBeforeUIStartup(manager, param) {
       if (param) {
-        blockAboutPage(manager, "about:support", true);
+        blockAboutPage(manager, "about:support");
       }
     }
   },
 
   "Bookmarks": {
     onAllWindowsRestored(manager, param) {
       BookmarksPolicies.processBookmarks(param);
     }
@@ -334,17 +334,17 @@ var Policies = {
         setAndLockPref("browser.safebrowsing.allowOverride", !param.SafeBrowsing);
       }
     }
   },
 
   "DisableSetDesktopBackground": {
     onBeforeUIStartup(manager, param) {
       if (param) {
-        manager.disallowFeature("setDesktopBackground", true);
+        manager.disallowFeature("setDesktopBackground");
       }
     }
   },
 
   "DisableSystemAddonUpdate": {
     onBeforeAddons(manager, param) {
       if (param) {
         manager.disallowFeature("SysAddonUpdate");
--- a/browser/components/enterprisepolicies/tests/browser/browser_policies_getActivePolicies.js
+++ b/browser/components/enterprisepolicies/tests/browser/browser_policies_getActivePolicies.js
@@ -29,12 +29,12 @@ add_task(async function test_wrong_polic
   Assert.deepEqual(await Services.policies.getActivePolicies(), expected, "Wrong policies ignored");
 });
 
 add_task(async function test_content_process() {
   await ContentTask.spawn(gBrowser.selectedBrowser, null, function() {
     try {
       Services.policies.getActivePolicies();
     } catch (ex) {
-      is(ex.result, Cr.NS_ERROR_NOT_AVAILABLE, "Function getActivePolicies() doesn't have a valid definition in the content process");
+      is(ex.result, Cr.NS_ERROR_XPC_JSOBJECT_HAS_NO_FUNCTION_NAMED, "Function getActivePolicies() doesn't have a valid definition in the content process");
     }
   });
 });