| 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 app_state != base::android::APPLICATION_STATE_UNKNOWN && |
| 100 exit_status == base::TERMINATION_STATUS_OOM_PROTECTED) { |
| 101 bool is_running = |
| 102 (app_state == base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES); |
| 103 bool is_paused = |
| 104 (app_state == base::android::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES); |
| 105 ExitStatus renderer_exit_status; |
| 106 if (file_size == 0) { |
| 107 if (is_running) { |
| 108 renderer_exit_status = EMPTY_MINIDUMP_WHILE_RUNNING; |
| 109 } else if (is_paused) { |
| 110 renderer_exit_status = EMPTY_MINIDUMP_WHILE_PAUSED; |
| 111 } else { |
| 112 renderer_exit_status = EMPTY_MINIDUMP_WHILE_BACKGROUND; |
| 113 } |
| 114 } else { |
| 115 if (is_running) { |
| 116 renderer_exit_status = VALID_MINIDUMP_WHILE_RUNNING; |
| 117 } else if (is_paused) { |
| 118 renderer_exit_status = VALID_MINIDUMP_WHILE_PAUSED; |
| 119 } else { |
| 120 renderer_exit_status = VALID_MINIDUMP_WHILE_BACKGROUND; |
| 121 } |
| 122 } |
| 123 UMA_HISTOGRAM_ENUMERATION("Tab.RendererDetailedExitStatus", |
| 124 renderer_exit_status, |
| 125 ExitStatus::MINIDUMP_STATUS_COUNT); |
| 126 } |
| 127 |
| 93 if (file_size == 0) { | 128 if (file_size == 0) { |
| 94 // Empty minidump, this process did not crash. Just remove the file. | 129 // Empty minidump, this process did not crash. Just remove the file. |
| 95 r = base::DeleteFile(minidump_path, false); | 130 r = base::DeleteFile(minidump_path, false); |
| 96 DCHECK(r) << "Failed to delete temporary minidump file " | 131 DCHECK(r) << "Failed to delete temporary minidump file " |
| 97 << minidump_path.value(); | 132 << minidump_path.value(); |
| 98 return; | 133 return; |
| 99 } | 134 } |
| 100 | 135 |
| 101 // We are dealing with a valid minidump. Copy it to the crash report | 136 // We are dealing with a valid minidump. Copy it to the crash report |
| 102 // directory from where Java code will upload it later on. | 137 // directory from where Java code will upload it later on. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 115 << " to " << dest_path.value(); | 150 << " to " << dest_path.value(); |
| 116 base::DeleteFile(minidump_path, false); | 151 base::DeleteFile(minidump_path, false); |
| 117 return; | 152 return; |
| 118 } | 153 } |
| 119 VLOG(1) << "Crash minidump successfully generated: " << | 154 VLOG(1) << "Crash minidump successfully generated: " << |
| 120 instance_->crash_dump_dir_.Append(filename).value(); | 155 instance_->crash_dump_dir_.Append(filename).value(); |
| 121 } | 156 } |
| 122 | 157 |
| 123 void CrashDumpManager::BrowserChildProcessHostDisconnected( | 158 void CrashDumpManager::BrowserChildProcessHostDisconnected( |
| 124 const content::ChildProcessData& data) { | 159 const content::ChildProcessData& data) { |
| 125 OnChildExit(data.id, data.handle); | 160 OnChildExit(data.id, |
| 161 data.handle, |
| 162 static_cast<content::ProcessType>(data.process_type), |
| 163 base::TERMINATION_STATUS_MAX_ENUM, |
| 164 base::android::APPLICATION_STATE_UNKNOWN); |
| 126 } | 165 } |
| 127 | 166 |
| 128 void CrashDumpManager::BrowserChildProcessCrashed( | 167 void CrashDumpManager::BrowserChildProcessCrashed( |
| 129 const content::ChildProcessData& data, | 168 const content::ChildProcessData& data, |
| 130 int exit_code) { | 169 int exit_code) { |
| 131 OnChildExit(data.id, data.handle); | 170 OnChildExit(data.id, |
| 171 data.handle, |
| 172 static_cast<content::ProcessType>(data.process_type), |
| 173 base::TERMINATION_STATUS_ABNORMAL_TERMINATION, |
| 174 base::android::APPLICATION_STATE_UNKNOWN); |
| 132 } | 175 } |
| 133 | 176 |
| 134 void CrashDumpManager::Observe(int type, | 177 void CrashDumpManager::Observe(int type, |
| 135 const content::NotificationSource& source, | 178 const content::NotificationSource& source, |
| 136 const content::NotificationDetails& details) { | 179 const content::NotificationDetails& details) { |
| 137 switch (type) { | 180 switch (type) { |
| 138 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: | 181 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: { |
| 139 // NOTIFICATION_RENDERER_PROCESS_TERMINATED is sent when the renderer | 182 // NOTIFICATION_RENDERER_PROCESS_TERMINATED is sent when the renderer |
| 140 // process is cleanly shutdown. However, we need to fallthrough so that | 183 // process is cleanly shutdown. However, we still need to close the |
| 141 // we close the minidump_fd we kept open. | 184 // minidump_fd we kept open. |
| 185 content::RenderProcessHost* rph = |
| 186 content::Source<content::RenderProcessHost>(source).ptr(); |
| 187 OnChildExit(rph->GetID(), |
| 188 rph->GetHandle(), |
| 189 content::PROCESS_TYPE_RENDERER, |
| 190 base::TERMINATION_STATUS_NORMAL_TERMINATION, |
| 191 base::android::APPLICATION_STATE_UNKNOWN); |
| 192 break; |
| 193 } |
| 142 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { | 194 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { |
| 143 content::RenderProcessHost* rph = | 195 content::RenderProcessHost* rph = |
| 144 content::Source<content::RenderProcessHost>(source).ptr(); | 196 content::Source<content::RenderProcessHost>(source).ptr(); |
| 145 OnChildExit(rph->GetID(), rph->GetHandle()); | 197 content::RenderProcessHost::RendererClosedDetails* process_details = |
| 198 content::Details<content::RenderProcessHost::RendererClosedDetails>( |
| 199 details).ptr(); |
| 200 OnChildExit(rph->GetID(), |
| 201 rph->GetHandle(), |
| 202 content::PROCESS_TYPE_RENDERER, |
| 203 process_details->status, |
| 204 base::android::ApplicationStatusListener::GetState()); |
| 146 break; | 205 break; |
| 147 } | 206 } |
| 148 default: | 207 default: |
| 149 NOTREACHED(); | 208 NOTREACHED(); |
| 150 return; | 209 return; |
| 151 } | 210 } |
| 152 } | 211 } |
| 153 | 212 |
| 154 void CrashDumpManager::OnChildExit(int child_process_id, | 213 void CrashDumpManager::OnChildExit(int child_process_id, |
| 155 base::ProcessHandle pid) { | 214 base::ProcessHandle pid, |
| 215 content::ProcessType process_type, |
| 216 base::TerminationStatus exit_status, |
| 217 base::android::ApplicationState app_state) { |
| 156 base::FilePath minidump_path; | 218 base::FilePath minidump_path; |
| 157 { | 219 { |
| 158 base::AutoLock auto_lock(child_process_id_to_minidump_path_lock_); | 220 base::AutoLock auto_lock(child_process_id_to_minidump_path_lock_); |
| 159 ChildProcessIDToMinidumpPath::iterator iter = | 221 ChildProcessIDToMinidumpPath::iterator iter = |
| 160 child_process_id_to_minidump_path_.find(child_process_id); | 222 child_process_id_to_minidump_path_.find(child_process_id); |
| 161 if (iter == child_process_id_to_minidump_path_.end()) { | 223 if (iter == child_process_id_to_minidump_path_.end()) { |
| 162 // We might get a NOTIFICATION_RENDERER_PROCESS_TERMINATED and a | 224 // We might get a NOTIFICATION_RENDERER_PROCESS_TERMINATED and a |
| 163 // NOTIFICATION_RENDERER_PROCESS_CLOSED. | 225 // NOTIFICATION_RENDERER_PROCESS_CLOSED. |
| 164 return; | 226 return; |
| 165 } | 227 } |
| 166 minidump_path = iter->second; | 228 minidump_path = iter->second; |
| 167 child_process_id_to_minidump_path_.erase(iter); | 229 child_process_id_to_minidump_path_.erase(iter); |
| 168 } | 230 } |
| 169 BrowserThread::PostTask( | 231 BrowserThread::PostTask( |
| 170 BrowserThread::FILE, FROM_HERE, | 232 BrowserThread::FILE, FROM_HERE, |
| 171 base::Bind(&CrashDumpManager::ProcessMinidump, minidump_path, pid)); | 233 base::Bind(&CrashDumpManager::ProcessMinidump, |
| 234 minidump_path, |
| 235 pid, |
| 236 process_type, |
| 237 exit_status, |
| 238 app_state)); |
| 172 } | 239 } |
| 173 | 240 |
| 174 } // namespace breakpad | 241 } // namespace breakpad |
| OLD | NEW |