[email protected] | 53556e1 | 2009-10-15 21:49:22 | [diff] [blame^] | 1 | // Copyright (c) 2009 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. |
| 4 | |
| 5 | // Implementation of wrapper around common crash reporting. |
| 6 | |
| 7 | #include "base/file_util.h" |
| 8 | #include "base/logging.h" |
| 9 | #include "base/win_util.h" |
| 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" |
| 13 | |
| 14 | // Well known SID for the system principal. |
| 15 | const wchar_t kSystemPrincipalSid[] = L"S-1-5-18"; |
| 16 | |
| 17 | // Returns the custom info structure based on the dll in parameter and the |
| 18 | // process type. |
| 19 | google_breakpad::CustomClientInfo* GetCustomInfo() { |
| 20 | // TODO(joshia): Grab these based on build. |
| 21 | static google_breakpad::CustomInfoEntry ver_entry(L"ver", L"0.1.0.0"); |
| 22 | static google_breakpad::CustomInfoEntry prod_entry(L"prod", L"ChromeFrame"); |
| 23 | static google_breakpad::CustomInfoEntry plat_entry(L"plat", L"Win32"); |
| 24 | static google_breakpad::CustomInfoEntry type_entry(L"ptype", L"chrome_frame"); |
| 25 | static google_breakpad::CustomInfoEntry entries[] = { |
| 26 | ver_entry, prod_entry, plat_entry, type_entry }; |
| 27 | static google_breakpad::CustomClientInfo custom_info = { |
| 28 | entries, arraysize(entries) }; |
| 29 | return &custom_info; |
| 30 | } |
| 31 | |
| 32 | extern "C" IMAGE_DOS_HEADER __ImageBase; |
| 33 | |
| 34 | bool InitializeCrashReporting() { |
| 35 | // We want to use the Google Update crash reporting. We need to check if the |
| 36 | // user allows it first. |
| 37 | if (!GoogleUpdateSettings::GetCollectStatsConsent()) |
| 38 | return true; |
| 39 | |
| 40 | // Build the pipe name. It can be either: |
| 41 | // System-wide install: "NamedPipe\GoogleCrashServices\S-1-5-18" |
| 42 | // Per-user install: "NamedPipe\GoogleCrashServices\<user SID>" |
| 43 | wchar_t dll_path[MAX_PATH * 2] = {0}; |
| 44 | GetModuleFileName(reinterpret_cast<HMODULE>(&__ImageBase), dll_path, |
| 45 | arraysize(dll_path)); |
| 46 | |
| 47 | std::wstring user_sid; |
| 48 | if (InstallUtil::IsPerUserInstall(dll_path)) { |
| 49 | if (!win_util::GetUserSidString(&user_sid)) { |
| 50 | return false; |
| 51 | } |
| 52 | } else { |
| 53 | user_sid = kSystemPrincipalSid; |
| 54 | } |
| 55 | |
| 56 | // Get the alternate dump directory. We use the temp path. |
| 57 | FilePath temp_directory; |
| 58 | if (!file_util::GetTempDir(&temp_directory) || temp_directory.empty()) { |
| 59 | return false; |
| 60 | } |
| 61 | |
| 62 | return InitializeVectoredCrashReporting(false, user_sid.c_str(), |
| 63 | temp_directory.value(), GetCustomInfo()); |
| 64 | } |
| 65 | |
| 66 | bool ShutdownCrashReporting() { |
| 67 | return ShutdownVectoredCrashReporting(); |
| 68 | } |