Bug 1542716: Allow overriding the update channel that is used when generating the default profile name. r=froydnj
authorDave Townsend <dtownsend@oxymoronical.com>
Tue, 09 Apr 2019 18:38:17 +0000
changeset 468624 a31032a16330ca069db82160d2203fa7a9737aca
parent 468623 17040bb20e256476df548a6be770e7d8f78387ef
child 468639 9982d52f7ba861051b9ac7c3b2ed1465985a38be
child 468640 c8c67ca7b3d907c0a3c88fa40f07cccd281932c4
push id35843
push usernbeleuzu@mozilla.com
push dateTue, 09 Apr 2019 22:08:13 +0000
treeherdermozilla-central@a31032a16330 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1542716
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1542716: Allow overriding the update channel that is used when generating the default profile name. r=froydnj Differential Revision: https://phabricator.services.mozilla.com/D26632
toolkit/profile/nsIToolkitProfileService.idl
toolkit/profile/nsToolkitProfileService.cpp
toolkit/profile/nsToolkitProfileService.h
toolkit/profile/xpcshell/head.js
--- a/toolkit/profile/nsIToolkitProfileService.idl
+++ b/toolkit/profile/nsIToolkitProfileService.idl
@@ -69,17 +69,17 @@ interface nsIToolkitProfileService : nsI
      * * The default profile.
      * aRootDir and aLocalDir are set to the data and local directories for the
      * profile data. If a profile from the database was selected it will be
      * returned in aProfile.
      * This returns true if a new profile was created.
      * This method is primarily for testing. It can be called only once.
      */
     bool selectStartupProfile(in Array<ACString> aArgv,
-                              in boolean aIsResetting,
+                              in boolean aIsResetting, in AUTF8String aUpdateChannel,
                               out nsIFile aRootDir, out nsIFile aLocalDir,
                               out nsIToolkitProfile aProfile);
 
     /**
      * Get a profile by name. This is mainly for use by the -P
      * commandline flag.
      *
      * @param aName The profile name to find.
--- a/toolkit/profile/nsToolkitProfileService.cpp
+++ b/toolkit/profile/nsToolkitProfileService.cpp
@@ -367,17 +367,18 @@ nsToolkitProfileService::nsToolkitProfil
       mUseDevEditionProfile(false),
 #ifdef MOZ_DEDICATED_PROFILES
       mUseDedicatedProfile(!IsSnapEnvironment()),
 #else
       mUseDedicatedProfile(false),
 #endif
       mCreatedAlternateProfile(false),
       mStartupReason(NS_LITERAL_STRING("unknown")),
-      mMaybeLockProfile(false) {
+      mMaybeLockProfile(false),
+      mUpdateChannel(NS_STRINGIFY(MOZ_UPDATE_CHANNEL)) {
 #ifdef MOZ_DEV_EDITION
   mUseDevEditionProfile = true;
 #endif
   gService = this;
 }
 
 nsToolkitProfileService::~nsToolkitProfileService() {
   gService = nullptr;
@@ -936,17 +937,17 @@ nsresult nsToolkitProfileService::GetPro
 
 nsresult nsToolkitProfileService::CreateDefaultProfile(
     nsIToolkitProfile** aResult) {
   // Create a new default profile
   nsAutoCString name;
   if (mUseDevEditionProfile) {
     name.AssignLiteral(DEV_EDITION_NAME);
   } else if (mUseDedicatedProfile) {
-    name.AssignLiteral("default-" NS_STRINGIFY(MOZ_UPDATE_CHANNEL));
+    name.AppendPrintf("default-%s", mUpdateChannel.get());
   } else {
     name.AssignLiteral(DEFAULT_NAME);
   }
 
   nsresult rv = CreateUniqueProfile(nullptr, name, aResult);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (mUseDedicatedProfile) {
@@ -961,32 +962,35 @@ nsresult nsToolkitProfileService::Create
 }
 
 /**
  * An implementation of SelectStartupProfile callable from JavaScript via XPCOM.
  * See nsIToolkitProfileService.idl.
  */
 NS_IMETHODIMP
 nsToolkitProfileService::SelectStartupProfile(
-    const nsTArray<nsCString>& aArgv, bool aIsResetting, nsIFile** aRootDir,
-    nsIFile** aLocalDir, nsIToolkitProfile** aProfile, bool* aDidCreate) {
+    const nsTArray<nsCString>& aArgv, bool aIsResetting,
+    const nsACString& aUpdateChannel, nsIFile** aRootDir, nsIFile** aLocalDir,
+    nsIToolkitProfile** aProfile, bool* aDidCreate) {
   int argc = aArgv.Length();
   // Our command line handling expects argv to be null-terminated so construct
   // an appropriate array.
   auto argv = MakeUnique<char*[]>(argc + 1);
   // Also, our command line handling removes things from the array without
   // freeing them so keep track of what we've created separately.
   auto allocated = MakeUnique<UniqueFreePtr<char>[]>(argc);
 
   for (int i = 0; i < argc; i++) {
     allocated[i].reset(ToNewCString(aArgv[i]));
     argv[i] = allocated[i].get();
   }
   argv[argc] = nullptr;
 
+  mUpdateChannel = aUpdateChannel;
+
   bool wasDefault;
   nsresult rv =
       SelectStartupProfile(&argc, argv.get(), aIsResetting, aRootDir, aLocalDir,
                            aProfile, aDidCreate, &wasDefault);
 
   // Since we were called outside of the normal startup path complete any
   // startup tasks.
   if (NS_SUCCEEDED(rv)) {
--- a/toolkit/profile/nsToolkitProfileService.h
+++ b/toolkit/profile/nsToolkitProfileService.h
@@ -145,16 +145,20 @@ class nsToolkitProfileService final : pu
   // True if this install should use a dedicated default profile.
   const bool mUseDedicatedProfile;
   // True if during startup no dedicated profile was already selected, an old
   // default profile existed but was rejected so a new profile was created.
   bool mCreatedAlternateProfile;
   nsString mStartupReason;
   bool mMaybeLockProfile;
 
+  // Holds the current application update channel. This is only really held
+  // so it can be overriden in tests.
+  nsCString mUpdateChannel;
+
   static nsToolkitProfileService* gService;
 
   class ProfileEnumerator final : public nsSimpleEnumerator {
    public:
     NS_DECL_NSISIMPLEENUMERATOR
 
     const nsID& DefaultInterface() override {
       return NS_GET_IID(nsIToolkitProfile);
--- a/toolkit/profile/xpcshell/head.js
+++ b/toolkit/profile/xpcshell/head.js
@@ -6,16 +6,18 @@ const { Services } = ChromeUtils.import(
 const { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
 const { FileUtils } = ChromeUtils.import("resource://gre/modules/FileUtils.jsm");
 const { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm");
 const { AppConstants } = ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
 const { TelemetryTestUtils } = ChromeUtils.import("resource://testing-common/TelemetryTestUtils.jsm");
 
 const NS_ERROR_START_PROFILE_MANAGER = 0x805800c9;
 
+const UPDATE_CHANNEL = AppConstants.MOZ_UPDATE_CHANNEL;
+
 let gProfD = do_get_profile();
 let gDataHome = gProfD.clone();
 gDataHome.append("data");
 gDataHome.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0o755);
 let gDataHomeLocal = gProfD.clone();
 gDataHomeLocal.append("local");
 gDataHomeLocal.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0o755);
 
@@ -65,17 +67,17 @@ function simulateSnapEnvironment() {
 }
 
 function getProfileService() {
   return Cc["@mozilla.org/toolkit/profile-service;1"].
          getService(Ci.nsIToolkitProfileService);
 }
 
 let PROFILE_DEFAULT = "default";
-let DEDICATED_NAME = `default-${AppConstants.MOZ_UPDATE_CHANNEL}`;
+let DEDICATED_NAME = `default-${UPDATE_CHANNEL}`;
 if (AppConstants.MOZ_DEV_EDITION) {
   DEDICATED_NAME = PROFILE_DEFAULT = "dev-edition-default";
 }
 
 /**
  * Creates a random profile path for use.
  */
 function makeRandomProfileDir(name) {
@@ -90,17 +92,18 @@ 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 = service.selectStartupProfile(["xpcshell", ...args], isResetting,
-                                               rootDir, localDir, profile);
+                                               UPDATE_CHANNEL, 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.");
   }