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

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

Issue 1904613002: Preparation patch for moving the chrome crashpad integration into chrome_elf. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build error on Windows builder Created 4 years, 8 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
« no previous file with comments | « chrome/app/chrome_crash_reporter_client_win.h ('k') | chrome/app/chrome_exe_main_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.h" 5 #include "chrome/app/chrome_crash_reporter_client_win.h"
6
7 #include <windows.h>
6 8
7 #include "base/command_line.h" 9 #include "base/command_line.h"
8 #include "base/environment.h" 10 #include "base/environment.h"
11 #include "base/file_version_info.h"
9 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
10 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.h"
11 #include "base/path_service.h" 15 #include "base/path_service.h"
12 #include "base/strings/string_split.h" 16 #include "base/strings/string_split.h"
13 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "base/win/registry.h"
14 #include "build/build_config.h" 19 #include "build/build_config.h"
15 #include "chrome/common/chrome_paths.h" 20 #include "chrome/common/chrome_paths.h"
16 #include "chrome/common/chrome_paths_internal.h" 21 #include "chrome/common/chrome_paths_internal.h"
17 #include "chrome/common/chrome_result_codes.h" 22 #include "chrome/common/chrome_result_codes.h"
18 #include "chrome/common/crash_keys.h" 23 #include "chrome/common/crash_keys.h"
19 #include "chrome/common/env_vars.h" 24 #include "chrome/common/env_vars.h"
20 #include "chrome/installer/util/google_update_settings.h"
21 #include "content/public/common/content_switches.h"
22
23 #if defined(OS_WIN)
24 #include <windows.h>
25
26 #include "base/file_version_info.h"
27 #include "base/win/registry.h"
28 #include "chrome/common/metrics_constants_util_win.h" 25 #include "chrome/common/metrics_constants_util_win.h"
29 #include "chrome/installer/util/google_chrome_sxs_distribution.h" 26 #include "chrome/installer/util/google_chrome_sxs_distribution.h"
27 #include "chrome/installer/util/google_update_settings.h"
30 #include "chrome/installer/util/install_util.h" 28 #include "chrome/installer/util/install_util.h"
31 #include "chrome/installer/util/util_constants.h" 29 #include "chrome/installer/util/util_constants.h"
32 #include "components/browser_watcher/crash_reporting_metrics_win.h" 30 #include "components/browser_watcher/crash_reporting_metrics_win.h"
31 #include "content/public/common/content_switches.h"
33 #include "policy/policy_constants.h" 32 #include "policy/policy_constants.h"
34 #endif
35 33
36 #if defined(OS_POSIX) && !defined(OS_MACOSX)
37 #include "components/upload_list/crash_upload_list.h"
38 #include "components/version_info/version_info_values.h"
39 #endif
40
41 #if defined(OS_POSIX)
42 #include "base/debug/dump_without_crashing.h"
43 #endif
44
45 #if defined(OS_ANDROID)
46 #include "chrome/common/descriptors_android.h"
47 #endif
48
49 #if defined(OS_CHROMEOS)
50 #include "chrome/common/channel_info.h"
51 #include "chromeos/chromeos_switches.h"
52 #include "components/version_info/version_info.h"
53 #endif
54 34
55 namespace { 35 namespace {
56 36
57 #if defined(OS_WIN)
58 // This is the minimum version of google update that is required for deferred 37 // This is the minimum version of google update that is required for deferred
59 // crash uploads to work. 38 // crash uploads to work.
60 const char kMinUpdateVersion[] = "1.3.21.115"; 39 const char kMinUpdateVersion[] = "1.3.21.115";
61 #endif
62 40
63 } // namespace 41 } // namespace
64 42
65 ChromeCrashReporterClient::ChromeCrashReporterClient() {} 43 ChromeCrashReporterClient::ChromeCrashReporterClient() {}
66 44
67 ChromeCrashReporterClient::~ChromeCrashReporterClient() {} 45 ChromeCrashReporterClient::~ChromeCrashReporterClient() {}
68 46
69 #if !defined(OS_MACOSX) && !defined(OS_WIN)
70 void ChromeCrashReporterClient::SetCrashReporterClientIdFromGUID(
71 const std::string& client_guid) {
72 crash_keys::SetMetricsClientIdFromGUID(client_guid);
73 }
74 #endif
75
76 #if defined(OS_WIN)
77 bool ChromeCrashReporterClient::GetAlternativeCrashDumpLocation( 47 bool ChromeCrashReporterClient::GetAlternativeCrashDumpLocation(
78 base::FilePath* crash_dir) { 48 base::FilePath* crash_dir) {
79 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate 49 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate
80 // location to write breakpad crash dumps can be set. 50 // location to write breakpad crash dumps can be set.
81 std::unique_ptr<base::Environment> env(base::Environment::Create()); 51 std::unique_ptr<base::Environment> env(base::Environment::Create());
82 std::string alternate_crash_dump_location; 52 std::string alternate_crash_dump_location;
83 if (env->GetVar("BREAKPAD_DUMP_LOCATION", &alternate_crash_dump_location)) { 53 if (env->GetVar("BREAKPAD_DUMP_LOCATION", &alternate_crash_dump_location)) {
84 *crash_dir = base::FilePath::FromUTF8Unsafe(alternate_crash_dump_location); 54 *crash_dir = base::FilePath::FromUTF8Unsafe(alternate_crash_dump_location);
85 return true; 55 return true;
86 } 56 }
87 57
88 return false; 58 return false;
89 } 59 }
90 60
91 void ChromeCrashReporterClient::GetProductNameAndVersion( 61 void ChromeCrashReporterClient::GetProductNameAndVersion(
92 const base::FilePath& exe_path, 62 const base::FilePath& exe_path,
93 base::string16* product_name, 63 base::string16* product_name,
94 base::string16* version, 64 base::string16* version,
95 base::string16* special_build, 65 base::string16* special_build,
96 base::string16* channel_name) { 66 base::string16* channel_name) {
97 DCHECK(product_name); 67 DCHECK(product_name);
98 DCHECK(version); 68 DCHECK(version);
99 DCHECK(special_build); 69 DCHECK(special_build);
100 DCHECK(channel_name); 70 DCHECK(channel_name);
101 71
102 std::unique_ptr<FileVersionInfo> version_info( 72 scoped_ptr<FileVersionInfo> version_info(
103 FileVersionInfo::CreateFileVersionInfo(exe_path)); 73 FileVersionInfo::CreateFileVersionInfo(exe_path));
104 74
105 if (version_info.get()) { 75 if (version_info.get()) {
106 // Get the information from the file. 76 // Get the information from the file.
107 *version = version_info->product_version(); 77 *version = version_info->product_version();
108 if (!version_info->is_official_build()) 78 if (!version_info->is_official_build())
109 version->append(base::ASCIIToUTF16("-devel")); 79 version->append(base::ASCIIToUTF16("-devel"));
110 80
111 *product_name = version_info->product_short_name(); 81 *product_name = version_info->product_short_name();
112 *special_build = version_info->special_build(); 82 *special_build = version_info->special_build();
113 } else { 83 } else {
114 // No version info found. Make up the values. 84 // No version info found. Make up the values.
115 *product_name = base::ASCIIToUTF16("Chrome"); 85 *product_name = base::ASCIIToUTF16("Chrome");
116 *version = base::ASCIIToUTF16("0.0.0.0-devel"); 86 *version = base::ASCIIToUTF16("0.0.0.0-devel");
117 } 87 }
118 88
119 GoogleUpdateSettings::GetChromeChannelAndModifiers( 89 GoogleUpdateSettings::GetChromeChannelAndModifiers(
120 !GetIsPerUserInstall(exe_path), channel_name); 90 !GetIsPerUserInstall(exe_path), channel_name);
121 } 91 }
122 92
123 bool ChromeCrashReporterClient::ShouldShowRestartDialog(base::string16* title, 93 bool ChromeCrashReporterClient::ShouldShowRestartDialog(base::string16* title,
124 base::string16* message, 94 base::string16* message,
125 bool* is_rtl_locale) { 95 bool* is_rtl_locale) {
126 std::unique_ptr<base::Environment> env(base::Environment::Create()); 96 scoped_ptr<base::Environment> env(base::Environment::Create());
127 if (!env->HasVar(env_vars::kShowRestart) || 97 if (!env->HasVar(env_vars::kShowRestart) ||
128 !env->HasVar(env_vars::kRestartInfo) || 98 !env->HasVar(env_vars::kRestartInfo) ||
129 env->HasVar(env_vars::kMetroConnected)) { 99 env->HasVar(env_vars::kMetroConnected)) {
130 return false; 100 return false;
131 } 101 }
132 102
133 std::string restart_info; 103 std::string restart_info;
134 env->GetVar(env_vars::kRestartInfo, &restart_info); 104 env->GetVar(env_vars::kRestartInfo, &restart_info);
135 105
136 // The CHROME_RESTART var contains the dialog strings separated by '|'. 106 // The CHROME_RESTART var contains the dialog strings separated by '|'.
137 // See ChromeBrowserMainPartsWin::PrepareRestartOnCrashEnviroment() 107 // See ChromeBrowserMainPartsWin::PrepareRestartOnCrashEnviroment()
138 // for details. 108 // for details.
139 std::vector<std::string> dlg_strings = base::SplitString( 109 std::vector<std::string> dlg_strings = base::SplitString(
140 restart_info, "|", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 110 restart_info, "|", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
141 111
142 if (dlg_strings.size() < 3) 112 if (dlg_strings.size() < 3)
143 return false; 113 return false;
144 114
145 *title = base::UTF8ToUTF16(dlg_strings[0]); 115 *title = base::UTF8ToUTF16(dlg_strings[0]);
146 *message = base::UTF8ToUTF16(dlg_strings[1]); 116 *message = base::UTF8ToUTF16(dlg_strings[1]);
147 *is_rtl_locale = dlg_strings[2] == env_vars::kRtlLocale; 117 *is_rtl_locale = dlg_strings[2] == env_vars::kRtlLocale;
148 return true; 118 return true;
149 } 119 }
150 120
151 bool ChromeCrashReporterClient::AboutToRestart() { 121 bool ChromeCrashReporterClient::AboutToRestart() {
152 std::unique_ptr<base::Environment> env(base::Environment::Create()); 122 scoped_ptr<base::Environment> env(base::Environment::Create());
153 if (!env->HasVar(env_vars::kRestartInfo)) 123 if (!env->HasVar(env_vars::kRestartInfo))
154 return false; 124 return false;
155 125
156 env->SetVar(env_vars::kShowRestart, "1"); 126 env->SetVar(env_vars::kShowRestart, "1");
157 return true; 127 return true;
158 } 128 }
159 129
160 bool ChromeCrashReporterClient::GetDeferredUploadsSupported( 130 bool ChromeCrashReporterClient::GetDeferredUploadsSupported(
161 bool is_per_user_install) { 131 bool is_per_user_install) {
162 Version update_version = GoogleUpdateSettings::GetGoogleUpdateVersion( 132 Version update_version = GoogleUpdateSettings::GetGoogleUpdateVersion(
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 213
244 base::win::RegKey hkcu_policy_key(HKEY_CURRENT_USER, 214 base::win::RegKey hkcu_policy_key(HKEY_CURRENT_USER,
245 policy::kRegistryChromePolicyKey, KEY_READ); 215 policy::kRegistryChromePolicyKey, KEY_READ);
246 if (hkcu_policy_key.ReadValueDW(key_name.c_str(), &value) == ERROR_SUCCESS) { 216 if (hkcu_policy_key.ReadValueDW(key_name.c_str(), &value) == ERROR_SUCCESS) {
247 *breakpad_enabled = value != 0; 217 *breakpad_enabled = value != 0;
248 return true; 218 return true;
249 } 219 }
250 220
251 return false; 221 return false;
252 } 222 }
253 #endif // defined(OS_WIN)
254 223
255 #if defined(OS_POSIX) && !defined(OS_MACOSX)
256 void ChromeCrashReporterClient::GetProductNameAndVersion(
257 const char** product_name,
258 const char** version) {
259 DCHECK(product_name);
260 DCHECK(version);
261 #if defined(OS_ANDROID)
262 *product_name = "Chrome_Android";
263 #elif defined(OS_CHROMEOS)
264 *product_name = "Chrome_ChromeOS";
265 #else // OS_LINUX
266 #if !defined(ADDRESS_SANITIZER)
267 *product_name = "Chrome_Linux";
268 #else
269 *product_name = "Chrome_Linux_ASan";
270 #endif
271 #endif
272
273 *version = PRODUCT_VERSION;
274 }
275
276 base::FilePath ChromeCrashReporterClient::GetReporterLogFilename() {
277 return base::FilePath(CrashUploadList::kReporterLogFilename);
278 }
279 #endif
280 224
281 bool ChromeCrashReporterClient::GetCrashDumpLocation( 225 bool ChromeCrashReporterClient::GetCrashDumpLocation(
282 base::FilePath* crash_dir) { 226 base::FilePath* crash_dir) {
283 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate 227 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate
284 // location to write breakpad crash dumps can be set. 228 // location to write breakpad crash dumps can be set.
285 std::unique_ptr<base::Environment> env(base::Environment::Create()); 229 scoped_ptr<base::Environment> env(base::Environment::Create());
286 std::string alternate_crash_dump_location; 230 std::string alternate_crash_dump_location;
287 if (env->GetVar("BREAKPAD_DUMP_LOCATION", &alternate_crash_dump_location)) { 231 if (env->GetVar("BREAKPAD_DUMP_LOCATION", &alternate_crash_dump_location)) {
288 base::FilePath crash_dumps_dir_path = 232 base::FilePath crash_dumps_dir_path =
289 base::FilePath::FromUTF8Unsafe(alternate_crash_dump_location); 233 base::FilePath::FromUTF8Unsafe(alternate_crash_dump_location);
290 234
291 #if defined(OS_WIN)
292 // If this environment variable exists, then for the time being, 235 // If this environment variable exists, then for the time being,
293 // short-circuit how it's handled on Windows. Honoring this 236 // short-circuit how it's handled on Windows. Honoring this
294 // variable is required in order to symbolize stack traces in 237 // variable is required in order to symbolize stack traces in
295 // Telemetry based tests: http://crbug.com/561763. 238 // Telemetry based tests: http://crbug.com/561763.
296 *crash_dir = crash_dumps_dir_path; 239 *crash_dir = crash_dumps_dir_path;
297 return true; 240 return true;
298 #else
299 PathService::Override(chrome::DIR_CRASH_DUMPS, crash_dumps_dir_path);
300 #endif
301 } 241 }
302 242
303 #if defined(OS_WIN)
304 // TODO(scottmg): Consider supporting --user-data-dir. See 243 // TODO(scottmg): Consider supporting --user-data-dir. See
305 // https://crbug.com/565446. 244 // https://crbug.com/565446.
306 return chrome::GetDefaultCrashDumpLocation(crash_dir); 245 return chrome::GetDefaultCrashDumpLocation(crash_dir);
307 #else
308 return PathService::Get(chrome::DIR_CRASH_DUMPS, crash_dir);
309 #endif
310 } 246 }
311 247
312 size_t ChromeCrashReporterClient::RegisterCrashKeys() { 248 size_t ChromeCrashReporterClient::RegisterCrashKeys() {
313 return crash_keys::RegisterChromeCrashKeys(); 249 return crash_keys::RegisterChromeCrashKeys();
314 } 250 }
315 251
316 bool ChromeCrashReporterClient::IsRunningUnattended() { 252 bool ChromeCrashReporterClient::IsRunningUnattended() {
317 std::unique_ptr<base::Environment> env(base::Environment::Create()); 253 scoped_ptr<base::Environment> env(base::Environment::Create());
318 return env->HasVar(env_vars::kHeadless); 254 return env->HasVar(env_vars::kHeadless);
319 } 255 }
320 256
321 bool ChromeCrashReporterClient::GetCollectStatsConsent() { 257 bool ChromeCrashReporterClient::GetCollectStatsConsent() {
322 #if defined(GOOGLE_CHROME_BUILD) 258 #if defined(GOOGLE_CHROME_BUILD)
323 bool is_official_chrome_build = true; 259 bool is_official_chrome_build = true;
324 #else 260 #else
325 bool is_official_chrome_build = false; 261 bool is_official_chrome_build = false;
326 #endif 262 #endif
327 263
328 #if defined(OS_CHROMEOS)
329 bool is_guest_session = base::CommandLine::ForCurrentProcess()->HasSwitch(
330 chromeos::switches::kGuestSession);
331 bool is_stable_channel =
332 chrome::GetChannel() == version_info::Channel::STABLE;
333
334 if (is_guest_session && is_stable_channel)
335 return false;
336 #endif // defined(OS_CHROMEOS)
337
338 #if defined(OS_ANDROID)
339 // TODO(jcivelli): we should not initialize the crash-reporter when it was not
340 // enabled. Right now if it is disabled we still generate the minidumps but we
341 // do not upload them.
342 return is_official_chrome_build;
343 #else // !defined(OS_ANDROID)
344 return is_official_chrome_build && 264 return is_official_chrome_build &&
345 GoogleUpdateSettings::GetCollectStatsConsent(); 265 GoogleUpdateSettings::GetCollectStatsConsent();
346 #endif // defined(OS_ANDROID)
347 } 266 }
348 267
349 #if defined(OS_ANDROID)
350 int ChromeCrashReporterClient::GetAndroidMinidumpDescriptor() {
351 return kAndroidMinidumpDescriptor;
352 }
353 #endif
354
355 bool ChromeCrashReporterClient::EnableBreakpadForProcess( 268 bool ChromeCrashReporterClient::EnableBreakpadForProcess(
356 const std::string& process_type) { 269 const std::string& process_type) {
357 return process_type == switches::kRendererProcess || 270 return process_type == switches::kRendererProcess ||
358 process_type == switches::kPpapiPluginProcess || 271 process_type == switches::kPpapiPluginProcess ||
359 process_type == switches::kZygoteProcess || 272 process_type == switches::kZygoteProcess ||
360 process_type == switches::kGpuProcess; 273 process_type == switches::kGpuProcess;
361 } 274 }
OLDNEW
« no previous file with comments | « chrome/app/chrome_crash_reporter_client_win.h ('k') | chrome/app/chrome_exe_main_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698