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