@@ -304,7 +304,8 @@ nsToolkitProfileService::nsToolkitProfileService()
304
304
mUseDedicatedProfile (false ),
305
305
#endif
306
306
mCreatedAlternateProfile (false ),
307
- mStartupReason(NS_LITERAL_STRING(" unknown" )) {
307
+ mStartupReason(NS_LITERAL_STRING(" unknown" )),
308
+ mMaybeLockProfile(false ) {
308
309
#ifdef MOZ_DEV_EDITION
309
310
mUseDevEditionProfile = true ;
310
311
#endif
@@ -313,13 +314,30 @@ nsToolkitProfileService::nsToolkitProfileService()
313
314
314
315
nsToolkitProfileService::~nsToolkitProfileService () { gService = nullptr ; }
315
316
316
- void nsToolkitProfileService::RecordStartupTelemetry () {
317
+ void nsToolkitProfileService::CompleteStartup () {
317
318
if (!mStartupProfileSelected ) {
318
319
return ;
319
320
}
320
321
321
322
ScalarSet (mozilla::Telemetry::ScalarID::STARTUP_PROFILE_SELECTION_REASON,
322
323
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
+ }
323
341
}
324
342
325
343
// Tests whether the passed profile was last used by this install.
@@ -457,29 +475,18 @@ bool nsToolkitProfileService::MaybeMakeDefaultDedicatedProfile(
457
475
// Set this as the default profile for this install.
458
476
SetDefaultProfile (aProfile);
459
477
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" );
479
482
480
483
// Persist the changes.
481
484
Flush ();
482
485
486
+ // Once XPCOM is available check if this is the default application and if so
487
+ // lock the profile again.
488
+ mMaybeLockProfile = true ;
489
+
483
490
return true ;
484
491
}
485
492
@@ -815,10 +822,10 @@ nsToolkitProfileService::SelectStartupProfile(
815
822
nsresult rv = SelectStartupProfile (&argc, argv.get (), aIsResetting, aRootDir,
816
823
aLocalDir, aProfile, aDidCreate);
817
824
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 .
820
827
if (NS_SUCCEEDED(rv)) {
821
- RecordStartupTelemetry ();
828
+ CompleteStartup ();
822
829
}
823
830
824
831
return rv;
@@ -1119,6 +1126,18 @@ nsresult nsToolkitProfileService::SelectStartupProfile(
1119
1126
1120
1127
mStartupReason = NS_LITERAL_STRING(" default" );
1121
1128
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
+
1122
1141
// Use the selected profile.
1123
1142
mCurrent ->GetRootDir (aRootDir);
1124
1143
mCurrent ->GetLocalDir (aLocalDir);
0 commit comments