Bug 1342588 - Use ProfD for Browser Toolbox profile. r=ochameau
Originally, the profile was placed in `ProfLD` instead of `ProfD`. On some
systems, such as macOS, `ProfLD` is in the user's Caches directory, which is not
an appropriate place to store supposedly persistent profile data.
MozReview-Commit-ID: IWudqEg3kbI
--- a/devtools/client/framework/ToolboxProcess.jsm
+++ b/devtools/client/framework/ToolboxProcess.jsm
@@ -156,17 +156,20 @@ BrowserToolboxProcess.prototype = {
},
/**
* Initializes a profile for the remote debugger process.
*/
_initProfile: function () {
dumpn("Initializing the chrome toolbox user profile.");
- let debuggingProfileDir = Services.dirsvc.get("ProfLD", Ci.nsIFile);
+ // We used to use `ProfLD` instead of `ProfD`, so migrate old profiles if they exist.
+ this._migrateProfileDir();
+
+ let debuggingProfileDir = Services.dirsvc.get("ProfD", Ci.nsIFile);
debuggingProfileDir.append(CHROME_DEBUGGER_PROFILE_NAME);
try {
debuggingProfileDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0o755);
} catch (ex) {
// Don't re-copy over the prefs again if this profile already exists
if (ex.result === Cr.NS_ERROR_FILE_ALREADY_EXISTS) {
this._dbgProfilePath = debuggingProfileDir.path;
} else {
@@ -190,16 +193,45 @@ BrowserToolboxProcess.prototype = {
// always works:
Services.prefs.savePrefFile(prefsFile);
dumpn("Finished creating the chrome toolbox user profile at: " +
this._dbgProfilePath);
},
/**
+ * Originally, the profile was placed in `ProfLD` instead of `ProfD`. On some systems,
+ * such as macOS, `ProfLD` is in the user's Caches directory, which is not an
+ * appropriate place to store supposedly persistent profile data.
+ */
+ _migrateProfileDir() {
+ let oldDebuggingProfileDir = Services.dirsvc.get("ProfLD", Ci.nsIFile);
+ oldDebuggingProfileDir.append(CHROME_DEBUGGER_PROFILE_NAME);
+ if (!oldDebuggingProfileDir.exists()) {
+ return;
+ }
+ dumpn(`Old debugging profile exists: ${oldDebuggingProfileDir.path}`);
+ try {
+ // Remove the directory from the target location, if it exists
+ let newDebuggingProfileDir = Services.dirsvc.get("ProfD", Ci.nsIFile);
+ newDebuggingProfileDir.append(CHROME_DEBUGGER_PROFILE_NAME);
+ if (newDebuggingProfileDir.exists()) {
+ dumpn(`Removing folder at destination: ${newDebuggingProfileDir.path}`);
+ newDebuggingProfileDir.remove(true);
+ }
+ // Move profile from old to new location
+ let newDebuggingProfileParent = Services.dirsvc.get("ProfD", Ci.nsIFile);
+ oldDebuggingProfileDir.moveTo(newDebuggingProfileParent, null);
+ dumpn("Debugging profile migrated successfully");
+ } catch (e) {
+ dumpn(`Debugging profile migration failed: ${e}`);
+ }
+ },
+
+ /**
* Creates and initializes the profile & process for the remote debugger.
*/
_create: function () {
dumpn("Initializing chrome debugging process.");
let process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
this._dbgProcess = process;
process.init(Services.dirsvc.get("XREExeF", Ci.nsIFile));