| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/crash/content/browser/crash_dump_manager_android.h" | 5 #include "components/crash/content/browser/crash_dump_manager_android.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_string.h" |
| 9 #include "base/bind.h" | 11 #include "base/bind.h" |
| 10 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 11 #include "base/format_macros.h" | 13 #include "base/format_macros.h" |
| 12 #include "base/logging.h" | 14 #include "base/logging.h" |
| 13 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
| 14 #include "base/posix/global_descriptors.h" | 16 #include "base/posix/global_descriptors.h" |
| 15 #include "base/process/process.h" | 17 #include "base/process/process.h" |
| 16 #include "base/rand_util.h" | 18 #include "base/rand_util.h" |
| 17 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
| 18 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 19 #include "components/crash/content/app/breakpad_linux.h" | 21 #include "components/crash/content/app/breakpad_linux.h" |
| 20 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/child_process_data.h" | 23 #include "content/public/browser/child_process_data.h" |
| 22 #include "content/public/browser/file_descriptor_info.h" | 24 #include "content/public/browser/file_descriptor_info.h" |
| 23 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
| 24 #include "content/public/browser/notification_types.h" | 26 #include "content/public/browser/notification_types.h" |
| 25 #include "content/public/browser/render_process_host.h" | 27 #include "content/public/browser/render_process_host.h" |
| 28 #include "jni/CrashDumpManager_jni.h" |
| 26 | 29 |
| 27 using content::BrowserThread; | 30 using content::BrowserThread; |
| 28 | 31 |
| 29 namespace breakpad { | 32 namespace breakpad { |
| 30 | 33 |
| 31 CrashDumpManager::CrashDumpManager(const base::FilePath& crash_dump_dir, | 34 CrashDumpManager::CrashDumpManager(const base::FilePath& crash_dump_dir, |
| 32 int descriptor_id) | 35 int descriptor_id) |
| 33 : crash_dump_dir_(crash_dump_dir), descriptor_id_(descriptor_id) {} | 36 : crash_dump_dir_(crash_dump_dir), descriptor_id_(descriptor_id) {} |
| 34 | 37 |
| 35 CrashDumpManager::~CrashDumpManager() { | 38 CrashDumpManager::~CrashDumpManager() { |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 base::StringPrintf("chromium-renderer-minidump-%016" PRIx64 ".dmp%d", | 149 base::StringPrintf("chromium-renderer-minidump-%016" PRIx64 ".dmp%d", |
| 147 rand, pid); | 150 rand, pid); |
| 148 base::FilePath dest_path = crash_dump_dir.Append(filename); | 151 base::FilePath dest_path = crash_dump_dir.Append(filename); |
| 149 r = base::Move(minidump_path, dest_path); | 152 r = base::Move(minidump_path, dest_path); |
| 150 if (!r) { | 153 if (!r) { |
| 151 LOG(ERROR) << "Failed to move crash dump from " << minidump_path.value() | 154 LOG(ERROR) << "Failed to move crash dump from " << minidump_path.value() |
| 152 << " to " << dest_path.value(); | 155 << " to " << dest_path.value(); |
| 153 base::DeleteFile(minidump_path, false); | 156 base::DeleteFile(minidump_path, false); |
| 154 return; | 157 return; |
| 155 } | 158 } |
| 156 VLOG(1) << "Crash minidump successfully generated: " | 159 VLOG(1) << "Crash minidump successfully generated: " << dest_path.value(); |
| 157 << crash_dump_dir.Append(filename).value(); | 160 |
| 161 // Hop over to Java to attempt to attach the logcat to the crash. This may |
| 162 // fail, which is ok -- if it does, the crash will still be uploaded on the |
| 163 // next browser start. |
| 164 JNIEnv* env = base::android::AttachCurrentThread(); |
| 165 base::android::ScopedJavaLocalRef<jstring> j_dest_path = |
| 166 base::android::ConvertUTF8ToJavaString(env, dest_path.value()); |
| 167 Java_CrashDumpManager_tryToUploadMinidump(env, j_dest_path); |
| 158 } | 168 } |
| 159 | 169 |
| 160 void CrashDumpManager::OnChildExit(int child_process_id, | 170 void CrashDumpManager::OnChildExit(int child_process_id, |
| 161 base::ProcessHandle pid, | 171 base::ProcessHandle pid, |
| 162 content::ProcessType process_type, | 172 content::ProcessType process_type, |
| 163 base::TerminationStatus termination_status, | 173 base::TerminationStatus termination_status, |
| 164 base::android::ApplicationState app_state) { | 174 base::android::ApplicationState app_state) { |
| 165 base::FilePath minidump_path; | 175 base::FilePath minidump_path; |
| 166 { | 176 { |
| 167 base::AutoLock auto_lock(child_process_id_to_minidump_path_lock_); | 177 base::AutoLock auto_lock(child_process_id_to_minidump_path_lock_); |
| 168 ChildProcessIDToMinidumpPath::iterator iter = | 178 ChildProcessIDToMinidumpPath::iterator iter = |
| 169 child_process_id_to_minidump_path_.find(child_process_id); | 179 child_process_id_to_minidump_path_.find(child_process_id); |
| 170 if (iter == child_process_id_to_minidump_path_.end()) { | 180 if (iter == child_process_id_to_minidump_path_.end()) { |
| 171 // We might get a NOTIFICATION_RENDERER_PROCESS_TERMINATED and a | 181 // We might get a NOTIFICATION_RENDERER_PROCESS_TERMINATED and a |
| 172 // NOTIFICATION_RENDERER_PROCESS_CLOSED. | 182 // NOTIFICATION_RENDERER_PROCESS_CLOSED. |
| 173 return; | 183 return; |
| 174 } | 184 } |
| 175 minidump_path = iter->second; | 185 minidump_path = iter->second; |
| 176 child_process_id_to_minidump_path_.erase(iter); | 186 child_process_id_to_minidump_path_.erase(iter); |
| 177 } | 187 } |
| 178 BrowserThread::PostTask( | 188 BrowserThread::PostTask( |
| 179 BrowserThread::FILE, FROM_HERE, | 189 BrowserThread::FILE, FROM_HERE, |
| 180 base::Bind(&CrashDumpManager::ProcessMinidump, minidump_path, | 190 base::Bind(&CrashDumpManager::ProcessMinidump, minidump_path, |
| 181 crash_dump_dir_, pid, process_type, termination_status, | 191 crash_dump_dir_, pid, process_type, termination_status, |
| 182 app_state)); | 192 app_state)); |
| 183 } | 193 } |
| 184 | 194 |
| 185 } // namespace breakpad | 195 } // namespace breakpad |
| OLD | NEW |