OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/app/chrome_crash_reporter_client.h" | 5 #include "chrome/app/chrome_crash_reporter_client.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/environment.h" | 8 #include "base/environment.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
15 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
16 #include "chrome/common/chrome_paths_internal.h" | 16 #include "chrome/common/chrome_paths_internal.h" |
17 #include "chrome/common/chrome_result_codes.h" | 17 #include "chrome/common/chrome_result_codes.h" |
18 #include "chrome/common/crash_keys.h" | 18 #include "chrome/common/crash_keys.h" |
19 #include "chrome/common/env_vars.h" | 19 #include "chrome/common/env_vars.h" |
20 #include "chrome/installer/util/google_update_settings.h" | 20 #include "chrome/installer/util/google_update_settings.h" |
21 #include "content/public/common/content_switches.h" | 21 #include "content/public/common/content_switches.h" |
22 | 22 |
23 #if defined(OS_WIN) | |
24 #include <windows.h> | |
25 | |
26 #include "base/file_version_info.h" | |
27 #include "base/win/registry.h" | |
28 #include "chrome/common/metrics_constants_util_win.h" | |
29 #include "chrome/installer/util/google_chrome_sxs_distribution.h" | |
30 #include "chrome/installer/util/install_util.h" | |
31 #include "chrome/installer/util/util_constants.h" | |
32 #include "components/browser_watcher/crash_reporting_metrics_win.h" | |
33 #include "policy/policy_constants.h" | |
34 #endif | |
35 | |
36 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 23 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
37 #include "components/upload_list/crash_upload_list.h" | 24 #include "components/upload_list/crash_upload_list.h" |
38 #include "components/version_info/version_info_values.h" | 25 #include "components/version_info/version_info_values.h" |
39 #endif | 26 #endif |
40 | 27 |
41 #if defined(OS_POSIX) | 28 #if defined(OS_POSIX) |
42 #include "base/debug/dump_without_crashing.h" | 29 #include "base/debug/dump_without_crashing.h" |
43 #endif | 30 #endif |
44 | 31 |
45 #if defined(OS_ANDROID) | 32 #if defined(OS_ANDROID) |
46 #include "chrome/common/descriptors_android.h" | 33 #include "chrome/common/descriptors_android.h" |
47 #endif | 34 #endif |
48 | 35 |
49 #if defined(OS_CHROMEOS) | 36 #if defined(OS_CHROMEOS) |
50 #include "chrome/common/channel_info.h" | 37 #include "chrome/common/channel_info.h" |
51 #include "chromeos/chromeos_switches.h" | 38 #include "chromeos/chromeos_switches.h" |
52 #include "components/version_info/version_info.h" | 39 #include "components/version_info/version_info.h" |
53 #endif | 40 #endif |
54 | 41 |
55 namespace { | |
56 | |
57 #if defined(OS_WIN) | |
58 // This is the minimum version of google update that is required for deferred | |
59 // crash uploads to work. | |
60 const char kMinUpdateVersion[] = "1.3.21.115"; | |
61 #endif | |
62 | |
63 } // namespace | |
64 | |
65 ChromeCrashReporterClient::ChromeCrashReporterClient() {} | 42 ChromeCrashReporterClient::ChromeCrashReporterClient() {} |
66 | 43 |
67 ChromeCrashReporterClient::~ChromeCrashReporterClient() {} | 44 ChromeCrashReporterClient::~ChromeCrashReporterClient() {} |
68 | 45 |
69 #if !defined(OS_MACOSX) && !defined(OS_WIN) | 46 #if !defined(OS_MACOSX) |
70 void ChromeCrashReporterClient::SetCrashReporterClientIdFromGUID( | 47 void ChromeCrashReporterClient::SetCrashReporterClientIdFromGUID( |
71 const std::string& client_guid) { | 48 const std::string& client_guid) { |
72 crash_keys::SetMetricsClientIdFromGUID(client_guid); | 49 crash_keys::SetMetricsClientIdFromGUID(client_guid); |
73 } | 50 } |
74 #endif | 51 #endif |
75 | 52 |
76 #if defined(OS_WIN) | |
77 bool ChromeCrashReporterClient::GetAlternativeCrashDumpLocation( | |
78 base::FilePath* crash_dir) { | |
79 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate | |
80 // location to write breakpad crash dumps can be set. | |
81 std::unique_ptr<base::Environment> env(base::Environment::Create()); | |
82 std::string alternate_crash_dump_location; | |
83 if (env->GetVar("BREAKPAD_DUMP_LOCATION", &alternate_crash_dump_location)) { | |
84 *crash_dir = base::FilePath::FromUTF8Unsafe(alternate_crash_dump_location); | |
85 return true; | |
86 } | |
87 | |
88 return false; | |
89 } | |
90 | |
91 void ChromeCrashReporterClient::GetProductNameAndVersion( | |
92 const base::FilePath& exe_path, | |
93 base::string16* product_name, | |
94 base::string16* version, | |
95 base::string16* special_build, | |
96 base::string16* channel_name) { | |
97 DCHECK(product_name); | |
98 DCHECK(version); | |
99 DCHECK(special_build); | |
100 DCHECK(channel_name); | |
101 | |
102 std::unique_ptr<FileVersionInfo> version_info( | |
103 FileVersionInfo::CreateFileVersionInfo(exe_path)); | |
104 | |
105 if (version_info.get()) { | |
106 // Get the information from the file. | |
107 *version = version_info->product_version(); | |
108 if (!version_info->is_official_build()) | |
109 version->append(base::ASCIIToUTF16("-devel")); | |
110 | |
111 *product_name = version_info->product_short_name(); | |
112 *special_build = version_info->special_build(); | |
113 } else { | |
114 // No version info found. Make up the values. | |
115 *product_name = base::ASCIIToUTF16("Chrome"); | |
116 *version = base::ASCIIToUTF16("0.0.0.0-devel"); | |
117 } | |
118 | |
119 GoogleUpdateSettings::GetChromeChannelAndModifiers( | |
120 !GetIsPerUserInstall(exe_path), channel_name); | |
121 } | |
122 | |
123 bool ChromeCrashReporterClient::ShouldShowRestartDialog(base::string16* title, | |
124 base::string16* message, | |
125 bool* is_rtl_locale) { | |
126 std::unique_ptr<base::Environment> env(base::Environment::Create()); | |
127 if (!env->HasVar(env_vars::kShowRestart) || | |
128 !env->HasVar(env_vars::kRestartInfo) || | |
129 env->HasVar(env_vars::kMetroConnected)) { | |
130 return false; | |
131 } | |
132 | |
133 std::string restart_info; | |
134 env->GetVar(env_vars::kRestartInfo, &restart_info); | |
135 | |
136 // The CHROME_RESTART var contains the dialog strings separated by '|'. | |
137 // See ChromeBrowserMainPartsWin::PrepareRestartOnCrashEnviroment() | |
138 // for details. | |
139 std::vector<std::string> dlg_strings = base::SplitString( | |
140 restart_info, "|", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | |
141 | |
142 if (dlg_strings.size() < 3) | |
143 return false; | |
144 | |
145 *title = base::UTF8ToUTF16(dlg_strings[0]); | |
146 *message = base::UTF8ToUTF16(dlg_strings[1]); | |
147 *is_rtl_locale = dlg_strings[2] == env_vars::kRtlLocale; | |
148 return true; | |
149 } | |
150 | |
151 bool ChromeCrashReporterClient::AboutToRestart() { | |
152 std::unique_ptr<base::Environment> env(base::Environment::Create()); | |
153 if (!env->HasVar(env_vars::kRestartInfo)) | |
154 return false; | |
155 | |
156 env->SetVar(env_vars::kShowRestart, "1"); | |
157 return true; | |
158 } | |
159 | |
160 bool ChromeCrashReporterClient::GetDeferredUploadsSupported( | |
161 bool is_per_user_install) { | |
162 Version update_version = GoogleUpdateSettings::GetGoogleUpdateVersion( | |
163 !is_per_user_install); | |
164 if (!update_version.IsValid() || | |
165 update_version < base::Version(kMinUpdateVersion)) | |
166 return false; | |
167 | |
168 return true; | |
169 } | |
170 | |
171 bool ChromeCrashReporterClient::GetIsPerUserInstall( | |
172 const base::FilePath& exe_path) { | |
173 return InstallUtil::IsPerUserInstall(exe_path); | |
174 } | |
175 | |
176 bool ChromeCrashReporterClient::GetShouldDumpLargerDumps( | |
177 bool is_per_user_install) { | |
178 base::string16 channel_name = | |
179 GoogleUpdateSettings::GetChromeChannel(!is_per_user_install); | |
180 | |
181 // Capture more detail in crash dumps for Beta, Dev, Canary channels and | |
182 // if channel is unknown (e.g. Chromium or developer builds). | |
183 return (channel_name == installer::kChromeChannelBeta || | |
184 channel_name == installer::kChromeChannelDev || | |
185 channel_name == GoogleChromeSxSDistribution::ChannelName() || | |
186 channel_name == installer::kChromeChannelUnknown); | |
187 } | |
188 | |
189 int ChromeCrashReporterClient::GetResultCodeRespawnFailed() { | |
190 return chrome::RESULT_CODE_RESPAWN_FAILED; | |
191 } | |
192 | |
193 void ChromeCrashReporterClient::InitBrowserCrashDumpsRegKey() { | |
194 #if !defined(NACL_WIN64) | |
195 if (GetCollectStatsConsent()){ | |
196 crash_reporting_metrics_.reset(new browser_watcher::CrashReportingMetrics( | |
197 chrome::GetBrowserCrashDumpAttemptsRegistryPath())); | |
198 } | |
199 #endif | |
200 } | |
201 | |
202 void ChromeCrashReporterClient::RecordCrashDumpAttempt(bool is_real_crash) { | |
203 #if !defined(NACL_WIN64) | |
204 if (!crash_reporting_metrics_) | |
205 return; | |
206 | |
207 if (is_real_crash) | |
208 crash_reporting_metrics_->RecordCrashDumpAttempt(); | |
209 else | |
210 crash_reporting_metrics_->RecordDumpWithoutCrashAttempt(); | |
211 #endif | |
212 } | |
213 | |
214 void ChromeCrashReporterClient::RecordCrashDumpAttemptResult(bool is_real_crash, | |
215 bool succeeded) { | |
216 #if !defined(NACL_WIN64) | |
217 if (!crash_reporting_metrics_) | |
218 return; | |
219 | |
220 if (is_real_crash) | |
221 crash_reporting_metrics_->RecordCrashDumpAttemptResult(succeeded); | |
222 else | |
223 crash_reporting_metrics_->RecordDumpWithoutCrashAttemptResult(succeeded); | |
224 #endif | |
225 } | |
226 | |
227 bool ChromeCrashReporterClient::ReportingIsEnforcedByPolicy( | |
228 bool* breakpad_enabled) { | |
229 // Determine whether configuration management allows loading the crash reporter. | |
230 // Since the configuration management infrastructure is not initialized at this | |
231 // point, we read the corresponding registry key directly. The return status | |
232 // indicates whether policy data was successfully read. If it is true, | |
233 // |breakpad_enabled| contains the value set by policy. | |
234 base::string16 key_name = | |
235 base::UTF8ToUTF16(policy::key::kMetricsReportingEnabled); | |
236 DWORD value = 0; | |
237 base::win::RegKey hklm_policy_key(HKEY_LOCAL_MACHINE, | |
238 policy::kRegistryChromePolicyKey, KEY_READ); | |
239 if (hklm_policy_key.ReadValueDW(key_name.c_str(), &value) == ERROR_SUCCESS) { | |
240 *breakpad_enabled = value != 0; | |
241 return true; | |
242 } | |
243 | |
244 base::win::RegKey hkcu_policy_key(HKEY_CURRENT_USER, | |
245 policy::kRegistryChromePolicyKey, KEY_READ); | |
246 if (hkcu_policy_key.ReadValueDW(key_name.c_str(), &value) == ERROR_SUCCESS) { | |
247 *breakpad_enabled = value != 0; | |
248 return true; | |
249 } | |
250 | |
251 return false; | |
252 } | |
253 #endif // defined(OS_WIN) | |
254 | |
255 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 53 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
256 void ChromeCrashReporterClient::GetProductNameAndVersion( | 54 void ChromeCrashReporterClient::GetProductNameAndVersion( |
257 const char** product_name, | 55 const char** product_name, |
258 const char** version) { | 56 const char** version) { |
259 DCHECK(product_name); | 57 DCHECK(product_name); |
260 DCHECK(version); | 58 DCHECK(version); |
261 #if defined(OS_ANDROID) | 59 #if defined(OS_ANDROID) |
262 *product_name = "Chrome_Android"; | 60 *product_name = "Chrome_Android"; |
263 #elif defined(OS_CHROMEOS) | 61 #elif defined(OS_CHROMEOS) |
264 *product_name = "Chrome_ChromeOS"; | 62 *product_name = "Chrome_ChromeOS"; |
(...skipping 15 matching lines...) Expand all Loading... |
280 | 78 |
281 bool ChromeCrashReporterClient::GetCrashDumpLocation( | 79 bool ChromeCrashReporterClient::GetCrashDumpLocation( |
282 base::FilePath* crash_dir) { | 80 base::FilePath* crash_dir) { |
283 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate | 81 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate |
284 // location to write breakpad crash dumps can be set. | 82 // location to write breakpad crash dumps can be set. |
285 std::unique_ptr<base::Environment> env(base::Environment::Create()); | 83 std::unique_ptr<base::Environment> env(base::Environment::Create()); |
286 std::string alternate_crash_dump_location; | 84 std::string alternate_crash_dump_location; |
287 if (env->GetVar("BREAKPAD_DUMP_LOCATION", &alternate_crash_dump_location)) { | 85 if (env->GetVar("BREAKPAD_DUMP_LOCATION", &alternate_crash_dump_location)) { |
288 base::FilePath crash_dumps_dir_path = | 86 base::FilePath crash_dumps_dir_path = |
289 base::FilePath::FromUTF8Unsafe(alternate_crash_dump_location); | 87 base::FilePath::FromUTF8Unsafe(alternate_crash_dump_location); |
290 | |
291 #if defined(OS_WIN) | |
292 // If this environment variable exists, then for the time being, | |
293 // short-circuit how it's handled on Windows. Honoring this | |
294 // variable is required in order to symbolize stack traces in | |
295 // Telemetry based tests: http://crbug.com/561763. | |
296 *crash_dir = crash_dumps_dir_path; | |
297 return true; | |
298 #else | |
299 PathService::Override(chrome::DIR_CRASH_DUMPS, crash_dumps_dir_path); | 88 PathService::Override(chrome::DIR_CRASH_DUMPS, crash_dumps_dir_path); |
300 #endif | |
301 } | 89 } |
302 | |
303 #if defined(OS_WIN) | |
304 // TODO(scottmg): Consider supporting --user-data-dir. See | |
305 // https://crbug.com/565446. | |
306 return chrome::GetDefaultCrashDumpLocation(crash_dir); | |
307 #else | |
308 return PathService::Get(chrome::DIR_CRASH_DUMPS, crash_dir); | 90 return PathService::Get(chrome::DIR_CRASH_DUMPS, crash_dir); |
309 #endif | |
310 } | 91 } |
311 | 92 |
312 size_t ChromeCrashReporterClient::RegisterCrashKeys() { | 93 size_t ChromeCrashReporterClient::RegisterCrashKeys() { |
313 return crash_keys::RegisterChromeCrashKeys(); | 94 return crash_keys::RegisterChromeCrashKeys(); |
314 } | 95 } |
315 | 96 |
316 bool ChromeCrashReporterClient::IsRunningUnattended() { | 97 bool ChromeCrashReporterClient::IsRunningUnattended() { |
317 std::unique_ptr<base::Environment> env(base::Environment::Create()); | 98 std::unique_ptr<base::Environment> env(base::Environment::Create()); |
318 return env->HasVar(env_vars::kHeadless); | 99 return env->HasVar(env_vars::kHeadless); |
319 } | 100 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 } | 133 } |
353 #endif | 134 #endif |
354 | 135 |
355 bool ChromeCrashReporterClient::EnableBreakpadForProcess( | 136 bool ChromeCrashReporterClient::EnableBreakpadForProcess( |
356 const std::string& process_type) { | 137 const std::string& process_type) { |
357 return process_type == switches::kRendererProcess || | 138 return process_type == switches::kRendererProcess || |
358 process_type == switches::kPpapiPluginProcess || | 139 process_type == switches::kPpapiPluginProcess || |
359 process_type == switches::kZygoteProcess || | 140 process_type == switches::kZygoteProcess || |
360 process_type == switches::kGpuProcess; | 141 process_type == switches::kGpuProcess; |
361 } | 142 } |
OLD | NEW |