Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(270)

Side by Side Diff: chrome/app/chrome_crash_reporter_client_win.cc

Issue 1913943003: Remove dependencies on chrome\installer from the ChromeCrashReporterClient class on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/environment.h"
11 #include "base/file_version_info.h"
12 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
13 #include "base/logging.h" 11 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
15 #include "base/path_service.h" 13 #include "base/path_service.h"
16 #include "base/strings/string_split.h" 14 #include "base/strings/string_split.h"
17 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
18 #include "base/win/registry.h"
19 #include "build/build_config.h" 16 #include "build/build_config.h"
20 #include "chrome/common/chrome_paths.h"
21 #include "chrome/common/chrome_paths_internal.h"
22 #include "chrome/common/chrome_result_codes.h" 17 #include "chrome/common/chrome_result_codes.h"
23 #include "chrome/common/crash_keys.h" 18 #include "chrome/common/crash_keys.h"
24 #include "chrome/common/env_vars.h" 19 #include "chrome/common/env_vars.h"
25 #include "chrome/common/metrics_constants_util_win.h" 20 #include "chrome/install_static/install_util.h"
26 #include "chrome/installer/util/google_chrome_sxs_distribution.h"
27 #include "chrome/installer/util/google_update_settings.h"
28 #include "chrome/installer/util/install_util.h"
29 #include "chrome/installer/util/util_constants.h"
30 #include "components/browser_watcher/crash_reporting_metrics_win.h" 21 #include "components/browser_watcher/crash_reporting_metrics_win.h"
31 #include "content/public/common/content_switches.h" 22 #include "content/public/common/content_switches.h"
32 #include "policy/policy_constants.h"
33
34 23
35 namespace { 24 namespace {
36 25
37 // This is the minimum version of google update that is required for deferred 26 // This is the minimum version of google update that is required for deferred
38 // crash uploads to work. 27 // crash uploads to work.
39 const char kMinUpdateVersion[] = "1.3.21.115"; 28 const char kMinUpdateVersion[] = "1.3.21.115";
40 29
41 } // namespace 30 } // namespace
42 31
43 ChromeCrashReporterClient::ChromeCrashReporterClient() {} 32 ChromeCrashReporterClient::ChromeCrashReporterClient() {}
44 33
45 ChromeCrashReporterClient::~ChromeCrashReporterClient() {} 34 ChromeCrashReporterClient::~ChromeCrashReporterClient() {}
46 35
47 bool ChromeCrashReporterClient::GetAlternativeCrashDumpLocation( 36 bool ChromeCrashReporterClient::GetAlternativeCrashDumpLocation(
48 base::FilePath* crash_dir) { 37 base::FilePath* crash_dir) {
49 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate 38 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate
50 // location to write breakpad crash dumps can be set. 39 // location to write breakpad crash dumps can be set.
51 std::unique_ptr<base::Environment> env(base::Environment::Create()); 40 std::string alternate_crash_dump_location =
52 std::string alternate_crash_dump_location; 41 install_static::GetEnvironmentString("BREAKPAD_DUMP_LOCATION");
53 if (env->GetVar("BREAKPAD_DUMP_LOCATION", &alternate_crash_dump_location)) { 42 if (!alternate_crash_dump_location.empty()) {
54 *crash_dir = base::FilePath::FromUTF8Unsafe(alternate_crash_dump_location); 43 *crash_dir = base::FilePath::FromUTF8Unsafe(alternate_crash_dump_location);
55 return true; 44 return true;
56 } 45 }
57
58 return false; 46 return false;
59 } 47 }
60 48
61 void ChromeCrashReporterClient::GetProductNameAndVersion( 49 void ChromeCrashReporterClient::GetProductNameAndVersion(
62 const base::FilePath& exe_path, 50 const base::FilePath& exe_path,
63 base::string16* product_name, 51 base::string16* product_name,
64 base::string16* version, 52 base::string16* version,
65 base::string16* special_build, 53 base::string16* special_build,
66 base::string16* channel_name) { 54 base::string16* channel_name) {
67 DCHECK(product_name); 55 DCHECK(product_name);
68 DCHECK(version); 56 DCHECK(version);
69 DCHECK(special_build); 57 DCHECK(special_build);
70 DCHECK(channel_name); 58 DCHECK(channel_name);
71 59
72 scoped_ptr<FileVersionInfo> version_info( 60 install_static::GetExecutableVersionDetails(exe_path.value(),
73 FileVersionInfo::CreateFileVersionInfo(exe_path)); 61 product_name,
74 62 version,
75 if (version_info.get()) { 63 special_build,
76 // Get the information from the file. 64 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 } 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 scoped_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 = install_static::GetEnvironmentString(
104 env->GetVar(env_vars::kRestartInfo, &restart_info); 77 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 scoped_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 Version update_version = install_static::GetGoogleUpdateVersion();
133 !is_per_user_install);
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 &channel_name);
151 // Capture more detail in crash dumps for Beta, Dev, Canary channels and 122 // Capture more detail in crash dumps for Beta, Dev, Canary channels and
152 // if channel is unknown (e.g. Chromium or developer builds). 123 // if channel is unknown (e.g. Chromium or developer builds).
153 return (channel_name == installer::kChromeChannelBeta || 124 return (channel_name == install_static::kChromeChannelBeta ||
154 channel_name == installer::kChromeChannelDev || 125 channel_name == install_static::kChromeChannelDev ||
155 channel_name == GoogleChromeSxSDistribution::ChannelName() || 126 channel_name == install_static::kChromeChannelCanary ||
156 channel_name == installer::kChromeChannelUnknown); 127 channel_name == install_static::kChromeChannelUnknown);
157 } 128 }
158 129
159 int ChromeCrashReporterClient::GetResultCodeRespawnFailed() { 130 int ChromeCrashReporterClient::GetResultCodeRespawnFailed() {
160 return chrome::RESULT_CODE_RESPAWN_FAILED; 131 return chrome::RESULT_CODE_RESPAWN_FAILED;
161 } 132 }
162 133
163 void ChromeCrashReporterClient::InitBrowserCrashDumpsRegKey() { 134 void ChromeCrashReporterClient::InitBrowserCrashDumpsRegKey() {
164 #if !defined(NACL_WIN64) 135 #if !defined(NACL_WIN64)
165 if (GetCollectStatsConsent()){ 136 if (GetCollectStatsConsent()) {
166 crash_reporting_metrics_.reset(new browser_watcher::CrashReportingMetrics( 137 crash_reporting_metrics_.reset(new browser_watcher::CrashReportingMetrics(
167 chrome::GetBrowserCrashDumpAttemptsRegistryPath())); 138 install_static::GetBrowserCrashDumpAttemptsRegistryPath()));
168 } 139 }
169 #endif 140 #endif
170 } 141 }
171 142
172 void ChromeCrashReporterClient::RecordCrashDumpAttempt(bool is_real_crash) { 143 void ChromeCrashReporterClient::RecordCrashDumpAttempt(bool is_real_crash) {
173 #if !defined(NACL_WIN64) 144 #if !defined(NACL_WIN64)
174 if (!crash_reporting_metrics_) 145 if (!crash_reporting_metrics_)
175 return; 146 return;
176 147
177 if (is_real_crash) 148 if (is_real_crash)
(...skipping 11 matching lines...) Expand all
189 160
190 if (is_real_crash) 161 if (is_real_crash)
191 crash_reporting_metrics_->RecordCrashDumpAttemptResult(succeeded); 162 crash_reporting_metrics_->RecordCrashDumpAttemptResult(succeeded);
192 else 163 else
193 crash_reporting_metrics_->RecordDumpWithoutCrashAttemptResult(succeeded); 164 crash_reporting_metrics_->RecordDumpWithoutCrashAttemptResult(succeeded);
194 #endif 165 #endif
195 } 166 }
196 167
197 bool ChromeCrashReporterClient::ReportingIsEnforcedByPolicy( 168 bool ChromeCrashReporterClient::ReportingIsEnforcedByPolicy(
198 bool* breakpad_enabled) { 169 bool* breakpad_enabled) {
199 // Determine whether configuration management allows loading the crash reporter. 170 // Determine whether configuration management allows loading the crash
200 // Since the configuration management infrastructure is not initialized at this 171 // reporter.
201 // point, we read the corresponding registry key directly. The return status 172 // Since the configuration management infrastructure is not initialized at
202 // indicates whether policy data was successfully read. If it is true, 173 // this point, we read the corresponding registry key directly. The return
203 // |breakpad_enabled| contains the value set by policy. 174 // status indicates whether policy data was successfully read. If it is true,
204 base::string16 key_name = 175 // |breakpad_enabled| contains the value set by policy.
205 base::UTF8ToUTF16(policy::key::kMetricsReportingEnabled); 176 return install_static::ReportingIsEnforcedByPolicy(breakpad_enabled);
206 DWORD value = 0;
207 base::win::RegKey hklm_policy_key(HKEY_LOCAL_MACHINE,
208 policy::kRegistryChromePolicyKey, KEY_READ);
209 if (hklm_policy_key.ReadValueDW(key_name.c_str(), &value) == ERROR_SUCCESS) {
210 *breakpad_enabled = value != 0;
211 return true;
212 }
213
214 base::win::RegKey hkcu_policy_key(HKEY_CURRENT_USER,
215 policy::kRegistryChromePolicyKey, KEY_READ);
216 if (hkcu_policy_key.ReadValueDW(key_name.c_str(), &value) == ERROR_SUCCESS) {
217 *breakpad_enabled = value != 0;
218 return true;
219 }
220
221 return false;
222 } 177 }
223 178
224 179
225 bool ChromeCrashReporterClient::GetCrashDumpLocation( 180 bool ChromeCrashReporterClient::GetCrashDumpLocation(
226 base::FilePath* crash_dir) { 181 base::FilePath* crash_dir) {
227 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate 182 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate
228 // location to write breakpad crash dumps can be set. 183 // location to write breakpad crash dumps can be set.
229 scoped_ptr<base::Environment> env(base::Environment::Create()); 184 // If this environment variable exists, then for the time being,
230 std::string alternate_crash_dump_location; 185 // short-circuit how it's handled on Windows. Honoring this
231 if (env->GetVar("BREAKPAD_DUMP_LOCATION", &alternate_crash_dump_location)) { 186 // variable is required in order to symbolize stack traces in
232 base::FilePath crash_dumps_dir_path = 187 // Telemetry based tests: http://crbug.com/561763.
233 base::FilePath::FromUTF8Unsafe(alternate_crash_dump_location); 188 if (GetAlternativeCrashDumpLocation(crash_dir))
234
235 // If this environment variable exists, then for the time being,
236 // short-circuit how it's handled on Windows. Honoring this
237 // variable is required in order to symbolize stack traces in
238 // Telemetry based tests: http://crbug.com/561763.
239 *crash_dir = crash_dumps_dir_path;
240 return true; 189 return true;
241 }
242 190
243 // TODO(scottmg): Consider supporting --user-data-dir. See 191 // TODO(scottmg): Consider supporting --user-data-dir. See
244 // https://crbug.com/565446. 192 // https://crbug.com/565446.
245 return chrome::GetDefaultCrashDumpLocation(crash_dir); 193 return install_static::GetDefaultCrashDumpLocation(crash_dir);
246 } 194 }
247 195
248 size_t ChromeCrashReporterClient::RegisterCrashKeys() { 196 size_t ChromeCrashReporterClient::RegisterCrashKeys() {
249 return crash_keys::RegisterChromeCrashKeys(); 197 return crash_keys::RegisterChromeCrashKeys();
250 } 198 }
251 199
252 bool ChromeCrashReporterClient::IsRunningUnattended() { 200 bool ChromeCrashReporterClient::IsRunningUnattended() {
253 scoped_ptr<base::Environment> env(base::Environment::Create()); 201 return install_static::HasEnvironmentVariable(env_vars::kHeadless);
254 return env->HasVar(env_vars::kHeadless);
255 } 202 }
256 203
257 bool ChromeCrashReporterClient::GetCollectStatsConsent() { 204 bool ChromeCrashReporterClient::GetCollectStatsConsent() {
258 #if defined(GOOGLE_CHROME_BUILD) 205 #if defined(GOOGLE_CHROME_BUILD)
259 bool is_official_chrome_build = true; 206 bool is_official_chrome_build = true;
260 #else 207 #else
261 bool is_official_chrome_build = false; 208 bool is_official_chrome_build = false;
262 #endif 209 #endif
263 210
264 return is_official_chrome_build && 211 return is_official_chrome_build && install_static::GetCollectStatsConsent();
265 GoogleUpdateSettings::GetCollectStatsConsent();
266 } 212 }
267 213
268 bool ChromeCrashReporterClient::EnableBreakpadForProcess( 214 bool ChromeCrashReporterClient::EnableBreakpadForProcess(
269 const std::string& process_type) { 215 const std::string& process_type) {
270 return process_type == switches::kRendererProcess || 216 return process_type == switches::kRendererProcess ||
271 process_type == switches::kPpapiPluginProcess || 217 process_type == switches::kPpapiPluginProcess ||
272 process_type == switches::kZygoteProcess || 218 process_type == switches::kZygoteProcess ||
273 process_type == switches::kGpuProcess; 219 process_type == switches::kGpuProcess;
274 } 220 }
OLDNEW
« no previous file with comments | « chrome/app/DEPS ('k') | chrome/chrome_dll.gypi » ('j') | chrome/install_static/install_util.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698