1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/common/child_process_logging.h"
9 #include "base/debug/crash_logging.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/common/chrome_constants.h"
12 #include "chrome/common/crash_keys.h"
14 namespace child_process_logging {
18 // exported in breakpad_win.cc:
19 // void __declspec(dllexport) __cdecl SetCrashKeyValueImpl.
20 typedef void (__cdecl *SetCrashKeyValue)(const wchar_t*, const wchar_t*);
22 // exported in breakpad_win.cc:
23 // void __declspec(dllexport) __cdecl ClearCrashKeyValueImpl.
24 typedef void (__cdecl *ClearCrashKeyValue)(const wchar_t*);
26 void SetCrashKeyValueTrampoline(const base::StringPiece& key,
27 const base::StringPiece& value) {
28 static SetCrashKeyValue set_crash_key = NULL;
30 HMODULE exe_module = GetModuleHandle(chrome::kBrowserProcessExecutableName);
33 set_crash_key = reinterpret_cast<SetCrashKeyValue>(
34 GetProcAddress(exe_module, "SetCrashKeyValueImpl"));
38 (set_crash_key)(UTF8ToWide(key).data(), UTF8ToWide(value).data());
41 void ClearCrashKeyValueTrampoline(const base::StringPiece& key) {
42 static ClearCrashKeyValue clear_crash_key = NULL;
43 if (!clear_crash_key) {
44 HMODULE exe_module = GetModuleHandle(chrome::kBrowserProcessExecutableName);
47 clear_crash_key = reinterpret_cast<ClearCrashKeyValue>(
48 GetProcAddress(exe_module, "ClearCrashKeyValueImpl"));
52 (clear_crash_key)(UTF8ToWide(key).data());
58 // Note: on other platforms, this is set up during Breakpad initialization,
59 // in ChromeBreakpadClient. But on Windows, that is before the DLL module is
60 // loaded, which is a prerequisite of the crash key system.
61 crash_keys::RegisterChromeCrashKeys();
62 base::debug::SetCrashKeyReportingFunctions(
63 &SetCrashKeyValueTrampoline, &ClearCrashKeyValueTrampoline);
66 } // namespace child_process_logging