mirror of
https://github.com/chromium/crashpad.git
synced 2024-12-27 15:32:10 +08:00
ios: Add ScopedBackgroundTask to more flock file access.
Use ScopedBackgroundTask to prevent file lock termination from happening when holding locked files in a shared AppGroup. Bug: 1313555 Change-Id: Idc0105f8ecdb65c26214a7265a216b9d480ed01d Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3573184 Reviewed-by: Robert Sesek <rsesek@chromium.org> Commit-Queue: Justin Cohen <justincohen@chromium.org>
This commit is contained in:
parent
f882d2af82
commit
646bba733b
@ -43,6 +43,10 @@
|
|||||||
#include "util/misc/initialization_state_dcheck.h"
|
#include "util/misc/initialization_state_dcheck.h"
|
||||||
#include "util/misc/metrics.h"
|
#include "util/misc/metrics.h"
|
||||||
|
|
||||||
|
#if BUILDFLAG(IS_IOS)
|
||||||
|
#include "util/ios/scoped_background_task.h"
|
||||||
|
#endif // BUILDFLAG(IS_IOS)
|
||||||
|
|
||||||
namespace crashpad {
|
namespace crashpad {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@ -182,6 +186,10 @@ class CrashReportDatabaseMac : public CrashReportDatabase {
|
|||||||
//! \brief Stores the flock of the file for the duration of
|
//! \brief Stores the flock of the file for the duration of
|
||||||
//! GetReportForUploading() and RecordUploadAttempt().
|
//! GetReportForUploading() and RecordUploadAttempt().
|
||||||
base::ScopedFD lock_fd;
|
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.
|
//! \brief Locates a crash report in the database by UUID.
|
||||||
|
@ -71,6 +71,30 @@ void Settings::ScopedLockedFileHandle::Destroy() {
|
|||||||
|
|
||||||
#else // BUILDFLAG(IS_FUCHSIA)
|
#else // BUILDFLAG(IS_FUCHSIA)
|
||||||
|
|
||||||
|
#if BUILDFLAG(IS_IOS)
|
||||||
|
|
||||||
|
Settings::ScopedLockedFileHandle::ScopedLockedFileHandle(
|
||||||
|
const FileHandle& value)
|
||||||
|
: ScopedGeneric(value) {
|
||||||
|
ios_background_task_ = std::make_unique<internal::ScopedBackgroundTask>(
|
||||||
|
"ScopedLockedFileHandle");
|
||||||
|
}
|
||||||
|
|
||||||
|
Settings::ScopedLockedFileHandle::ScopedLockedFileHandle(
|
||||||
|
Settings::ScopedLockedFileHandle&& rvalue) {
|
||||||
|
ios_background_task_.reset(rvalue.ios_background_task_.release());
|
||||||
|
reset(rvalue.release());
|
||||||
|
}
|
||||||
|
|
||||||
|
Settings::ScopedLockedFileHandle& Settings::ScopedLockedFileHandle::operator=(
|
||||||
|
Settings::ScopedLockedFileHandle&& rvalue) {
|
||||||
|
ios_background_task_.reset(rvalue.ios_background_task_.release());
|
||||||
|
reset(rvalue.release());
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // BUILDFLAG(IS_IOS)
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
// static
|
// static
|
||||||
@ -207,6 +231,10 @@ Settings::ScopedLockedFileHandle Settings::MakeScopedLockedFileHandle(
|
|||||||
}
|
}
|
||||||
return ScopedLockedFileHandle(scoped.release(), base::FilePath());
|
return ScopedLockedFileHandle(scoped.release(), base::FilePath());
|
||||||
#else
|
#else
|
||||||
|
// It's important to create the ScopedLockedFileHandle before calling
|
||||||
|
// LoggingLockFile on iOS, so a ScopedBackgroundTask is created *before*
|
||||||
|
// the LoggingLockFile call below.
|
||||||
|
ScopedLockedFileHandle handle(kInvalidFileHandle);
|
||||||
if (scoped.is_valid()) {
|
if (scoped.is_valid()) {
|
||||||
if (LoggingLockFile(
|
if (LoggingLockFile(
|
||||||
scoped.get(), locking, FileLockingBlocking::kBlocking) !=
|
scoped.get(), locking, FileLockingBlocking::kBlocking) !=
|
||||||
@ -214,7 +242,8 @@ Settings::ScopedLockedFileHandle Settings::MakeScopedLockedFileHandle(
|
|||||||
scoped.reset();
|
scoped.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ScopedLockedFileHandle(scoped.release());
|
handle.reset(scoped.release());
|
||||||
|
return handle;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,10 @@
|
|||||||
#include "util/misc/initialization_state.h"
|
#include "util/misc/initialization_state.h"
|
||||||
#include "util/misc/uuid.h"
|
#include "util/misc/uuid.h"
|
||||||
|
|
||||||
|
#if BUILDFLAG(IS_IOS)
|
||||||
|
#include "util/ios/scoped_background_task.h"
|
||||||
|
#endif // BUILDFLAG(IS_IOS)
|
||||||
|
|
||||||
namespace crashpad {
|
namespace crashpad {
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
@ -153,7 +157,24 @@ class Settings {
|
|||||||
FileHandle handle_;
|
FileHandle handle_;
|
||||||
base::FilePath lockfile_path_;
|
base::FilePath lockfile_path_;
|
||||||
};
|
};
|
||||||
#else // BUILDFLAG(IS_FUCHSIA)
|
#elif BUILDFLAG(IS_IOS)
|
||||||
|
// iOS needs to use ScopedBackgroundTask anytime a file lock is used.
|
||||||
|
class ScopedLockedFileHandle
|
||||||
|
: public base::ScopedGeneric<FileHandle,
|
||||||
|
internal::ScopedLockedFileHandleTraits> {
|
||||||
|
public:
|
||||||
|
using base::ScopedGeneric<
|
||||||
|
FileHandle,
|
||||||
|
internal::ScopedLockedFileHandleTraits>::ScopedGeneric;
|
||||||
|
|
||||||
|
ScopedLockedFileHandle(const FileHandle& value);
|
||||||
|
ScopedLockedFileHandle(ScopedLockedFileHandle&& rvalue);
|
||||||
|
ScopedLockedFileHandle& operator=(ScopedLockedFileHandle&& rvalue);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unique_ptr<internal::ScopedBackgroundTask> ios_background_task_;
|
||||||
|
};
|
||||||
|
#else
|
||||||
using ScopedLockedFileHandle =
|
using ScopedLockedFileHandle =
|
||||||
base::ScopedGeneric<FileHandle, internal::ScopedLockedFileHandleTraits>;
|
base::ScopedGeneric<FileHandle, internal::ScopedLockedFileHandleTraits>;
|
||||||
#endif // BUILDFLAG(IS_FUCHSIA)
|
#endif // BUILDFLAG(IS_FUCHSIA)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user