Bug 1470324 - Use sharedData instead of initialProcessData in the enterprise policies code. r=kmag
This significantly simplifies the content-side implementation of the enterprise policies code since it doesn't have to listen for updates on the disallowed features list (with that, it also doesn't need to load early in order to set up those listeners)
MozReview-Commit-ID: 3lyZXq1j3D5
--- a/browser/components/enterprisepolicies/EnterprisePolicies.js
+++ b/browser/components/enterprisepolicies/EnterprisePolicies.js
@@ -190,26 +190,26 @@ EnterprisePoliciesManager.prototype = {
async _restart() {
if (!Cu.isInAutomation) {
return;
}
DisallowedFeatures = {};
+ Services.ppmm.sharedData.delete("EnterprisePolicies:Status");
+ Services.ppmm.sharedData.delete("EnterprisePolicies:DisallowedFeatures");
+
this._status = Ci.nsIEnterprisePolicies.UNINITIALIZED;
for (let timing of Object.keys(this._callbacks)) {
this._callbacks[timing] = [];
}
- delete Services.ppmm.initialProcessData.policies;
- Services.ppmm.broadcastAsyncMessage("EnterprisePolicies:Restart", null);
let { PromiseUtils } = ChromeUtils.import("resource://gre/modules/PromiseUtils.jsm",
{});
-
// Simulate the startup process. This step-by-step is a bit ugly but it
// tries to emulate the same behavior as of a normal startup.
await PromiseUtils.idleDispatch(() => {
this.observe(null, "policies-startup", null);
});
await PromiseUtils.idleDispatch(() => {
@@ -254,47 +254,36 @@ EnterprisePoliciesManager.prototype = {
case "EnterprisePolicies:Restart":
this._restart().then(null, Cu.reportError);
break;
}
},
disallowFeature(feature, neededOnContentProcess = false) {
- DisallowedFeatures[feature] = true;
+ DisallowedFeatures[feature] = neededOnContentProcess;
// NOTE: For optimization purposes, only features marked as needed
// on content process will be passed onto the child processes.
if (neededOnContentProcess) {
- Services.ppmm.initialProcessData.policies
- .disallowedFeatures.push(feature);
-
- if (Services.ppmm.childCount > 1) {
- // If there has been a content process already initialized, let's
- // broadcast the newly disallowed feature.
- Services.ppmm.broadcastAsyncMessage(
- "EnterprisePolicies:DisallowFeature", {feature}
- );
- }
+ Services.ppmm.sharedData.set("EnterprisePolicies:DisallowedFeatures",
+ new Set(Object.keys(DisallowedFeatures).filter(key => DisallowedFeatures[key])));
}
},
// ------------------------------
// public nsIEnterprisePolicies members
// ------------------------------
_status: Ci.nsIEnterprisePolicies.UNINITIALIZED,
set status(val) {
this._status = val;
if (val != Ci.nsIEnterprisePolicies.INACTIVE) {
- Services.ppmm.initialProcessData.policies = {
- status: val,
- disallowedFeatures: [],
- };
+ Services.ppmm.sharedData.set("EnterprisePolicies:Status", val);
}
return val;
},
get status() {
return this._status;
},
--- a/browser/components/enterprisepolicies/EnterprisePoliciesContent.js
+++ b/browser/components/enterprisepolicies/EnterprisePoliciesContent.js
@@ -31,58 +31,35 @@ const EnterprisePoliciesFactory = {
this._instance = new EnterprisePoliciesManagerContent() : this._instance;
}
};
// ==== End XPCOM Boilerplate ==== //
function EnterprisePoliciesManagerContent() {
- let policies = Services.cpmm.initialProcessData.policies;
- if (policies) {
- this._status = policies.status;
- // make a copy of the array so that we can keep adding to it
- // in a way that is not confusing.
- this._disallowedFeatures = policies.disallowedFeatures.slice();
- }
-
- Services.cpmm.addMessageListener("EnterprisePolicies:DisallowFeature", this);
- Services.cpmm.addMessageListener("EnterprisePolicies:Restart", this);
}
EnterprisePoliciesManagerContent.prototype = {
// for XPCOM
classID: Components.ID("{dc6358f8-d167-4566-bf5b-4350b5e6a7a2}"),
QueryInterface: ChromeUtils.generateQI([Ci.nsIEnterprisePolicies]),
// redefine the default factory for XPCOMUtils
_xpcom_factory: EnterprisePoliciesFactory,
- _status: Ci.nsIEnterprisePolicies.INACTIVE,
-
- _disallowedFeatures: [],
-
- receiveMessage({name, data}) {
- switch (name) {
- case "EnterprisePolicies:DisallowFeature":
- this._disallowedFeatures.push(data.feature);
- break;
-
- case "EnterprisePolicies:Restart":
- this._disallowedFeatures = [];
- break;
- }
- },
get status() {
- return this._status;
+ return Services.cpmm.sharedData.get("EnterprisePolicies:Status") ||
+ Ci.nsIEnterprisePolicies.INACTIVE;
},
isAllowed(feature) {
- return !this._disallowedFeatures.includes(feature);
+ let disallowedFeatures = Services.cpmm.sharedData.get("EnterprisePolicies:DisallowedFeatures");
+ return !(disallowedFeatures && disallowedFeatures.has(feature));
},
getActivePolicies() {
throw Cr.NS_ERROR_NOT_AVAILABLE;
}
};
var components = [EnterprisePoliciesManagerContent];
--- a/browser/components/enterprisepolicies/tests/browser/browser_policies_basic_tests.js
+++ b/browser/components/enterprisepolicies/tests/browser/browser_policies_basic_tests.js
@@ -1,20 +1,14 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
add_task(async function test_simple_policies() {
- await ContentTask.spawn(gBrowser.selectedBrowser, null, async function() {
- // Initialize the service in the content process, in case it hasn't
- // already started.
- Services.policies;
- });
-
let { Policies } = ChromeUtils.import("resource:///modules/policies/Policies.jsm", {});
let policy0Ran = false, policy1Ran = false, policy2Ran = false, policy3Ran = false;
// Implement functions to handle the four simple policies that will be added
// to the schema.
Policies.simple_policy0 = {
onProfileAfterChange(manager, param) {