Commit 3f99635d authored by Olivier Robin's avatar Olivier Robin Committed by Commit Bot

Do not block main thread when setting crash report keys

Do not wait for the Breakpad thread when setting a value.
The Breakpad thread can be busy for quite a long time (seconds)
waiting for it will freeze the UI thread.

The get functions are still blocking but are only used in tests.

Bug: 960378
Change-Id: Ia9d58087baaecfe5e42f798cfbb8c37bb4859c42
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1605409Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Commit-Queue: Olivier Robin <olivierrobin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#658568}
parent e587ddc4
...@@ -27,6 +27,8 @@ namespace { ...@@ -27,6 +27,8 @@ namespace {
// Accessing the BreakpadRef is done on an async queue, so serialize the // Accessing the BreakpadRef is done on an async queue, so serialize the
// access to the current thread, as the CrashKeyString API is sync. This // access to the current thread, as the CrashKeyString API is sync. This
// matches //ios/chrome/browser/crash_report/breakpad_helper.mm. // matches //ios/chrome/browser/crash_report/breakpad_helper.mm.
// When getting a value, wait until the value is received.
// Note: This will block the current thread.
void WithBreakpadRefSync(void (^block)(BreakpadRef ref)) { void WithBreakpadRefSync(void (^block)(BreakpadRef ref)) {
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
...@@ -37,13 +39,20 @@ void WithBreakpadRefSync(void (^block)(BreakpadRef ref)) { ...@@ -37,13 +39,20 @@ void WithBreakpadRefSync(void (^block)(BreakpadRef ref)) {
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
} }
// When setting a value, avoid to block the current thread.
void WithBreakpadRefAsync(void (^block)(BreakpadRef ref)) {
[[BreakpadController sharedInstance] withBreakpadRef:^(BreakpadRef ref) {
block(ref);
}];
}
} // namespace } // namespace
void CrashKeyStringImpl::Set(base::StringPiece value) { void CrashKeyStringImpl::Set(base::StringPiece value) {
NSString* key = base::SysUTF8ToNSString(name_); NSString* key = base::SysUTF8ToNSString(name_);
NSString* value_ns = base::SysUTF8ToNSString(value.as_string()); NSString* value_ns = base::SysUTF8ToNSString(value.as_string());
WithBreakpadRefSync(^(BreakpadRef ref) { WithBreakpadRefAsync(^(BreakpadRef ref) {
BreakpadAddUploadParameter(ref, key, value_ns); BreakpadAddUploadParameter(ref, key, value_ns);
}); });
} }
...@@ -51,7 +60,7 @@ void CrashKeyStringImpl::Set(base::StringPiece value) { ...@@ -51,7 +60,7 @@ void CrashKeyStringImpl::Set(base::StringPiece value) {
void CrashKeyStringImpl::Clear() { void CrashKeyStringImpl::Clear() {
NSString* key = base::SysUTF8ToNSString(name_); NSString* key = base::SysUTF8ToNSString(name_);
WithBreakpadRefSync(^(BreakpadRef ref) { WithBreakpadRefAsync(^(BreakpadRef ref) {
BreakpadRemoveUploadParameter(ref, key); BreakpadRemoveUploadParameter(ref, key);
}); });
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment