diff --git a/client/crash_report_database_mac.mm b/client/crash_report_database_mac.mm index e72838a0..c6abe8aa 100644 --- a/client/crash_report_database_mac.mm +++ b/client/crash_report_database_mac.mm @@ -183,13 +183,14 @@ class CrashReportDatabaseMac : public CrashReportDatabase { //! \brief A private extension of the Report class that maintains bookkeeping //! information of the database. struct UploadReportMac : public UploadReport { +#if BUILDFLAG(IS_IOS) + //! \brief Obtain a background task assertion while a flock is in use. + //! Ensure this is defined first so it is destroyed last. + internal::ScopedBackgroundTask ios_background_task{"UploadReportMac"}; +#endif // BUILDFLAG(IS_IOS) //! \brief Stores the flock of the file for the duration of //! GetReportForUploading() and RecordUploadAttempt(). base::ScopedFD lock_fd; -#if BUILDFLAG(IS_IOS) - //! \brief Obtain a background task assertion while a flock is in use. - internal::ScopedBackgroundTask ios_background_task{"UploadReportMac"}; -#endif // BUILDFLAG(IS_IOS) }; //! \brief Locates a crash report in the database by UUID. diff --git a/client/settings.cc b/client/settings.cc index 8fe578f9..eef24f71 100644 --- a/client/settings.cc +++ b/client/settings.cc @@ -93,6 +93,11 @@ Settings::ScopedLockedFileHandle& Settings::ScopedLockedFileHandle::operator=( return *this; } +Settings::ScopedLockedFileHandle::~ScopedLockedFileHandle() { + // Call reset() to ensure the lock is released before the ios_background_task. + reset(); +} + #endif // BUILDFLAG(IS_IOS) namespace internal { diff --git a/client/settings.h b/client/settings.h index aedf30cd..8ad8a2b1 100644 --- a/client/settings.h +++ b/client/settings.h @@ -171,6 +171,8 @@ class Settings { ScopedLockedFileHandle(ScopedLockedFileHandle&& rvalue); ScopedLockedFileHandle& operator=(ScopedLockedFileHandle&& rvalue); + ~ScopedLockedFileHandle(); + private: std::unique_ptr ios_background_task_; };