Refactor Mac crash key reporting - move to base/mac/crash_logging.{h,mm}
Breakpad support currently resides in chrome/app/breakpad_mac.* this makes it inaccessible to lower level code that would also like to set crash keys e.g. The sandboxing infrastructure.
This CL refactors the crash key reporting code to reside in base/mac.
Logging is also added to the Sandbox code to try to track down the cause of crbug.com/94758.
BUG=95272, 94758
TEST=On official builds crash logs should contain crash keys e.g. OS version.
Review URL: http://codereview.chromium.org/7849011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100626 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/common/child_process_logging_mac.mm b/chrome/common/child_process_logging_mac.mm
index ab3d021..70ee2a7 100644
--- a/chrome/common/child_process_logging_mac.mm
+++ b/chrome/common/child_process_logging_mac.mm
@@ -16,6 +16,11 @@
namespace child_process_logging {
+using base::mac::SetCrashKeyValueFuncPtr;
+using base::mac::ClearCrashKeyValueFuncPtr;
+using base::mac::SetCrashKeyValue;
+using base::mac::ClearCrashKey;
+
const int kMaxNumCrashURLChunks = 8;
const int kMaxNumURLChunkValueLength = 255;
const char *kUrlChunkFormatStr = "url-chunk-%d";
@@ -30,19 +35,10 @@
NSString* const kNumExtensionsName = @"num-extensions";
NSString* const kExtensionNameFormat = @"extension-%d";
-static SetCrashKeyValueFuncPtr g_set_key_func;
-static ClearCrashKeyValueFuncPtr g_clear_key_func;
-
// Account for the terminating null character.
static const size_t kClientIdSize = 32 + 1;
static char g_client_id[kClientIdSize];
-void SetCrashKeyFunctions(SetCrashKeyValueFuncPtr set_key_func,
- ClearCrashKeyValueFuncPtr clear_key_func) {
- g_set_key_func = set_key_func;
- g_clear_key_func = clear_key_func;
-}
-
void SetActiveURLImpl(const GURL& url,
SetCrashKeyValueFuncPtr set_key_func,
ClearCrashKeyValueFuncPtr clear_key_func) {
@@ -94,8 +90,7 @@
}
void SetActiveURL(const GURL& url) {
- if (g_set_key_func && g_clear_key_func)
- SetActiveURLImpl(url, g_set_key_func, g_clear_key_func);
+ SetActiveURLImpl(url, SetCrashKeyValue, ClearCrashKey);
}
void SetClientId(const std::string& client_id) {
@@ -103,8 +98,7 @@
ReplaceSubstringsAfterOffset(&str, 0, "-", "");
base::strlcpy(g_client_id, str.c_str(), kClientIdSize);
- if (g_set_key_func)
- SetClientIdImpl(str, g_set_key_func);
+ SetClientIdImpl(str, SetCrashKeyValue);
std::wstring wstr = ASCIIToWide(str);
GoogleUpdateSettings::SetMetricsId(wstr);
@@ -115,12 +109,10 @@
}
void SetActiveExtensions(const std::set<std::string>& extension_ids) {
- if (!g_set_key_func)
- return;
-
// Log the count separately to track heavy users.
const int count = static_cast<int>(extension_ids.size());
- g_set_key_func(kNumExtensionsName, [NSString stringWithFormat:@"%i", count]);
+ SetCrashKeyValue(kNumExtensionsName,
+ [NSString stringWithFormat:@"%i", count]);
// Record up to |kMaxReportedActiveExtensions| extensions, clearing
// keys if there aren't that many.
@@ -128,10 +120,10 @@
for (int i = 0; i < kMaxReportedActiveExtensions; ++i) {
NSString* key = [NSString stringWithFormat:kExtensionNameFormat, i];
if (iter != extension_ids.end()) {
- g_set_key_func(key, [NSString stringWithUTF8String:iter->c_str()]);
+ SetCrashKeyValue(key, [NSString stringWithUTF8String:iter->c_str()]);
++iter;
} else {
- g_clear_key_func(key);
+ ClearCrashKey(key);
}
}
}
@@ -166,8 +158,7 @@
}
void SetGpuInfo(const GPUInfo& gpu_info) {
- if (g_set_key_func)
- SetGpuInfoImpl(gpu_info, g_set_key_func);
+ SetGpuInfoImpl(gpu_info, SetCrashKeyValue);
}
@@ -179,8 +170,7 @@
}
void SetNumberOfViews(int number_of_views) {
- if (g_set_key_func)
- SetNumberOfViewsImpl(number_of_views, g_set_key_func);
+ SetNumberOfViewsImpl(number_of_views, SetCrashKeyValue);
}
} // namespace child_process_logging