Update code documentation for enum in EWK headers
[platform/framework/web/chromium-efl.git] / chrome / notification_helper / notification_helper_crash_reporter_client.cc
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.
4
5 #include "chrome/notification_helper/notification_helper_crash_reporter_client.h"
6
7 #include <memory>
8
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"
20
21 NotificationHelperCrashReporterClient::NotificationHelperCrashReporterClient() =
22     default;
23
24 NotificationHelperCrashReporterClient::
25     ~NotificationHelperCrashReporterClient() = default;
26
27 // static
28 void NotificationHelperCrashReporterClient::
29     InitializeCrashReportingForProcessWithHandler(
30         const base::FilePath& exe_path) {
31   DCHECK(!exe_path.empty());
32
33   static NotificationHelperCrashReporterClient* instance = nullptr;
34   if (instance)
35     return;
36
37   instance = new NotificationHelperCrashReporterClient();
38   ANNOTATE_LEAKING_OBJECT_PTR(instance);
39
40   crash_reporter::SetCrashReporterClient(instance);
41
42   std::wstring user_data_dir;
43   install_static::GetUserDataDirectory(&user_data_dir, nullptr);
44
45   crash_reporter::InitializeCrashpadWithEmbeddedHandler(
46       true, "notification-helper", install_static::WideToUTF8(user_data_dir),
47       exe_path);
48 }
49
50 bool NotificationHelperCrashReporterClient::ShouldCreatePipeName(
51     const std::wstring& process_type) {
52   return true;
53 }
54
55 bool NotificationHelperCrashReporterClient::GetAlternativeCrashDumpLocation(
56     std::wstring* crash_dir) {
57   return false;
58 }
59
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);
69
70   std::unique_ptr<FileVersionInfo> version_info(
71       FileVersionInfo::CreateFileVersionInfo(base::FilePath(exe_path)));
72   if (version_info) {
73     *version = base::AsWString(version_info->product_version());
74     *special_build = base::AsWString(version_info->special_build());
75   } else {
76     *version = L"0.0.0.0-devel";
77     *special_build = std::wstring();
78   }
79
80   *channel_name =
81       install_static::GetChromeChannelName(/*with_extended_stable=*/true);
82 }
83
84 bool NotificationHelperCrashReporterClient::ShouldShowRestartDialog(
85     std::wstring* title,
86     std::wstring* message,
87     bool* is_rtl_locale) {
88   // There is no UX associated with notification_helper, so no dialog should be
89   // shown.
90   return false;
91 }
92
93 bool NotificationHelperCrashReporterClient::AboutToRestart() {
94   // The notification_helper should never be restarted after a crash.
95   return false;
96 }
97
98 bool NotificationHelperCrashReporterClient::GetIsPerUserInstall() {
99   return !install_static::IsSystemInstall();
100 }
101
102 bool NotificationHelperCrashReporterClient::GetShouldDumpLargerDumps() {
103   // Use large dumps for all but the stable channel.
104   return install_static::GetChromeChannel() != version_info::Channel::STABLE;
105 }
106
107 int NotificationHelperCrashReporterClient::GetResultCodeRespawnFailed() {
108   // The restart dialog is never shown for the notification_helper.
109   NOTREACHED();
110   return 0;
111 }
112
113 bool NotificationHelperCrashReporterClient::GetCrashDumpLocation(
114     std::wstring* crash_dir) {
115   *crash_dir = install_static::GetCrashDumpLocation();
116   return !crash_dir->empty();
117 }
118
119 bool NotificationHelperCrashReporterClient::GetCrashMetricsLocation(
120     std::wstring* metrics_dir) {
121   install_static::GetUserDataDirectory(metrics_dir, nullptr);
122   return !metrics_dir->empty();
123 }
124
125 bool NotificationHelperCrashReporterClient::IsRunningUnattended() {
126   return install_static::HasEnvironmentVariable(install_static::kHeadless);
127 }
128
129 bool NotificationHelperCrashReporterClient::GetCollectStatsConsent() {
130   return install_static::GetCollectStatsConsent();
131 }
132
133 bool NotificationHelperCrashReporterClient::GetCollectStatsInSample() {
134   return install_static::GetCollectStatsInSample();
135 }
136
137 bool NotificationHelperCrashReporterClient::ReportingIsEnforcedByPolicy(
138     bool* enabled) {
139   return install_static::ReportingIsEnforcedByPolicy(enabled);
140 }
141
142 bool NotificationHelperCrashReporterClient::
143     ShouldMonitorCrashHandlerExpensively() {
144   // The expensive mechanism dedicates a process to be crashpad_handler's own
145   // crashpad_handler.
146   return false;
147 }
148
149 bool NotificationHelperCrashReporterClient::EnableBreakpadForProcess(
150     const std::string& process_type) {
151   // This is not used by Crashpad (at least on Windows).
152   NOTREACHED();
153   return true;
154 }