Truly independent web browser
LibWebView: Delete expired crash reports while the browser runs
Andreas Kling8692a9eb8d7c
diff --git a/Libraries/LibWebView/Application.cpp b/Libraries/LibWebView/Application.cppindex dbdd663aeab..f37c64b8e79 100644--- a/Libraries/LibWebView/Application.cpp+++ b/Libraries/LibWebView/Application.cpp@@ -739,6 +739,8 @@ ErrorOr<void> Application::initialize(Main::Arguments const& arguments)if (!m_event_loop)m_event_loop = &create_platform_event_loop();+ if (captures_browser_crashes())+ CrashReportOutbox::the().start_removing_expired_reports();// NB: The host's thread makes an event loop, which would install the default event loop manager if the platform// one were not installed yet.diff --git a/Libraries/LibWebView/CrashReportOutbox.cpp b/Libraries/LibWebView/CrashReportOutbox.cppindex fbeb28dc9f0..35fad15edf4 100644--- a/Libraries/LibWebView/CrashReportOutbox.cpp+++ b/Libraries/LibWebView/CrashReportOutbox.cpp@@ -10,6 +10,8 @@namespace WebView {+static constexpr auto expiry_interval = AK::Duration::from_seconds(60 * 60);+CrashReportOutbox& CrashReportOutbox::the(){static NeverDestroyed<CrashReportOutbox> outbox;@@ -167,6 +169,23 @@ size_t CrashReportOutbox::waiting_report_count() constreturn count;}+void CrashReportOutbox::start_removing_expired_reports()+{+ VERIFY(!m_expiry_timer);+ m_expiry_timer = Core::Timer::create_repeating(expiry_interval, [this] { remove_expired_reports(); });+ m_expiry_timer->start();+}++// The browser can stay open for longer than a report may wait. Whatever is on its way now can wait for the next run.+void CrashReportOutbox::remove_expired_reports()+{+ if (m_report_being_sent.has_value() || !m_queue.is_empty() || !m_submissions_from_reviews.is_empty())+ return;+ if (auto result = m_store.remove_expired_reports(); result.is_error())+ warnln("Could not remove expired crash reports: {}", result.error());+ reports_changed();+}+void CrashReportOutbox::reports_changed(){for (auto& observer : m_observers)diff --git a/Libraries/LibWebView/CrashReportOutbox.h b/Libraries/LibWebView/CrashReportOutbox.hindex f3af1b67796..70f7eb312c2 100644--- a/Libraries/LibWebView/CrashReportOutbox.h+++ b/Libraries/LibWebView/CrashReportOutbox.h@@ -11,6 +11,7 @@#include <AK/Optional.h>#include <AK/String.h>#include <AK/Vector.h>+#include <LibCore/Timer.h>#include <LibWebView/CrashReportReview.h>#include <LibWebView/Forward.h>@@ -33,6 +34,9 @@ public:explicit CrashReportOutbox(CrashReportStore& = CrashReportStore::the());+ // NB: A timer needs the event loop manager, and an observer can create the outbox before the platform's is installed.+ void start_removing_expired_reports();+void send(Vector<Report>);// Sends the report a review has open, for a review that shows the sending itself. Returns why nothing was sent, or@@ -63,6 +67,7 @@ public:private:void send_next();void report_failed();+ void remove_expired_reports();CrashReportStore& m_store;CrashReportReview m_review;@@ -72,6 +77,7 @@ private:HashMap<ByteString, Optional<CrashReportReview::PreparedSubmission>> m_could_not_send;bool m_report_being_sent_was_retried { false };Vector<CrashReportOutboxObserver&> m_observers;+ RefPtr<Core::Timer> m_expiry_timer;};class WEBVIEW_API CrashReportOutboxObserver {