Skip to content

Commit 2e8205f

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 UltraBlame original commit: c132ef1b7c8ab954be0049c95f8b42039029c3e1
1 parent 8a03a96 commit 2e8205f

File tree

3 files changed

+44
-25
lines changed

3 files changed

+44
-25
lines changed

toolkit/profile/nsToolkitProfileService.cpp

+41-22
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

@@ -457,29 +475,18 @@ bool nsToolkitProfileService::MaybeMakeDefaultDedicatedProfile(
457475

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-
467-
468-
if (NS_FAILED(rv)) {
469-
isDefaultApp = false;
470-
}
471-
}
472-
473-
if (!isDefaultApp) {
474-
475-
476-
477-
mInstallData.DeleteString(mInstallHash.get(), "Locked");
478-
}
478+
479+
480+
481+
mInstallData.DeleteString(mInstallHash.get(), "Locked");
479482

480483

481484
Flush();
482485

486+
487+
488+
mMaybeLockProfile = true;
489+
483490
return true;
484491
}
485492

@@ -818,7 +825,7 @@ nsToolkitProfileService::SelectStartupProfile(
818825

819826

820827
if (NS_SUCCEEDED(rv)) {
821-
RecordStartupTelemetry();
828+
CompleteStartup();
822829
}
823830

824831
return rv;
@@ -1120,6 +1127,18 @@ nsresult nsToolkitProfileService::SelectStartupProfile(
11201127
mStartupReason = NS_LITERAL_STRING("default");
11211128

11221129

1130+
if (mUseDedicatedProfile) {
1131+
nsCString locked;
1132+
rv = mInstallData.GetString(mInstallHash.get(), "Locked", locked);
1133+
if (NS_FAILED(rv) || !locked.EqualsLiteral("1")) {
1134+
1135+
1136+
1137+
mMaybeLockProfile = true;
1138+
}
1139+
}
1140+
1141+
11231142
mCurrent->GetRootDir(aRootDir);
11241143
mCurrent->GetLocalDir(aLocalDir);
11251144
NS_ADDREF(*aProfile = mCurrent);

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

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
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)