1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chromecast/app/linux/cast_crash_reporter_client.h"
7 #include "base/time/time.h"
8 #include "chromecast/base/error_codes.h"
9 #include "chromecast/crash/linux/crash_util.h"
10 #include "components/crash/content/app/breakpad_linux.h"
11 #include "content/public/common/content_switches.h"
13 namespace chromecast
{
17 std::string
* g_process_type
= nullptr;
18 uint64_t g_process_start_time_ms
= 0u;
23 void CastCrashReporterClient::InitCrashReporter(
24 const std::string
& process_type
) {
25 DCHECK(!g_process_type
);
26 g_process_start_time_ms
=
27 (base::TimeTicks::Now() - base::TimeTicks()).InMilliseconds();
29 // Save the process type (leaked).
30 g_process_type
= new std::string(process_type
);
32 // Start up breakpad for this process, if applicable.
33 breakpad::InitCrashReporter(process_type
);
37 const char* CastCrashReporterClient::GetProcessType() {
38 return g_process_type
? g_process_type
->c_str() : nullptr;
42 uint64_t CastCrashReporterClient::GetProcessStartTime() {
43 return g_process_start_time_ms
;
46 CastCrashReporterClient::CastCrashReporterClient() {
48 CastCrashReporterClient::~CastCrashReporterClient() {
51 bool CastCrashReporterClient::EnableBreakpadForProcess(
52 const std::string
& process_type
) {
53 return process_type
== switches::kRendererProcess
||
54 process_type
== switches::kZygoteProcess
||
55 process_type
== switches::kGpuProcess
;
58 bool CastCrashReporterClient::HandleCrashDump(const char* crashdump_filename
) {
59 // Set the initial error code to ERROR_WEB_CONTENT_RENDER_VIEW_GONE to show
60 // an error message on next cast_shell run. Though the error code is for
61 // renderer process crash, the actual messages can be used for browser process
63 if (!GetProcessType() || !strcmp(GetProcessType(), ""))
64 SetInitialErrorCode(ERROR_WEB_CONTENT_RENDER_VIEW_GONE
);
66 // Upload crash dump. If user didn't opt-in crash report, minidump writer
67 // instantiated within CrashUtil::RequestUploadCrashDump() does nothing.
68 CrashUtil::RequestUploadCrashDump(crashdump_filename
,
69 GetProcessType() ? GetProcessType() : "",
70 GetProcessStartTime());
72 // Always return true to indicate that this crash dump has been processed,
73 // so that it won't fallback to use chrome's default uploader.
77 } // namespace chromecast