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

--HG--
extra : rebase_source : 042e1c7efbeb02c7e7928419445aba15f972b746
This commit is contained in:
Felipe Gomes 2018-07-27 14:51:10 -03:00
Родитель 25e4f07d6c
Коммит ba935a61cb
3 изменённых файлов: 11 добавлений и 51 удалений

Просмотреть файл

@ -195,16 +195,16 @@ EnterprisePoliciesManager.prototype = {
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.
@ -259,21 +259,13 @@ EnterprisePoliciesManager.prototype = {
},
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])));
}
},
@ -286,10 +278,7 @@ EnterprisePoliciesManager.prototype = {
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;
},

Просмотреть файл

@ -36,16 +36,6 @@ const EnterprisePoliciesFactory = {
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 = {
@ -56,28 +46,15 @@ EnterprisePoliciesManagerContent.prototype = {
// 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() {

Просмотреть файл

@ -4,12 +4,6 @@
"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;