Chromium Code Reviews| 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/android/application_status_listener.h" | |
| 7 #include "base/bind.h" | 8 #include "base/bind.h" |
| 8 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 9 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/metrics/histogram_macros.h" | |
| 11 #include "base/posix/global_descriptors.h" | 13 #include "base/posix/global_descriptors.h" |
| 12 #include "base/process/process.h" | 14 #include "base/process/process.h" |
| 13 #include "base/rand_util.h" | 15 #include "base/rand_util.h" |
| 14 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
| 15 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 16 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/child_process_data.h" | 19 #include "content/public/browser/child_process_data.h" |
| 18 #include "content/public/browser/file_descriptor_info.h" | 20 #include "content/public/browser/file_descriptor_info.h" |
| 19 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
| 20 #include "content/public/browser/notification_types.h" | 22 #include "content/public/browser/notification_types.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 { | 77 { |
| 76 base::AutoLock auto_lock(child_process_id_to_minidump_path_lock_); | 78 base::AutoLock auto_lock(child_process_id_to_minidump_path_lock_); |
| 77 DCHECK(!ContainsKey(child_process_id_to_minidump_path_, child_process_id)); | 79 DCHECK(!ContainsKey(child_process_id_to_minidump_path_, child_process_id)); |
| 78 child_process_id_to_minidump_path_[child_process_id] = minidump_path; | 80 child_process_id_to_minidump_path_[child_process_id] = minidump_path; |
| 79 } | 81 } |
| 80 return minidump_file.Pass(); | 82 return minidump_file.Pass(); |
| 81 } | 83 } |
| 82 | 84 |
| 83 // static | 85 // static |
| 84 void CrashDumpManager::ProcessMinidump(const base::FilePath& minidump_path, | 86 void CrashDumpManager::ProcessMinidump(const base::FilePath& minidump_path, |
| 85 base::ProcessHandle pid) { | 87 base::ProcessHandle pid, |
| 88 bool recordExitStatus) { | |
| 86 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 89 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 87 CHECK(instance_); | 90 CHECK(instance_); |
| 88 int64 file_size = 0; | 91 int64 file_size = 0; |
| 89 int r = base::GetFileSize(minidump_path, &file_size); | 92 int r = base::GetFileSize(minidump_path, &file_size); |
| 90 DCHECK(r) << "Failed to retrieve size for minidump " | 93 DCHECK(r) << "Failed to retrieve size for minidump " |
| 91 << minidump_path.value(); | 94 << minidump_path.value(); |
| 92 | 95 |
| 96 if (recordExitStatus) { | |
|
no sievers
2015/11/17 22:28:53
nit: style here and elsewhere in C++ code - |recor
Peter Wen
2015/11/18 22:00:53
Done.
| |
| 97 int exitStatus = ExitStatus::COUNT; | |
|
no sievers
2015/11/17 22:28:53
nit: no need to init since it's if-else.
Peter Wen
2015/11/18 22:00:53
Done.
| |
| 98 if (file_size == 0) { | |
| 99 exitStatus = ExitStatus::EMPTY_MINIDUMP; | |
| 100 } else { | |
| 101 exitStatus = ExitStatus::VALID_MINIDUMP; | |
| 102 } | |
| 103 UMA_HISTOGRAM_ENUMERATION("Tab.RendererDetailedExitStatus", | |
|
no sievers
2015/11/17 22:28:53
nit: since this is also called for other process t
Peter Wen
2015/11/18 22:00:53
Done.
| |
| 104 exitStatus, | |
| 105 ExitStatus::COUNT); | |
| 106 } | |
| 107 | |
| 93 if (file_size == 0) { | 108 if (file_size == 0) { |
| 94 // Empty minidump, this process did not crash. Just remove the file. | 109 // Empty minidump, this process did not crash. Just remove the file. |
| 95 r = base::DeleteFile(minidump_path, false); | 110 r = base::DeleteFile(minidump_path, false); |
| 96 DCHECK(r) << "Failed to delete temporary minidump file " | 111 DCHECK(r) << "Failed to delete temporary minidump file " |
| 97 << minidump_path.value(); | 112 << minidump_path.value(); |
| 98 return; | 113 return; |
| 99 } | 114 } |
| 100 | 115 |
| 101 // We are dealing with a valid minidump. Copy it to the crash report | 116 // We are dealing with a valid minidump. Copy it to the crash report |
| 102 // directory from where Java code will upload it later on. | 117 // directory from where Java code will upload it later on. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 115 << " to " << dest_path.value(); | 130 << " to " << dest_path.value(); |
| 116 base::DeleteFile(minidump_path, false); | 131 base::DeleteFile(minidump_path, false); |
| 117 return; | 132 return; |
| 118 } | 133 } |
| 119 VLOG(1) << "Crash minidump successfully generated: " << | 134 VLOG(1) << "Crash minidump successfully generated: " << |
| 120 instance_->crash_dump_dir_.Append(filename).value(); | 135 instance_->crash_dump_dir_.Append(filename).value(); |
| 121 } | 136 } |
| 122 | 137 |
| 123 void CrashDumpManager::BrowserChildProcessHostDisconnected( | 138 void CrashDumpManager::BrowserChildProcessHostDisconnected( |
| 124 const content::ChildProcessData& data) { | 139 const content::ChildProcessData& data) { |
| 125 OnChildExit(data.id, data.handle); | 140 OnChildExit(data.id, data.handle, /* recordExitStatus */ false); |
| 126 } | 141 } |
| 127 | 142 |
| 128 void CrashDumpManager::BrowserChildProcessCrashed( | 143 void CrashDumpManager::BrowserChildProcessCrashed( |
| 129 const content::ChildProcessData& data, | 144 const content::ChildProcessData& data, |
| 130 int exit_code) { | 145 int exit_code) { |
| 131 OnChildExit(data.id, data.handle); | 146 OnChildExit(data.id, data.handle, /* recordExitStatus */ false); |
| 132 } | 147 } |
| 133 | 148 |
| 134 void CrashDumpManager::Observe(int type, | 149 void CrashDumpManager::Observe(int type, |
| 135 const content::NotificationSource& source, | 150 const content::NotificationSource& source, |
| 136 const content::NotificationDetails& details) { | 151 const content::NotificationDetails& details) { |
| 137 switch (type) { | 152 switch (type) { |
| 138 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: | 153 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: |
| 139 // NOTIFICATION_RENDERER_PROCESS_TERMINATED is sent when the renderer | 154 // NOTIFICATION_RENDERER_PROCESS_TERMINATED is sent when the renderer |
| 140 // process is cleanly shutdown. However, we need to fallthrough so that | 155 // process is cleanly shutdown. However, we need to fallthrough so that |
| 141 // we close the minidump_fd we kept open. | 156 // we close the minidump_fd we kept open. |
| 142 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { | 157 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { |
| 143 content::RenderProcessHost* rph = | 158 content::RenderProcessHost* rph = |
| 144 content::Source<content::RenderProcessHost>(source).ptr(); | 159 content::Source<content::RenderProcessHost>(source).ptr(); |
| 145 OnChildExit(rph->GetID(), rph->GetHandle()); | 160 content::RenderProcessHost::RendererClosedDetails* process_details = |
| 161 content::Details<content::RenderProcessHost::RendererClosedDetails>( | |
| 162 details).ptr(); | |
| 163 bool recordExitStatus = false; | |
| 164 // Only record OOM protected renderers that die while the app is in the | |
| 165 // foreground. This matches with conditions in TabWebContentsObserver. | |
| 166 if (process_details->status == base::TERMINATION_STATUS_OOM_PROTECTED && | |
| 167 base::android::ApplicationStatusListener::HasVisibleActivities()) { | |
| 168 recordExitStatus = true; | |
| 169 } | |
| 170 OnChildExit(rph->GetID(), rph->GetHandle(), recordExitStatus); | |
| 146 break; | 171 break; |
| 147 } | 172 } |
| 148 default: | 173 default: |
| 149 NOTREACHED(); | 174 NOTREACHED(); |
| 150 return; | 175 return; |
| 151 } | 176 } |
| 152 } | 177 } |
| 153 | 178 |
| 154 void CrashDumpManager::OnChildExit(int child_process_id, | 179 void CrashDumpManager::OnChildExit(int child_process_id, |
| 155 base::ProcessHandle pid) { | 180 base::ProcessHandle pid, |
| 181 bool recordExitStatus) { | |
| 156 base::FilePath minidump_path; | 182 base::FilePath minidump_path; |
| 157 { | 183 { |
| 158 base::AutoLock auto_lock(child_process_id_to_minidump_path_lock_); | 184 base::AutoLock auto_lock(child_process_id_to_minidump_path_lock_); |
| 159 ChildProcessIDToMinidumpPath::iterator iter = | 185 ChildProcessIDToMinidumpPath::iterator iter = |
| 160 child_process_id_to_minidump_path_.find(child_process_id); | 186 child_process_id_to_minidump_path_.find(child_process_id); |
| 161 if (iter == child_process_id_to_minidump_path_.end()) { | 187 if (iter == child_process_id_to_minidump_path_.end()) { |
| 162 // We might get a NOTIFICATION_RENDERER_PROCESS_TERMINATED and a | 188 // We might get a NOTIFICATION_RENDERER_PROCESS_TERMINATED and a |
| 163 // NOTIFICATION_RENDERER_PROCESS_CLOSED. | 189 // NOTIFICATION_RENDERER_PROCESS_CLOSED. |
| 164 return; | 190 return; |
| 165 } | 191 } |
| 166 minidump_path = iter->second; | 192 minidump_path = iter->second; |
| 167 child_process_id_to_minidump_path_.erase(iter); | 193 child_process_id_to_minidump_path_.erase(iter); |
| 168 } | 194 } |
| 169 BrowserThread::PostTask( | 195 BrowserThread::PostTask( |
| 170 BrowserThread::FILE, FROM_HERE, | 196 BrowserThread::FILE, FROM_HERE, |
| 171 base::Bind(&CrashDumpManager::ProcessMinidump, minidump_path, pid)); | 197 base::Bind(&CrashDumpManager::ProcessMinidump, |
| 198 minidump_path, | |
| 199 pid, | |
| 200 recordExitStatus)); | |
| 172 } | 201 } |
| 173 | 202 |
| 174 } // namespace breakpad | 203 } // namespace breakpad |
| OLD | NEW |