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( |
73 FileVersionInfo::CreateFileVersionInfo(exe_path)); | 63 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 } | 64 } |
92 | 65 |
93 bool ChromeCrashReporterClient::ShouldShowRestartDialog(base::string16* title, | 66 bool ChromeCrashReporterClient::ShouldShowRestartDialog(base::string16* title, |
94 base::string16* message, | 67 base::string16* message, |
95 bool* is_rtl_locale) { | 68 bool* is_rtl_locale) { |
96 std::unique_ptr<base::Environment> env(base::Environment::Create()); | 69 if (!install_static::HasEnvironmentVariable(env_vars::kShowRestart) || |
97 if (!env->HasVar(env_vars::kShowRestart) || | 70 !install_static::HasEnvironmentVariable(env_vars::kRestartInfo) || |
98 !env->HasVar(env_vars::kRestartInfo) || | 71 install_static::HasEnvironmentVariable(env_vars::kMetroConnected)) { |
99 env->HasVar(env_vars::kMetroConnected)) { | |
100 return false; | 72 return false; |
101 } | 73 } |
102 | 74 |
103 std::string restart_info; | 75 std::string restart_info = |
104 env->GetVar(env_vars::kRestartInfo, &restart_info); | 76 install_static::GetEnvironmentString(env_vars::kRestartInfo); |
105 | 77 |
106 // The CHROME_RESTART var contains the dialog strings separated by '|'. | 78 // The CHROME_RESTART var contains the dialog strings separated by '|'. |
107 // See ChromeBrowserMainPartsWin::PrepareRestartOnCrashEnviroment() | 79 // See ChromeBrowserMainPartsWin::PrepareRestartOnCrashEnviroment() |
108 // for details. | 80 // for details. |
109 std::vector<std::string> dlg_strings = base::SplitString( | 81 std::vector<std::string> dlg_strings = base::SplitString( |
110 restart_info, "|", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 82 restart_info, "|", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
111 | 83 |
112 if (dlg_strings.size() < 3) | 84 if (dlg_strings.size() < 3) |
113 return false; | 85 return false; |
114 | 86 |
115 *title = base::UTF8ToUTF16(dlg_strings[0]); | 87 *title = base::UTF8ToUTF16(dlg_strings[0]); |
116 *message = base::UTF8ToUTF16(dlg_strings[1]); | 88 *message = base::UTF8ToUTF16(dlg_strings[1]); |
117 *is_rtl_locale = dlg_strings[2] == env_vars::kRtlLocale; | 89 *is_rtl_locale = dlg_strings[2] == env_vars::kRtlLocale; |
118 return true; | 90 return true; |
119 } | 91 } |
120 | 92 |
121 bool ChromeCrashReporterClient::AboutToRestart() { | 93 bool ChromeCrashReporterClient::AboutToRestart() { |
122 std::unique_ptr<base::Environment> env(base::Environment::Create()); | 94 if (!install_static::HasEnvironmentVariable(env_vars::kRestartInfo)) |
123 if (!env->HasVar(env_vars::kRestartInfo)) | |
124 return false; | 95 return false; |
125 | 96 |
126 env->SetVar(env_vars::kShowRestart, "1"); | 97 install_static::SetEnvironmentString(env_vars::kShowRestart, "1"); |
127 return true; | 98 return true; |
128 } | 99 } |
129 | 100 |
130 bool ChromeCrashReporterClient::GetDeferredUploadsSupported( | 101 bool ChromeCrashReporterClient::GetDeferredUploadsSupported( |
131 bool is_per_user_install) { | 102 bool is_per_user_install) { |
132 Version update_version = GoogleUpdateSettings::GetGoogleUpdateVersion( | 103 std::string version_string = install_static::GetGoogleUpdateVersion(); |
133 !is_per_user_install); | 104 Version update_version(version_string); |
134 if (!update_version.IsValid() || | 105 if (!update_version.IsValid() || |
135 update_version < base::Version(kMinUpdateVersion)) | 106 update_version < base::Version(kMinUpdateVersion)) { |
136 return false; | 107 return false; |
137 | 108 } |
138 return true; | 109 return true; |
139 } | 110 } |
140 | 111 |
141 bool ChromeCrashReporterClient::GetIsPerUserInstall( | 112 bool ChromeCrashReporterClient::GetIsPerUserInstall( |
142 const base::FilePath& exe_path) { | 113 const base::FilePath& exe_path) { |
143 return InstallUtil::IsPerUserInstall(exe_path); | 114 return !install_static::IsSystemInstall(exe_path.value().c_str()); |
144 } | 115 } |
145 | 116 |
146 bool ChromeCrashReporterClient::GetShouldDumpLargerDumps( | 117 bool ChromeCrashReporterClient::GetShouldDumpLargerDumps( |
147 bool is_per_user_install) { | 118 bool is_per_user_install) { |
148 base::string16 channel_name = | 119 base::string16 channel_name; |
149 GoogleUpdateSettings::GetChromeChannel(!is_per_user_install); | 120 install_static::GetChromeChannelName(is_per_user_install, |
150 | 121 false, |
grt (UTC plus 2)
2016/05/05 20:36:52
nit: false, // !add_modifier
ananta
2016/05/05 20:57:34
Done.
| |
122 &channel_name); | |
151 // Capture more detail in crash dumps for Beta, Dev, Canary channels and | 123 // Capture more detail in crash dumps for Beta, Dev, Canary channels and |
152 // if channel is unknown (e.g. Chromium or developer builds). | 124 // if channel is unknown (e.g. Chromium or developer builds). |
153 return (channel_name == installer::kChromeChannelBeta || | 125 return (channel_name == install_static::kChromeChannelBeta || |
154 channel_name == installer::kChromeChannelDev || | 126 channel_name == install_static::kChromeChannelDev || |
155 channel_name == GoogleChromeSxSDistribution::ChannelName() || | 127 channel_name == install_static::kChromeChannelCanary || |
156 channel_name == installer::kChromeChannelUnknown); | 128 channel_name == install_static::kChromeChannelUnknown); |
157 } | 129 } |
158 | 130 |
159 int ChromeCrashReporterClient::GetResultCodeRespawnFailed() { | 131 int ChromeCrashReporterClient::GetResultCodeRespawnFailed() { |
160 return chrome::RESULT_CODE_RESPAWN_FAILED; | 132 return chrome::RESULT_CODE_RESPAWN_FAILED; |
161 } | 133 } |
162 | 134 |
163 bool ChromeCrashReporterClient::ReportingIsEnforcedByPolicy( | 135 bool ChromeCrashReporterClient::ReportingIsEnforcedByPolicy( |
164 bool* breakpad_enabled) { | 136 bool* breakpad_enabled) { |
165 // Determine whether configuration management allows loading the crash reporter. | 137 // Determine whether configuration management allows loading the crash |
166 // Since the configuration management infrastructure is not initialized at this | 138 // reporter. |
167 // point, we read the corresponding registry key directly. The return status | 139 // Since the configuration management infrastructure is not initialized at |
168 // indicates whether policy data was successfully read. If it is true, | 140 // this point, we read the corresponding registry key directly. The return |
169 // |breakpad_enabled| contains the value set by policy. | 141 // status indicates whether policy data was successfully read. If it is true, |
170 base::string16 key_name = | 142 // |breakpad_enabled| contains the value set by policy. |
171 base::UTF8ToUTF16(policy::key::kMetricsReportingEnabled); | 143 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 } | 144 } |
189 | 145 |
190 | 146 |
191 bool ChromeCrashReporterClient::GetCrashDumpLocation( | 147 bool ChromeCrashReporterClient::GetCrashDumpLocation( |
192 base::FilePath* crash_dir) { | 148 base::FilePath* crash_dir) { |
193 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate | 149 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate |
194 // location to write breakpad crash dumps can be set. | 150 // location to write breakpad crash dumps can be set. |
195 std::unique_ptr<base::Environment> env(base::Environment::Create()); | 151 // If this environment variable exists, then for the time being, |
196 std::string alternate_crash_dump_location; | 152 // short-circuit how it's handled on Windows. Honoring this |
197 if (env->GetVar("BREAKPAD_DUMP_LOCATION", &alternate_crash_dump_location)) { | 153 // variable is required in order to symbolize stack traces in |
198 base::FilePath crash_dumps_dir_path = | 154 // Telemetry based tests: http://crbug.com/561763. |
199 base::FilePath::FromUTF8Unsafe(alternate_crash_dump_location); | 155 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; | 156 return true; |
207 } | |
208 | 157 |
209 // TODO(scottmg): Consider supporting --user-data-dir. See | 158 // TODO(scottmg): Consider supporting --user-data-dir. See |
210 // https://crbug.com/565446. | 159 // https://crbug.com/565446. |
211 return chrome::GetDefaultCrashDumpLocation(crash_dir); | 160 base::string16 crash_dump_location; |
161 if (!install_static::GetDefaultCrashDumpLocation(&crash_dump_location)) | |
162 return false; | |
163 *crash_dir = base::FilePath(crash_dump_location); | |
164 return true; | |
212 } | 165 } |
213 | 166 |
214 size_t ChromeCrashReporterClient::RegisterCrashKeys() { | 167 size_t ChromeCrashReporterClient::RegisterCrashKeys() { |
215 return crash_keys::RegisterChromeCrashKeys(); | 168 return crash_keys::RegisterChromeCrashKeys(); |
216 } | 169 } |
217 | 170 |
218 bool ChromeCrashReporterClient::IsRunningUnattended() { | 171 bool ChromeCrashReporterClient::IsRunningUnattended() { |
219 std::unique_ptr<base::Environment> env(base::Environment::Create()); | 172 return install_static::HasEnvironmentVariable(env_vars::kHeadless); |
220 return env->HasVar(env_vars::kHeadless); | |
221 } | 173 } |
222 | 174 |
223 bool ChromeCrashReporterClient::GetCollectStatsConsent() { | 175 bool ChromeCrashReporterClient::GetCollectStatsConsent() { |
224 #if defined(GOOGLE_CHROME_BUILD) | 176 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 } | 177 } |
233 | 178 |
234 bool ChromeCrashReporterClient::EnableBreakpadForProcess( | 179 bool ChromeCrashReporterClient::EnableBreakpadForProcess( |
235 const std::string& process_type) { | 180 const std::string& process_type) { |
236 return process_type == switches::kRendererProcess || | 181 return process_type == switches::kRendererProcess || |
237 process_type == switches::kPpapiPluginProcess || | 182 process_type == switches::kPpapiPluginProcess || |
238 process_type == switches::kZygoteProcess || | 183 process_type == switches::kZygoteProcess || |
239 process_type == switches::kGpuProcess; | 184 process_type == switches::kGpuProcess; |
240 } | 185 } |
OLD | NEW |