| 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 // TODO(ananta/scottmg) |
| 5 // Add test coverage for Crashpad. |
| 5 #include "chrome/app/chrome_crash_reporter_client_win.h" | 6 #include "chrome/app/chrome_crash_reporter_client_win.h" |
| 6 | 7 |
| 7 #include <windows.h> | 8 #include <windows.h> |
| 8 | 9 |
| 9 #include <memory> | 10 #include <memory> |
| 11 #include <string> |
| 10 | 12 |
| 11 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 12 #include "base/environment.h" | |
| 13 #include "base/file_version_info.h" | |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 17 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/win/registry.h" | 19 #include "base/version.h" |
| 20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 21 #include "chrome/common/chrome_paths.h" | |
| 22 #include "chrome/common/chrome_paths_internal.h" | |
| 23 #include "chrome/common/chrome_result_codes.h" | 21 #include "chrome/common/chrome_result_codes.h" |
| 24 #include "chrome/common/crash_keys.h" | 22 #include "chrome/common/crash_keys.h" |
| 25 #include "chrome/common/env_vars.h" | 23 #include "chrome/common/env_vars.h" |
| 26 #include "chrome/common/metrics_constants_util_win.h" | 24 #include "chrome/install_static/install_util.h" |
| 27 #include "chrome/installer/util/google_chrome_sxs_distribution.h" | |
| 28 #include "chrome/installer/util/google_update_settings.h" | |
| 29 #include "chrome/installer/util/install_util.h" | |
| 30 #include "chrome/installer/util/util_constants.h" | |
| 31 #include "content/public/common/content_switches.h" | 25 #include "content/public/common/content_switches.h" |
| 32 #include "policy/policy_constants.h" | |
| 33 | |
| 34 | 26 |
| 35 namespace { | 27 namespace { |
| 36 | 28 |
| 37 // This is the minimum version of google update that is required for deferred | 29 // This is the minimum version of google update that is required for deferred |
| 38 // crash uploads to work. | 30 // crash uploads to work. |
| 39 const char kMinUpdateVersion[] = "1.3.21.115"; | 31 const char kMinUpdateVersion[] = "1.3.21.115"; |
| 40 | 32 |
| 41 } // namespace | 33 } // namespace |
| 42 | 34 |
| 43 ChromeCrashReporterClient::ChromeCrashReporterClient() {} | 35 ChromeCrashReporterClient::ChromeCrashReporterClient() {} |
| 44 | 36 |
| 45 ChromeCrashReporterClient::~ChromeCrashReporterClient() {} | 37 ChromeCrashReporterClient::~ChromeCrashReporterClient() {} |
| 46 | 38 |
| 47 bool ChromeCrashReporterClient::GetAlternativeCrashDumpLocation( | 39 bool ChromeCrashReporterClient::GetAlternativeCrashDumpLocation( |
| 48 base::FilePath* crash_dir) { | 40 base::FilePath* crash_dir) { |
| 49 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate | 41 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate |
| 50 // location to write breakpad crash dumps can be set. | 42 // location to write breakpad crash dumps can be set. |
| 51 std::unique_ptr<base::Environment> env(base::Environment::Create()); | 43 std::string alternate_crash_dump_location = |
| 52 std::string alternate_crash_dump_location; | 44 install_static::GetEnvironmentString("BREAKPAD_DUMP_LOCATION"); |
| 53 if (env->GetVar("BREAKPAD_DUMP_LOCATION", &alternate_crash_dump_location)) { | 45 if (!alternate_crash_dump_location.empty()) { |
| 54 *crash_dir = base::FilePath::FromUTF8Unsafe(alternate_crash_dump_location); | 46 *crash_dir = base::FilePath::FromUTF8Unsafe(alternate_crash_dump_location); |
| 55 return true; | 47 return true; |
| 56 } | 48 } |
| 57 | |
| 58 return false; | 49 return false; |
| 59 } | 50 } |
| 60 | 51 |
| 61 void ChromeCrashReporterClient::GetProductNameAndVersion( | 52 void ChromeCrashReporterClient::GetProductNameAndVersion( |
| 62 const base::FilePath& exe_path, | 53 const base::FilePath& exe_path, |
| 63 base::string16* product_name, | 54 base::string16* product_name, |
| 64 base::string16* version, | 55 base::string16* version, |
| 65 base::string16* special_build, | 56 base::string16* special_build, |
| 66 base::string16* channel_name) { | 57 base::string16* channel_name) { |
| 67 DCHECK(product_name); | 58 DCHECK(product_name); |
| 68 DCHECK(version); | 59 DCHECK(version); |
| 69 DCHECK(special_build); | 60 DCHECK(special_build); |
| 70 DCHECK(channel_name); | 61 DCHECK(channel_name); |
| 71 | 62 |
| 72 std::unique_ptr<FileVersionInfo> version_info( | 63 install_static::GetExecutableVersionDetails( |
| 73 FileVersionInfo::CreateFileVersionInfo(exe_path)); | 64 exe_path.value(), product_name, version, special_build, channel_name); |
| 74 | |
| 75 if (version_info.get()) { | |
| 76 // Get the information from the file. | |
| 77 *version = version_info->product_version(); | |
| 78 if (!version_info->is_official_build()) | |
| 79 version->append(base::ASCIIToUTF16("-devel")); | |
| 80 | |
| 81 *product_name = version_info->product_short_name(); | |
| 82 *special_build = version_info->special_build(); | |
| 83 } else { | |
| 84 // No version info found. Make up the values. | |
| 85 *product_name = base::ASCIIToUTF16("Chrome"); | |
| 86 *version = base::ASCIIToUTF16("0.0.0.0-devel"); | |
| 87 } | |
| 88 | |
| 89 GoogleUpdateSettings::GetChromeChannelAndModifiers( | |
| 90 !GetIsPerUserInstall(exe_path), channel_name); | |
| 91 } | 65 } |
| 92 | 66 |
| 93 bool ChromeCrashReporterClient::ShouldShowRestartDialog(base::string16* title, | 67 bool ChromeCrashReporterClient::ShouldShowRestartDialog(base::string16* title, |
| 94 base::string16* message, | 68 base::string16* message, |
| 95 bool* is_rtl_locale) { | 69 bool* is_rtl_locale) { |
| 96 std::unique_ptr<base::Environment> env(base::Environment::Create()); | 70 if (!install_static::HasEnvironmentVariable(env_vars::kShowRestart) || |
| 97 if (!env->HasVar(env_vars::kShowRestart) || | 71 !install_static::HasEnvironmentVariable(env_vars::kRestartInfo) || |
| 98 !env->HasVar(env_vars::kRestartInfo) || | 72 install_static::HasEnvironmentVariable(env_vars::kMetroConnected)) { |
| 99 env->HasVar(env_vars::kMetroConnected)) { | |
| 100 return false; | 73 return false; |
| 101 } | 74 } |
| 102 | 75 |
| 103 std::string restart_info; | 76 std::string restart_info = |
| 104 env->GetVar(env_vars::kRestartInfo, &restart_info); | 77 install_static::GetEnvironmentString(env_vars::kRestartInfo); |
| 105 | 78 |
| 106 // The CHROME_RESTART var contains the dialog strings separated by '|'. | 79 // The CHROME_RESTART var contains the dialog strings separated by '|'. |
| 107 // See ChromeBrowserMainPartsWin::PrepareRestartOnCrashEnviroment() | 80 // See ChromeBrowserMainPartsWin::PrepareRestartOnCrashEnviroment() |
| 108 // for details. | 81 // for details. |
| 109 std::vector<std::string> dlg_strings = base::SplitString( | 82 std::vector<std::string> dlg_strings = base::SplitString( |
| 110 restart_info, "|", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 83 restart_info, "|", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 111 | 84 |
| 112 if (dlg_strings.size() < 3) | 85 if (dlg_strings.size() < 3) |
| 113 return false; | 86 return false; |
| 114 | 87 |
| 115 *title = base::UTF8ToUTF16(dlg_strings[0]); | 88 *title = base::UTF8ToUTF16(dlg_strings[0]); |
| 116 *message = base::UTF8ToUTF16(dlg_strings[1]); | 89 *message = base::UTF8ToUTF16(dlg_strings[1]); |
| 117 *is_rtl_locale = dlg_strings[2] == env_vars::kRtlLocale; | 90 *is_rtl_locale = dlg_strings[2] == env_vars::kRtlLocale; |
| 118 return true; | 91 return true; |
| 119 } | 92 } |
| 120 | 93 |
| 121 bool ChromeCrashReporterClient::AboutToRestart() { | 94 bool ChromeCrashReporterClient::AboutToRestart() { |
| 122 std::unique_ptr<base::Environment> env(base::Environment::Create()); | 95 if (!install_static::HasEnvironmentVariable(env_vars::kRestartInfo)) |
| 123 if (!env->HasVar(env_vars::kRestartInfo)) | |
| 124 return false; | 96 return false; |
| 125 | 97 |
| 126 env->SetVar(env_vars::kShowRestart, "1"); | 98 install_static::SetEnvironmentString(env_vars::kShowRestart, "1"); |
| 127 return true; | 99 return true; |
| 128 } | 100 } |
| 129 | 101 |
| 130 bool ChromeCrashReporterClient::GetDeferredUploadsSupported( | 102 bool ChromeCrashReporterClient::GetDeferredUploadsSupported( |
| 131 bool is_per_user_install) { | 103 bool is_per_user_install) { |
| 132 Version update_version = GoogleUpdateSettings::GetGoogleUpdateVersion( | 104 std::string version_string = install_static::GetGoogleUpdateVersion(); |
| 133 !is_per_user_install); | 105 Version update_version(version_string); |
| 134 if (!update_version.IsValid() || | 106 if (!update_version.IsValid() || |
| 135 update_version < base::Version(kMinUpdateVersion)) | 107 update_version < base::Version(kMinUpdateVersion)) { |
| 136 return false; | 108 return false; |
| 137 | 109 } |
| 138 return true; | 110 return true; |
| 139 } | 111 } |
| 140 | 112 |
| 141 bool ChromeCrashReporterClient::GetIsPerUserInstall( | 113 bool ChromeCrashReporterClient::GetIsPerUserInstall( |
| 142 const base::FilePath& exe_path) { | 114 const base::FilePath& exe_path) { |
| 143 return InstallUtil::IsPerUserInstall(exe_path); | 115 return !install_static::IsSystemInstall(exe_path.value().c_str()); |
| 144 } | 116 } |
| 145 | 117 |
| 146 bool ChromeCrashReporterClient::GetShouldDumpLargerDumps( | 118 bool ChromeCrashReporterClient::GetShouldDumpLargerDumps( |
| 147 bool is_per_user_install) { | 119 bool is_per_user_install) { |
| 148 base::string16 channel_name = | 120 base::string16 channel_name; |
| 149 GoogleUpdateSettings::GetChromeChannel(!is_per_user_install); | 121 install_static::GetChromeChannelName(is_per_user_install, |
| 150 | 122 false, // !add_modifier |
| 123 &channel_name); |
| 151 // Capture more detail in crash dumps for Beta, Dev, Canary channels and | 124 // Capture more detail in crash dumps for Beta, Dev, Canary channels and |
| 152 // if channel is unknown (e.g. Chromium or developer builds). | 125 // if channel is unknown (e.g. Chromium or developer builds). |
| 153 return (channel_name == installer::kChromeChannelBeta || | 126 return (channel_name == install_static::kChromeChannelBeta || |
| 154 channel_name == installer::kChromeChannelDev || | 127 channel_name == install_static::kChromeChannelDev || |
| 155 channel_name == GoogleChromeSxSDistribution::ChannelName() || | 128 channel_name == install_static::kChromeChannelCanary || |
| 156 channel_name == installer::kChromeChannelUnknown); | 129 channel_name == install_static::kChromeChannelUnknown); |
| 157 } | 130 } |
| 158 | 131 |
| 159 int ChromeCrashReporterClient::GetResultCodeRespawnFailed() { | 132 int ChromeCrashReporterClient::GetResultCodeRespawnFailed() { |
| 160 return chrome::RESULT_CODE_RESPAWN_FAILED; | 133 return chrome::RESULT_CODE_RESPAWN_FAILED; |
| 161 } | 134 } |
| 162 | 135 |
| 163 bool ChromeCrashReporterClient::ReportingIsEnforcedByPolicy( | 136 bool ChromeCrashReporterClient::ReportingIsEnforcedByPolicy( |
| 164 bool* breakpad_enabled) { | 137 bool* breakpad_enabled) { |
| 165 // Determine whether configuration management allows loading the crash reporter. | 138 // Determine whether configuration management allows loading the crash |
| 166 // Since the configuration management infrastructure is not initialized at this | 139 // reporter. |
| 167 // point, we read the corresponding registry key directly. The return status | 140 // Since the configuration management infrastructure is not initialized at |
| 168 // indicates whether policy data was successfully read. If it is true, | 141 // this point, we read the corresponding registry key directly. The return |
| 169 // |breakpad_enabled| contains the value set by policy. | 142 // status indicates whether policy data was successfully read. If it is true, |
| 170 base::string16 key_name = | 143 // |breakpad_enabled| contains the value set by policy. |
| 171 base::UTF8ToUTF16(policy::key::kMetricsReportingEnabled); | 144 return install_static::ReportingIsEnforcedByPolicy(breakpad_enabled); |
| 172 DWORD value = 0; | |
| 173 base::win::RegKey hklm_policy_key(HKEY_LOCAL_MACHINE, | |
| 174 policy::kRegistryChromePolicyKey, KEY_READ); | |
| 175 if (hklm_policy_key.ReadValueDW(key_name.c_str(), &value) == ERROR_SUCCESS) { | |
| 176 *breakpad_enabled = value != 0; | |
| 177 return true; | |
| 178 } | |
| 179 | |
| 180 base::win::RegKey hkcu_policy_key(HKEY_CURRENT_USER, | |
| 181 policy::kRegistryChromePolicyKey, KEY_READ); | |
| 182 if (hkcu_policy_key.ReadValueDW(key_name.c_str(), &value) == ERROR_SUCCESS) { | |
| 183 *breakpad_enabled = value != 0; | |
| 184 return true; | |
| 185 } | |
| 186 | |
| 187 return false; | |
| 188 } | 145 } |
| 189 | 146 |
| 190 | 147 |
| 191 bool ChromeCrashReporterClient::GetCrashDumpLocation( | 148 bool ChromeCrashReporterClient::GetCrashDumpLocation( |
| 192 base::FilePath* crash_dir) { | 149 base::FilePath* crash_dir) { |
| 193 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate | 150 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate |
| 194 // location to write breakpad crash dumps can be set. | 151 // location to write breakpad crash dumps can be set. |
| 195 std::unique_ptr<base::Environment> env(base::Environment::Create()); | 152 // If this environment variable exists, then for the time being, |
| 196 std::string alternate_crash_dump_location; | 153 // short-circuit how it's handled on Windows. Honoring this |
| 197 if (env->GetVar("BREAKPAD_DUMP_LOCATION", &alternate_crash_dump_location)) { | 154 // variable is required in order to symbolize stack traces in |
| 198 base::FilePath crash_dumps_dir_path = | 155 // Telemetry based tests: http://crbug.com/561763. |
| 199 base::FilePath::FromUTF8Unsafe(alternate_crash_dump_location); | 156 if (GetAlternativeCrashDumpLocation(crash_dir)) |
| 200 | |
| 201 // If this environment variable exists, then for the time being, | |
| 202 // short-circuit how it's handled on Windows. Honoring this | |
| 203 // variable is required in order to symbolize stack traces in | |
| 204 // Telemetry based tests: http://crbug.com/561763. | |
| 205 *crash_dir = crash_dumps_dir_path; | |
| 206 return true; | 157 return true; |
| 207 } | |
| 208 | 158 |
| 209 // TODO(scottmg): Consider supporting --user-data-dir. See | 159 // TODO(scottmg): Consider supporting --user-data-dir. See |
| 210 // https://crbug.com/565446. | 160 // https://crbug.com/565446. |
| 211 return chrome::GetDefaultCrashDumpLocation(crash_dir); | 161 base::string16 crash_dump_location; |
| 162 if (!install_static::GetDefaultCrashDumpLocation(&crash_dump_location)) |
| 163 return false; |
| 164 *crash_dir = base::FilePath(crash_dump_location); |
| 165 return true; |
| 212 } | 166 } |
| 213 | 167 |
| 214 size_t ChromeCrashReporterClient::RegisterCrashKeys() { | 168 size_t ChromeCrashReporterClient::RegisterCrashKeys() { |
| 215 return crash_keys::RegisterChromeCrashKeys(); | 169 return crash_keys::RegisterChromeCrashKeys(); |
| 216 } | 170 } |
| 217 | 171 |
| 218 bool ChromeCrashReporterClient::IsRunningUnattended() { | 172 bool ChromeCrashReporterClient::IsRunningUnattended() { |
| 219 std::unique_ptr<base::Environment> env(base::Environment::Create()); | 173 return install_static::HasEnvironmentVariable(env_vars::kHeadless); |
| 220 return env->HasVar(env_vars::kHeadless); | |
| 221 } | 174 } |
| 222 | 175 |
| 223 bool ChromeCrashReporterClient::GetCollectStatsConsent() { | 176 bool ChromeCrashReporterClient::GetCollectStatsConsent() { |
| 224 #if defined(GOOGLE_CHROME_BUILD) | 177 return install_static::GetCollectStatsConsent(); |
| 225 bool is_official_chrome_build = true; | |
| 226 #else | |
| 227 bool is_official_chrome_build = false; | |
| 228 #endif | |
| 229 | |
| 230 return is_official_chrome_build && | |
| 231 GoogleUpdateSettings::GetCollectStatsConsent(); | |
| 232 } | 178 } |
| 233 | 179 |
| 234 bool ChromeCrashReporterClient::EnableBreakpadForProcess( | 180 bool ChromeCrashReporterClient::EnableBreakpadForProcess( |
| 235 const std::string& process_type) { | 181 const std::string& process_type) { |
| 236 return process_type == switches::kRendererProcess || | 182 return process_type == switches::kRendererProcess || |
| 237 process_type == switches::kPpapiPluginProcess || | 183 process_type == switches::kPpapiPluginProcess || |
| 238 process_type == switches::kZygoteProcess || | 184 process_type == switches::kZygoteProcess || |
| 239 process_type == switches::kGpuProcess; | 185 process_type == switches::kGpuProcess; |
| 240 } | 186 } |
| OLD | NEW |