Bug 814086 - Limit the size of the pending queue of crash reports to 10. r=bsmedberg

--HG--
extra : rebase_source : d4cb9a6f65d0838609b2f723f527ae90ba966459
This commit is contained in:
Hubert Figuière 2012-12-11 17:06:48 -05:00
parent 94337d3c59
commit e6bc42aed0
2 changed files with 53 additions and 2 deletions

View File

@ -107,6 +107,9 @@ var shell = {
return;
}
// purge the queue.
this.CrashSubmit.pruneSavedDumps();
try {
// Check if we should automatically submit this crash.
if (Services.prefs.getBoolPref("app.reportCrashes")) {
@ -135,7 +138,7 @@ var shell = {
&& network.type == Ci.nsINetworkInterface.NETWORK_TYPE_WIFI) {
shell.CrashSubmit.submit(aCrashID);
// purge the queue.
// submit the pending queue.
let pending = shell.CrashSubmit.pendingIDs();
for (let crashid of pending) {
shell.CrashSubmit.submit(crashid);

View File

@ -100,7 +100,6 @@ function getAllPendingMinidumpsIDs() {
while (entries.hasMoreElements()) {
let entry = entries.getNext().QueryInterface(Ci.nsIFile);
if (entry.isFile()) {
entry.leafName
let matches = entry.leafName.match(/(.+)\.extra$/);
if (matches)
minidumps.push(matches[1]);
@ -110,6 +109,48 @@ function getAllPendingMinidumpsIDs() {
return minidumps;
}
function pruneSavedDumps() {
const KEEP = 10;
let pendingDir = getPendingDir();
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.sort(function(a,b) {
let dateA = a.lastModifiedTime;
let dateB = b.lastModifiedTime;
if (dateA < dateB)
return -1;
if (dateB < dateA)
return 1;
return 0;
});
if (entriesArray.length > KEEP) {
for (let i = 0; i < entriesArray.length - KEEP; ++i) {
let extra = entriesArray[i];
let matches = extra.leafName.match(/(.+)\.extra$/);
if (matches) {
let dump = extra.clone();
dump.leafName = matches[1] + '.dmp';
dump.remove(false);
extra.remove(false);
}
}
}
}
function addFormEntry(doc, form, name, value) {
var input = doc.createElement("input");
input.type = "hidden";
@ -387,6 +428,13 @@ this.CrashSubmit = {
return getAllPendingMinidumpsIDs();
},
/**
* Prune the saved dumps.
*/
pruneSavedDumps: function CrashSubmit_pruneSavedDumps() {
pruneSavedDumps();
},
// List of currently active submit objects
_activeSubmissions: []
};