Skip to content

Commit 49c86a9

Browse files
committed
Bug 1525119: Check if this is the default install and if so lock the profile. r=froydnj
Previously we attempted to do this when XPCOM wasn't available so it always failed to get the shell service. Instead set a flag telling us to do it later when we choose the old default profile. Also includes a block of code to attempt to fix the issue for existing nightly users, this can be removed before betas. Differential Revision: https://phabricator.services.mozilla.com/D18596 --HG-- extra : moz-landing-system : lando
1 parent 74108f3 commit 49c86a9

File tree

3 files changed

+46
-27
lines changed

3 files changed

+46
-27
lines changed

toolkit/profile/nsToolkitProfileService.cpp

+43-24
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ nsToolkitProfileService::nsToolkitProfileService()
304304
mUseDedicatedProfile(false),
305305
#endif
306306
mCreatedAlternateProfile(false),
307-
mStartupReason(NS_LITERAL_STRING("unknown")) {
307+
mStartupReason(NS_LITERAL_STRING("unknown")),
308+
mMaybeLockProfile(false) {
308309
#ifdef MOZ_DEV_EDITION
309310
mUseDevEditionProfile = true;
310311
#endif
@@ -313,13 +314,30 @@ nsToolkitProfileService::nsToolkitProfileService()
313314

314315
nsToolkitProfileService::~nsToolkitProfileService() { gService = nullptr; }
315316

316-
void nsToolkitProfileService::RecordStartupTelemetry() {
317+
void nsToolkitProfileService::CompleteStartup() {
317318
if (!mStartupProfileSelected) {
318319
return;
319320
}
320321

321322
ScalarSet(mozilla::Telemetry::ScalarID::STARTUP_PROFILE_SELECTION_REASON,
322323
mStartupReason);
324+
325+
if (mMaybeLockProfile) {
326+
nsCOMPtr<nsIToolkitShellService> shell =
327+
do_GetService(NS_TOOLKITSHELLSERVICE_CONTRACTID);
328+
if (!shell) {
329+
return;
330+
}
331+
332+
bool isDefaultApp;
333+
nsresult rv = shell->IsDefaultApplication(&isDefaultApp);
334+
NS_ENSURE_SUCCESS_VOID(rv);
335+
336+
if (isDefaultApp) {
337+
mInstallData.SetString(mInstallHash.get(), "Locked", "1");
338+
Flush();
339+
}
340+
}
323341
}
324342

325343
// Tests whether the passed profile was last used by this install.
@@ -457,29 +475,18 @@ bool nsToolkitProfileService::MaybeMakeDefaultDedicatedProfile(
457475
// Set this as the default profile for this install.
458476
SetDefaultProfile(aProfile);
459477

460-
bool isDefaultApp = false;
461-
462-
nsCOMPtr<nsIToolkitShellService> shell =
463-
do_GetService(NS_TOOLKITSHELLSERVICE_CONTRACTID);
464-
if (shell) {
465-
rv = shell->IsDefaultApplication(&isDefaultApp);
466-
// If the shell component is following XPCOM rules then this shouldn't be
467-
// needed, but let's be safe.
468-
if (NS_FAILED(rv)) {
469-
isDefaultApp = false;
470-
}
471-
}
472-
473-
if (!isDefaultApp) {
474-
// SetDefaultProfile will have locked this profile to this install so no
475-
// other installs will steal it, but this was auto-selected so we want to
476-
// unlock it so that the OS default install can take it at a later time.
477-
mInstallData.DeleteString(mInstallHash.get(), "Locked");
478-
}
478+
// SetDefaultProfile will have locked this profile to this install so no
479+
// other installs will steal it, but this was auto-selected so we want to
480+
// unlock it so that other installs can potentially take it.
481+
mInstallData.DeleteString(mInstallHash.get(), "Locked");
479482

480483
// Persist the changes.
481484
Flush();
482485

486+
// Once XPCOM is available check if this is the default application and if so
487+
// lock the profile again.
488+
mMaybeLockProfile = true;
489+
483490
return true;
484491
}
485492

@@ -815,10 +822,10 @@ nsToolkitProfileService::SelectStartupProfile(
815822
nsresult rv = SelectStartupProfile(&argc, argv.get(), aIsResetting, aRootDir,
816823
aLocalDir, aProfile, aDidCreate);
817824

818-
// Since we were called outside of the normal startup path record the
819-
// telemetry now.
825+
// Since we were called outside of the normal startup path complete any
826+
// startup tasks.
820827
if (NS_SUCCEEDED(rv)) {
821-
RecordStartupTelemetry();
828+
CompleteStartup();
822829
}
823830

824831
return rv;
@@ -1119,6 +1126,18 @@ nsresult nsToolkitProfileService::SelectStartupProfile(
11191126

11201127
mStartupReason = NS_LITERAL_STRING("default");
11211128

1129+
// This code block can be removed before riding the trains to 68.
1130+
if (mUseDedicatedProfile) {
1131+
nsCString locked;
1132+
rv = mInstallData.GetString(mInstallHash.get(), "Locked", locked);
1133+
if (NS_FAILED(rv) || !locked.EqualsLiteral("1")) {
1134+
// The profile is unlocked. This can only happen if this profile was the
1135+
// old default profile and it was chosen as the dedicated default on a
1136+
// previous run. Check later if this is the default app and if so lock it.
1137+
mMaybeLockProfile = true;
1138+
}
1139+
}
1140+
11221141
// Use the selected profile.
11231142
mCurrent->GetRootDir(aRootDir);
11241143
mCurrent->GetLocalDir(aLocalDir);

toolkit/profile/nsToolkitProfileService.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class nsToolkitProfileService final : public nsIToolkitProfileService {
7979
nsIToolkitProfile** aProfile, bool* aDidCreate);
8080
nsresult CreateResetProfile(nsIToolkitProfile** aNewProfile);
8181
nsresult ApplyResetProfile(nsIToolkitProfile* aOldProfile);
82-
void RecordStartupTelemetry();
82+
void CompleteStartup();
8383

8484
private:
8585
friend class nsToolkitProfile;
@@ -143,6 +143,7 @@ class nsToolkitProfileService final : public nsIToolkitProfileService {
143143
// default profile existed but was rejected so a new profile was created.
144144
bool mCreatedAlternateProfile;
145145
nsString mStartupReason;
146+
bool mMaybeLockProfile;
146147

147148
static nsToolkitProfileService* gService;
148149

toolkit/xre/nsAppRunner.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -4695,8 +4695,7 @@ nsresult XREMain::XRE_mainRun() {
46954695
AddSandboxAnnotations();
46964696
#endif /* MOZ_CONTENT_SANDBOX */
46974697

4698-
static_cast<nsToolkitProfileService*>(mProfileSvc.get())
4699-
->RecordStartupTelemetry();
4698+
static_cast<nsToolkitProfileService*>(mProfileSvc.get())->CompleteStartup();
47004699

47014700
{
47024701
rv = appStartup->Run();

0 commit comments

Comments
 (0)