Bug 1798711 - Remove duplication of DisableCrashReporter on gtest r=ahal
[gecko.git] / toolkit / crashreporter / CrashReports.jsm
blob9cab0419afd7158018f51fca30c720cb8879e466
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 var EXPORTED_SYMBOLS = ["CrashReports"];
7 var CrashReports = {
8   pendingDir: null,
9   reportsDir: null,
10   submittedDir: null,
11   getReports: function CrashReports_getReports() {
12     let reports = [];
14     try {
15       // Ignore any non http/https urls
16       if (!/^https?:/i.test(Services.prefs.getCharPref("breakpad.reportURL"))) {
17         return reports;
18       }
19     } catch (e) {}
21     if (this.submittedDir.exists() && this.submittedDir.isDirectory()) {
22       let entries = this.submittedDir.directoryEntries;
23       while (entries.hasMoreElements()) {
24         let file = entries.nextFile;
25         let leaf = file.leafName;
26         if (leaf.startsWith("bp-") && leaf.endsWith(".txt")) {
27           let entry = {
28             id: leaf.slice(0, -4),
29             date: file.lastModifiedTime,
30             pending: false,
31           };
32           reports.push(entry);
33         }
34       }
35     }
37     if (this.pendingDir.exists() && this.pendingDir.isDirectory()) {
38       let uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
39       let entries = this.pendingDir.directoryEntries;
40       while (entries.hasMoreElements()) {
41         let file = entries.nextFile;
42         let leaf = file.leafName;
43         let id = leaf.slice(0, -4);
44         if (leaf.endsWith(".dmp") && uuidRegex.test(id)) {
45           let entry = {
46             id,
47             date: file.lastModifiedTime,
48             pending: true,
49           };
50           reports.push(entry);
51         }
52       }
53     }
55     // Sort reports descending by date
56     return reports.sort((a, b) => b.date - a.date);
57   },
60 function CrashReports_pendingDir() {
61   let pendingDir = Services.dirsvc.get("UAppData", Ci.nsIFile);
62   pendingDir.append("Crash Reports");
63   pendingDir.append("pending");
64   return pendingDir;
67 function CrashReports_reportsDir() {
68   let reportsDir = Services.dirsvc.get("UAppData", Ci.nsIFile);
69   reportsDir.append("Crash Reports");
70   return reportsDir;
73 function CrashReports_submittedDir() {
74   let submittedDir = Services.dirsvc.get("UAppData", Ci.nsIFile);
75   submittedDir.append("Crash Reports");
76   submittedDir.append("submitted");
77   return submittedDir;
80 CrashReports.pendingDir = CrashReports_pendingDir();
81 CrashReports.reportsDir = CrashReports_reportsDir();
82 CrashReports.submittedDir = CrashReports_submittedDir();