| // Copyright 2013 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| // TODO(ananta/scottmg) |
| // Add test coverage for Crashpad. |
| #include "chrome/app/chrome_crash_reporter_client_win.h" |
| |
| #include <assert.h> |
| #include <windows.h> |
| |
| #include <memory> |
| #include <string> |
| |
| #include "build/build_config.h" |
| #include "chrome/common/chrome_result_codes.h" |
| #include "chrome/common/crash_keys.h" |
| #include "chrome/install_static/install_util.h" |
| |
| ChromeCrashReporterClient::ChromeCrashReporterClient() {} |
| |
| ChromeCrashReporterClient::~ChromeCrashReporterClient() {} |
| |
| bool ChromeCrashReporterClient::GetAlternativeCrashDumpLocation( |
| base::string16* crash_dir) { |
| // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate |
| // location to write breakpad crash dumps can be set. |
| *crash_dir = |
| install_static::GetEnvironmentString16(L"BREAKPAD_DUMP_LOCATION"); |
| return !crash_dir->empty(); |
| } |
| |
| void ChromeCrashReporterClient::GetProductNameAndVersion( |
| const base::string16& exe_path, |
| base::string16* product_name, |
| base::string16* version, |
| base::string16* special_build, |
| base::string16* channel_name) { |
| assert(product_name); |
| assert(version); |
| assert(special_build); |
| assert(channel_name); |
| |
| install_static::GetExecutableVersionDetails( |
| exe_path, product_name, version, special_build, channel_name); |
| } |
| |
| bool ChromeCrashReporterClient::ShouldShowRestartDialog(base::string16* title, |
| base::string16* message, |
| bool* is_rtl_locale) { |
| if (!install_static::HasEnvironmentVariable16( |
| install_static::kShowRestart) || |
| !install_static::HasEnvironmentVariable16( |
| install_static::kRestartInfo)) { |
| return false; |
| } |
| |
| base::string16 restart_info = |
| install_static::GetEnvironmentString16(install_static::kRestartInfo); |
| |
| // The CHROME_RESTART var contains the dialog strings separated by '|'. |
| // See ChromeBrowserMainPartsWin::PrepareRestartOnCrashEnviroment() |
| // for details. |
| std::vector<base::string16> dlg_strings = install_static::TokenizeString16( |
| restart_info, L'|', true); // true = Trim whitespace. |
| |
| if (dlg_strings.size() < 3) |
| return false; |
| |
| *title = dlg_strings[0]; |
| *message = dlg_strings[1]; |
| *is_rtl_locale = dlg_strings[2] == install_static::kRtlLocale; |
| return true; |
| } |
| |
| bool ChromeCrashReporterClient::AboutToRestart() { |
| if (!install_static::HasEnvironmentVariable16(install_static::kRestartInfo)) |
| return false; |
| |
| install_static::SetEnvironmentString16(install_static::kShowRestart, L"1"); |
| return true; |
| } |
| |
| bool ChromeCrashReporterClient::GetDeferredUploadsSupported( |
| bool is_per_user_install) { |
| return false; |
| } |
| |
| bool ChromeCrashReporterClient::GetIsPerUserInstall( |
| const base::string16& exe_path) { |
| return !install_static::IsSystemInstall(exe_path.c_str()); |
| } |
| |
| bool ChromeCrashReporterClient::GetShouldDumpLargerDumps( |
| bool is_per_user_install) { |
| base::string16 channel_name; |
| install_static::GetChromeChannelName(is_per_user_install, |
| false, // !add_modifier |
| &channel_name); |
| // Capture more detail in crash dumps for Beta, Dev, Canary channels and |
| // if channel is unknown (e.g. Chromium or developer builds). |
| return (channel_name == install_static::kChromeChannelBeta || |
| channel_name == install_static::kChromeChannelDev || |
| channel_name == install_static::kChromeChannelCanary || |
| channel_name == install_static::kChromeChannelUnknown); |
| } |
| |
| int ChromeCrashReporterClient::GetResultCodeRespawnFailed() { |
| return chrome::RESULT_CODE_RESPAWN_FAILED; |
| } |
| |
| bool ChromeCrashReporterClient::ReportingIsEnforcedByPolicy( |
| bool* crashpad_enabled) { |
| // Determine whether configuration management allows loading the crash |
| // reporter. |
| // Since the configuration management infrastructure is not initialized at |
| // this point, we read the corresponding registry key directly. The return |
| // status indicates whether policy data was successfully read. If it is true, |
| // |breakpad_enabled| contains the value set by policy. |
| return install_static::ReportingIsEnforcedByPolicy(crashpad_enabled); |
| } |
| |
| |
| bool ChromeCrashReporterClient::GetCrashDumpLocation( |
| base::string16* crash_dir) { |
| // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate |
| // location to write breakpad crash dumps can be set. |
| // If this environment variable exists, then for the time being, |
| // short-circuit how it's handled on Windows. Honoring this |
| // variable is required in order to symbolize stack traces in |
| // Telemetry based tests: http://crbug.com/561763. |
| if (GetAlternativeCrashDumpLocation(crash_dir)) |
| return true; |
| |
| // TODO(scottmg): Consider supporting --user-data-dir. See |
| // https://crbug.com/565446. |
| return install_static::GetDefaultCrashDumpLocation(crash_dir); |
| } |
| |
| size_t ChromeCrashReporterClient::RegisterCrashKeys() { |
| return crash_keys::RegisterChromeCrashKeys(); |
| } |
| |
| bool ChromeCrashReporterClient::IsRunningUnattended() { |
| return install_static::HasEnvironmentVariable16(install_static::kHeadless); |
| } |
| |
| bool ChromeCrashReporterClient::GetCollectStatsConsent() { |
| return install_static::GetCollectStatsConsent(); |
| } |
| |
| bool ChromeCrashReporterClient::EnableBreakpadForProcess( |
| const std::string& process_type) { |
| return process_type == install_static::kRendererProcess || |
| process_type == install_static::kPpapiPluginProcess || |
| process_type == install_static::kGpuProcess; |
| } |