blob: 4c210aaf45ee3cf0062a19636b619e6e4a28527f [file] [log] [blame]
[email protected]1407b6e2010-08-27 21:39:481// Copyright (c) 2010 The Chromium Authors. All rights reserved.
[email protected]53556e12009-10-15 21:49:222// 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]fbe67262009-10-16 22:32:538#include "base/file_version_info.h"
[email protected]a8e20582010-12-31 17:18:509#include "base/win/win_util.h"
[email protected]53556e12009-10-15 21:49:2210#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]219d1a62010-04-28 00:45:0813#include "chrome_frame/exception_barrier.h"
[email protected]7bc272f2009-12-09 01:09:2814#include "chrome_frame/utils.h"
[email protected]53556e12009-10-15 21:49:2215
16// Well known SID for the system principal.
17const wchar_t kSystemPrincipalSid[] = L"S-1-5-18";
[email protected]3b781fe2009-12-09 19:59:2518const wchar_t kChromePipeName[] = L"\\\\.\\pipe\\ChromeCrashServices";
[email protected]53556e12009-10-15 21:49:2219
[email protected]fbe67262009-10-16 22:32:5320// Returns the custom info structure based on the dll in parameter
21google_breakpad::CustomClientInfo* GetCustomInfo(const wchar_t* dll_path) {
22 std::wstring product;
23 std::wstring version;
24 scoped_ptr<FileVersionInfo>
[email protected]663f339a2010-07-07 17:24:1725 version_info(FileVersionInfo::CreateFileVersionInfo(FilePath(dll_path)));
[email protected]fbe67262009-10-16 22:32:5326 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]53556e12009-10-15 21:49:2239 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
48extern "C" IMAGE_DOS_HEADER __ImageBase;
49
50bool InitializeCrashReporting() {
[email protected]7bc272f2009-12-09 01:09:2851 // In headless mode we want crashes to be reported back.
[email protected]3b781fe2009-12-09 19:59:2552 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]7bc272f2009-12-09 01:09:2856 return true;
[email protected]3b781fe2009-12-09 19:59:2557
[email protected]72354312010-05-01 02:10:0658 // 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]219d1a62010-04-28 00:45:0861
[email protected]3b781fe2009-12-09 19:59:2562 // 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]7bc272f2009-12-09 01:09:2866 }
[email protected]3b781fe2009-12-09 19:59:2567
[email protected]53556e12009-10-15 21:49:2268 wchar_t dll_path[MAX_PATH * 2] = {0};
69 GetModuleFileName(reinterpret_cast<HMODULE>(&__ImageBase), dll_path,
70 arraysize(dll_path));
71
[email protected]3b781fe2009-12-09 19:59:2572 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]53556e12009-10-15 21:49:2280 std::wstring user_sid;
81 if (InstallUtil::IsPerUserInstall(dll_path)) {
[email protected]a8e20582010-12-31 17:18:5082 if (!base::win::GetUserSidString(&user_sid)) {
[email protected]53556e12009-10-15 21:49:2283 return false;
84 }
85 } else {
86 user_sid = kSystemPrincipalSid;
87 }
88
[email protected]53556e12009-10-15 21:49:2289 return InitializeVectoredCrashReporting(false, user_sid.c_str(),
[email protected]fbe67262009-10-16 22:32:5390 temp_directory.value(), GetCustomInfo(dll_path));
[email protected]53556e12009-10-15 21:49:2291}
92
93bool ShutdownCrashReporting() {
[email protected]72354312010-05-01 02:10:0694 ExceptionBarrierConfig::set_enabled(false);
[email protected]53556e12009-10-15 21:49:2295 return ShutdownVectoredCrashReporting();
96}