Bug 994708 - Part 1: Cleanup CrashSubmit.jsm. r=gps
authorBirunthan Mohanathas <birunthan@mohanathas.com>
Fri, 20 Jun 2014 08:31:29 -0700
changeset 190352 56246d479b89f750abbe4c577687c0640b5875fd
parent 190351 4413df3a4694b763aa775153b980c95a2f639aa7
child 190353 43a7ce129020b6c34182b6750f521fe5b7f43077
push id27004
push useremorley@mozilla.com
push dateTue, 24 Jun 2014 15:52:34 +0000
treeherdermozilla-central@7b174d47f3cc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs994708
milestone33.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 994708 - Part 1: Cleanup CrashSubmit.jsm. r=gps
toolkit/crashreporter/CrashSubmit.jsm
--- a/toolkit/crashreporter/CrashSubmit.jsm
+++ b/toolkit/crashreporter/CrashSubmit.jsm
@@ -66,37 +66,54 @@ function getL10nStrings() {
     crstrings = parseINIStrings(path);
     if ('CrashID' in crstrings)
       strings['crashid'] = crstrings.CrashID;
     if ('CrashDetailsURL' in crstrings)
       strings['reporturl'] = crstrings.CrashDetailsURL;
   }
 }
 
-function getPendingDir() {
+function getDir(name) {
   let directoryService = Cc["@mozilla.org/file/directory_service;1"].
                          getService(Ci.nsIProperties);
-  let pendingDir = directoryService.get("UAppData", Ci.nsIFile);
-  pendingDir.append("Crash Reports");
-  pendingDir.append("pending");
-  return pendingDir;
+  let dir = directoryService.get("UAppData", Ci.nsIFile);
+  dir.append("Crash Reports");
+  dir.append(name);
+  return dir;
+}
+
+function writeFile(dirName, fileName, data) {
+  let path = getDir(dirName);
+  if (!path.exists())
+    path.create(Ci.nsIFile.DIRECTORY_TYPE, 0700);
+  path.append(fileName);
+  var fs = Cc["@mozilla.org/network/file-output-stream;1"].
+           createInstance(Ci.nsIFileOutputStream);
+  // open, write, truncate
+  fs.init(path, -1, -1, 0);
+  var os = Cc["@mozilla.org/intl/converter-output-stream;1"].
+           createInstance(Ci.nsIConverterOutputStream);
+  os.init(fs, "UTF-8", 0, 0x0000);
+  os.writeString(data);
+  os.close();
+  fs.close();
 }
 
 function getPendingMinidump(id) {
-  let pendingDir = getPendingDir();
+  let pendingDir = getDir("pending");
   let dump = pendingDir.clone();
   let extra = pendingDir.clone();
   dump.append(id + ".dmp");
   extra.append(id + ".extra");
   return [dump, extra];
 }
 
 function getAllPendingMinidumpsIDs() {
   let minidumps = [];
-  let pendingDir = getPendingDir();
+  let pendingDir = getDir("pending");
 
   if (!(pendingDir.exists() && pendingDir.isDirectory()))
     return [];
   let entries = pendingDir.directoryEntries;
 
   while (entries.hasMoreElements()) {
     let entry = entries.getNext().QueryInterface(Ci.nsIFile);
     if (entry.isFile()) {
@@ -107,28 +124,28 @@ function getAllPendingMinidumpsIDs() {
   }
 
   return minidumps;
 }
 
 function pruneSavedDumps() {
   const KEEP = 10;
 
-  let pendingDir = getPendingDir();
+  let pendingDir = getDir("pending");
   if (!(pendingDir.exists() && pendingDir.isDirectory()))
     return;
   let entries = pendingDir.directoryEntries;
   let entriesArray = [];
 
   while (entries.hasMoreElements()) {
     let entry = entries.getNext().QueryInterface(Ci.nsIFile);
     if (entry.isFile()) {
       let matches = entry.leafName.match(/(.+)\.extra$/);
       if (matches)
-	entriesArray.push(entry);
+        entriesArray.push(entry);
     }
   }
 
   entriesArray.sort(function(a,b) {
     let dateA = a.lastModifiedTime;
     let dateB = b.lastModifiedTime;
     if (dateA < dateB)
       return -1;
@@ -155,39 +172,21 @@ function addFormEntry(doc, form, name, v
   var input = doc.createElement("input");
   input.type = "hidden";
   input.name = name;
   input.value = value;
   form.appendChild(input);
 }
 
 function writeSubmittedReport(crashID, viewURL) {
-  let directoryService = Cc["@mozilla.org/file/directory_service;1"].
-                           getService(Ci.nsIProperties);
-  let reportFile = directoryService.get("UAppData", Ci.nsIFile);
-  reportFile.append("Crash Reports");
-  reportFile.append("submitted");
-  if (!reportFile.exists())
-    reportFile.create(Ci.nsIFile.DIRECTORY_TYPE, 0700);
-  reportFile.append(crashID + ".txt");
-  var fstream = Cc["@mozilla.org/network/file-output-stream;1"].
-                createInstance(Ci.nsIFileOutputStream);
-  // open, write, truncate
-  fstream.init(reportFile, -1, -1, 0);
-  var os = Cc["@mozilla.org/intl/converter-output-stream;1"].
-           createInstance(Ci.nsIConverterOutputStream);
-  os.init(fstream, "UTF-8", 0, 0x0000);
-
   var data = strings.crashid.replace("%s", crashID);
   if (viewURL)
      data += "\n" + strings.reporturl.replace("%s", viewURL);
 
-  os.writeString(data);
-  os.close();
-  fstream.close();
+  writeFile("submitted", crashID + ".txt", data);
 }
 
 // the Submitter class represents an individual submission.
 function Submitter(id, submitSuccess, submitError, noThrottle,
                    extraExtraKeyVals) {
   this.id = id;
   this.successCallback = submitSuccess;
   this.errorCallback = submitError;