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 // TODO(ananta/scottmg) | 5 // TODO(ananta/scottmg) |
6 // Add test coverage for Crashpad. | 6 // Add test coverage for Crashpad. |
7 #include "chrome/app/chrome_crash_reporter_client_win.h" | 7 #include "chrome/app/chrome_crash_reporter_client_win.h" |
8 | 8 |
9 #include <assert.h> | 9 #include <assert.h> |
10 #include <windows.h> | 10 #include <windows.h> |
11 #include <shellapi.h> | 11 #include <shellapi.h> |
12 #include <memory> | 12 #include <memory> |
13 #include <string> | 13 #include <string> |
14 | 14 |
15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
16 #include "base/debug/crash_logging.h" | 16 #include "base/debug/crash_logging.h" |
17 #include "base/debug/leak_annotations.h" | 17 #include "base/debug/leak_annotations.h" |
18 #include "base/format_macros.h" | 18 #include "base/format_macros.h" |
19 #include "chrome/common/chrome_result_codes.h" | 19 #include "chrome/common/chrome_result_codes.h" |
20 #include "chrome/install_static/install_details.h" | 20 #include "chrome/install_static/install_details.h" |
21 #include "chrome/install_static/install_util.h" | 21 #include "chrome/install_static/install_util.h" |
| 22 #include "chrome/install_static/user_data_dir.h" |
22 #include "components/crash/content/app/crashpad.h" | 23 #include "components/crash/content/app/crashpad.h" |
23 #include "components/crash/core/common/crash_keys.h" | 24 #include "components/crash/core/common/crash_keys.h" |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
27 // TODO(ananta) | 28 // TODO(ananta) |
28 // When the new crash key map implementation lands, we should remove the | 29 // When the new crash key map implementation lands, we should remove the |
29 // constants defined below, the RegisterCrashKeysHelper function, the | 30 // constants defined below, the RegisterCrashKeysHelper function, the |
30 // RegisterCrashKeys function in the crash_keys::CrashReporterClient interface | 31 // RegisterCrashKeys function in the crash_keys::CrashReporterClient interface |
31 // and the snprintf function defined here. | 32 // and the snprintf function defined here. |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 #if !defined(NACL_WIN64) | 243 #if !defined(NACL_WIN64) |
243 // static | 244 // static |
244 void ChromeCrashReporterClient::InitializeCrashReportingForProcess() { | 245 void ChromeCrashReporterClient::InitializeCrashReportingForProcess() { |
245 static ChromeCrashReporterClient* instance = nullptr; | 246 static ChromeCrashReporterClient* instance = nullptr; |
246 if (instance) | 247 if (instance) |
247 return; | 248 return; |
248 | 249 |
249 instance = new ChromeCrashReporterClient(); | 250 instance = new ChromeCrashReporterClient(); |
250 ANNOTATE_LEAKING_OBJECT_PTR(instance); | 251 ANNOTATE_LEAKING_OBJECT_PTR(instance); |
251 | 252 |
252 std::string process_type = install_static::GetSwitchValueFromCommandLine( | 253 std::wstring process_type = install_static::GetSwitchValueFromCommandLine( |
253 ::GetCommandLineA(), install_static::kProcessType); | 254 ::GetCommandLine(), install_static::kProcessType); |
254 if (process_type != install_static::kCrashpadHandler) { | 255 if (process_type != install_static::kCrashpadHandler) { |
255 crash_reporter::SetCrashReporterClient(instance); | 256 crash_reporter::SetCrashReporterClient(instance); |
256 crash_reporter::InitializeCrashpadWithEmbeddedHandler(process_type.empty(), | 257 crash_reporter::InitializeCrashpadWithEmbeddedHandler( |
257 process_type); | 258 process_type.empty(), install_static::UTF16ToUTF8(process_type)); |
258 } | 259 } |
259 } | 260 } |
260 #endif // NACL_WIN64 | 261 #endif // NACL_WIN64 |
261 | 262 |
262 bool ChromeCrashReporterClient::GetAlternativeCrashDumpLocation( | 263 bool ChromeCrashReporterClient::GetAlternativeCrashDumpLocation( |
263 base::string16* crash_dir) { | 264 base::string16* crash_dir) { |
264 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate | 265 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate |
265 // location to write breakpad crash dumps can be set. | 266 // location to write breakpad crash dumps can be set. |
266 *crash_dir = | 267 *crash_dir = |
267 install_static::GetEnvironmentString16(L"BREAKPAD_DUMP_LOCATION"); | 268 install_static::GetEnvironmentString16(L"BREAKPAD_DUMP_LOCATION"); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 base::string16* crash_dir) { | 361 base::string16* crash_dir) { |
361 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate | 362 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate |
362 // location to write breakpad crash dumps can be set. | 363 // location to write breakpad crash dumps can be set. |
363 // If this environment variable exists, then for the time being, | 364 // If this environment variable exists, then for the time being, |
364 // short-circuit how it's handled on Windows. Honoring this | 365 // short-circuit how it's handled on Windows. Honoring this |
365 // variable is required in order to symbolize stack traces in | 366 // variable is required in order to symbolize stack traces in |
366 // Telemetry based tests: http://crbug.com/561763. | 367 // Telemetry based tests: http://crbug.com/561763. |
367 if (GetAlternativeCrashDumpLocation(crash_dir)) | 368 if (GetAlternativeCrashDumpLocation(crash_dir)) |
368 return true; | 369 return true; |
369 | 370 |
370 // TODO(scottmg): Consider supporting --user-data-dir. See | 371 *crash_dir = install_static::GetCrashDumpLocation(); |
371 // https://crbug.com/565446. | 372 return true; |
372 return install_static::GetDefaultCrashDumpLocation(crash_dir); | |
373 } | 373 } |
374 | 374 |
375 bool ChromeCrashReporterClient::GetCrashMetricsLocation( | 375 bool ChromeCrashReporterClient::GetCrashMetricsLocation( |
376 base::string16* metrics_dir) { | 376 base::string16* metrics_dir) { |
377 return install_static::GetDefaultUserDataDirectory(metrics_dir); | 377 return install_static::GetUserDataDirectory(metrics_dir, nullptr); |
378 } | 378 } |
379 | 379 |
380 // TODO(ananta) | 380 // TODO(ananta) |
381 // This function should be removed when the new crash key map implementation | 381 // This function should be removed when the new crash key map implementation |
382 // lands. | 382 // lands. |
383 size_t ChromeCrashReporterClient::RegisterCrashKeys() { | 383 size_t ChromeCrashReporterClient::RegisterCrashKeys() { |
384 return RegisterCrashKeysHelper(); | 384 return RegisterCrashKeysHelper(); |
385 } | 385 } |
386 | 386 |
387 bool ChromeCrashReporterClient::IsRunningUnattended() { | 387 bool ChromeCrashReporterClient::IsRunningUnattended() { |
388 return install_static::HasEnvironmentVariable16(install_static::kHeadless); | 388 return install_static::HasEnvironmentVariable16(install_static::kHeadless); |
389 } | 389 } |
390 | 390 |
391 bool ChromeCrashReporterClient::GetCollectStatsConsent() { | 391 bool ChromeCrashReporterClient::GetCollectStatsConsent() { |
392 return install_static::GetCollectStatsConsent(); | 392 return install_static::GetCollectStatsConsent(); |
393 } | 393 } |
394 | 394 |
395 bool ChromeCrashReporterClient::GetCollectStatsInSample() { | 395 bool ChromeCrashReporterClient::GetCollectStatsInSample() { |
396 return install_static::GetCollectStatsInSample(); | 396 return install_static::GetCollectStatsInSample(); |
397 } | 397 } |
398 | 398 |
399 bool ChromeCrashReporterClient::EnableBreakpadForProcess( | 399 bool ChromeCrashReporterClient::EnableBreakpadForProcess( |
400 const std::string& process_type) { | 400 const std::string& process_type) { |
401 return process_type == install_static::kRendererProcess || | 401 // This is not used by Crashpad (at least on Windows). |
402 process_type == install_static::kPpapiPluginProcess || | 402 NOTREACHED(); |
403 process_type == install_static::kGpuProcess; | 403 return true; |
404 } | 404 } |
OLD | NEW |