Bug 1024672 - Part 5: Allow classifications to be stored in crash metadata. r=gps
authorBirunthan Mohanathas <birunthan@mohanathas.com>
Tue, 02 Sep 2014 09:55:16 -0700
changeset 203628 56475acd5100a3438949d8c1e0fdaffc6e2572c1
parent 203627 19997663ce0abf785e97e7c0b1b1bba8c572b908
child 203629 565868ef8a29a3a369018b4e1e5c4700e24c9ac1
push id27433
push userkwierso@gmail.com
push dateFri, 05 Sep 2014 01:31:29 +0000
treeherdermozilla-central@db7212847c14 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs1024672
milestone35.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 1024672 - Part 5: Allow classifications to be stored in crash metadata. r=gps
toolkit/components/crashes/CrashManager.jsm
toolkit/components/crashes/tests/xpcshell/test_crash_manager.js
toolkit/components/crashes/tests/xpcshell/test_crash_store.js
--- a/toolkit/components/crashes/CrashManager.jsm
+++ b/toolkit/components/crashes/CrashManager.jsm
@@ -415,16 +415,31 @@ this.CrashManager.prototype = Object.fre
   addSubmissionResult: Task.async(function* (crashID, submissionID, date, result) {
     let store = yield this._getStore();
     if (store.addSubmissionResult(crashID, submissionID, date, result)) {
       yield store.save();
     }
   }),
 
   /**
+   * Set the classification of a crash.
+   *
+   * @param crashID (string) Crash ID. Likely a UUID.
+   * @param classification (string) Crash classification/reason.
+   *
+   * @return boolean True if the classification was recorded and false if not.
+   */
+  setCrashClassification: Task.async(function* (crashID, classification) {
+    let store = yield this._getStore();
+    if (store.setCrashClassification(crashID, classification)) {
+      yield store.save();
+    }
+  }),
+
+  /**
    * Obtain the paths of all unprocessed events files.
    *
    * The promise-resolved array is sorted by file mtime, oldest to newest.
    */
   _getUnprocessedEventsFiles: function () {
     return Task.spawn(function* () {
       let entries = [];
 
@@ -1057,16 +1072,17 @@ CrashStore.prototype = Object.freeze({
       }
 
       this._data.crashes.set(id, {
         id: id,
         remoteID: null,
         type: type,
         crashDate: date,
         submissions: new Map(),
+        classification: null,
       });
     }
 
     let crash = this._data.crashes.get(id);
     crash.type = type;
     crash.crashDate = date;
 
     return crash;
@@ -1165,16 +1181,29 @@ CrashStore.prototype = Object.freeze({
     if (!submission) {
       return false;
     }
 
     submission.responseDate = date;
     submission.result = result;
     return true;
   },
+
+  /**
+   * @return boolean True if the classification was set.
+   */
+  setCrashClassification: function (crashID, classification) {
+    let crash = this._data.crashes.get(crashID);
+    if (!crash) {
+      return false;
+    }
+
+    crash.classification = classification;
+    return true;
+  },
 });
 
 /**
  * Represents an individual crash with metadata.
  *
  * This is a wrapper around the low-level anonymous JS objects that define
  * crashes. It exposes a consistent and helpful API.
  *
@@ -1222,16 +1251,20 @@ CrashRecord.prototype = Object.freeze({
 
   isOfType: function (processType, crashType) {
     return processType + "-" + crashType == this.type;
   },
 
   get submissions() {
     return this._o.submissions;
   },
+
+  get classification() {
+    return this._o.classification;
+  },
 });
 
 /**
  * Obtain the global CrashManager instance used by the running application.
  *
  * CrashManager is likely only ever instantiated once per application lifetime.
  * The main reason it's implemented as a reusable type is to facilitate testing.
  */
--- a/toolkit/components/crashes/tests/xpcshell/test_crash_manager.js
+++ b/toolkit/components/crashes/tests/xpcshell/test_crash_manager.js
@@ -391,16 +391,25 @@ add_task(function* test_addSubmissionAtt
 
   let submission = submissions.get("submission");
   Assert.ok(!!submission);
   Assert.equal(submission.requestDate.getTime(), DUMMY_DATE.getTime());
   Assert.equal(submission.responseDate.getTime(), DUMMY_DATE_2.getTime());
   Assert.equal(submission.result, m.SUBMISSION_RESULT_OK);
 });
 
+add_task(function* test_setCrashClassification() {
+  let m = yield getManager();
+
+  yield m.addCrash(m.PROCESS_TYPE_MAIN, m.CRASH_TYPE_CRASH,
+                   "main-crash", DUMMY_DATE);
+  yield m.setCrashClassification("main-crash", "class");
+  Assert.equal((yield m.getCrashes())[0].classification, "class");
+});
+
 add_task(function* test_setRemoteCrashID() {
   let m = yield getManager();
 
   yield m.addCrash(m.PROCESS_TYPE_MAIN, m.CRASH_TYPE_CRASH,
                    "main-crash", DUMMY_DATE);
   yield m.setRemoteCrashID("main-crash", "bp-1");
   Assert.equal((yield m.getCrashes())[0].remoteID, "bp-1");
 });
--- a/toolkit/components/crashes/tests/xpcshell/test_crash_store.js
+++ b/toolkit/components/crashes/tests/xpcshell/test_crash_store.js
@@ -561,16 +561,27 @@ add_task(function* test_convertSubmissio
 
   submission = s.getSubmission("hang1", "converted");
   Assert.ok(!!submission);
   Assert.equal(submission.result, SUBMISSION_RESULT_FAILED);
   Assert.equal(submission.requestDate.getTime(), DUMMY_DATE_2.getTime());
   Assert.equal(submission.responseDate.getTime(), DUMMY_DATE_2.getTime());
 });
 
+add_task(function* test_setCrashClassification() {
+  let s = yield getStore();
+
+  Assert.ok(s.addCrash(PROCESS_TYPE_MAIN, CRASH_TYPE_CRASH, "crash1",
+                       new Date()));
+  Assert.equal(s.crashes[0].classification, null);
+
+  Assert.ok(s.setCrashClassification("crash1", "foo"));
+  Assert.equal(s.crashes[0].classification, "foo");
+});
+
 add_task(function* test_setRemoteCrashID() {
   let s = yield getStore();
 
   Assert.ok(s.addCrash(PROCESS_TYPE_MAIN, CRASH_TYPE_CRASH, "crash1",
                        new Date()));
   Assert.equal(s.crashes[0].remoteID, null);
   Assert.ok(s.setRemoteCrashID("crash1", "bp-1"));
   Assert.equal(s.crashes[0].remoteID, "bp-1");