[email protected] | 6724e59 | 2012-03-16 04:49:14 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | ef91627 | 2009-07-08 21:40:55 | [diff] [blame] | 2 | // 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] | 264c0acac | 2013-10-01 13:33:30 | [diff] [blame] | 9 | #include "base/debug/crash_logging.h" |
[email protected] | 8e885de | 2014-07-22 23:36:53 | [diff] [blame] | 10 | #include "base/memory/scoped_ptr.h" |
[email protected] | 12bfb61 | 2013-06-07 19:54:02 | [diff] [blame] | 11 | #include "base/strings/utf_string_conversions.h" |
[email protected] | ef91627 | 2009-07-08 21:40:55 | [diff] [blame] | 12 | #include "chrome/common/chrome_constants.h" |
[email protected] | 27b38d6 | 2013-08-14 18:12:11 | [diff] [blame] | 13 | #include "chrome/common/crash_keys.h" |
[email protected] | d63b097 | 2014-04-17 17:35:30 | [diff] [blame] | 14 | #include "chrome/installer/util/google_update_settings.h" |
[email protected] | 8e885de | 2014-07-22 23:36:53 | [diff] [blame] | 15 | #include "components/metrics/client_info.h" |
[email protected] | ef91627 | 2009-07-08 21:40:55 | [diff] [blame] | 16 | |
| 17 | namespace child_process_logging { |
[email protected] | 603e1f3 | 2012-05-22 20:53:16 | [diff] [blame] | 18 | |
| 19 | namespace { |
| 20 | |
[email protected] | 27b38d6 | 2013-08-14 18:12:11 | [diff] [blame] | 21 | // exported in breakpad_win.cc: |
| 22 | // void __declspec(dllexport) __cdecl SetCrashKeyValueImpl. |
| 23 | typedef void (__cdecl *SetCrashKeyValue)(const wchar_t*, const wchar_t*); |
| 24 | |
| 25 | // exported in breakpad_win.cc: |
| 26 | // void __declspec(dllexport) __cdecl ClearCrashKeyValueImpl. |
| 27 | typedef void (__cdecl *ClearCrashKeyValue)(const wchar_t*); |
| 28 | |
[email protected] | 27b38d6 | 2013-08-14 18:12:11 | [diff] [blame] | 29 | void 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] | 036a5f3 | 2013-12-25 00:26:11 | [diff] [blame] | 40 | if (set_crash_key) { |
| 41 | (set_crash_key)(base::UTF8ToWide(key).data(), |
| 42 | base::UTF8ToWide(value).data()); |
| 43 | } |
[email protected] | 27b38d6 | 2013-08-14 18:12:11 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | void 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] | 036a5f3 | 2013-12-25 00:26:11 | [diff] [blame] | 57 | (clear_crash_key)(base::UTF8ToWide(key).data()); |
[email protected] | 27b38d6 | 2013-08-14 18:12:11 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | } // namespace |
| 61 | |
| 62 | void 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] | d63b097 | 2014-04-17 17:35:30 | [diff] [blame] | 69 | |
[email protected] | 9d1b015 | 2014-07-09 18:53:22 | [diff] [blame] | 70 | // 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] | 8e885de | 2014-07-22 23:36:53 | [diff] [blame] | 74 | scoped_ptr<metrics::ClientInfo> client_info = |
| 75 | GoogleUpdateSettings::LoadMetricsClientInfo(); |
| 76 | if (client_info) |
Mark Mentovai | c67fa64f | 2015-03-24 14:00:06 | [diff] [blame] | 77 | crash_keys::SetMetricsClientIdFromGUID(client_info->client_id); |
[email protected] | 27b38d6 | 2013-08-14 18:12:11 | [diff] [blame] | 78 | } |
| 79 | |
[email protected] | ef91627 | 2009-07-08 21:40:55 | [diff] [blame] | 80 | } // namespace child_process_logging |