OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "chromecast/crash/cast_crash_reporter_client.h" | 5 #include "chromecast/crash/linux/cast_crash_reporter_client.h" |
6 | 6 |
7 #include "base/time/time.h" | 7 #include "base/time/time.h" |
| 8 #include "chromecast/base/error_codes.h" |
| 9 #include "chromecast/crash/linux/crash_util.h" |
8 #include "components/crash/app/breakpad_linux.h" | 10 #include "components/crash/app/breakpad_linux.h" |
9 #include "content/public/common/content_switches.h" | 11 #include "content/public/common/content_switches.h" |
10 | 12 |
11 namespace chromecast { | 13 namespace chromecast { |
12 | 14 |
13 namespace { | 15 namespace { |
14 | 16 |
15 char* g_process_type = NULL; | 17 char* g_process_type = NULL; |
16 uint64_t g_process_start_time = 0; | 18 uint64_t g_process_start_time = 0; |
17 | 19 |
18 } // namespace | 20 } // namespace |
19 | 21 |
20 // static | 22 // static |
21 void CastCrashReporterClient::InitCrashReporter( | 23 void CastCrashReporterClient::InitCrashReporter( |
22 const std::string& process_type) { | 24 const std::string& process_type) { |
23 g_process_start_time = (base::TimeTicks::Now() - | 25 g_process_start_time = |
24 base::TimeTicks()).InMilliseconds(); | 26 (base::TimeTicks::Now() - base::TimeTicks()).InMilliseconds(); |
25 | 27 |
26 // Save the process type (leaked). | 28 // Save the process type (leaked). |
27 // Note: "browser" process is identified by empty process type string. | 29 // Note: "browser" process is identified by empty process type string. |
28 const std::string& named_process_type( | 30 const std::string& named_process_type(process_type.empty() ? "browser" |
29 process_type.empty() ? "browser" : process_type); | 31 : process_type); |
30 const size_t process_type_len = named_process_type.size() + 1; | 32 const size_t process_type_len = named_process_type.size() + 1; |
31 g_process_type = new char[process_type_len]; | 33 g_process_type = new char[process_type_len]; |
32 strncpy(g_process_type, named_process_type.c_str(), process_type_len); | 34 strncpy(g_process_type, named_process_type.c_str(), process_type_len); |
33 | 35 |
34 // Start up breakpad for this process, if applicable. | 36 // Start up breakpad for this process, if applicable. |
35 breakpad::InitCrashReporter(process_type); | 37 breakpad::InitCrashReporter(process_type); |
36 } | 38 } |
37 | 39 |
38 // static | 40 // static |
39 char* CastCrashReporterClient::GetProcessType() { | 41 char* CastCrashReporterClient::GetProcessType() { |
40 return g_process_type; | 42 return g_process_type; |
41 } | 43 } |
42 | 44 |
43 // static | 45 // static |
44 uint64_t CastCrashReporterClient::GetProcessStartTime() { | 46 uint64_t CastCrashReporterClient::GetProcessStartTime() { |
45 return g_process_start_time; | 47 return g_process_start_time; |
46 } | 48 } |
47 | 49 |
48 CastCrashReporterClient::CastCrashReporterClient() {} | 50 CastCrashReporterClient::CastCrashReporterClient() { |
49 CastCrashReporterClient::~CastCrashReporterClient() {} | 51 } |
| 52 CastCrashReporterClient::~CastCrashReporterClient() { |
| 53 } |
50 | 54 |
51 bool CastCrashReporterClient::EnableBreakpadForProcess( | 55 bool CastCrashReporterClient::EnableBreakpadForProcess( |
52 const std::string& process_type) { | 56 const std::string& process_type) { |
53 return process_type == switches::kRendererProcess || | 57 return process_type == switches::kRendererProcess || |
54 process_type == switches::kZygoteProcess || | 58 process_type == switches::kZygoteProcess || |
55 process_type == switches::kGpuProcess; | 59 process_type == switches::kGpuProcess; |
56 } | 60 } |
57 | 61 |
| 62 bool CastCrashReporterClient::HandleCrashDump(const char* crashdump_filename) { |
| 63 // Set the initial error code to ERROR_WEB_CONTENT_RENDER_VIEW_GONE to show |
| 64 // an error message on next cast_shell run. Though the error code is for |
| 65 // renderer process crash, the actual messages can be used for browser process |
| 66 // as well. |
| 67 if (!GetProcessType() || !strcmp(GetProcessType(), "browser")) |
| 68 SetInitialErrorCode(ERROR_WEB_CONTENT_RENDER_VIEW_GONE); |
| 69 |
| 70 // Upload crash dump. If user didn't opt-in crash report, minidump writer |
| 71 // instantiated within CrashUtil::RequestUploadCrashDump() does nothing. |
| 72 CrashUtil::RequestUploadCrashDump( |
| 73 crashdump_filename, GetProcessType(), GetProcessStartTime()); |
| 74 |
| 75 // Always return true to indicate that this crash dump has been processed, |
| 76 // so that it won't fallback to use chrome's default uploader. |
| 77 return true; |
| 78 } |
| 79 |
58 } // namespace chromecast | 80 } // namespace chromecast |
OLD | NEW |