Bug 1322797: Replace selectedProfile with currentProfile and fix defaultProfile. r=froydnj, r=flod

The current properties selectedProfile and defaultProfile are somewhat confusing
selectedProfile actually returns the default profile for the build and
defaultProfile returns the default profile for non-dev-edition builds. This
confusion leads to callers doing the wrong thing in some places.

What most code actually cares about is being able to set/get the default profile
for this build and getting the current profile in use. So this patch replaces
the previous properties with currentProfile and defaultProfile which do what
makes more sense.

This patch also switches from using the preprocessor to change behaviour for
dev-edition builds to using a boolean flag since some code was incorrectly
ignoring the setting to make dev-edition use the same profile as normal builds.

In order to make currentProfile correct when resetting a profile I had to move
CreateResetProfile into nsToolkitProfileService.

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

--HG--
extra : rebase_source : cefe252618cd3a1b0e0cd5a71b056dd2b557f1a3
extra : intermediate-source : 35af79575f54f75d22e213fdac7ddd704b40807a
extra : source : 732d1ce192408d4f595f2fce16f45c7354ce3097
This commit is contained in:
Dave Townsend 2018-12-28 09:44:47 -08:00
Родитель d86279fca1
Коммит 9127e8bbdc
15 изменённых файлов: 219 добавлений и 223 удалений

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

@ -72,7 +72,7 @@ FirefoxProfileMigrator.prototype.getResources = function(aProfile) {
let sourceProfileDir = aProfile ? this._getAllProfiles().get(aProfile.id) :
Cc["@mozilla.org/toolkit/profile-service;1"]
.getService(Ci.nsIToolkitProfileService)
.selectedProfile.rootDir;
.currentProfile.rootDir;
if (!sourceProfileDir || !sourceProfileDir.exists() ||
!sourceProfileDir.isReadable())
return null;

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

@ -180,13 +180,14 @@ function getDeviceName() {
function getProfileLocation() {
// In child processes, we cannot access the profile location.
try {
// For some reason this line must come first or in xpcshell tests
// nsXREDirProvider never gets initialised and so the profile service
// crashes on initialisation.
const profd = Services.dirsvc.get("ProfD", Ci.nsIFile);
const profservice = Cc["@mozilla.org/toolkit/profile-service;1"]
.getService(Ci.nsIToolkitProfileService);
for (const profile of profservice.profiles) {
if (profile.rootDir.path == profd.path) {
return profile.name;
}
if (profservice.currentProfile) {
return profservice.currentProfile.name;
}
return profd.leafName;

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

@ -14,33 +14,6 @@ XPCOMUtils.defineLazyServiceGetter(
"nsIToolkitProfileService"
);
// nsIToolkitProfileService.selectProfile can be used only during the selection
// of the profile in the ProfileManager. If we are showing about:profiles in a
// tab, the selectedProfile returns the default profile.
// In this function we use the ProfD to find the current profile.
function findCurrentProfile() {
let cpd;
try {
cpd = Services.dirsvc.get("ProfD", Ci.nsIFile);
} catch (e) {}
if (cpd) {
for (let profile of ProfileService.profiles) {
if (profile.rootDir.path == cpd.path) {
return profile;
}
}
}
// selectedProfile can throw if nothing is selected or if the selected profile
// has been deleted.
try {
return ProfileService.selectedProfile;
} catch (e) {
return null;
}
}
function refreshUI() {
let parent = document.getElementById("profiles");
while (parent.firstChild) {
@ -52,7 +25,7 @@ function refreshUI() {
defaultProfile = ProfileService.defaultProfile;
} catch (e) {}
let currentProfile = findCurrentProfile();
let currentProfile = ProfileService.currentProfile;
for (let profile of ProfileService.profiles) {
let isCurrentProfile = profile == currentProfile;
@ -197,10 +170,10 @@ function display(profileData) {
div.appendChild(sep);
}
// This is called from the createProfileWizard.xul dialog.
function CreateProfile(profile) {
ProfileService.selectedProfile = profile;
ProfileService.flush();
refreshUI();
// The wizard created a profile, just make it the default.
defaultProfile(profile);
}
function createProfileWizard() {
@ -269,30 +242,26 @@ async function removeProfile(profile) {
}
}
// If we are deleting the selected or the default profile we must choose a
// different one.
let isSelected = false;
try {
isSelected = ProfileService.selectedProfile == profile;
} catch (e) {}
// If we are deleting the default profile we must choose a different one.
let isDefault = false;
try {
isDefault = ProfileService.defaultProfile == profile;
} catch (e) {}
if (isSelected || isDefault) {
if (isDefault) {
for (let p of ProfileService.profiles) {
if (profile == p) {
continue;
}
if (isSelected) {
ProfileService.selectedProfile = p;
}
if (isDefault) {
ProfileService.defaultProfile = p;
try {
ProfileService.defaultProfile = p;
} catch (e) {
// This can happen on dev-edition if a non-default profile is in use.
// In such a case the next time that dev-edition is started it will
// find no default profile and just create a new one.
}
}
break;
@ -315,10 +284,19 @@ async function removeProfile(profile) {
refreshUI();
}
function defaultProfile(profile) {
ProfileService.defaultProfile = profile;
ProfileService.selectedProfile = profile;
ProfileService.flush();
async function defaultProfile(profile) {
try {
ProfileService.defaultProfile = profile;
ProfileService.flush();
} catch (e) {
// This can happen on dev-edition.
let [title, msg] = await document.l10n.formatValues([
{ id: "profiles-cannot-set-as-default-title" },
{ id: "profiles-cannot-set-as-default-message" },
]);
Services.prompt.alert(window, title, msg);
}
refreshUI();
}

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

@ -12,6 +12,7 @@
<link rel="icon" type="image/png" id="favicon" href="chrome://branding/content/icon32.png" />
<link rel="stylesheet" href="chrome://mozapps/skin/aboutProfiles.css" type="text/css" />
<script type="application/javascript" src="chrome://global/content/aboutProfiles.js" />
<link rel="localization" href="branding/brand.ftl" />
<link rel="localization" href="toolkit/about/aboutProfiles.ftl" />
</head>
<body id="body" class="wide-container">

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

@ -31,6 +31,9 @@ profiles-remove = Remove
profiles-set-as-default = Set as default profile
profiles-launch-profile = Launch profile in new browser
profiles-cannot-set-as-default-title = Unable to set default
profiles-cannot-set-as-default-message = The default profile cannot be changed for { -brand-short-name }.
profiles-yes = yes
profiles-no = no

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

@ -39,7 +39,7 @@ function startup() {
listitem.setAttribute("tooltiptext", tooltiptext);
listitem.profile = profile;
try {
if (profile === gProfileService.selectedProfile) {
if (profile === gProfileService.defaultProfile) {
setTimeout(function(a) {
profilesElement.ensureElementIsVisible(a);
profilesElement.selectItem(a);
@ -93,16 +93,18 @@ function acceptDialog() {
}
gDialogParams.objects.insertElementAt(profileLock.nsIProfileLock, 0);
gProfileService.selectedProfile = selectedProfile.profile;
gProfileService.defaultProfile = selectedProfile.profile;
try {
gProfileService.defaultProfile = selectedProfile.profile;
} catch (e) {
// This can happen on dev-edition. We'll still restart with the selected
// profile based on the lock's directories.
}
updateStartupPrefs();
gDialogParams.SetInt(0, 1);
/* Bug 257777 */
gDialogParams.SetInt(1, document.getElementById("offlineState").checked ? 1 : 0);
gDialogParams.SetString(0, selectedProfile.profile.name);
return true;
}

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

@ -18,22 +18,18 @@ interface nsIToolkitProfileService : nsISupports
readonly attribute nsISimpleEnumerator /*nsIToolkitProfile*/ profiles;
/**
* The currently selected profile (the one used or about to be used by the
* browser).
* The profile currently in use if it is a named profile. This will return
* null if the current profile path doesn't match a profile in the database.
*/
attribute nsIToolkitProfile selectedProfile;
readonly attribute nsIToolkitProfile currentProfile;
/**
* The default profile (the one used or about to be used by the
* browser if no other profile is specified at runtime). This is the profile
* marked with Default=1 in profiles.ini and is usually the same as
* selectedProfile, except on Developer Edition.
*
* Developer Edition uses a profile named "dev-edition-default" as the
* default profile (which it creates if it doesn't exist), unless a special
* empty file named "ignore-dev-edition-profile" is present next to
* profiles.ini. In that case Developer Edition behaves the same as any
* other build of Firefox.
* The default profile for this build.
* On startup this is the profile selected unless overridden by command line
* arguments or environment variables. Setting this will change the profile
* used by default the next time the application is started.
* Attempting to change the default may throw an exception on builds that do
* not support changing the default profile, such as developer edition.
*/
attribute nsIToolkitProfile defaultProfile;

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

@ -42,6 +42,7 @@
#include "nsNativeCharsetUtils.h"
#include "mozilla/Attributes.h"
#include "mozilla/Sprintf.h"
#include "nsPrintfCString.h"
using namespace mozilla;
@ -88,8 +89,26 @@ NS_IMETHODIMP
nsToolkitProfile::SetName(const nsACString& aName) {
NS_ASSERTION(nsToolkitProfileService::gService, "Where did my service go?");
if (mName.Equals(aName)) {
return NS_OK;
}
// Changing the name from the dev-edition default profile name makes this
// profile no longer the dev-edition default.
if (mName.EqualsLiteral(DEV_EDITION_NAME) &&
nsToolkitProfileService::gService->mDevEditionDefault == this) {
nsToolkitProfileService::gService->mDevEditionDefault = nullptr;
}
mName = aName;
// Setting the name to the dev-edition default profile name will cause this
// profile to become the dev-edition default.
if (aName.EqualsLiteral(DEV_EDITION_NAME) &&
!nsToolkitProfileService::gService->mDevEditionDefault) {
nsToolkitProfileService::gService->mDevEditionDefault = this;
}
return NS_OK;
}
@ -147,8 +166,12 @@ nsresult nsToolkitProfile::RemoveInternal(bool aRemoveFiles,
mPrev = nullptr;
mNext = nullptr;
if (nsToolkitProfileService::gService->mChosen == this)
nsToolkitProfileService::gService->mChosen = nullptr;
if (nsToolkitProfileService::gService->mNormalDefault == this) {
nsToolkitProfileService::gService->mNormalDefault = nullptr;
}
if (nsToolkitProfileService::gService->mDevEditionDefault == this) {
nsToolkitProfileService::gService->mDevEditionDefault = nullptr;
}
return NS_OK;
}
@ -265,7 +288,13 @@ nsToolkitProfileService* nsToolkitProfileService::gService = nullptr;
NS_IMPL_ISUPPORTS(nsToolkitProfileService, nsIToolkitProfileService)
nsToolkitProfileService::nsToolkitProfileService()
: mStartupProfileSelected(false), mStartWithLast(true), mIsFirstRun(true) {
: mStartupProfileSelected(false),
mStartWithLast(true),
mIsFirstRun(true),
mUseDevEditionProfile(false) {
#ifdef MOZ_DEV_EDITION
mUseDevEditionProfile = true;
#endif
gService = this;
}
@ -323,6 +352,8 @@ nsresult nsToolkitProfileService::Init() {
bool shouldIgnoreSeparateProfile;
rv = ignoreSeparateProfile->Exists(&shouldIgnoreSeparateProfile);
if (NS_FAILED(rv)) return rv;
mUseDevEditionProfile = !shouldIgnoreSeparateProfile;
#endif
nsCOMPtr<nsIToolkitProfile> autoSelectProfile;
@ -382,17 +413,11 @@ nsresult nsToolkitProfileService::Init() {
rv = parser.GetString(profileID.get(), "Default", buffer);
if (NS_SUCCEEDED(rv) && buffer.EqualsLiteral("1")) {
mDefault = currentProfile;
mNormalDefault = currentProfile;
}
if (name.EqualsLiteral(DEV_EDITION_NAME)) {
#ifdef MOZ_DEV_EDITION
// Use the dev-edition-default profile if this is an Aurora build and
// ignore-dev-edition-profile is not present.
if (!shouldIgnoreSeparateProfile) {
mChosen = currentProfile;
}
#endif
mDevEditionDefault = currentProfile;
} else {
nonDevEditionProfiles++;
autoSelectProfile = currentProfile;
@ -400,24 +425,18 @@ nsresult nsToolkitProfileService::Init() {
}
// If there is only one non-dev-edition profile then mark it as the default.
if (!mDefault && nonDevEditionProfiles == 1) {
mDefault = autoSelectProfile;
if (!mNormalDefault && nonDevEditionProfiles == 1) {
mNormalDefault = autoSelectProfile;
}
// Normally having no non-dev-edition builds suggests this is the first run.
mIsFirstRun = nonDevEditionProfiles == 0;
#ifdef MOZ_DEV_EDITION
if (!shouldIgnoreSeparateProfile) {
// Except when using the separate dev-edition profile, in which case not
// finding it means this is a first run.
mIsFirstRun = !mChosen;
if (mUseDevEditionProfile) {
// When using the separate dev-edition profile not finding it means this is
// a first run.
mIsFirstRun = !mDevEditionDefault;
} else {
mChosen = mDefault;
// If there are no normal profiles then this is a first run.
mIsFirstRun = nonDevEditionProfiles == 0;
}
#else
mChosen = mDefault;
#endif
return NS_OK;
}
@ -462,37 +481,30 @@ nsToolkitProfileService::ProfileEnumerator::GetNext(nsISupports** aResult) {
}
NS_IMETHODIMP
nsToolkitProfileService::GetSelectedProfile(nsIToolkitProfile** aResult) {
if (!mChosen && mFirst && !mFirst->mNext) // only one profile
mChosen = mFirst;
if (!mChosen) return NS_ERROR_FAILURE;
NS_ADDREF(*aResult = mChosen);
return NS_OK;
}
NS_IMETHODIMP
nsToolkitProfileService::SetSelectedProfile(nsIToolkitProfile* aProfile) {
if (mChosen != aProfile) {
mChosen = aProfile;
}
nsToolkitProfileService::GetCurrentProfile(nsIToolkitProfile** aResult) {
NS_IF_ADDREF(*aResult = mCurrent);
return NS_OK;
}
NS_IMETHODIMP
nsToolkitProfileService::GetDefaultProfile(nsIToolkitProfile** aResult) {
if (!mDefault) return NS_ERROR_FAILURE;
if (mUseDevEditionProfile) {
NS_IF_ADDREF(*aResult = mDevEditionDefault);
return NS_OK;
}
NS_ADDREF(*aResult = mDefault);
NS_IF_ADDREF(*aResult = mNormalDefault);
return NS_OK;
}
NS_IMETHODIMP
nsToolkitProfileService::SetDefaultProfile(nsIToolkitProfile* aProfile) {
if (mDefault != aProfile) {
mDefault = aProfile;
if (mUseDevEditionProfile && aProfile != mDevEditionDefault) {
// The separate profile is hardcoded.
return NS_ERROR_FAILURE;
}
mNormalDefault = aProfile;
return NS_OK;
}
@ -555,7 +567,6 @@ nsresult nsToolkitProfileService::SelectStartupProfile(
nsresult rv;
const char* arg;
nsCOMPtr<nsIToolkitProfile> profile;
// Use the profile specified in the environment variables (generally from an
// app initiated restart).
@ -572,9 +583,10 @@ nsresult nsToolkitProfileService::SelectStartupProfile(
CheckArg(*aArgc, aArgv, "profile", &dummy);
CheckArg(*aArgc, aArgv, "profilemanager");
GetProfileByDir(lf, localDir, aProfile);
GetProfileByDir(lf, localDir, getter_AddRefs(mCurrent));
lf.forget(aRootDir);
localDir.forget(aLocalDir);
NS_IF_ADDREF(*aProfile = mCurrent);
return NS_OK;
}
@ -612,9 +624,10 @@ nsresult nsToolkitProfileService::SelectStartupProfile(
// If a profile path is specified directly on the command line, then
// assume that the temp directory is the same as the given directory.
GetProfileByDir(lf, lf, aProfile);
GetProfileByDir(lf, lf, getter_AddRefs(mCurrent));
NS_ADDREF(*aRootDir = lf);
lf.forget(aLocalDir);
NS_IF_ADDREF(*aProfile = mCurrent);
return NS_OK;
}
@ -630,6 +643,7 @@ nsresult nsToolkitProfileService::SelectStartupProfile(
}
if (ar) {
const char* delim = strchr(arg, ' ');
nsCOMPtr<nsIToolkitProfile> profile;
if (delim) {
nsCOMPtr<nsIFile> lf;
rv = NS_NewNativeLocalFile(nsDependentCString(delim + 1), true,
@ -681,11 +695,12 @@ nsresult nsToolkitProfileService::SelectStartupProfile(
return NS_ERROR_FAILURE;
}
rv = GetProfileByName(nsDependentCString(arg), getter_AddRefs(profile));
rv = GetProfileByName(nsDependentCString(arg), getter_AddRefs(mCurrent));
if (NS_SUCCEEDED(rv)) {
profile->GetRootDir(aRootDir);
profile->GetLocalDir(aLocalDir);
profile.forget(aProfile);
mCurrent->GetRootDir(aRootDir);
mCurrent->GetLocalDir(aLocalDir);
NS_ADDREF(*aProfile = mCurrent);
return NS_OK;
}
@ -714,30 +729,33 @@ nsresult nsToolkitProfileService::SelectStartupProfile(
}
// create a default profile
nsresult rv = CreateProfile(nullptr, // choose a default dir for us
#ifdef MOZ_DEV_EDITION
NS_LITERAL_CSTRING(DEV_EDITION_NAME),
#else
NS_LITERAL_CSTRING(DEFAULT_NAME),
#endif
getter_AddRefs(mChosen));
nsAutoCString name;
if (mUseDevEditionProfile) {
name.AssignLiteral(DEV_EDITION_NAME);
} else {
name.AssignLiteral(DEFAULT_NAME);
}
nsresult rv = CreateProfile(nullptr, name, getter_AddRefs(mCurrent));
if (NS_SUCCEEDED(rv)) {
#ifdef MOZ_DEV_EDITION
// If the only profile is the new dev-edition-profile then older versions
// may try to auto-select it. Create a default profile for them to use
// instead.
if (mFirst && !mFirst->mNext) {
CreateProfile(nullptr, NS_LITERAL_CSTRING(DEFAULT_NAME),
getter_AddRefs(mDefault));
if (mUseDevEditionProfile) {
mDevEditionDefault = mCurrent;
// If the only profile is the new dev-edition-profile then older
// versions may try to auto-select it. Create a default profile for them
// to use instead.
if (mFirst && !mFirst->mNext) {
CreateProfile(nullptr, NS_LITERAL_CSTRING(DEFAULT_NAME),
getter_AddRefs(mNormalDefault));
}
} else {
mNormalDefault = mCurrent;
}
#else
SetDefaultProfile(mChosen);
#endif
Flush();
mChosen->GetRootDir(aRootDir);
mChosen->GetLocalDir(aLocalDir);
NS_ADDREF(*aProfile = mChosen);
mCurrent->GetRootDir(aRootDir);
mCurrent->GetLocalDir(aLocalDir);
NS_ADDREF(*aProfile = mCurrent);
*aDidCreate = true;
return NS_OK;
@ -749,19 +767,50 @@ nsresult nsToolkitProfileService::SelectStartupProfile(
return NS_ERROR_SHOW_PROFILE_MANAGER;
}
// GetSelectedProfile will auto-select the only profile if there's just one
GetSelectedProfile(getter_AddRefs(profile));
GetDefaultProfile(getter_AddRefs(mCurrent));
// None of the profiles was marked as default (generally only happens if the
// user modifies profiles.ini manually). Let the user choose.
if (!profile) {
if (!mCurrent) {
return NS_ERROR_SHOW_PROFILE_MANAGER;
}
// Use the selected profile.
profile->GetRootDir(aRootDir);
profile->GetLocalDir(aLocalDir);
profile.forget(aProfile);
mCurrent->GetRootDir(aRootDir);
mCurrent->GetLocalDir(aLocalDir);
NS_ADDREF(*aProfile = mCurrent);
return NS_OK;
}
/**
* Creates a new profile for reset and mark it as the current profile.
*/
nsresult nsToolkitProfileService::CreateResetProfile(
nsIToolkitProfile** aNewProfile) {
nsAutoCString oldProfileName;
mCurrent->GetName(oldProfileName);
nsCOMPtr<nsIToolkitProfile> newProfile;
// Make the new profile name the old profile (or "default-") + the time in
// seconds since epoch for uniqueness.
nsAutoCString newProfileName;
if (!oldProfileName.IsEmpty()) {
newProfileName.Assign(oldProfileName);
newProfileName.Append("-");
} else {
newProfileName.AssignLiteral("default-");
}
newProfileName.AppendPrintf("%" PRId64, PR_Now() / 1000);
nsresult rv = CreateProfile(nullptr, // choose a default dir for us
newProfileName, getter_AddRefs(newProfile));
if (NS_FAILED(rv)) return rv;
rv = Flush();
if (NS_FAILED(rv)) return rv;
mCurrent = newProfile;
newProfile.forget(aNewProfile);
return NS_OK;
}
@ -912,13 +961,19 @@ nsToolkitProfileService::CreateProfile(nsIFile* aRootDir,
nsToolkitProfile* last = mFirst.get();
if (last) {
while (last->mNext) last = last->mNext;
while (last->mNext) {
last = last->mNext;
}
}
nsCOMPtr<nsIToolkitProfile> profile =
new nsToolkitProfile(aName, rootDir, localDir, last);
if (!profile) return NS_ERROR_OUT_OF_MEMORY;
if (aName.Equals(DEV_EDITION_NAME)) {
mDevEditionDefault = profile;
}
profile.forget(aResult);
return NS_OK;
}
@ -1015,9 +1070,7 @@ nsToolkitProfileService::Flush() {
"Path=%s\n",
pCount, cur->mName.get(), isRelative ? "1" : "0", path.get());
nsCOMPtr<nsIToolkitProfile> profile;
rv = this->GetDefaultProfile(getter_AddRefs(profile));
if (NS_SUCCEEDED(rv) && profile == cur) {
if (cur == mNormalDefault) {
pos += snprintf(pos, end - pos, "Default=1\n");
}

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

@ -76,6 +76,7 @@ class nsToolkitProfileService final : public nsIToolkitProfileService {
nsresult SelectStartupProfile(int* aArgc, char* aArgv[], bool aIsResetting,
nsIFile** aRootDir, nsIFile** aLocalDir,
nsIToolkitProfile** aProfile, bool* aDidCreate);
nsresult CreateResetProfile(nsIToolkitProfile** aNewProfile);
private:
friend class nsToolkitProfile;
@ -91,15 +92,29 @@ class nsToolkitProfileService final : public nsIToolkitProfileService {
void GetProfileByDir(nsIFile* aRootDir, nsIFile* aLocalDir,
nsIToolkitProfile** aResult);
// Tracks whether SelectStartupProfile has been called.
bool mStartupProfileSelected;
// The first profile in a linked list of profiles loaded from profiles.ini.
RefPtr<nsToolkitProfile> mFirst;
nsCOMPtr<nsIToolkitProfile> mChosen;
nsCOMPtr<nsIToolkitProfile> mDefault;
// The profile selected for use at startup, if it exists in profiles.ini.
nsCOMPtr<nsIToolkitProfile> mCurrent;
// The default profile used by non-dev-edition builds.
nsCOMPtr<nsIToolkitProfile> mNormalDefault;
// The profile used if mUseDevEditionProfile is true (the default on
// dev-edition builds).
nsCOMPtr<nsIToolkitProfile> mDevEditionDefault;
// The directory that holds profiles.ini and profile directories.
nsCOMPtr<nsIFile> mAppData;
// The directory that holds the cache files for profiles.
nsCOMPtr<nsIFile> mTempData;
// The location of profiles.ini.
nsCOMPtr<nsIFile> mListFile;
// Whether to start with the selected profile by default.
bool mStartWithLast;
// True if during startup it appeared that this is the first run.
bool mIsFirstRun;
// True if the default profile is the separate dev-edition-profile.
bool mUseDevEditionProfile;
static nsToolkitProfileService* gService;

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

@ -48,15 +48,19 @@ function makeRandomProfileDir(name) {
* a bit nicer to use from JS.
*/
function selectStartupProfile(args = [], isResetting = false) {
let service = getProfileService();
let rootDir = {};
let localDir = {};
let profile = {};
let didCreate = getProfileService().selectStartupProfile(["xpcshell", ...args], isResetting,
rootDir, localDir, profile);
let didCreate = service.selectStartupProfile(["xpcshell", ...args], isResetting,
rootDir, localDir, profile);
if (profile.value) {
Assert.ok(rootDir.value.equals(profile.value.rootDir), "Should have matched the root dir.");
Assert.ok(localDir.value.equals(profile.value.localDir), "Should have matched the local dir.");
Assert.equal(service.currentProfile, profile.value, "Should have marked the profile as the current profile.");
} else {
Assert.ok(!service.currentProfile, "Should be no current profile.");
}
return {
@ -210,12 +214,5 @@ function checkProfileService(profileData = readProfilesIni()) {
}
}
let selectedProfile = null;
try {
selectedProfile = service.selectedProfile;
} catch (e) {
// GetSelectedProfile throws when there are no profiles.
}
Assert.equal(selectedProfile, defaultProfile, "Should have seen the right profile selected.");
Assert.equal(service.defaultProfile, defaultProfile, "Should have seen the right profile as default.");
}

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

@ -4,7 +4,6 @@
add_task(async () => {
let service = getProfileService();
let { profile, didCreate } = selectStartupProfile();
checkProfileService();
@ -13,7 +12,7 @@ add_task(async () => {
Assert.equal(service.profileCount, 2, "Should be two profiles.");
} else {
Assert.equal(service.profileCount, 1, "Should be only one profile.");
Assert.equal(profile, service.selectedProfile, "Should now be the selected profile.");
Assert.equal(profile, service.defaultProfile, "Should now be the default profile.");
}
Assert.equal(profile.name, PROFILE_DEFAULT, "Should have created a new profile with the right name.");
});

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

@ -41,6 +41,6 @@ add_task(async () => {
let { profile, didCreate } = selectStartupProfile();
Assert.ok(!didCreate, "Should not have created a new profile.");
Assert.equal(profile, service.selectedProfile, "Should have returned the selected profile.");
Assert.equal(profile, service.defaultProfile, "Should have returned the default profile.");
Assert.equal(profile.name, PROFILE_DEFAULT, "Should have selected the right profile");
});

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

@ -14,7 +14,6 @@
#include "nsDirectoryServiceDefs.h"
#include "nsDirectoryServiceUtils.h"
#include "nsPIDOMWindow.h"
#include "nsPrintfCString.h"
#include "nsString.h"
#include "nsXPCOMCIDInternal.h"
#include "mozilla/Components.h"
@ -31,41 +30,6 @@ extern const XREAppData* gAppData;
static const char kProfileProperties[] =
"chrome://mozapps/locale/profile/profileSelection.properties";
/**
* Creates a new profile with a timestamp in the name to use for profile reset.
*/
nsresult CreateResetProfile(nsIToolkitProfileService* aProfileSvc,
nsIToolkitProfile* aOldProfile,
nsIToolkitProfile** aNewProfile) {
MOZ_ASSERT(aProfileSvc, "NULL profile service");
nsAutoCString oldProfileName;
aOldProfile->GetName(oldProfileName);
nsCOMPtr<nsIToolkitProfile> newProfile;
// Make the new profile the old profile (or "default-") + the time in seconds
// since epoch for uniqueness.
nsAutoCString newProfileName;
if (!oldProfileName.IsEmpty()) {
newProfileName.Assign(oldProfileName);
newProfileName.Append("-");
} else {
newProfileName.AssignLiteral("default-");
}
newProfileName.Append(nsPrintfCString("%" PRId64, PR_Now() / 1000));
nsresult rv =
aProfileSvc->CreateProfile(nullptr, // choose a default dir for us
newProfileName, getter_AddRefs(newProfile));
if (NS_FAILED(rv)) return rv;
rv = aProfileSvc->Flush();
if (NS_FAILED(rv)) return rv;
newProfile.swap(*aNewProfile);
return NS_OK;
}
/**
* Delete the profile directory being reset after a backup and delete the local
* profile directory.

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

@ -11,10 +11,6 @@ static bool gProfileResetCleanupCompleted = false;
static const char kResetProgressURL[] =
"chrome://global/content/resetProfileProgress.xul";
nsresult CreateResetProfile(nsIToolkitProfileService* aProfileSvc,
nsIToolkitProfile* aOldProfile,
nsIToolkitProfile** aNewProfile);
nsresult ProfileResetCleanup(nsIToolkitProfile* aOldProfile);
class ProfileResetCleanupResultTask : public mozilla::Runnable {

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

@ -1958,8 +1958,6 @@ static ReturnAbortOnError ShowProfileManager(
nsresult rv;
nsCOMPtr<nsIFile> profD, profLD;
char16_t* profileNamePtr;
nsAutoCString profileName;
bool offline = false;
{
@ -2029,12 +2027,6 @@ static ReturnAbortOnError ShowProfileManager(
rv = lock->GetLocalDirectory(getter_AddRefs(profLD));
NS_ENSURE_SUCCESS(rv, rv);
rv = ioParamBlock->GetString(0, &profileNamePtr);
NS_ENSURE_SUCCESS(rv, rv);
CopyUTF16toUTF8(MakeStringSpan(profileNamePtr), profileName);
free(profileNamePtr);
lock->Unlock();
}
}
@ -2210,8 +2202,7 @@ static nsresult SelectProfile(nsIProfileLock** aResult,
// If we're resetting a profile, create a new one and use it to startup.
gResetOldProfile = profile;
rv = CreateResetProfile(aProfileSvc, gResetOldProfile,
getter_AddRefs(profile));
rv = service->CreateResetProfile(getter_AddRefs(profile));
if (NS_SUCCEEDED(rv)) {
rv = profile->GetRootDir(getter_AddRefs(rootDir));
NS_ENSURE_SUCCESS(rv, rv);
@ -4139,15 +4130,15 @@ nsresult XREMain::XRE_mainRun() {
}
{
bool profileWasSelected = false;
bool profileWasDefault = false;
if (gDoProfileReset) {
nsCOMPtr<nsIToolkitProfile> defaultProfile;
// This can fail if there is no default profile.
// That shouldn't stop reset from proceeding.
nsresult gotSelected =
mProfileSvc->GetSelectedProfile(getter_AddRefs(defaultProfile));
if (NS_SUCCEEDED(gotSelected)) {
profileWasSelected = defaultProfile == gResetOldProfile;
nsresult gotDefault =
mProfileSvc->GetDefaultProfile(getter_AddRefs(defaultProfile));
if (NS_SUCCEEDED(gotDefault)) {
profileWasDefault = defaultProfile == gResetOldProfile;
}
}
@ -4183,7 +4174,7 @@ nsresult XREMain::XRE_mainRun() {
mProfileName.Assign(name);
// Set the new profile as the default after we're done cleaning up the
// old profile, iff that profile was already the default
if (profileWasSelected) {
if (profileWasDefault) {
rv = mProfileSvc->SetDefaultProfile(newProfile);
if (NS_FAILED(rv))
NS_WARNING("Could not set current profile as the default");