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