1 // Copyright 2018 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/notification_helper/notification_helper_crash_reporter_client.h"
9 #include "base/check.h"
10 #include "base/debug/leak_annotations.h"
11 #include "base/file_version_info.h"
12 #include "base/notreached.h"
13 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h"
15 #include "chrome/common/chrome_version.h"
16 #include "chrome/install_static/install_util.h"
17 #include "chrome/install_static/user_data_dir.h"
18 #include "components/crash/core/app/crashpad.h"
19 #include "components/version_info/channel.h"
21 NotificationHelperCrashReporterClient::NotificationHelperCrashReporterClient() =
24 NotificationHelperCrashReporterClient::
25 ~NotificationHelperCrashReporterClient() = default;
28 void NotificationHelperCrashReporterClient::
29 InitializeCrashReportingForProcessWithHandler(
30 const base::FilePath& exe_path) {
31 DCHECK(!exe_path.empty());
33 static NotificationHelperCrashReporterClient* instance = nullptr;
37 instance = new NotificationHelperCrashReporterClient();
38 ANNOTATE_LEAKING_OBJECT_PTR(instance);
40 crash_reporter::SetCrashReporterClient(instance);
42 std::wstring user_data_dir;
43 install_static::GetUserDataDirectory(&user_data_dir, nullptr);
45 crash_reporter::InitializeCrashpadWithEmbeddedHandler(
46 true, "notification-helper", install_static::WideToUTF8(user_data_dir),
50 bool NotificationHelperCrashReporterClient::ShouldCreatePipeName(
51 const std::wstring& process_type) {
55 bool NotificationHelperCrashReporterClient::GetAlternativeCrashDumpLocation(
56 std::wstring* crash_dir) {
60 void NotificationHelperCrashReporterClient::GetProductNameAndVersion(
61 const std::wstring& exe_path,
62 std::wstring* product_name,
63 std::wstring* version,
64 std::wstring* special_build,
65 std::wstring* channel_name) {
66 // Report crashes under the same product name as the browser. This string
67 // MUST match server-side configuration.
68 *product_name = base::ASCIIToWide(PRODUCT_SHORTNAME_STRING);
70 std::unique_ptr<FileVersionInfo> version_info(
71 FileVersionInfo::CreateFileVersionInfo(base::FilePath(exe_path)));
73 *version = base::AsWString(version_info->product_version());
74 *special_build = base::AsWString(version_info->special_build());
76 *version = L"0.0.0.0-devel";
77 *special_build = std::wstring();
81 install_static::GetChromeChannelName(/*with_extended_stable=*/true);
84 bool NotificationHelperCrashReporterClient::ShouldShowRestartDialog(
86 std::wstring* message,
87 bool* is_rtl_locale) {
88 // There is no UX associated with notification_helper, so no dialog should be
93 bool NotificationHelperCrashReporterClient::AboutToRestart() {
94 // The notification_helper should never be restarted after a crash.
98 bool NotificationHelperCrashReporterClient::GetIsPerUserInstall() {
99 return !install_static::IsSystemInstall();
102 bool NotificationHelperCrashReporterClient::GetShouldDumpLargerDumps() {
103 // Use large dumps for all but the stable channel.
104 return install_static::GetChromeChannel() != version_info::Channel::STABLE;
107 int NotificationHelperCrashReporterClient::GetResultCodeRespawnFailed() {
108 // The restart dialog is never shown for the notification_helper.
113 bool NotificationHelperCrashReporterClient::GetCrashDumpLocation(
114 std::wstring* crash_dir) {
115 *crash_dir = install_static::GetCrashDumpLocation();
116 return !crash_dir->empty();
119 bool NotificationHelperCrashReporterClient::GetCrashMetricsLocation(
120 std::wstring* metrics_dir) {
121 install_static::GetUserDataDirectory(metrics_dir, nullptr);
122 return !metrics_dir->empty();
125 bool NotificationHelperCrashReporterClient::IsRunningUnattended() {
126 return install_static::HasEnvironmentVariable(install_static::kHeadless);
129 bool NotificationHelperCrashReporterClient::GetCollectStatsConsent() {
130 return install_static::GetCollectStatsConsent();
133 bool NotificationHelperCrashReporterClient::GetCollectStatsInSample() {
134 return install_static::GetCollectStatsInSample();
137 bool NotificationHelperCrashReporterClient::ReportingIsEnforcedByPolicy(
139 return install_static::ReportingIsEnforcedByPolicy(enabled);
142 bool NotificationHelperCrashReporterClient::
143 ShouldMonitorCrashHandlerExpensively() {
144 // The expensive mechanism dedicates a process to be crashpad_handler's own
149 bool NotificationHelperCrashReporterClient::EnableBreakpadForProcess(
150 const std::string& process_type) {
151 // This is not used by Crashpad (at least on Windows).