1 // Copyright (c) 2010 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 // Implementation of wrapper around common crash reporting.
7 #include "base/file_util.h"
8 #include "base/file_version_info.h"
9 #include "base/win/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 #include "chrome_frame/exception_barrier.h"
14 #include "chrome_frame/utils.h"
16 // Well known SID for the system principal.
17 const wchar_t kSystemPrincipalSid
[] = L
"S-1-5-18";
18 const wchar_t kChromePipeName
[] = L
"\\\\.\\pipe\\ChromeCrashServices";
20 // Returns the custom info structure based on the dll in parameter
21 google_breakpad::CustomClientInfo
* GetCustomInfo(const wchar_t* dll_path
) {
24 scoped_ptr
<FileVersionInfo
>
25 version_info(FileVersionInfo::CreateFileVersionInfo(FilePath(dll_path
)));
26 if (version_info
.get()) {
27 version
= version_info
->product_version();
28 product
= version_info
->product_short_name();
35 product
= L
"ChromeFrame";
37 static google_breakpad::CustomInfoEntry
ver_entry(L
"ver", version
.c_str());
38 static google_breakpad::CustomInfoEntry
prod_entry(L
"prod", product
.c_str());
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
) };
48 extern "C" IMAGE_DOS_HEADER __ImageBase
;
50 bool InitializeCrashReporting() {
51 // In headless mode we want crashes to be reported back.
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())
58 // If we got here, we want to report crashes, so make sure all
59 // ExceptionBarrierBase instances do so.
60 ExceptionBarrierConfig::set_enabled(true);
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()) {
68 wchar_t dll_path
[MAX_PATH
* 2] = {0};
69 GetModuleFileName(reinterpret_cast<HMODULE
>(&__ImageBase
), dll_path
,
72 if (always_take_dump
) {
73 return InitializeVectoredCrashReportingWithPipeName(true, kChromePipeName
,
74 temp_directory
.value(), GetCustomInfo(dll_path
));
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>"
80 std::wstring user_sid
;
81 if (InstallUtil::IsPerUserInstall(dll_path
)) {
82 if (!base::win::GetUserSidString(&user_sid
)) {
86 user_sid
= kSystemPrincipalSid
;
89 return InitializeVectoredCrashReporting(false, user_sid
.c_str(),
90 temp_directory
.value(), GetCustomInfo(dll_path
));
93 bool ShutdownCrashReporting() {
94 ExceptionBarrierConfig::set_enabled(false);
95 return ShutdownVectoredCrashReporting();