Bug 1059390 - Part 1: Allow remote Breakpad ID to be stored in crash metadata. r=gps
authorBirunthan Mohanathas <birunthan@mohanathas.com>
Thu, 28 Aug 2014 21:03:02 -0700
changeset 223830 28176a2e986134abd737cd2a5936aa82efbc20e8
parent 223829 688a1864cd588fd6d63e98f9239878bd2797834b
child 223831 47551e5606d5e016f1dd108e6770be2a46894a4c
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs1059390
milestone34.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 1059390 - Part 1: Allow remote Breakpad ID 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
@@ -363,16 +363,31 @@ this.CrashManager.prototype = Object.fre
       let store = yield this._getStore();
       if (store.addCrash(processType, crashType, id, date)) {
         yield store.save();
       }
     }.bind(this));
   },
 
   /**
+   * Record the remote ID for a crash.
+   *
+   * @param crashID (string) Crash ID. Likely a UUID.
+   * @param remoteID (Date) Server/Breakpad ID.
+   *
+   * @return boolean True if the remote ID was recorded.
+   */
+  setRemoteCrashID: Task.async(function* (crashID, remoteID) {
+    let store = yield this._getStore();
+    if (store.setRemoteCrashID(crashID, remoteID)) {
+      yield store.save();
+    }
+  }),
+
+  /**
    * Record the occurrence of a submission attempt for a crash.
    *
    * @param crashID (string) Crash ID. Likely a UUID.
    * @param submissionID (string) Submission ID. Likely a UUID.
    * @param date (Date) When the attempt occurred.
    *
    * @return boolean True if the attempt was recorded and false if not.
    */
@@ -1000,16 +1015,17 @@ CrashStore.prototype = Object.freeze({
     if (count > this.HIGH_WATER_DAILY_THRESHOLD &&
         processType != CrashManager.prototype.PROCESS_TYPE_MAIN) {
       return null;
     }
 
     if (!this._data.crashes.has(id)) {
       this._data.crashes.set(id, {
         id: id,
+        remoteID: null,
         type: type,
         crashDate: date,
         submissions: new Map(),
       });
     }
 
     let crash = this._data.crashes.get(id);
     crash.type = type;
@@ -1027,16 +1043,29 @@ CrashStore.prototype = Object.freeze({
    * @param date (Date) When the crash occurred.
    *
    * @return boolean True if the crash was recorded and false if not.
    */
   addCrash: function (processType, crashType, id, date) {
     return !!this._ensureCrashRecord(processType, crashType, id, date);
   },
 
+  /**
+   * @return boolean True if the remote ID was recorded and false if not.
+   */
+  setRemoteCrashID: function (crashID, remoteID) {
+    let crash = this._data.crashes.get(crashID);
+    if (!crash || !remoteID) {
+      return false;
+    }
+
+    crash.remoteID = remoteID;
+    return true;
+  },
+
   getCrashesOfType: function (processType, crashType) {
     let crashes = [];
     for (let crash of this.crashes) {
       if (crash.isOfType(processType, crashType)) {
         crashes.push(crash);
       }
     }
 
@@ -1121,16 +1150,20 @@ function CrashRecord(o) {
   this._o = o;
 }
 
 CrashRecord.prototype = Object.freeze({
   get id() {
     return this._o.id;
   },
 
+  get remoteID() {
+    return this._o.remoteID;
+  },
+
   get crashDate() {
     return this._o.crashDate;
   },
 
   /**
    * Obtain the newest date in this record.
    *
    * This is a convenience getter. The returned value is used to determine when
--- a/toolkit/components/crashes/tests/xpcshell/test_crash_manager.js
+++ b/toolkit/components/crashes/tests/xpcshell/test_crash_manager.js
@@ -348,8 +348,17 @@ add_task(function* test_addSubmissionAtt
   Assert.ok(!!submissions);
 
   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_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
@@ -85,26 +85,28 @@ add_task(function test_save_load() {
   yield s.save();
 
   let d1 = new Date();
   let d2 = new Date(d1.getTime() - 10000);
   Assert.ok(s.addCrash(PROCESS_TYPE_MAIN, CRASH_TYPE_CRASH, "id1", d1));
   Assert.ok(s.addCrash(PROCESS_TYPE_MAIN, CRASH_TYPE_CRASH, "id2", d2));
   Assert.ok(s.addSubmissionAttempt("id1", "sub1", d1));
   Assert.ok(s.addSubmissionResult("id1", "sub1", d2, SUBMISSION_RESULT_OK));
+  Assert.ok(s.setRemoteCrashID("id1", "bp-1"));
 
   yield s.save();
 
   yield s.load();
   Assert.ok(!s.corruptDate);
   let crashes = s.crashes;
 
   Assert.equal(crashes.length, 2);
   let c = s.getCrash("id1");
   Assert.equal(c.crashDate.getTime(), d1.getTime());
+  Assert.equal(c.remoteID, "bp-1");
 
   Assert.ok(!!c.submissions);
   let submission = c.submissions.get("sub1");
   Assert.ok(!!submission);
   Assert.equal(submission.requestDate.getTime(), d1.getTime());
   Assert.equal(submission.responseDate.getTime(), d2.getTime());
   Assert.equal(submission.result, SUBMISSION_RESULT_OK);
 });
@@ -549,8 +551,19 @@ add_task(function* test_convertSubmissio
   Assert.equal(submission.responseDate.getTime(), DUMMY_DATE.getTime());
 
   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_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");
+});
+