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) { |
| 97 int exitStatus = ExitStatus::COUNT; |
| 98 if (file_size == 0) { |
| 99 exitStatus = ExitStatus::EMPTY_MINIDUMP; |
| 100 } else { |
| 101 exitStatus = ExitStatus::VALID_MINIDUMP; |
| 102 } |
| 103 UMA_HISTOGRAM_ENUMERATION("Tab.RendererDetailedExitStatus", |
| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 if (process_details->status == base::TERMINATION_STATUS_OOM_PROTECTED && |
| 164 base::android::ApplicationStatusListener::HasRunningActivities()) { |
| 165 OnChildExit(rph->GetID(), |
| 166 rph->GetHandle(), |
| 167 /* recordExitStatus */ true); |
| 168 } else { |
| 169 OnChildExit(rph->GetID(), rph->GetHandle()); |
| 170 } |
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 OnChildExit(child_process_id, pid, /* recordExitStatus */ false); |
| 182 } |
| 183 |
| 184 void CrashDumpManager::OnChildExit(int child_process_id, |
| 185 base::ProcessHandle pid, |
| 186 bool recordExitStatus) { |
156 base::FilePath minidump_path; | 187 base::FilePath minidump_path; |
157 { | 188 { |
158 base::AutoLock auto_lock(child_process_id_to_minidump_path_lock_); | 189 base::AutoLock auto_lock(child_process_id_to_minidump_path_lock_); |
159 ChildProcessIDToMinidumpPath::iterator iter = | 190 ChildProcessIDToMinidumpPath::iterator iter = |
160 child_process_id_to_minidump_path_.find(child_process_id); | 191 child_process_id_to_minidump_path_.find(child_process_id); |
161 if (iter == child_process_id_to_minidump_path_.end()) { | 192 if (iter == child_process_id_to_minidump_path_.end()) { |
162 // We might get a NOTIFICATION_RENDERER_PROCESS_TERMINATED and a | 193 // We might get a NOTIFICATION_RENDERER_PROCESS_TERMINATED and a |
163 // NOTIFICATION_RENDERER_PROCESS_CLOSED. | 194 // NOTIFICATION_RENDERER_PROCESS_CLOSED. |
164 return; | 195 return; |
165 } | 196 } |
166 minidump_path = iter->second; | 197 minidump_path = iter->second; |
167 child_process_id_to_minidump_path_.erase(iter); | 198 child_process_id_to_minidump_path_.erase(iter); |
168 } | 199 } |
169 BrowserThread::PostTask( | 200 BrowserThread::PostTask( |
170 BrowserThread::FILE, FROM_HERE, | 201 BrowserThread::FILE, FROM_HERE, |
171 base::Bind(&CrashDumpManager::ProcessMinidump, minidump_path, pid)); | 202 base::Bind(&CrashDumpManager::ProcessMinidump, |
| 203 minidump_path, |
| 204 pid, |
| 205 recordExitStatus)); |
172 } | 206 } |
173 | 207 |
174 } // namespace breakpad | 208 } // namespace breakpad |
OLD | NEW |