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 content::ProcessType process_type, | |
89 bool record_exit_status) { | |
86 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 90 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
87 CHECK(instance_); | 91 CHECK(instance_); |
88 int64 file_size = 0; | 92 int64 file_size = 0; |
89 int r = base::GetFileSize(minidump_path, &file_size); | 93 int r = base::GetFileSize(minidump_path, &file_size); |
90 DCHECK(r) << "Failed to retrieve size for minidump " | 94 DCHECK(r) << "Failed to retrieve size for minidump " |
91 << minidump_path.value(); | 95 << minidump_path.value(); |
92 | 96 |
97 if (record_exit_status) { | |
98 DCHECK(process_type == content::PROCESS_TYPE_RENDERER); | |
Yaron
2015/11/19 18:57:05
DCHECK_EQ
Peter Wen
2015/11/19 19:48:15
Acknowledged.
| |
99 int exitStatus; | |
Yaron
2015/11/19 18:57:05
exit_status
Peter Wen
2015/11/19 19:48:15
Done.
| |
100 if (file_size == 0) { | |
101 exitStatus = ExitStatus::EMPTY_MINIDUMP; | |
102 } else { | |
103 exitStatus = ExitStatus::VALID_MINIDUMP; | |
104 } | |
105 UMA_HISTOGRAM_ENUMERATION("Tab.RendererDetailedExitStatus", | |
106 exitStatus, | |
107 ExitStatus::COUNT); | |
108 } | |
109 | |
93 if (file_size == 0) { | 110 if (file_size == 0) { |
94 // Empty minidump, this process did not crash. Just remove the file. | 111 // Empty minidump, this process did not crash. Just remove the file. |
95 r = base::DeleteFile(minidump_path, false); | 112 r = base::DeleteFile(minidump_path, false); |
96 DCHECK(r) << "Failed to delete temporary minidump file " | 113 DCHECK(r) << "Failed to delete temporary minidump file " |
97 << minidump_path.value(); | 114 << minidump_path.value(); |
98 return; | 115 return; |
99 } | 116 } |
100 | 117 |
101 // We are dealing with a valid minidump. Copy it to the crash report | 118 // We are dealing with a valid minidump. Copy it to the crash report |
102 // directory from where Java code will upload it later on. | 119 // directory from where Java code will upload it later on. |
(...skipping 12 matching lines...) Expand all Loading... | |
115 << " to " << dest_path.value(); | 132 << " to " << dest_path.value(); |
116 base::DeleteFile(minidump_path, false); | 133 base::DeleteFile(minidump_path, false); |
117 return; | 134 return; |
118 } | 135 } |
119 VLOG(1) << "Crash minidump successfully generated: " << | 136 VLOG(1) << "Crash minidump successfully generated: " << |
120 instance_->crash_dump_dir_.Append(filename).value(); | 137 instance_->crash_dump_dir_.Append(filename).value(); |
121 } | 138 } |
122 | 139 |
123 void CrashDumpManager::BrowserChildProcessHostDisconnected( | 140 void CrashDumpManager::BrowserChildProcessHostDisconnected( |
124 const content::ChildProcessData& data) { | 141 const content::ChildProcessData& data) { |
125 OnChildExit(data.id, data.handle); | 142 OnChildExit(data.id, |
143 data.handle, | |
144 static_cast<content::ProcessType>(data.process_type), | |
145 /* record_exit_status */ false); | |
126 } | 146 } |
127 | 147 |
128 void CrashDumpManager::BrowserChildProcessCrashed( | 148 void CrashDumpManager::BrowserChildProcessCrashed( |
129 const content::ChildProcessData& data, | 149 const content::ChildProcessData& data, |
130 int exit_code) { | 150 int exit_code) { |
131 OnChildExit(data.id, data.handle); | 151 OnChildExit(data.id, |
152 data.handle, | |
153 static_cast<content::ProcessType>(data.process_type), | |
154 /* record_exit_status */ false); | |
132 } | 155 } |
133 | 156 |
134 void CrashDumpManager::Observe(int type, | 157 void CrashDumpManager::Observe(int type, |
135 const content::NotificationSource& source, | 158 const content::NotificationSource& source, |
136 const content::NotificationDetails& details) { | 159 const content::NotificationDetails& details) { |
137 switch (type) { | 160 switch (type) { |
138 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: | 161 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: |
139 // NOTIFICATION_RENDERER_PROCESS_TERMINATED is sent when the renderer | 162 // NOTIFICATION_RENDERER_PROCESS_TERMINATED is sent when the renderer |
140 // process is cleanly shutdown. However, we need to fallthrough so that | 163 // process is cleanly shutdown. However, we need to fallthrough so that |
141 // we close the minidump_fd we kept open. | 164 // we close the minidump_fd we kept open. |
142 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { | 165 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { |
143 content::RenderProcessHost* rph = | 166 content::RenderProcessHost* rph = |
144 content::Source<content::RenderProcessHost>(source).ptr(); | 167 content::Source<content::RenderProcessHost>(source).ptr(); |
145 OnChildExit(rph->GetID(), rph->GetHandle()); | 168 content::RenderProcessHost::RendererClosedDetails* process_details = |
169 content::Details<content::RenderProcessHost::RendererClosedDetails>( | |
170 details).ptr(); | |
171 bool record_exit_status = false; | |
172 // Only record OOM protected renderers that die while the app is in the | |
173 // foreground. This matches with conditions in TabWebContentsObserver. | |
174 if (process_details->status == base::TERMINATION_STATUS_OOM_PROTECTED && | |
175 base::android::ApplicationStatusListener::HasVisibleActivities()) { | |
176 record_exit_status = true; | |
177 } | |
178 OnChildExit(rph->GetID(), | |
179 rph->GetHandle(), | |
180 content::PROCESS_TYPE_RENDERER, | |
181 record_exit_status); | |
146 break; | 182 break; |
147 } | 183 } |
148 default: | 184 default: |
149 NOTREACHED(); | 185 NOTREACHED(); |
150 return; | 186 return; |
151 } | 187 } |
152 } | 188 } |
153 | 189 |
154 void CrashDumpManager::OnChildExit(int child_process_id, | 190 void CrashDumpManager::OnChildExit(int child_process_id, |
155 base::ProcessHandle pid) { | 191 base::ProcessHandle pid, |
192 content::ProcessType process_type, | |
193 bool record_exit_status) { | |
156 base::FilePath minidump_path; | 194 base::FilePath minidump_path; |
157 { | 195 { |
158 base::AutoLock auto_lock(child_process_id_to_minidump_path_lock_); | 196 base::AutoLock auto_lock(child_process_id_to_minidump_path_lock_); |
159 ChildProcessIDToMinidumpPath::iterator iter = | 197 ChildProcessIDToMinidumpPath::iterator iter = |
160 child_process_id_to_minidump_path_.find(child_process_id); | 198 child_process_id_to_minidump_path_.find(child_process_id); |
161 if (iter == child_process_id_to_minidump_path_.end()) { | 199 if (iter == child_process_id_to_minidump_path_.end()) { |
162 // We might get a NOTIFICATION_RENDERER_PROCESS_TERMINATED and a | 200 // We might get a NOTIFICATION_RENDERER_PROCESS_TERMINATED and a |
163 // NOTIFICATION_RENDERER_PROCESS_CLOSED. | 201 // NOTIFICATION_RENDERER_PROCESS_CLOSED. |
164 return; | 202 return; |
165 } | 203 } |
166 minidump_path = iter->second; | 204 minidump_path = iter->second; |
167 child_process_id_to_minidump_path_.erase(iter); | 205 child_process_id_to_minidump_path_.erase(iter); |
168 } | 206 } |
169 BrowserThread::PostTask( | 207 BrowserThread::PostTask( |
170 BrowserThread::FILE, FROM_HERE, | 208 BrowserThread::FILE, FROM_HERE, |
171 base::Bind(&CrashDumpManager::ProcessMinidump, minidump_path, pid)); | 209 base::Bind(&CrashDumpManager::ProcessMinidump, |
210 minidump_path, | |
211 pid, | |
212 process_type, | |
213 record_exit_status)); | |
172 } | 214 } |
173 | 215 |
174 } // namespace breakpad | 216 } // namespace breakpad |
OLD | NEW |