blob: 9571701ed575f00917369c59d71a358ed1552c17 [file] [log] [blame]
[email protected]6724e592012-03-16 04:49:141// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]ef916272009-07-08 21:40:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/common/child_process_logging.h"
6
7#include <windows.h>
8
[email protected]264c0acac2013-10-01 13:33:309#include "base/debug/crash_logging.h"
[email protected]8e885de2014-07-22 23:36:5310#include "base/memory/scoped_ptr.h"
[email protected]12bfb612013-06-07 19:54:0211#include "base/strings/utf_string_conversions.h"
[email protected]ef916272009-07-08 21:40:5512#include "chrome/common/chrome_constants.h"
[email protected]27b38d62013-08-14 18:12:1113#include "chrome/common/crash_keys.h"
[email protected]d63b0972014-04-17 17:35:3014#include "chrome/installer/util/google_update_settings.h"
[email protected]8e885de2014-07-22 23:36:5315#include "components/metrics/client_info.h"
[email protected]ef916272009-07-08 21:40:5516
17namespace child_process_logging {
[email protected]603e1f32012-05-22 20:53:1618
19namespace {
20
[email protected]27b38d62013-08-14 18:12:1121// exported in breakpad_win.cc:
22// void __declspec(dllexport) __cdecl SetCrashKeyValueImpl.
23typedef void (__cdecl *SetCrashKeyValue)(const wchar_t*, const wchar_t*);
24
25// exported in breakpad_win.cc:
26// void __declspec(dllexport) __cdecl ClearCrashKeyValueImpl.
27typedef void (__cdecl *ClearCrashKeyValue)(const wchar_t*);
28
[email protected]27b38d62013-08-14 18:12:1129void SetCrashKeyValueTrampoline(const base::StringPiece& key,
30 const base::StringPiece& value) {
31 static SetCrashKeyValue set_crash_key = NULL;
32 if (!set_crash_key) {
33 HMODULE exe_module = GetModuleHandle(chrome::kBrowserProcessExecutableName);
34 if (!exe_module)
35 return;
36 set_crash_key = reinterpret_cast<SetCrashKeyValue>(
37 GetProcAddress(exe_module, "SetCrashKeyValueImpl"));
38 }
39
[email protected]036a5f32013-12-25 00:26:1140 if (set_crash_key) {
41 (set_crash_key)(base::UTF8ToWide(key).data(),
42 base::UTF8ToWide(value).data());
43 }
[email protected]27b38d62013-08-14 18:12:1144}
45
46void ClearCrashKeyValueTrampoline(const base::StringPiece& key) {
47 static ClearCrashKeyValue clear_crash_key = NULL;
48 if (!clear_crash_key) {
49 HMODULE exe_module = GetModuleHandle(chrome::kBrowserProcessExecutableName);
50 if (!exe_module)
51 return;
52 clear_crash_key = reinterpret_cast<ClearCrashKeyValue>(
53 GetProcAddress(exe_module, "ClearCrashKeyValueImpl"));
54 }
55
56 if (clear_crash_key)
[email protected]036a5f32013-12-25 00:26:1157 (clear_crash_key)(base::UTF8ToWide(key).data());
[email protected]27b38d62013-08-14 18:12:1158}
59
60} // namespace
61
62void Init() {
63 // Note: on other platforms, this is set up during Breakpad initialization,
64 // in ChromeBreakpadClient. But on Windows, that is before the DLL module is
65 // loaded, which is a prerequisite of the crash key system.
66 crash_keys::RegisterChromeCrashKeys();
67 base::debug::SetCrashKeyReportingFunctions(
68 &SetCrashKeyValueTrampoline, &ClearCrashKeyValueTrampoline);
[email protected]d63b0972014-04-17 17:35:3069
[email protected]9d1b0152014-07-09 18:53:2270 // This would be handled by BreakpadClient::SetCrashClientIdFromGUID(), but
71 // because of the aforementioned issue, crash keys aren't ready yet at the
72 // time of Breakpad initialization, load the client id backed up in Google
73 // Update settings instead.
[email protected]8e885de2014-07-22 23:36:5374 scoped_ptr<metrics::ClientInfo> client_info =
75 GoogleUpdateSettings::LoadMetricsClientInfo();
76 if (client_info)
Mark Mentovaic67fa64f2015-03-24 14:00:0677 crash_keys::SetMetricsClientIdFromGUID(client_info->client_id);
[email protected]27b38d62013-08-14 18:12:1178}
79
[email protected]ef916272009-07-08 21:40:5580} // namespace child_process_logging