| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/posix/global_descriptors.h" | 12 #include "base/posix/global_descriptors.h" |
| 12 #include "base/process/process.h" | 13 #include "base/process/process.h" |
| 13 #include "base/rand_util.h" | 14 #include "base/rand_util.h" |
| 14 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 15 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/child_process_data.h" | 18 #include "content/public/browser/child_process_data.h" |
| 18 #include "content/public/browser/file_descriptor_info.h" | 19 #include "content/public/browser/file_descriptor_info.h" |
| 19 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
| 20 #include "content/public/browser/notification_types.h" | 21 #include "content/public/browser/notification_types.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 | 75 |
| 75 { | 76 { |
| 76 base::AutoLock auto_lock(child_process_id_to_minidump_path_lock_); | 77 base::AutoLock auto_lock(child_process_id_to_minidump_path_lock_); |
| 77 DCHECK(!ContainsKey(child_process_id_to_minidump_path_, child_process_id)); | 78 DCHECK(!ContainsKey(child_process_id_to_minidump_path_, child_process_id)); |
| 78 child_process_id_to_minidump_path_[child_process_id] = minidump_path; | 79 child_process_id_to_minidump_path_[child_process_id] = minidump_path; |
| 79 } | 80 } |
| 80 return minidump_file.Pass(); | 81 return minidump_file.Pass(); |
| 81 } | 82 } |
| 82 | 83 |
| 83 // static | 84 // static |
| 84 void CrashDumpManager::ProcessMinidump(const base::FilePath& minidump_path, | 85 void CrashDumpManager::ProcessMinidump( |
| 85 base::ProcessHandle pid) { | 86 const base::FilePath& minidump_path, |
| 87 base::ProcessHandle pid, |
| 88 content::ProcessType process_type, |
| 89 base::TerminationStatus exit_status, |
| 90 base::android::ApplicationState app_state) { |
| 86 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 91 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 87 CHECK(instance_); | 92 CHECK(instance_); |
| 88 int64 file_size = 0; | 93 int64 file_size = 0; |
| 89 int r = base::GetFileSize(minidump_path, &file_size); | 94 int r = base::GetFileSize(minidump_path, &file_size); |
| 90 DCHECK(r) << "Failed to retrieve size for minidump " | 95 DCHECK(r) << "Failed to retrieve size for minidump " |
| 91 << minidump_path.value(); | 96 << minidump_path.value(); |
| 92 | 97 |
| 98 if (process_type == content::PROCESS_TYPE_RENDERER && |
| 99 exit_status == base::TERMINATION_STATUS_OOM_PROTECTED) { |
| 100 bool is_running = |
| 101 (app_state == base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES); |
| 102 bool is_paused = |
| 103 (app_state == base::android::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES); |
| 104 ExitStatus renderer_exit_status; |
| 105 if (file_size == 0) { |
| 106 if (is_running) { |
| 107 renderer_exit_status = EMPTY_MINIDUMP_WHILE_RUNNING; |
| 108 } else if (is_paused) { |
| 109 renderer_exit_status = EMPTY_MINIDUMP_WHILE_PAUSED; |
| 110 } else { |
| 111 renderer_exit_status = EMPTY_MINIDUMP_WHILE_BACKGROUND; |
| 112 } |
| 113 } else { |
| 114 if (is_running) { |
| 115 renderer_exit_status = VALID_MINIDUMP_WHILE_RUNNING; |
| 116 } else if (is_paused) { |
| 117 renderer_exit_status = VALID_MINIDUMP_WHILE_PAUSED; |
| 118 } else { |
| 119 renderer_exit_status = VALID_MINIDUMP_WHILE_BACKGROUND; |
| 120 } |
| 121 } |
| 122 UMA_HISTOGRAM_ENUMERATION("Tab.RendererDetailedExitStatus", |
| 123 renderer_exit_status, |
| 124 ExitStatus::COUNT); |
| 125 } |
| 126 |
| 93 if (file_size == 0) { | 127 if (file_size == 0) { |
| 94 // Empty minidump, this process did not crash. Just remove the file. | 128 // Empty minidump, this process did not crash. Just remove the file. |
| 95 r = base::DeleteFile(minidump_path, false); | 129 r = base::DeleteFile(minidump_path, false); |
| 96 DCHECK(r) << "Failed to delete temporary minidump file " | 130 DCHECK(r) << "Failed to delete temporary minidump file " |
| 97 << minidump_path.value(); | 131 << minidump_path.value(); |
| 98 return; | 132 return; |
| 99 } | 133 } |
| 100 | 134 |
| 101 // We are dealing with a valid minidump. Copy it to the crash report | 135 // We are dealing with a valid minidump. Copy it to the crash report |
| 102 // directory from where Java code will upload it later on. | 136 // directory from where Java code will upload it later on. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 115 << " to " << dest_path.value(); | 149 << " to " << dest_path.value(); |
| 116 base::DeleteFile(minidump_path, false); | 150 base::DeleteFile(minidump_path, false); |
| 117 return; | 151 return; |
| 118 } | 152 } |
| 119 VLOG(1) << "Crash minidump successfully generated: " << | 153 VLOG(1) << "Crash minidump successfully generated: " << |
| 120 instance_->crash_dump_dir_.Append(filename).value(); | 154 instance_->crash_dump_dir_.Append(filename).value(); |
| 121 } | 155 } |
| 122 | 156 |
| 123 void CrashDumpManager::BrowserChildProcessHostDisconnected( | 157 void CrashDumpManager::BrowserChildProcessHostDisconnected( |
| 124 const content::ChildProcessData& data) { | 158 const content::ChildProcessData& data) { |
| 125 OnChildExit(data.id, data.handle); | 159 OnChildExit(data.id, |
| 160 data.handle, |
| 161 static_cast<content::ProcessType>(data.process_type), |
| 162 /* exit_status */ base::TERMINATION_STATUS_MAX_ENUM, |
| 163 /* app_state */ base::android::APPLICATION_STATE_UNKNOWN); |
| 126 } | 164 } |
| 127 | 165 |
| 128 void CrashDumpManager::BrowserChildProcessCrashed( | 166 void CrashDumpManager::BrowserChildProcessCrashed( |
| 129 const content::ChildProcessData& data, | 167 const content::ChildProcessData& data, |
| 130 int exit_code) { | 168 int exit_code) { |
| 131 OnChildExit(data.id, data.handle); | 169 OnChildExit(data.id, |
| 170 data.handle, |
| 171 static_cast<content::ProcessType>(data.process_type), |
| 172 /* exit_status */ base::TERMINATION_STATUS_ABNORMAL_TERMINATION, |
| 173 /* app_state */ base::android::APPLICATION_STATE_UNKNOWN); |
| 132 } | 174 } |
| 133 | 175 |
| 134 void CrashDumpManager::Observe(int type, | 176 void CrashDumpManager::Observe(int type, |
| 135 const content::NotificationSource& source, | 177 const content::NotificationSource& source, |
| 136 const content::NotificationDetails& details) { | 178 const content::NotificationDetails& details) { |
| 137 switch (type) { | 179 switch (type) { |
| 138 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: | 180 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: |
| 139 // NOTIFICATION_RENDERER_PROCESS_TERMINATED is sent when the renderer | 181 // NOTIFICATION_RENDERER_PROCESS_TERMINATED is sent when the renderer |
| 140 // process is cleanly shutdown. However, we need to fallthrough so that | 182 // process is cleanly shutdown. However, we need to fallthrough so that |
| 141 // we close the minidump_fd we kept open. | 183 // we close the minidump_fd we kept open. |
| 142 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { | 184 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { |
| 143 content::RenderProcessHost* rph = | 185 content::RenderProcessHost* rph = |
| 144 content::Source<content::RenderProcessHost>(source).ptr(); | 186 content::Source<content::RenderProcessHost>(source).ptr(); |
| 145 OnChildExit(rph->GetID(), rph->GetHandle()); | 187 content::RenderProcessHost::RendererClosedDetails* process_details = |
| 188 content::Details<content::RenderProcessHost::RendererClosedDetails>( |
| 189 details).ptr(); |
| 190 OnChildExit(rph->GetID(), |
| 191 rph->GetHandle(), |
| 192 content::PROCESS_TYPE_RENDERER, |
| 193 process_details->status, |
| 194 base::android::ApplicationStatusListener::GetState()); |
| 146 break; | 195 break; |
| 147 } | 196 } |
| 148 default: | 197 default: |
| 149 NOTREACHED(); | 198 NOTREACHED(); |
| 150 return; | 199 return; |
| 151 } | 200 } |
| 152 } | 201 } |
| 153 | 202 |
| 154 void CrashDumpManager::OnChildExit(int child_process_id, | 203 void CrashDumpManager::OnChildExit(int child_process_id, |
| 155 base::ProcessHandle pid) { | 204 base::ProcessHandle pid, |
| 205 content::ProcessType process_type, |
| 206 base::TerminationStatus exit_status, |
| 207 base::android::ApplicationState app_state) { |
| 156 base::FilePath minidump_path; | 208 base::FilePath minidump_path; |
| 157 { | 209 { |
| 158 base::AutoLock auto_lock(child_process_id_to_minidump_path_lock_); | 210 base::AutoLock auto_lock(child_process_id_to_minidump_path_lock_); |
| 159 ChildProcessIDToMinidumpPath::iterator iter = | 211 ChildProcessIDToMinidumpPath::iterator iter = |
| 160 child_process_id_to_minidump_path_.find(child_process_id); | 212 child_process_id_to_minidump_path_.find(child_process_id); |
| 161 if (iter == child_process_id_to_minidump_path_.end()) { | 213 if (iter == child_process_id_to_minidump_path_.end()) { |
| 162 // We might get a NOTIFICATION_RENDERER_PROCESS_TERMINATED and a | 214 // We might get a NOTIFICATION_RENDERER_PROCESS_TERMINATED and a |
| 163 // NOTIFICATION_RENDERER_PROCESS_CLOSED. | 215 // NOTIFICATION_RENDERER_PROCESS_CLOSED. |
| 164 return; | 216 return; |
| 165 } | 217 } |
| 166 minidump_path = iter->second; | 218 minidump_path = iter->second; |
| 167 child_process_id_to_minidump_path_.erase(iter); | 219 child_process_id_to_minidump_path_.erase(iter); |
| 168 } | 220 } |
| 169 BrowserThread::PostTask( | 221 BrowserThread::PostTask( |
| 170 BrowserThread::FILE, FROM_HERE, | 222 BrowserThread::FILE, FROM_HERE, |
| 171 base::Bind(&CrashDumpManager::ProcessMinidump, minidump_path, pid)); | 223 base::Bind(&CrashDumpManager::ProcessMinidump, |
| 224 minidump_path, |
| 225 pid, |
| 226 process_type, |
| 227 exit_status, |
| 228 app_state)); |
| 172 } | 229 } |
| 173 | 230 |
| 174 } // namespace breakpad | 231 } // namespace breakpad |
| OLD | NEW |