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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 } | 73 } |
84 | 74 |
85 CrashHandler::~CrashHandler() { | 75 CrashHandler::~CrashHandler() { |
86 DCHECK(g_crash_handler); | 76 DCHECK(g_crash_handler); |
87 g_crash_handler = NULL; | 77 g_crash_handler = NULL; |
88 } | 78 } |
89 | 79 |
90 void CrashHandler::Initialize(const std::string& process_type) { | 80 void CrashHandler::Initialize(const std::string& process_type) { |
91 if (process_type.empty()) { | 81 if (process_type.empty()) { |
92 InitializeUploader(); | 82 InitializeUploader(); |
93 | |
94 // ExceptionHandlers are called on crash in reverse order of | |
95 // instantiation. This ExceptionHandler will attempt to upload crashes | |
96 // and the log file written out by the main process. | |
97 | |
98 // Dummy MinidumpDescriptor just to start up another ExceptionHandler. | |
99 google_breakpad::MinidumpDescriptor dummy(crash_dump_path_.value()); | |
100 crash_uploader_.reset(new google_breakpad::ExceptionHandler( | |
101 dummy, &HandleCrash, NULL, NULL, true, -1)); | |
102 | |
103 breakpad::InitCrashReporter(process_type); | 83 breakpad::InitCrashReporter(process_type); |
104 | |
105 return; | 84 return; |
106 } | 85 } |
107 | 86 |
108 if (process_type != switches::kZygoteProcess) { | 87 if (process_type != switches::kZygoteProcess) { |
109 breakpad::InitNonBrowserCrashReporterForAndroid(process_type); | 88 breakpad::InitNonBrowserCrashReporterForAndroid(process_type); |
110 } | 89 } |
111 } | 90 } |
112 | 91 |
113 void CrashHandler::InitializeUploader() { | 92 void CrashHandler::InitializeUploader() { |
114 JNIEnv* env = base::android::AttachCurrentThread(); | 93 JNIEnv* env = base::android::AttachCurrentThread(); |
115 base::android::ScopedJavaLocalRef<jstring> crash_dump_path_java = | 94 base::android::ScopedJavaLocalRef<jstring> crash_dump_path_java = |
116 base::android::ConvertUTF8ToJavaString(env, | 95 base::android::ConvertUTF8ToJavaString(env, |
117 crash_dump_path_.value()); | 96 crash_dump_path_.value()); |
118 Java_CastCrashHandler_initializeUploader( | 97 Java_CastCrashHandler_initializeUploader( |
119 env, crash_dump_path_java.obj(), UploadCrashToStaging()); | 98 env, base::android::GetApplicationContext(), |
120 } | 99 crash_dump_path_java.obj(), UploadCrashToStaging()); |
121 | |
122 bool CrashHandler::CanUploadCrashDump() { | |
123 DCHECK(crash_reporter_client_); | |
124 return crash_reporter_client_->GetCollectStatsConsent(); | |
125 } | |
126 | |
127 void CrashHandler::UploadCrashDumps() { | |
128 VLOG(1) << "Attempting to upload current process crash"; | |
129 | |
130 if (CanUploadCrashDump()) { | |
131 JNIEnv* env = base::android::AttachCurrentThread(); | |
132 // Current log file location | |
133 base::android::ScopedJavaLocalRef<jstring> log_file_path_java = | |
134 base::android::ConvertUTF8ToJavaString(env, log_file_path_.value()); | |
135 Java_CastCrashHandler_uploadCrashDumps(env, log_file_path_java.obj()); | |
136 } else { | |
137 VLOG(1) << "Removing crash dumps instead of uploading"; | |
138 JNIEnv* env = base::android::AttachCurrentThread(); | |
139 Java_CastCrashHandler_removeCrashDumps(env); | |
140 } | |
141 } | 100 } |
142 | 101 |
143 } // namespace chromecast | 102 } // namespace chromecast |
OLD | NEW |