Bug 814086 - Limit the size of the pending queue of crash reports to 10. r=bsmedberg
--- a/b2g/chrome/content/shell.js
+++ b/b2g/chrome/content/shell.js
@@ -102,16 +102,19 @@ var shell = {
}
} catch(e) { }
// Bail if there isn't a valid crashID.
if (!crashID) {
return;
}
+ // purge the queue.
+ this.CrashSubmit.pruneSavedDumps();
+
try {
// Check if we should automatically submit this crash.
if (Services.prefs.getBoolPref("app.reportCrashes")) {
this.submitCrash(crashID);
}
} catch (e) { }
// Let Gaia notify the user of the crash.
@@ -130,17 +133,17 @@ var shell = {
}
Services.obs.addObserver(function observer(subject, topic, state) {
let network = subject.QueryInterface(Ci.nsINetworkInterface);
if (network.state == Ci.nsINetworkInterface.NETWORK_STATE_CONNECTED
&& 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);
}
Services.obs.removeObserver(observer, topic);
}
}, "network-interface-state-changed", false);
--- a/toolkit/crashreporter/CrashSubmit.jsm
+++ b/toolkit/crashreporter/CrashSubmit.jsm
@@ -95,26 +95,67 @@ function getAllPendingMinidumpsIDs() {
if (!(pendingDir.exists() && pendingDir.isDirectory()))
return [];
let entries = pendingDir.directoryEntries;
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]);
}
}
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";
input.name = name;
input.value = value;
form.appendChild(input);
}
@@ -382,14 +423,21 @@ this.CrashSubmit = {
*
* @return an array of string, each being an ID as
* expected to be passed to submit()
*/
pendingIDs: function CrashSubmit_pendingIDs() {
return getAllPendingMinidumpsIDs();
},
+ /**
+ * Prune the saved dumps.
+ */
+ pruneSavedDumps: function CrashSubmit_pruneSavedDumps() {
+ pruneSavedDumps();
+ },
+
// List of currently active submit objects
_activeSubmissions: []
};
// Run this when first loaded
getL10nStrings();