blob: 170a71048432b8dfb659e8163408efa0b3f65e0c [file] [log] [blame]
[email protected]53556e12009-10-15 21:49:221// 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"
[email protected]fbe67262009-10-16 22:32:539#include "base/file_version_info.h"
[email protected]53556e12009-10-15 21:49:2210#include "base/win_util.h"
11#include "chrome/installer/util/google_update_settings.h"
12#include "chrome/installer/util/install_util.h"
13#include "chrome_frame/chrome_frame_reporting.h"
14
15// Well known SID for the system principal.
16const wchar_t kSystemPrincipalSid[] = L"S-1-5-18";
17
[email protected]fbe67262009-10-16 22:32:5318// Returns the custom info structure based on the dll in parameter
19google_breakpad::CustomClientInfo* GetCustomInfo(const wchar_t* dll_path) {
20 std::wstring product;
21 std::wstring version;
22 scoped_ptr<FileVersionInfo>
23 version_info(FileVersionInfo::CreateFileVersionInfo(dll_path));
24 if (version_info.get()) {
25 version = version_info->product_version();
26 product = version_info->product_short_name();
27 }
28
29 if (version.empty())
30 version = L"0.1.0.0";
31
32 if (product.empty())
33 product = L"ChromeFrame";
34
35 static google_breakpad::CustomInfoEntry ver_entry(L"ver", version.c_str());
36 static google_breakpad::CustomInfoEntry prod_entry(L"prod", product.c_str());
[email protected]53556e12009-10-15 21:49:2237 static google_breakpad::CustomInfoEntry plat_entry(L"plat", L"Win32");
38 static google_breakpad::CustomInfoEntry type_entry(L"ptype", L"chrome_frame");
39 static google_breakpad::CustomInfoEntry entries[] = {
40 ver_entry, prod_entry, plat_entry, type_entry };
41 static google_breakpad::CustomClientInfo custom_info = {
42 entries, arraysize(entries) };
43 return &custom_info;
44}
45
46extern "C" IMAGE_DOS_HEADER __ImageBase;
47
48bool InitializeCrashReporting() {
49 // We want to use the Google Update crash reporting. We need to check if the
50 // user allows it first.
51 if (!GoogleUpdateSettings::GetCollectStatsConsent())
52 return true;
53
54 // Build the pipe name. It can be either:
55 // System-wide install: "NamedPipe\GoogleCrashServices\S-1-5-18"
56 // Per-user install: "NamedPipe\GoogleCrashServices\<user SID>"
57 wchar_t dll_path[MAX_PATH * 2] = {0};
58 GetModuleFileName(reinterpret_cast<HMODULE>(&__ImageBase), dll_path,
59 arraysize(dll_path));
60
61 std::wstring user_sid;
62 if (InstallUtil::IsPerUserInstall(dll_path)) {
63 if (!win_util::GetUserSidString(&user_sid)) {
64 return false;
65 }
66 } else {
67 user_sid = kSystemPrincipalSid;
68 }
69
70 // Get the alternate dump directory. We use the temp path.
71 FilePath temp_directory;
72 if (!file_util::GetTempDir(&temp_directory) || temp_directory.empty()) {
73 return false;
74 }
75
76 return InitializeVectoredCrashReporting(false, user_sid.c_str(),
[email protected]fbe67262009-10-16 22:32:5377 temp_directory.value(), GetCustomInfo(dll_path));
[email protected]53556e12009-10-15 21:49:2278}
79
80bool ShutdownCrashReporting() {
81 return ShutdownVectoredCrashReporting();
82}