Backed out changeset c1319f301eb0 (bug 1060464) for devtools bustage
authorWes Kocher <wkocher@mozilla.com>
Tue, 02 Sep 2014 18:02:01 -0700
changeset 203395 19ad1a4a9bb2d7bc7e8643cd732baec1f419b71c
parent 203394 c1319f301eb0ef895a6f5ac73a499d2eb993de36
child 203396 c8dc98469fc0950aef15c589473f4440cd19e115
push id48665
push userryanvm@gmail.com
push dateWed, 03 Sep 2014 20:40:15 +0000
treeherdermozilla-inbound@0da762e6868a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1060464
milestone35.0a1
backs outc1319f301eb0ef895a6f5ac73a499d2eb993de36
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
Backed out changeset c1319f301eb0 (bug 1060464) for devtools bustage
browser/devtools/framework/ToolboxProcess.jsm
--- a/browser/devtools/framework/ToolboxProcess.jsm
+++ b/browser/devtools/framework/ToolboxProcess.jsm
@@ -3,17 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 "use strict";
 
 const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
 
 const DBG_XUL = "chrome://browser/content/devtools/framework/toolbox-process-window.xul";
-const CHROME_DEBUGGER_PROFILE_NAME = "chrome_debugger_profile";
+const CHROME_DEBUGGER_PROFILE_NAME = "-chrome-debugger";
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm")
 
 XPCOMUtils.defineLazyModuleGetter(this, "DevToolsLoader",
   "resource://gre/modules/devtools/Loader.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "devtools",
   "resource://gre/modules/devtools/Loader.jsm");
@@ -149,43 +149,64 @@ 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);
-    debuggingProfileDir.append(CHROME_DEBUGGER_PROFILE_NAME);
+    let profileService = Cc["@mozilla.org/toolkit/profile-service;1"]
+      .createInstance(Ci.nsIToolkitProfileService);
+
+    let profileName;
     try {
-      debuggingProfileDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0o755);
-    } catch (ex) {
-      if (ex.result !== Cr.NS_ERROR_FILE_ALREADY_EXISTS) {
-        dumpn("Error trying to create a profile directory, failing.");
-        dumpn("Error: " + (ex.message || ex));
-        return;
-      }
+      // Attempt to get the required chrome debugging profile name string.
+      profileName = profileService.selectedProfile.name + CHROME_DEBUGGER_PROFILE_NAME;
+      dumpn("Using chrome toolbox profile name: " + profileName);
+    } catch (e) {
+      // Requested profile string could not be retrieved.
+      profileName = CHROME_DEBUGGER_PROFILE_NAME;
+      let msg = "Querying the current profile failed. " + e.name + ": " + e.message;
+      dumpn(msg);
+      Cu.reportError(msg);
     }
 
-    this._dbgProfilePath = debuggingProfileDir.path;
+    let profileObject;
+    try {
+      // Attempt to get the required chrome debugging profile toolkit object.
+      profileObject = profileService.getProfileByName(profileName);
+      dumpn("Using chrome toolbox profile object: " + profileObject);
 
-    // We would like to copy prefs into this new profile...
-    let prefsFile = debuggingProfileDir.clone();
-    prefsFile.append("prefs.js");
-    // ... but unfortunately, when we run tests, it seems the starting profile
-    // clears out the prefs file before re-writing it, and in practice the
-    // file is empty when we get here. So just copying doesn't work in that
-    // case.
-    // We could force a sync pref flush and then copy it... but if we're doing
-    // that, we might as well just flush directly to the new profile, which
-    // always works:
-    Services.prefs.savePrefFile(prefsFile);
+      // The profile exists but the corresponding folder may have been deleted.
+      var enumerator = Services.dirsvc.get("ProfD", Ci.nsIFile).parent.directoryEntries;
+      while (enumerator.hasMoreElements()) {
+        let profileDir = enumerator.getNext().QueryInterface(Ci.nsIFile);
+        if (profileDir.leafName.contains(profileName)) {
+          // Requested profile was found and the folder exists.
+          this._dbgProfile = profileObject;
+          return;
+        }
+      }
+      // Requested profile was found but the folder was deleted. Cleanup needed.
+      profileObject.remove(true);
+      dumpn("The already existing chrome toolbox profile was invalid.");
+    } catch (e) {
+      // Requested profile object was not found.
+      let msg = "Creating a profile failed. " + e.name + ": " + e.message;
+      dumpn(msg);
+      Cu.reportError(msg);
+    }
 
-    dumpn("Finished creating the chrome toolbox user profile at: " + this._dbgProfilePath);
+    // Create a new chrome debugging profile.
+    this._dbgProfile = profileService.createProfile(null, profileName);
+    profileService.flush();
+
+    dumpn("Finished creating the chrome toolbox user profile.");
+    dumpn("Flushed profile service with: " + profileName);
   },
 
   /**
    * Creates and initializes the profile & process for the remote debugger.
    */
   _create: function() {
     dumpn("Initializing chrome debugging process.");
     let process = this._dbgProcess = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
@@ -193,17 +214,17 @@ BrowserToolboxProcess.prototype = {
 
     let xulURI = DBG_XUL;
 
     if (this._options.addonID) {
       xulURI += "?addonID=" + this._options.addonID;
     }
 
     dumpn("Running chrome debugging process.");
-    let args = ["-no-remote", "-foreground", "-profile", this._dbgProfilePath, "-chrome", xulURI];
+    let args = ["-no-remote", "-foreground", "-P", this._dbgProfile.name, "-chrome", xulURI];
 
     process.runwAsync(args, args.length, { observe: () => this.close() });
 
     this._telemetry.toolOpened("jsbrowserdebugger");
 
     dumpn("Chrome toolbox is now running...");
     this.emit("run", this);
   },