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