OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "chromecast/crash/android/crash_handler.h" | |
6 | |
7 #include <jni.h> | |
8 #include <string> | |
9 | |
10 #include "base/android/jni_android.h" | |
11 #include "base/android/jni_string.h" | |
12 #include "base/files/file_path.h" | |
13 #include "base/lazy_instance.h" | |
Lei Zhang
2014/10/06 22:44:25
nit: not used
gunsch
2014/10/09 00:20:55
Done.
| |
14 #include "base/logging.h" | |
15 #include "breakpad/src/client/linux/handler/exception_handler.h" | |
16 #include "breakpad/src/client/linux/handler/minidump_descriptor.h" | |
17 #include "chromecast/common/version.h" | |
18 #include "chromecast/crash/android/cast_crash_reporter_client_android.h" | |
19 #include "components/crash/app/breakpad_linux.h" | |
20 #include "components/crash/app/crash_reporter_client.h" | |
21 #include "content/public/common/content_switches.h" | |
22 #include "jni/CastCrashHandler_jni.h" | |
23 | |
24 namespace { | |
25 | |
26 chromecast::CrashHandler* g_crash_handler = NULL; | |
27 | |
28 // ExceptionHandler requires a HandlerCallback as a function pointer. This | |
29 // function exists to proxy into the global CrashHandler instance. | |
30 bool HandleCrash(const void*, size_t, void*) { | |
Lei Zhang
2014/10/06 22:44:25
nit: you can write in the parameter names but comm
gunsch
2014/10/09 00:20:55
Done.
| |
31 DCHECK(g_crash_handler); | |
32 if (g_crash_handler->CanUploadCrashDump()) { | |
33 g_crash_handler->AttemptUploadCrashDump(); | |
34 } else { | |
35 g_crash_handler->RemoveCrashDumps(); | |
36 } | |
37 | |
38 // Let the exception continue to propagate up to the system. | |
39 return false; | |
40 } | |
41 | |
42 } // namespace | |
43 | |
44 namespace chromecast { | |
45 | |
46 CrashHandler::CrashHandler(const std::string& process_type, | |
47 const base::FilePath& log_file_path) | |
48 : log_file_path_(log_file_path), | |
49 crash_reporter_client_(new CastCrashReporterClientAndroid) { | |
50 CHECK(crash_reporter_client_->GetCrashDumpLocation(&crash_dump_path_)); | |
Lei Zhang
2014/10/06 22:44:25
Do you have to CHECK() here?
gunsch
2014/10/09 00:20:55
I'll change it to a LOG(ERROR) --- but I don't nec
| |
51 SetCrashReporterClient(crash_reporter_client_.get()); | |
52 | |
53 if (process_type != switches::kZygoteProcess) { | |
54 if (process_type.empty()) { | |
55 // ExceptionHandlers are called on crash in reverse order of | |
56 // instantiation. This ExceptionHandler will attempt to upload crashes | |
57 // and the log file written out by the main process. | |
58 | |
59 // Dummy MinidumpDescriptor just to start up another ExceptionHandler. | |
60 google_breakpad::MinidumpDescriptor dummy(crash_dump_path_.value()); | |
61 crash_uploader_.reset(new google_breakpad::ExceptionHandler( | |
62 dummy, NULL, NULL, NULL, true, -1)); | |
63 crash_uploader_->set_crash_handler(&::HandleCrash); | |
64 | |
65 breakpad::InitCrashReporter(process_type); | |
66 } else { | |
67 breakpad::InitNonBrowserCrashReporterForAndroid(process_type); | |
68 } | |
69 } | |
70 | |
71 UploadCrashDumpsAsync(); | |
72 } | |
73 | |
74 // static | |
75 void CrashHandler::Initialize(const std::string& process_type, | |
76 const base::FilePath& log_file_path) { | |
77 DCHECK(!g_crash_handler); | |
78 g_crash_handler = new CrashHandler(process_type, log_file_path); | |
79 } | |
80 | |
81 // static | |
82 bool CrashHandler::GetCrashDumpLocation(base::FilePath* crash_dir) { | |
83 DCHECK(g_crash_handler); | |
84 return g_crash_handler->crash_reporter_client_-> | |
85 GetCrashDumpLocation(crash_dir); | |
86 } | |
87 | |
88 CrashHandler::~CrashHandler() { | |
89 DCHECK(g_crash_handler); | |
90 g_crash_handler = NULL; | |
91 } | |
92 | |
93 bool CrashHandler::CanUploadCrashDump() { | |
94 DCHECK(crash_reporter_client_); | |
95 return crash_reporter_client_->GetCollectStatsConsent(); | |
96 } | |
97 | |
98 void CrashHandler::AttemptUploadCrashDump() { | |
99 LOG(INFO) << "Attempting to upload current process crash"; | |
Lei Zhang
2014/10/06 22:44:25
No LOG(INFO) please. Use VLOG() if you want to kee
gunsch
2014/10/09 00:20:55
Done (this isn't terribly important), but in gener
| |
100 JNIEnv* env = base::android::AttachCurrentThread(); | |
101 // Crash dump location | |
102 base::android::ScopedJavaLocalRef<jstring> crash_dump_path_java = | |
103 base::android::ConvertUTF8ToJavaString(env, | |
104 crash_dump_path_.value()); | |
105 // Current log file location | |
106 base::android::ScopedJavaLocalRef<jstring> log_file_path_java = | |
107 base::android::ConvertUTF8ToJavaString(env, log_file_path_.value()); | |
108 Java_CastCrashHandler_uploadCurrentProcessDumpSync( | |
109 env, | |
110 crash_dump_path_java.obj(), | |
111 log_file_path_java.obj(), | |
112 CAST_IS_DEBUG_BUILD); | |
113 } | |
114 | |
115 void CrashHandler::UploadCrashDumpsAsync() { | |
116 JNIEnv* env = base::android::AttachCurrentThread(); | |
117 base::android::ScopedJavaLocalRef<jstring> crash_dump_path_java = | |
118 base::android::ConvertUTF8ToJavaString(env, | |
119 crash_dump_path_.value()); | |
120 Java_CastCrashHandler_uploadCrashDumpsAsync(env, | |
121 crash_dump_path_java.obj(), | |
122 CAST_IS_DEBUG_BUILD); | |
123 } | |
124 | |
125 void CrashHandler::RemoveCrashDumps() { | |
126 LOG(INFO) << "Removing crash dumps instead of uploading"; | |
Lei Zhang
2014/10/06 22:44:25
ditto
gunsch
2014/10/09 00:20:55
Done.
| |
127 JNIEnv* env = base::android::AttachCurrentThread(); | |
128 base::android::ScopedJavaLocalRef<jstring> crash_dump_path_java = | |
129 base::android::ConvertUTF8ToJavaString(env, | |
130 crash_dump_path_.value()); | |
131 Java_CastCrashHandler_removeCrashDumpsSync( | |
132 env, crash_dump_path_java.obj(), CAST_IS_DEBUG_BUILD); | |
133 } | |
134 | |
135 // static | |
136 bool CrashHandler::RegisterCastCrashJni(JNIEnv* env) { | |
137 return RegisterNativesImpl(env); | |
138 } | |
139 | |
140 } // namespace chromecast | |
OLD | NEW |