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_win.h" |
| 6 |
| 7 #include <windows.h> |
6 | 8 |
7 #include "base/command_line.h" | 9 #include "base/command_line.h" |
8 #include "base/environment.h" | 10 #include "base/environment.h" |
| 11 #include "base/file_version_info.h" |
9 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
10 #include "base/logging.h" | 13 #include "base/logging.h" |
11 #include "base/path_service.h" | 14 #include "base/path_service.h" |
12 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
13 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/win/registry.h" |
14 #include "build/build_config.h" | 18 #include "build/build_config.h" |
15 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
16 #include "chrome/common/chrome_paths_internal.h" | 20 #include "chrome/common/chrome_paths_internal.h" |
17 #include "chrome/common/chrome_result_codes.h" | 21 #include "chrome/common/chrome_result_codes.h" |
18 #include "chrome/common/crash_keys.h" | 22 #include "chrome/common/crash_keys.h" |
19 #include "chrome/common/env_vars.h" | 23 #include "chrome/common/env_vars.h" |
20 #include "chrome/installer/util/google_update_settings.h" | |
21 #include "content/public/common/content_switches.h" | |
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" | 24 #include "chrome/common/metrics_constants_util_win.h" |
29 #include "chrome/installer/util/google_chrome_sxs_distribution.h" | 25 #include "chrome/installer/util/google_chrome_sxs_distribution.h" |
| 26 #include "chrome/installer/util/google_update_settings.h" |
30 #include "chrome/installer/util/install_util.h" | 27 #include "chrome/installer/util/install_util.h" |
31 #include "chrome/installer/util/util_constants.h" | 28 #include "chrome/installer/util/util_constants.h" |
32 #include "components/browser_watcher/crash_reporting_metrics_win.h" | 29 #include "components/browser_watcher/crash_reporting_metrics_win.h" |
| 30 #include "content/public/common/content_switches.h" |
33 #include "policy/policy_constants.h" | 31 #include "policy/policy_constants.h" |
34 #endif | |
35 | 32 |
36 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
37 #include "components/upload_list/crash_upload_list.h" | |
38 #include "components/version_info/version_info_values.h" | |
39 #endif | |
40 | |
41 #if defined(OS_POSIX) | |
42 #include "base/debug/dump_without_crashing.h" | |
43 #endif | |
44 | |
45 #if defined(OS_ANDROID) | |
46 #include "chrome/common/descriptors_android.h" | |
47 #endif | |
48 | |
49 #if defined(OS_CHROMEOS) | |
50 #include "chrome/common/channel_info.h" | |
51 #include "chromeos/chromeos_switches.h" | |
52 #include "components/version_info/version_info.h" | |
53 #endif | |
54 | 33 |
55 namespace { | 34 namespace { |
56 | 35 |
57 #if defined(OS_WIN) | |
58 // This is the minimum version of google update that is required for deferred | 36 // This is the minimum version of google update that is required for deferred |
59 // crash uploads to work. | 37 // crash uploads to work. |
60 const char kMinUpdateVersion[] = "1.3.21.115"; | 38 const char kMinUpdateVersion[] = "1.3.21.115"; |
61 #endif | |
62 | 39 |
63 } // namespace | 40 } // namespace |
64 | 41 |
65 ChromeCrashReporterClient::ChromeCrashReporterClient() {} | 42 ChromeCrashReporterClient::ChromeCrashReporterClient() {} |
66 | 43 |
67 ChromeCrashReporterClient::~ChromeCrashReporterClient() {} | 44 ChromeCrashReporterClient::~ChromeCrashReporterClient() {} |
68 | 45 |
69 #if !defined(OS_MACOSX) && !defined(OS_WIN) | |
70 void ChromeCrashReporterClient::SetCrashReporterClientIdFromGUID( | |
71 const std::string& client_guid) { | |
72 crash_keys::SetMetricsClientIdFromGUID(client_guid); | |
73 } | |
74 #endif | |
75 | |
76 #if defined(OS_WIN) | |
77 bool ChromeCrashReporterClient::GetAlternativeCrashDumpLocation( | 46 bool ChromeCrashReporterClient::GetAlternativeCrashDumpLocation( |
78 base::FilePath* crash_dir) { | 47 base::FilePath* crash_dir) { |
79 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate | 48 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate |
80 // location to write breakpad crash dumps can be set. | 49 // location to write breakpad crash dumps can be set. |
81 std::unique_ptr<base::Environment> env(base::Environment::Create()); | 50 std::unique_ptr<base::Environment> env(base::Environment::Create()); |
82 std::string alternate_crash_dump_location; | 51 std::string alternate_crash_dump_location; |
83 if (env->GetVar("BREAKPAD_DUMP_LOCATION", &alternate_crash_dump_location)) { | 52 if (env->GetVar("BREAKPAD_DUMP_LOCATION", &alternate_crash_dump_location)) { |
84 *crash_dir = base::FilePath::FromUTF8Unsafe(alternate_crash_dump_location); | 53 *crash_dir = base::FilePath::FromUTF8Unsafe(alternate_crash_dump_location); |
85 return true; | 54 return true; |
86 } | 55 } |
87 | 56 |
88 return false; | 57 return false; |
89 } | 58 } |
90 | 59 |
91 void ChromeCrashReporterClient::GetProductNameAndVersion( | 60 void ChromeCrashReporterClient::GetProductNameAndVersion( |
92 const base::FilePath& exe_path, | 61 const base::FilePath& exe_path, |
93 base::string16* product_name, | 62 base::string16* product_name, |
94 base::string16* version, | 63 base::string16* version, |
95 base::string16* special_build, | 64 base::string16* special_build, |
96 base::string16* channel_name) { | 65 base::string16* channel_name) { |
97 DCHECK(product_name); | 66 DCHECK(product_name); |
98 DCHECK(version); | 67 DCHECK(version); |
99 DCHECK(special_build); | 68 DCHECK(special_build); |
100 DCHECK(channel_name); | 69 DCHECK(channel_name); |
101 | 70 |
102 std::unique_ptr<FileVersionInfo> version_info( | 71 scoped_ptr<FileVersionInfo> version_info( |
103 FileVersionInfo::CreateFileVersionInfo(exe_path)); | 72 FileVersionInfo::CreateFileVersionInfo(exe_path)); |
104 | 73 |
105 if (version_info.get()) { | 74 if (version_info.get()) { |
106 // Get the information from the file. | 75 // Get the information from the file. |
107 *version = version_info->product_version(); | 76 *version = version_info->product_version(); |
108 if (!version_info->is_official_build()) | 77 if (!version_info->is_official_build()) |
109 version->append(base::ASCIIToUTF16("-devel")); | 78 version->append(base::ASCIIToUTF16("-devel")); |
110 | 79 |
111 *product_name = version_info->product_short_name(); | 80 *product_name = version_info->product_short_name(); |
112 *special_build = version_info->special_build(); | 81 *special_build = version_info->special_build(); |
113 } else { | 82 } else { |
114 // No version info found. Make up the values. | 83 // No version info found. Make up the values. |
115 *product_name = base::ASCIIToUTF16("Chrome"); | 84 *product_name = base::ASCIIToUTF16("Chrome"); |
116 *version = base::ASCIIToUTF16("0.0.0.0-devel"); | 85 *version = base::ASCIIToUTF16("0.0.0.0-devel"); |
117 } | 86 } |
118 | 87 |
119 GoogleUpdateSettings::GetChromeChannelAndModifiers( | 88 GoogleUpdateSettings::GetChromeChannelAndModifiers( |
120 !GetIsPerUserInstall(exe_path), channel_name); | 89 !GetIsPerUserInstall(exe_path), channel_name); |
121 } | 90 } |
122 | 91 |
123 bool ChromeCrashReporterClient::ShouldShowRestartDialog(base::string16* title, | 92 bool ChromeCrashReporterClient::ShouldShowRestartDialog(base::string16* title, |
124 base::string16* message, | 93 base::string16* message, |
125 bool* is_rtl_locale) { | 94 bool* is_rtl_locale) { |
126 std::unique_ptr<base::Environment> env(base::Environment::Create()); | 95 scoped_ptr<base::Environment> env(base::Environment::Create()); |
127 if (!env->HasVar(env_vars::kShowRestart) || | 96 if (!env->HasVar(env_vars::kShowRestart) || |
128 !env->HasVar(env_vars::kRestartInfo) || | 97 !env->HasVar(env_vars::kRestartInfo) || |
129 env->HasVar(env_vars::kMetroConnected)) { | 98 env->HasVar(env_vars::kMetroConnected)) { |
130 return false; | 99 return false; |
131 } | 100 } |
132 | 101 |
133 std::string restart_info; | 102 std::string restart_info; |
134 env->GetVar(env_vars::kRestartInfo, &restart_info); | 103 env->GetVar(env_vars::kRestartInfo, &restart_info); |
135 | 104 |
136 // The CHROME_RESTART var contains the dialog strings separated by '|'. | 105 // The CHROME_RESTART var contains the dialog strings separated by '|'. |
137 // See ChromeBrowserMainPartsWin::PrepareRestartOnCrashEnviroment() | 106 // See ChromeBrowserMainPartsWin::PrepareRestartOnCrashEnviroment() |
138 // for details. | 107 // for details. |
139 std::vector<std::string> dlg_strings = base::SplitString( | 108 std::vector<std::string> dlg_strings = base::SplitString( |
140 restart_info, "|", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 109 restart_info, "|", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
141 | 110 |
142 if (dlg_strings.size() < 3) | 111 if (dlg_strings.size() < 3) |
143 return false; | 112 return false; |
144 | 113 |
145 *title = base::UTF8ToUTF16(dlg_strings[0]); | 114 *title = base::UTF8ToUTF16(dlg_strings[0]); |
146 *message = base::UTF8ToUTF16(dlg_strings[1]); | 115 *message = base::UTF8ToUTF16(dlg_strings[1]); |
147 *is_rtl_locale = dlg_strings[2] == env_vars::kRtlLocale; | 116 *is_rtl_locale = dlg_strings[2] == env_vars::kRtlLocale; |
148 return true; | 117 return true; |
149 } | 118 } |
150 | 119 |
151 bool ChromeCrashReporterClient::AboutToRestart() { | 120 bool ChromeCrashReporterClient::AboutToRestart() { |
152 std::unique_ptr<base::Environment> env(base::Environment::Create()); | 121 scoped_ptr<base::Environment> env(base::Environment::Create()); |
153 if (!env->HasVar(env_vars::kRestartInfo)) | 122 if (!env->HasVar(env_vars::kRestartInfo)) |
154 return false; | 123 return false; |
155 | 124 |
156 env->SetVar(env_vars::kShowRestart, "1"); | 125 env->SetVar(env_vars::kShowRestart, "1"); |
157 return true; | 126 return true; |
158 } | 127 } |
159 | 128 |
160 bool ChromeCrashReporterClient::GetDeferredUploadsSupported( | 129 bool ChromeCrashReporterClient::GetDeferredUploadsSupported( |
161 bool is_per_user_install) { | 130 bool is_per_user_install) { |
162 Version update_version = GoogleUpdateSettings::GetGoogleUpdateVersion( | 131 Version update_version = GoogleUpdateSettings::GetGoogleUpdateVersion( |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 | 212 |
244 base::win::RegKey hkcu_policy_key(HKEY_CURRENT_USER, | 213 base::win::RegKey hkcu_policy_key(HKEY_CURRENT_USER, |
245 policy::kRegistryChromePolicyKey, KEY_READ); | 214 policy::kRegistryChromePolicyKey, KEY_READ); |
246 if (hkcu_policy_key.ReadValueDW(key_name.c_str(), &value) == ERROR_SUCCESS) { | 215 if (hkcu_policy_key.ReadValueDW(key_name.c_str(), &value) == ERROR_SUCCESS) { |
247 *breakpad_enabled = value != 0; | 216 *breakpad_enabled = value != 0; |
248 return true; | 217 return true; |
249 } | 218 } |
250 | 219 |
251 return false; | 220 return false; |
252 } | 221 } |
253 #endif // defined(OS_WIN) | |
254 | 222 |
255 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
256 void ChromeCrashReporterClient::GetProductNameAndVersion( | |
257 const char** product_name, | |
258 const char** version) { | |
259 DCHECK(product_name); | |
260 DCHECK(version); | |
261 #if defined(OS_ANDROID) | |
262 *product_name = "Chrome_Android"; | |
263 #elif defined(OS_CHROMEOS) | |
264 *product_name = "Chrome_ChromeOS"; | |
265 #else // OS_LINUX | |
266 #if !defined(ADDRESS_SANITIZER) | |
267 *product_name = "Chrome_Linux"; | |
268 #else | |
269 *product_name = "Chrome_Linux_ASan"; | |
270 #endif | |
271 #endif | |
272 | |
273 *version = PRODUCT_VERSION; | |
274 } | |
275 | |
276 base::FilePath ChromeCrashReporterClient::GetReporterLogFilename() { | |
277 return base::FilePath(CrashUploadList::kReporterLogFilename); | |
278 } | |
279 #endif | |
280 | 223 |
281 bool ChromeCrashReporterClient::GetCrashDumpLocation( | 224 bool ChromeCrashReporterClient::GetCrashDumpLocation( |
282 base::FilePath* crash_dir) { | 225 base::FilePath* crash_dir) { |
283 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate | 226 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate |
284 // location to write breakpad crash dumps can be set. | 227 // location to write breakpad crash dumps can be set. |
285 std::unique_ptr<base::Environment> env(base::Environment::Create()); | 228 scoped_ptr<base::Environment> env(base::Environment::Create()); |
286 std::string alternate_crash_dump_location; | 229 std::string alternate_crash_dump_location; |
287 if (env->GetVar("BREAKPAD_DUMP_LOCATION", &alternate_crash_dump_location)) { | 230 if (env->GetVar("BREAKPAD_DUMP_LOCATION", &alternate_crash_dump_location)) { |
288 base::FilePath crash_dumps_dir_path = | 231 base::FilePath crash_dumps_dir_path = |
289 base::FilePath::FromUTF8Unsafe(alternate_crash_dump_location); | 232 base::FilePath::FromUTF8Unsafe(alternate_crash_dump_location); |
290 | 233 |
291 #if defined(OS_WIN) | |
292 // If this environment variable exists, then for the time being, | 234 // If this environment variable exists, then for the time being, |
293 // short-circuit how it's handled on Windows. Honoring this | 235 // short-circuit how it's handled on Windows. Honoring this |
294 // variable is required in order to symbolize stack traces in | 236 // variable is required in order to symbolize stack traces in |
295 // Telemetry based tests: http://crbug.com/561763. | 237 // Telemetry based tests: http://crbug.com/561763. |
296 *crash_dir = crash_dumps_dir_path; | 238 *crash_dir = crash_dumps_dir_path; |
297 return true; | 239 return true; |
298 #else | |
299 PathService::Override(chrome::DIR_CRASH_DUMPS, crash_dumps_dir_path); | |
300 #endif | |
301 } | 240 } |
302 | 241 |
303 #if defined(OS_WIN) | |
304 // TODO(scottmg): Consider supporting --user-data-dir. See | 242 // TODO(scottmg): Consider supporting --user-data-dir. See |
305 // https://crbug.com/565446. | 243 // https://crbug.com/565446. |
306 return chrome::GetDefaultCrashDumpLocation(crash_dir); | 244 return chrome::GetDefaultCrashDumpLocation(crash_dir); |
307 #else | |
308 return PathService::Get(chrome::DIR_CRASH_DUMPS, crash_dir); | |
309 #endif | |
310 } | 245 } |
311 | 246 |
312 size_t ChromeCrashReporterClient::RegisterCrashKeys() { | 247 size_t ChromeCrashReporterClient::RegisterCrashKeys() { |
313 return crash_keys::RegisterChromeCrashKeys(); | 248 return crash_keys::RegisterChromeCrashKeys(); |
314 } | 249 } |
315 | 250 |
316 bool ChromeCrashReporterClient::IsRunningUnattended() { | 251 bool ChromeCrashReporterClient::IsRunningUnattended() { |
317 std::unique_ptr<base::Environment> env(base::Environment::Create()); | 252 scoped_ptr<base::Environment> env(base::Environment::Create()); |
318 return env->HasVar(env_vars::kHeadless); | 253 return env->HasVar(env_vars::kHeadless); |
319 } | 254 } |
320 | 255 |
321 bool ChromeCrashReporterClient::GetCollectStatsConsent() { | 256 bool ChromeCrashReporterClient::GetCollectStatsConsent() { |
322 #if defined(GOOGLE_CHROME_BUILD) | 257 #if defined(GOOGLE_CHROME_BUILD) |
323 bool is_official_chrome_build = true; | 258 bool is_official_chrome_build = true; |
324 #else | 259 #else |
325 bool is_official_chrome_build = false; | 260 bool is_official_chrome_build = false; |
326 #endif | 261 #endif |
327 | 262 |
328 #if defined(OS_CHROMEOS) | |
329 bool is_guest_session = base::CommandLine::ForCurrentProcess()->HasSwitch( | |
330 chromeos::switches::kGuestSession); | |
331 bool is_stable_channel = | |
332 chrome::GetChannel() == version_info::Channel::STABLE; | |
333 | |
334 if (is_guest_session && is_stable_channel) | |
335 return false; | |
336 #endif // defined(OS_CHROMEOS) | |
337 | |
338 #if defined(OS_ANDROID) | |
339 // TODO(jcivelli): we should not initialize the crash-reporter when it was not | |
340 // enabled. Right now if it is disabled we still generate the minidumps but we | |
341 // do not upload them. | |
342 return is_official_chrome_build; | |
343 #else // !defined(OS_ANDROID) | |
344 return is_official_chrome_build && | 263 return is_official_chrome_build && |
345 GoogleUpdateSettings::GetCollectStatsConsent(); | 264 GoogleUpdateSettings::GetCollectStatsConsent(); |
346 #endif // defined(OS_ANDROID) | |
347 } | 265 } |
348 | 266 |
349 #if defined(OS_ANDROID) | |
350 int ChromeCrashReporterClient::GetAndroidMinidumpDescriptor() { | |
351 return kAndroidMinidumpDescriptor; | |
352 } | |
353 #endif | |
354 | |
355 bool ChromeCrashReporterClient::EnableBreakpadForProcess( | 267 bool ChromeCrashReporterClient::EnableBreakpadForProcess( |
356 const std::string& process_type) { | 268 const std::string& process_type) { |
357 return process_type == switches::kRendererProcess || | 269 return process_type == switches::kRendererProcess || |
358 process_type == switches::kPpapiPluginProcess || | 270 process_type == switches::kPpapiPluginProcess || |
359 process_type == switches::kZygoteProcess || | 271 process_type == switches::kZygoteProcess || |
360 process_type == switches::kGpuProcess; | 272 process_type == switches::kGpuProcess; |
361 } | 273 } |
OLD | NEW |