Bug 1528082: Add an environment variable to disable dedicated profiles for enterprise use. r=froydnj

In some situations dedicated profile support does not work well. This includes a
handful of linux distributions which always install different application
versions to different locations, some application sandboxing systems as well as
enterprise deployments. This environment variable provides a way to opt out of
dedicated profiles for these cases.

Differential Revision: https://phabricator.services.mozilla.com/D35249

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Dave Townsend 2019-06-20 13:47:42 +00:00
Родитель 79e118fb86
Коммит 69f70ce6ae
6 изменённых файлов: 102 добавлений и 8 удалений

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

@ -382,7 +382,7 @@ nsToolkitProfileService::nsToolkitProfileService()
mIsFirstRun(true),
mUseDevEditionProfile(false),
#ifdef MOZ_DEDICATED_PROFILES
mUseDedicatedProfile(!IsSnapEnvironment()),
mUseDedicatedProfile(!IsSnapEnvironment() && !UseLegacyProfiles()),
#else
mUseDedicatedProfile(false),
#endif
@ -1752,6 +1752,17 @@ bool nsToolkitProfileService::IsSnapEnvironment() {
return !!PR_GetEnv("SNAP_NAME");
}
/**
* In some situations dedicated profile support does not work well. This
* includes a handful of linux distributions which always install different
* application versions to different locations, some application sandboxing
* systems as well as enterprise deployments. This environment variable provides
* a way to opt out of dedicated profiles for these cases.
*/
bool nsToolkitProfileService::UseLegacyProfiles() {
return !!PR_GetEnv("MOZ_LEGACY_PROFILES");
}
struct FindInstallsClosure {
nsINIParser* installData;
nsTArray<nsCString>* installs;

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

@ -105,6 +105,7 @@ class nsToolkitProfileService final : public nsIToolkitProfileService {
nsresult MaybeMakeDefaultDedicatedProfile(nsIToolkitProfile* aProfile,
bool* aResult);
bool IsSnapEnvironment();
bool UseLegacyProfiles();
nsresult CreateDefaultProfile(nsIToolkitProfile** aResult);
void SetNormalDefault(nsIToolkitProfile* aProfile);

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

@ -55,14 +55,22 @@ const ShellService = {
ShellService.register();
let gIsSnap = false;
let gIsLegacy = false;
function simulateSnapEnvironment() {
let env = Cc["@mozilla.org/process/environment;1"].
getService(Ci.nsIEnvironment);
env.set("SNAP_NAME", "foo");
gIsSnap = true;
gIsLegacy = true;
}
function enableLegacyProfiles() {
let env = Cc["@mozilla.org/process/environment;1"].
getService(Ci.nsIEnvironment);
env.set("MOZ_LEGACY_PROFILES", "1");
gIsLegacy = true;
}
function getProfileService() {
@ -398,7 +406,7 @@ function checkProfileService(profileData = readProfilesIni(), verifyBackup = tru
let defaultPath = (profileData.installs && hash in profileData.installs) ?
profileData.installs[hash].default : null;
let dedicatedProfile = null;
let snapProfile = null;
let legacyProfile = null;
for (let i = 0; i < serviceProfiles.length; i++) {
let serviceProfile = serviceProfiles[i];
@ -416,15 +424,15 @@ function checkProfileService(profileData = readProfilesIni(), verifyBackup = tru
if (AppConstants.MOZ_DEV_EDITION) {
if (expectedProfile.name == PROFILE_DEFAULT) {
snapProfile = serviceProfile;
legacyProfile = serviceProfile;
}
} else if (expectedProfile.default) {
snapProfile = serviceProfile;
legacyProfile = serviceProfile;
}
}
if (gIsSnap) {
Assert.equal(service.defaultProfile, snapProfile, "Should have seen the right profile selected.");
if (gIsLegacy) {
Assert.equal(service.defaultProfile, legacyProfile, "Should have seen the right profile selected.");
} else {
Assert.equal(service.defaultProfile, dedicatedProfile, "Should have seen the right profile selected.");
}

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

@ -0,0 +1,24 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/*
* Tests that setting MOZ_LEGACY_PROFILES disables dedicated profiles.
*/
add_task(async () => {
enableLegacyProfiles();
let service = getProfileService();
let { profile, didCreate } = selectStartupProfile();
checkStartupReason("firstrun-created-default");
Assert.ok(didCreate, "Should have created a new profile.");
Assert.equal(profile.name, PROFILE_DEFAULT, "Should have used the normal name.");
if (AppConstants.MOZ_DEV_EDITION) {
Assert.equal(service.profileCount, 2, "Should be two profiles.");
} else {
Assert.equal(service.profileCount, 1, "Should be only one profile.");
}
checkProfileService();
});

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

@ -0,0 +1,48 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/*
* Tests that an old-style default profile not previously used by this build
* gets selected when configured for legacy profiles.
*/
add_task(async () => {
let defaultProfile = makeRandomProfileDir("default");
// Just pretend this profile was last used by something in the profile dir.
let greDir = gProfD.clone();
greDir.append("app");
writeCompatibilityIni(defaultProfile, greDir, greDir);
writeProfilesIni({
profiles: [{
name: PROFILE_DEFAULT,
path: defaultProfile.leafName,
default: true,
}],
});
enableLegacyProfiles();
let { profile: selectedProfile, didCreate } = selectStartupProfile();
checkStartupReason("default");
let profileData = readProfilesIni();
let installsINI = gDataHome.clone();
installsINI.append("installs.ini");
Assert.ok(!installsINI.exists(), "Installs database should not have been created.");
Assert.ok(profileData.options.startWithLastProfile, "Should be set to start with the last profile.");
Assert.equal(profileData.profiles.length, 1, "Should have the right number of profiles.");
let profile = profileData.profiles[0];
Assert.equal(profile.name, PROFILE_DEFAULT, "Should have the right name.");
Assert.equal(profile.path, defaultProfile.leafName, "Should be the original default profile.");
Assert.ok(profile.default, "Should be marked as the old-style default.");
checkProfileService(profileData);
Assert.ok(!didCreate, "Should not have created a new profile.");
Assert.ok(selectedProfile.rootDir.equals(defaultProfile), "Should be using the right directory.");
Assert.equal(selectedProfile.name, PROFILE_DEFAULT);
});

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

@ -38,3 +38,5 @@ skip-if = devedition
[test_conflict_profiles.js]
[test_conflict_installs.js]
[test_invalid_descriptor.js]
[test_legacy_empty.js]
[test_legacy_select.js]