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/android/crash_handler.h" | 5 #include "chromecast/crash/android/crash_handler.h" |
6 | 6 |
7 #include <jni.h> | 7 #include <jni.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/android/jni_android.h" | 11 #include "base/android/jni_android.h" |
12 #include "base/android/jni_string.h" | 12 #include "base/android/jni_string.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
16 #include "breakpad/src/client/linux/handler/exception_handler.h" | 16 #include "breakpad/src/client/linux/handler/exception_handler.h" |
17 #include "breakpad/src/client/linux/handler/minidump_descriptor.h" | 17 #include "breakpad/src/client/linux/handler/minidump_descriptor.h" |
18 #include "chromecast/base/version.h" | 18 #include "chromecast/base/version.h" |
19 #include "chromecast/crash/android/cast_crash_reporter_client_android.h" | 19 #include "chromecast/crash/android/cast_crash_reporter_client_android.h" |
20 #include "components/crash/app/breakpad_linux.h" | 20 #include "components/crash/app/breakpad_linux.h" |
21 #include "components/crash/app/crash_reporter_client.h" | 21 #include "components/crash/app/crash_reporter_client.h" |
22 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
23 #include "jni/CastCrashHandler_jni.h" | 23 #include "jni/CastCrashHandler_jni.h" |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 chromecast::CrashHandler* g_crash_handler = NULL; | 27 chromecast::CrashHandler* g_crash_handler = NULL; |
28 | 28 |
29 bool HandleCrash(void* /* crash_context */) { | |
30 DCHECK(g_crash_handler); | |
31 g_crash_handler->UploadCrashDumps(); | |
32 | |
33 // TODO(gunsch): clean up the ATV crash handling code. | |
34 // Don't write another minidump. Chrome's default ExceptionHandler has already | |
35 // written a minidump by this point in the crash handling sequence. | |
36 return false; | |
37 } | |
38 | |
39 // Debug builds: always to crash-staging | 29 // Debug builds: always to crash-staging |
40 // Release builds: only to crash-staging for local/invalid build numbers | 30 // Release builds: only to crash-staging for local/invalid build numbers |
41 bool UploadCrashToStaging() { | 31 bool UploadCrashToStaging() { |
42 #if CAST_IS_DEBUG_BUILD() | 32 #if CAST_IS_DEBUG_BUILD() |
43 return true; | 33 return true; |
44 #else | 34 #else |
45 int build_number; | 35 int build_number; |
46 if (base::StringToInt(CAST_BUILD_INCREMENTAL, &build_number)) | 36 if (base::StringToInt(CAST_BUILD_INCREMENTAL, &build_number)) |
47 return build_number == 0; | 37 return build_number == 0; |
48 return true; | 38 return true; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 } | 75 } |
86 | 76 |
87 CrashHandler::~CrashHandler() { | 77 CrashHandler::~CrashHandler() { |
88 DCHECK(g_crash_handler); | 78 DCHECK(g_crash_handler); |
89 g_crash_handler = NULL; | 79 g_crash_handler = NULL; |
90 } | 80 } |
91 | 81 |
92 void CrashHandler::Initialize() { | 82 void CrashHandler::Initialize() { |
93 if (process_type_.empty()) { | 83 if (process_type_.empty()) { |
94 InitializeUploader(); | 84 InitializeUploader(); |
95 | |
96 // ExceptionHandlers are called on crash in reverse order of | |
97 // instantiation. This ExceptionHandler will attempt to upload crashes | |
98 // and the log file written out by the main process. | |
99 | |
100 // Dummy MinidumpDescriptor just to start up another ExceptionHandler. | |
101 google_breakpad::MinidumpDescriptor dummy(crash_dump_path_.value()); | |
102 crash_uploader_.reset(new google_breakpad::ExceptionHandler( | |
103 dummy, &HandleCrash, NULL, NULL, true, -1)); | |
104 | |
105 breakpad::InitCrashReporter(process_type_); | 85 breakpad::InitCrashReporter(process_type_); |
106 | |
107 return; | 86 return; |
108 } | 87 } |
109 | 88 |
110 if (process_type_ != switches::kZygoteProcess) { | 89 if (process_type_ != switches::kZygoteProcess) { |
111 breakpad::InitNonBrowserCrashReporterForAndroid(process_type_); | 90 breakpad::InitNonBrowserCrashReporterForAndroid(process_type_); |
112 } | 91 } |
113 } | 92 } |
114 | 93 |
115 void CrashHandler::InitializeUploader() { | 94 void CrashHandler::InitializeUploader() { |
116 JNIEnv* env = base::android::AttachCurrentThread(); | 95 JNIEnv* env = base::android::AttachCurrentThread(); |
117 base::android::ScopedJavaLocalRef<jstring> crash_dump_path_java = | 96 base::android::ScopedJavaLocalRef<jstring> crash_dump_path_java = |
118 base::android::ConvertUTF8ToJavaString(env, | 97 base::android::ConvertUTF8ToJavaString(env, |
119 crash_dump_path_.value()); | 98 crash_dump_path_.value()); |
120 Java_CastCrashHandler_initializeUploader( | 99 Java_CastCrashHandler_initializeUploader( |
121 env, crash_dump_path_java.obj(), UploadCrashToStaging()); | 100 env, base::android::GetApplicationContext(), |
122 } | 101 crash_dump_path_java.obj(), UploadCrashToStaging()); |
123 | |
124 bool CrashHandler::CanUploadCrashDump() { | |
125 DCHECK(crash_reporter_client_); | |
126 return crash_reporter_client_->GetCollectStatsConsent(); | |
127 } | |
128 | |
129 void CrashHandler::UploadCrashDumps() { | |
130 VLOG(1) << "Attempting to upload current process crash"; | |
131 | |
132 if (CanUploadCrashDump()) { | |
133 JNIEnv* env = base::android::AttachCurrentThread(); | |
134 // Current log file location | |
135 base::android::ScopedJavaLocalRef<jstring> log_file_path_java = | |
136 base::android::ConvertUTF8ToJavaString(env, log_file_path_.value()); | |
137 Java_CastCrashHandler_uploadCrashDumps(env, log_file_path_java.obj()); | |
138 } else { | |
139 VLOG(1) << "Removing crash dumps instead of uploading"; | |
140 JNIEnv* env = base::android::AttachCurrentThread(); | |
141 Java_CastCrashHandler_removeCrashDumps(env); | |
142 } | |
143 } | 102 } |
144 | 103 |
145 } // namespace chromecast | 104 } // namespace chromecast |
OLD | NEW |