Bug 1024672 - Part 3: Remove CrashManager.addSubmission in favor of CrashManager.addSubmission{Attempt,Result}. r=gps

This commit is contained in:
Birunthan Mohanathas 2014-08-21 15:43:50 -07:00
parent 1c081f8552
commit b809847eaf
7 changed files with 25 additions and 165 deletions

View File

@ -504,8 +504,7 @@ var gPluginHandler = {
keyVals.PluginContentURL = plugin.ownerDocument.URL;
}
let pluginProcessType = Services.crashmanager.PROCESS_TYPE_PLUGIN;
this.CrashSubmit.submit(pluginDumpID, { processType: pluginProcessType,
this.CrashSubmit.submit(pluginDumpID, { recordSubmission: true,
extraExtraKeyVals: keyVals });
if (browserDumpID)
this.CrashSubmit.submit(browserDumpID);

View File

@ -58,8 +58,7 @@ this.TabCrashReporter = {
if (!dumpID)
return
let contentProcessType = Services.crashmanager.PROCESS_TYPE_CONTENT;
if (CrashSubmit.submit(dumpID, { processType: contentProcessType })) {
if (CrashSubmit.submit(dumpID, { recordSubmission: true })) {
this.childMap.set(childID, null); // Avoid resubmission.
}
},

View File

@ -50,17 +50,9 @@ add_task(function* test_collect() {
yield manager.addCrash(manager.PROCESS_TYPE_MAIN,
manager.CRASH_TYPE_CRASH,
"mc1", day1);
yield manager.addSubmission(manager.PROCESS_TYPE_MAIN,
manager.CRASH_TYPE_CRASH,
true,
"mc1", day1)
yield manager.addCrash(manager.PROCESS_TYPE_MAIN,
manager.CRASH_TYPE_CRASH,
"mc2", day1);
yield manager.addSubmission(manager.PROCESS_TYPE_MAIN,
manager.CRASH_TYPE_CRASH,
false,
"mc2", day1)
yield manager.addCrash(manager.PROCESS_TYPE_CONTENT,
manager.CRASH_TYPE_HANG,
"ch", day1);
@ -74,20 +66,12 @@ add_task(function* test_collect() {
yield manager.addCrash(manager.PROCESS_TYPE_CONTENT,
manager.CRASH_TYPE_CRASH,
"cc", day2);
yield manager.addSubmission(manager.PROCESS_TYPE_CONTENT,
manager.CRASH_TYPE_CRASH,
true,
"cc", day2)
yield manager.addCrash(manager.PROCESS_TYPE_PLUGIN,
manager.CRASH_TYPE_HANG,
"ph", day2);
yield manager.addCrash(manager.PROCESS_TYPE_GMPLUGIN,
manager.CRASH_TYPE_CRASH,
"gmpc", day2);
yield manager.addSubmission(manager.PROCESS_TYPE_GMPLUGIN,
manager.CRASH_TYPE_CRASH,
true,
"gmpc", day2)
yield provider.collectDailyData();
@ -100,10 +84,6 @@ add_task(function* test_collect() {
let value = values.days.getDay(day1);
do_check_true(value.has("main-crash"));
do_check_eq(value.get("main-crash"), 2);
do_check_true(value.has("main-crash-submission-succeeded"));
do_check_eq(value.get("main-crash-submission-succeeded"), 1);
do_check_true(value.has("main-crash-submission-failed"));
do_check_eq(value.get("main-crash-submission-failed"), 1);
do_check_true(value.has("content-hang"));
do_check_eq(value.get("content-hang"), 1);
do_check_true(value.has("plugin-crash"));
@ -114,14 +94,10 @@ add_task(function* test_collect() {
do_check_eq(value.get("main-hang"), 1);
do_check_true(value.has("content-crash"));
do_check_eq(value.get("content-crash"), 1);
do_check_true(value.has("content-crash-submission-succeeded"));
do_check_eq(value.get("content-crash-submission-succeeded"), 1);
do_check_true(value.has("plugin-hang"));
do_check_eq(value.get("plugin-hang"), 1);
do_check_true(value.has("gmplugin-crash"));
do_check_eq(value.get("gmplugin-crash"), 1);
do_check_true(value.has("gmplugin-crash-submission-succeeded"));
do_check_eq(value.get("gmplugin-crash-submission-succeeded"), 1);
// Check that adding a new crash increments counter on next collect.
yield manager.addCrash(manager.PROCESS_TYPE_MAIN,

View File

@ -133,21 +133,12 @@ this.CrashManager.prototype = Object.freeze({
// A crash in a Gecko media plugin process.
PROCESS_TYPE_GMPLUGIN: "gmplugin",
// A submission of a crash.
PROCESS_TYPE_SUBMISSION: "submission",
// A real crash.
CRASH_TYPE_CRASH: "crash",
// A hang.
CRASH_TYPE_HANG: "hang",
// A successful submission.
SUBMISSION_TYPE_SUCCEEDED: "succeeded",
// A failed submission.
SUBMISSION_TYPE_FAILED: "failed",
// Submission result values.
SUBMISSION_RESULT_OK: "ok",
SUBMISSION_RESULT_FAILED: "failed",
@ -376,38 +367,6 @@ this.CrashManager.prototype = Object.freeze({
}.bind(this));
},
/**
* Record the occurrence of a crash submission.
*
* @param processType (string) One of the PROCESS_TYPE constants.
* @param crashType (string) One of the CRASH_TYPE constants.
* @param succeeded (boolean) Whether the submission succeeded.
* @param id (string) Crash ID. Likely a UUID.
* @param date (Date) When the crash occurred.
*
* @return boolean True if the crash submission was recorded and false if not.
*/
addSubmission: function (processType, crashType, succeeded, id, date) {
return Task.spawn(function* () {
let store = yield this._getStore();
if (this._addSubmissionAsCrash(store, processType, crashType, succeeded,
id, date)) {
yield store.save();
}
}.bind(this));
},
_addSubmissionAsCrash: function (store, processType, crashType, succeeded,
id, date) {
id += "-" + this.PROCESS_TYPE_SUBMISSION;
let process = processType + "-" + crashType + "-" +
this.PROCESS_TYPE_SUBMISSION;
let submission_type = (
succeeded ? this.SUBMISSION_TYPE_SUCCEEDED : this.SUBMISSION_TYPE_FAILED);
return store.addCrash(process, submission_type, id, date);
},
/**
* Record the occurrence of a submission attempt for a crash.
*

View File

@ -329,44 +329,6 @@ add_task(function* test_addCrash() {
Assert.ok(crash.isOfType(m.PROCESS_TYPE_CONTENT, m.CRASH_TYPE_HANG));
});
add_task(function* test_addSubmission() {
let m = yield getManager();
let crashes = yield m.getCrashes();
Assert.equal(crashes.length, 0);
yield m.addSubmission(m.PROCESS_TYPE_MAIN, m.CRASH_TYPE_CRASH, true,
"success", DUMMY_DATE);
yield m.addSubmission(m.PROCESS_TYPE_MAIN, m.CRASH_TYPE_CRASH, false,
"failure", DUMMY_DATE);
crashes = yield m.getCrashes();
Assert.equal(crashes.length, 2);
let map = new Map(crashes.map(crash => [crash.id, crash]));
let crash = map.get("success-submission");
Assert.ok(!!crash);
Assert.equal(crash.crashDate, DUMMY_DATE);
Assert.equal(crash.type,
m.PROCESS_TYPE_MAIN + "-" + m.CRASH_TYPE_CRASH + "-" +
m.PROCESS_TYPE_SUBMISSION + "-" + m.SUBMISSION_TYPE_SUCCEEDED);
Assert.ok(
crash.isOfType(m.PROCESS_TYPE_MAIN + "-" + m.CRASH_TYPE_CRASH + "-" +
m.PROCESS_TYPE_SUBMISSION, m.SUBMISSION_TYPE_SUCCEEDED));
let crash = map.get("failure-submission");
Assert.ok(!!crash);
Assert.equal(crash.crashDate, DUMMY_DATE);
Assert.equal(crash.type,
m.PROCESS_TYPE_MAIN + "-" + m.CRASH_TYPE_CRASH + "-" +
m.PROCESS_TYPE_SUBMISSION + "-" + m.SUBMISSION_TYPE_FAILED);
Assert.ok(
crash.isOfType(m.PROCESS_TYPE_MAIN + "-" + m.CRASH_TYPE_CRASH + "-" +
m.PROCESS_TYPE_SUBMISSION, m.SUBMISSION_TYPE_FAILED));
});
add_task(function* test_addSubmissionAttemptAndResult() {
let m = yield getManager();

View File

@ -24,11 +24,8 @@ const {
PROCESS_TYPE_CONTENT,
PROCESS_TYPE_PLUGIN,
PROCESS_TYPE_GMPLUGIN,
PROCESS_TYPE_SUBMISSION,
CRASH_TYPE_CRASH,
CRASH_TYPE_HANG,
SUBMISSION_TYPE_SUCCEEDED,
SUBMISSION_TYPE_FAILED,
SUBMISSION_RESULT_OK,
SUBMISSION_RESULT_FAILED,
} = CrashManager.prototype;
@ -319,44 +316,6 @@ add_task(function* test_add_gmplugin_crash() {
Assert.equal(crashes.length, 2);
});
add_task(function* test_add_submission() {
let s = yield getStore();
Assert.ok(
s.addCrash(PROCESS_TYPE_MAIN + "-" + CRASH_TYPE_CRASH + "-" +
PROCESS_TYPE_SUBMISSION, SUBMISSION_TYPE_SUCCEEDED,
"id1", new Date())
);
Assert.equal(s.crashesCount, 1);
let c = s.crashes[0];
Assert.ok(c.crashDate);
Assert.equal(c.type, PROCESS_TYPE_MAIN + "-" + CRASH_TYPE_CRASH + "-" +
PROCESS_TYPE_SUBMISSION + "-" + SUBMISSION_TYPE_SUCCEEDED);
Assert.ok(c.isOfType(PROCESS_TYPE_MAIN + "-" + CRASH_TYPE_CRASH + "-" +
PROCESS_TYPE_SUBMISSION, SUBMISSION_TYPE_SUCCEEDED));
Assert.ok(
s.addCrash(PROCESS_TYPE_MAIN + "-" + CRASH_TYPE_CRASH + "-" +
PROCESS_TYPE_SUBMISSION, SUBMISSION_TYPE_FAILED,
"id2", new Date())
);
Assert.equal(s.crashesCount, 2);
// Duplicate.
Assert.ok(
s.addCrash(PROCESS_TYPE_MAIN + "-" + CRASH_TYPE_CRASH + "-" +
PROCESS_TYPE_SUBMISSION, SUBMISSION_TYPE_SUCCEEDED,
"id1", new Date())
);
Assert.equal(s.crashesCount, 2);
let crashes = s.getCrashesOfType(PROCESS_TYPE_MAIN + "-" + CRASH_TYPE_CRASH +
"-" + PROCESS_TYPE_SUBMISSION,
SUBMISSION_TYPE_SUCCEEDED);
Assert.equal(crashes.length, 1);
});
add_task(function* test_add_mixed_types() {
let s = yield getStore();

View File

@ -185,10 +185,10 @@ function writeSubmittedReport(crashID, viewURL) {
}
// the Submitter class represents an individual submission.
function Submitter(id, processType, submitSuccess, submitError, noThrottle,
extraExtraKeyVals) {
function Submitter(id, recordSubmission, submitSuccess, submitError,
noThrottle, extraExtraKeyVals) {
this.id = id;
this.processType = processType;
this.recordSubmission = recordSubmission;
this.successCallback = submitSuccess;
this.errorCallback = submitError;
this.noThrottle = noThrottle;
@ -280,6 +280,11 @@ Submitter.prototype = {
}
}
let submissionID = Cc["@mozilla.org/uuid-generator;1"]
.getService(Ci.nsIUUIDGenerator)
.generateUUID().toString();
let manager = Services.crashmanager;
let self = this;
xhr.addEventListener("readystatechange", function (aEvt) {
if (xhr.readyState == 4) {
@ -287,13 +292,11 @@ Submitter.prototype = {
xhr.status == 200 ? parseKeyValuePairs(xhr.responseText) : {};
let submitted = !!ret.CrashID;
if (self.processType) {
// TODO: Use exact crash time?
let crashTime = new Date();
let manager = Services.crashmanager;
manager.addSubmission(self.processType, manager.CRASH_TYPE_CRASH,
submitted, submitted ? ret.CrashID : "",
crashTime);
if (self.recordSubmission) {
let result = submitted ? manager.SUBMISSION_RESULT_OK :
manager.SUBMISSION_RESULT_FAILED;
manager.addSubmissionResult(self.id, submissionID, new Date(),
result);
}
if (submitted) {
@ -306,6 +309,9 @@ Submitter.prototype = {
}
}, false);
if (this.recordSubmission) {
manager.addSubmissionAttempt(this.id, submissionID, new Date());
}
xhr.send(formData);
return true;
},
@ -397,9 +403,8 @@ this.CrashSubmit = {
* Filename (minus .dmp extension) of the minidump to submit.
* @param params
* An object containing any of the following optional parameters:
* - processType
* One of the CrashManager.PROCESS_TYPE constants. If set, a
* submission event is recorded in CrashManager.
* - recordSubmission
* If true, a submission event is recorded in CrashManager.
* - submitSuccess
* A function that will be called if the report is submitted
* successfully with two parameters: the id that was passed
@ -428,14 +433,14 @@ this.CrashSubmit = {
submit: function CrashSubmit_submit(id, params)
{
params = params || {};
let processType = null;
let recordSubmission = false;
let submitSuccess = null;
let submitError = null;
let noThrottle = false;
let extraExtraKeyVals = null;
if ('processType' in params)
processType = params.processType;
if ('recordSubmission' in params)
recordSubmission = params.recordSubmission;
if ('submitSuccess' in params)
submitSuccess = params.submitSuccess;
if ('submitError' in params)
@ -445,7 +450,8 @@ this.CrashSubmit = {
if ('extraExtraKeyVals' in params)
extraExtraKeyVals = params.extraExtraKeyVals;
let submitter = new Submitter(id, processType, submitSuccess, submitError,
let submitter = new Submitter(id, recordSubmission,
submitSuccess, submitError,
noThrottle, extraExtraKeyVals);
CrashSubmit._activeSubmissions.push(submitter);
return submitter.submit();