Commit 42d3293e authored by Robert Sesek's avatar Robert Sesek Committed by Commit Bot

crash_keys: Provide an iOS implementation of the new API.

Bug: 598854
Change-Id: Ia8bf724deef748dafa262125bad8e8b1bdaf64bd
Reviewed-on: https://chromium-review.googlesource.com/826002Reviewed-by: default avatarMark Mentovai <mark@chromium.org>
Commit-Queue: Robert Sesek <rsesek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524115}
parent 30eafbaf
......@@ -57,12 +57,18 @@ target(crash_key_target_type, "crash_key") {
} else if (use_stubs) {
sources += [ "crash_key_stubs.cc" ]
} else {
include_dirs = [ "//third_party/breakpad/breakpad/src/" ]
sources += [
"crash_key_breakpad.cc",
"crash_key_internal.h",
]
include_dirs = [ "//third_party/breakpad/breakpad/src" ]
if (is_ios) {
sources += [ "crash_key_breakpad_ios.mm" ]
configs += [ "//build/config/compiler:enable_arc" ]
} else {
sources += [
"crash_key_breakpad.cc",
"crash_key_internal.h",
]
}
deps += [ "//third_party/breakpad:client" ]
}
......
include_rules = [
"+third_party/breakpad/breakpad/src/client/ios/Breakpad.h",
"+third_party/breakpad/breakpad/src/client/ios/BreakpadController.h",
]
......@@ -14,8 +14,8 @@
#include "components/crash/core/common/crash_key_base_support.h"
#include "components/crash/core/common/crash_key_internal.h"
#if (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_WIN)
#error "This file should not be used when Crashpad is available."
#if defined(OS_MACOSX) || defined(OS_IOS) || defined(OS_WIN)
#error "This file should not be used when Crashpad is available, nor on iOS."
#endif
namespace crash_reporter {
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/crash/core/common/crash_key.h"
#include <dispatch/dispatch.h>
#include "base/strings/sys_string_conversions.h"
#include "components/crash/core/common/crash_key_base_support.h"
#import "third_party/breakpad/breakpad/src/client/ios/Breakpad.h"
#import "third_party/breakpad/breakpad/src/client/ios/BreakpadController.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
// The iOS Breakpad implementation internally uses a LongStringDictionary,
// which performs the same chunking done by crash_key_breakpad.cc. This class
// implementation therefore just wraps the iOS Breakpad interface.
namespace crash_reporter {
namespace internal {
namespace {
// Accessing the BreakpadRef is done on an async queue, so serialize the
// access to the current thread, as the CrashKeyString API is sync. This
// matches //ios/chrome/browser/crash_report/breakpad_helper.mm.
void WithBreakpadRefSync(void (^block)(BreakpadRef ref)) {
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
[[BreakpadController sharedInstance] withBreakpadRef:^(BreakpadRef ref) {
block(ref);
dispatch_semaphore_signal(semaphore);
}];
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
}
} // namespace
void CrashKeyStringImpl::Set(base::StringPiece value) {
NSString* key = base::SysUTF8ToNSString(name_);
NSString* value_ns = base::SysUTF8ToNSString(value.as_string());
WithBreakpadRefSync(^(BreakpadRef ref) {
BreakpadSetKeyValue(ref, key, value_ns);
});
}
void CrashKeyStringImpl::Clear() {
NSString* key = base::SysUTF8ToNSString(name_);
WithBreakpadRefSync(^(BreakpadRef ref) {
BreakpadRemoveKeyValue(ref, key);
});
}
bool CrashKeyStringImpl::is_set() const {
__block bool is_set = false;
NSString* key = base::SysUTF8ToNSString(name_);
WithBreakpadRefSync(^(BreakpadRef ref) {
is_set = BreakpadKeyValue(ref, key) != nil;
});
return is_set;
}
} // namespace internal
void InitializeCrashKeys() {
InitializeCrashKeyBaseSupport();
}
} // namespace crash_reporter
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