[email protected] | 1407b6e | 2010-08-27 21:39:48 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
[email protected] | 53556e1 | 2009-10-15 21:49:22 | [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 | // Implementation of wrapper around common crash reporting. |
| 6 | |
| 7 | #include "base/file_util.h" |
[email protected] | fbe6726 | 2009-10-16 22:32:53 | [diff] [blame] | 8 | #include "base/file_version_info.h" |
[email protected] | a8e2058 | 2010-12-31 17:18:50 | [diff] [blame] | 9 | #include "base/win/win_util.h" |
[email protected] | 53556e1 | 2009-10-15 21:49:22 | [diff] [blame] | 10 | #include "chrome/installer/util/google_update_settings.h" |
| 11 | #include "chrome/installer/util/install_util.h" |
| 12 | #include "chrome_frame/chrome_frame_reporting.h" |
[email protected] | 219d1a6 | 2010-04-28 00:45:08 | [diff] [blame] | 13 | #include "chrome_frame/exception_barrier.h" |
[email protected] | 7bc272f | 2009-12-09 01:09:28 | [diff] [blame] | 14 | #include "chrome_frame/utils.h" |
[email protected] | 53556e1 | 2009-10-15 21:49:22 | [diff] [blame] | 15 | |
| 16 | // Well known SID for the system principal. |
| 17 | const wchar_t kSystemPrincipalSid[] = L"S-1-5-18"; |
[email protected] | 3b781fe | 2009-12-09 19:59:25 | [diff] [blame] | 18 | const wchar_t kChromePipeName[] = L"\\\\.\\pipe\\ChromeCrashServices"; |
[email protected] | 53556e1 | 2009-10-15 21:49:22 | [diff] [blame] | 19 | |
[email protected] | fbe6726 | 2009-10-16 22:32:53 | [diff] [blame] | 20 | // Returns the custom info structure based on the dll in parameter |
| 21 | google_breakpad::CustomClientInfo* GetCustomInfo(const wchar_t* dll_path) { |
| 22 | std::wstring product; |
| 23 | std::wstring version; |
| 24 | scoped_ptr<FileVersionInfo> |
[email protected] | 663f339a | 2010-07-07 17:24:17 | [diff] [blame] | 25 | version_info(FileVersionInfo::CreateFileVersionInfo(FilePath(dll_path))); |
[email protected] | fbe6726 | 2009-10-16 22:32:53 | [diff] [blame] | 26 | if (version_info.get()) { |
| 27 | version = version_info->product_version(); |
| 28 | product = version_info->product_short_name(); |
| 29 | } |
| 30 | |
| 31 | if (version.empty()) |
| 32 | version = L"0.1.0.0"; |
| 33 | |
| 34 | if (product.empty()) |
| 35 | product = L"ChromeFrame"; |
| 36 | |
| 37 | static google_breakpad::CustomInfoEntry ver_entry(L"ver", version.c_str()); |
| 38 | static google_breakpad::CustomInfoEntry prod_entry(L"prod", product.c_str()); |
[email protected] | 53556e1 | 2009-10-15 21:49:22 | [diff] [blame] | 39 | static google_breakpad::CustomInfoEntry plat_entry(L"plat", L"Win32"); |
| 40 | static google_breakpad::CustomInfoEntry type_entry(L"ptype", L"chrome_frame"); |
| 41 | static google_breakpad::CustomInfoEntry entries[] = { |
| 42 | ver_entry, prod_entry, plat_entry, type_entry }; |
| 43 | static google_breakpad::CustomClientInfo custom_info = { |
| 44 | entries, arraysize(entries) }; |
| 45 | return &custom_info; |
| 46 | } |
| 47 | |
| 48 | extern "C" IMAGE_DOS_HEADER __ImageBase; |
| 49 | |
| 50 | bool InitializeCrashReporting() { |
[email protected] | 7bc272f | 2009-12-09 01:09:28 | [diff] [blame] | 51 | // In headless mode we want crashes to be reported back. |
[email protected] | 3b781fe | 2009-12-09 19:59:25 | [diff] [blame] | 52 | bool always_take_dump = IsHeadlessMode(); |
| 53 | // We want to use the Google Update crash reporting. We need to check if the |
| 54 | // user allows it first. |
| 55 | if (!always_take_dump && !GoogleUpdateSettings::GetCollectStatsConsent()) |
[email protected] | 7bc272f | 2009-12-09 01:09:28 | [diff] [blame] | 56 | return true; |
[email protected] | 3b781fe | 2009-12-09 19:59:25 | [diff] [blame] | 57 | |
[email protected] | 7235431 | 2010-05-01 02:10:06 | [diff] [blame] | 58 | // If we got here, we want to report crashes, so make sure all |
| 59 | // ExceptionBarrierBase instances do so. |
| 60 | ExceptionBarrierConfig::set_enabled(true); |
[email protected] | 219d1a6 | 2010-04-28 00:45:08 | [diff] [blame] | 61 | |
[email protected] | 3b781fe | 2009-12-09 19:59:25 | [diff] [blame] | 62 | // Get the alternate dump directory. We use the temp path. |
| 63 | FilePath temp_directory; |
| 64 | if (!file_util::GetTempDir(&temp_directory) || temp_directory.empty()) { |
| 65 | return false; |
[email protected] | 7bc272f | 2009-12-09 01:09:28 | [diff] [blame] | 66 | } |
[email protected] | 3b781fe | 2009-12-09 19:59:25 | [diff] [blame] | 67 | |
[email protected] | 53556e1 | 2009-10-15 21:49:22 | [diff] [blame] | 68 | wchar_t dll_path[MAX_PATH * 2] = {0}; |
| 69 | GetModuleFileName(reinterpret_cast<HMODULE>(&__ImageBase), dll_path, |
| 70 | arraysize(dll_path)); |
| 71 | |
[email protected] | 3b781fe | 2009-12-09 19:59:25 | [diff] [blame] | 72 | if (always_take_dump) { |
| 73 | return InitializeVectoredCrashReportingWithPipeName(true, kChromePipeName, |
| 74 | temp_directory.value(), GetCustomInfo(dll_path)); |
| 75 | } |
| 76 | |
| 77 | // Build the pipe name. It can be either: |
| 78 | // System-wide install: "NamedPipe\GoogleCrashServices\S-1-5-18" |
| 79 | // Per-user install: "NamedPipe\GoogleCrashServices\<user SID>" |
[email protected] | 53556e1 | 2009-10-15 21:49:22 | [diff] [blame] | 80 | std::wstring user_sid; |
| 81 | if (InstallUtil::IsPerUserInstall(dll_path)) { |
[email protected] | a8e2058 | 2010-12-31 17:18:50 | [diff] [blame] | 82 | if (!base::win::GetUserSidString(&user_sid)) { |
[email protected] | 53556e1 | 2009-10-15 21:49:22 | [diff] [blame] | 83 | return false; |
| 84 | } |
| 85 | } else { |
| 86 | user_sid = kSystemPrincipalSid; |
| 87 | } |
| 88 | |
[email protected] | 53556e1 | 2009-10-15 21:49:22 | [diff] [blame] | 89 | return InitializeVectoredCrashReporting(false, user_sid.c_str(), |
[email protected] | fbe6726 | 2009-10-16 22:32:53 | [diff] [blame] | 90 | temp_directory.value(), GetCustomInfo(dll_path)); |
[email protected] | 53556e1 | 2009-10-15 21:49:22 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | bool ShutdownCrashReporting() { |
[email protected] | 7235431 | 2010-05-01 02:10:06 | [diff] [blame] | 94 | ExceptionBarrierConfig::set_enabled(false); |
[email protected] | 53556e1 | 2009-10-15 21:49:22 | [diff] [blame] | 95 | return ShutdownVectoredCrashReporting(); |
| 96 | } |