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 base::TerminationStatus exit_status, | |
90 int app_state) { | |
no sievers
2015/11/19 20:43:27
can you change int to |ApplicationState|? and then
Peter Wen
2015/11/19 21:01:25
Done.
| |
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 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 | |
93 if (file_size == 0) { | 127 if (file_size == 0) { |
94 // Empty minidump, this process did not crash. Just remove the file. | 128 // Empty minidump, this process did not crash. Just remove the file. |
95 r = base::DeleteFile(minidump_path, false); | 129 r = base::DeleteFile(minidump_path, false); |
96 DCHECK(r) << "Failed to delete temporary minidump file " | 130 DCHECK(r) << "Failed to delete temporary minidump file " |
97 << minidump_path.value(); | 131 << minidump_path.value(); |
98 return; | 132 return; |
99 } | 133 } |
100 | 134 |
101 // We are dealing with a valid minidump. Copy it to the crash report | 135 // We are dealing with a valid minidump. Copy it to the crash report |
102 // directory from where Java code will upload it later on. | 136 // directory from where Java code will upload it later on. |
(...skipping 12 matching lines...) Expand all Loading... | |
115 << " to " << dest_path.value(); | 149 << " to " << dest_path.value(); |
116 base::DeleteFile(minidump_path, false); | 150 base::DeleteFile(minidump_path, false); |
117 return; | 151 return; |
118 } | 152 } |
119 VLOG(1) << "Crash minidump successfully generated: " << | 153 VLOG(1) << "Crash minidump successfully generated: " << |
120 instance_->crash_dump_dir_.Append(filename).value(); | 154 instance_->crash_dump_dir_.Append(filename).value(); |
121 } | 155 } |
122 | 156 |
123 void CrashDumpManager::BrowserChildProcessHostDisconnected( | 157 void CrashDumpManager::BrowserChildProcessHostDisconnected( |
124 const content::ChildProcessData& data) { | 158 const content::ChildProcessData& data) { |
125 OnChildExit(data.id, data.handle); | 159 OnChildExit(data.id, |
160 data.handle, | |
161 static_cast<content::ProcessType>(data.process_type), | |
162 // Disconnects don't have a specific termination status. | |
163 /* exit_status */ base::TERMINATION_STATUS_MAX_ENUM, | |
164 /* app_state */ 0); | |
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 /* exit_status */ base::TERMINATION_STATUS_ABNORMAL_TERMINATION, | |
174 /* app_state */ 0); | |
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 need to fallthrough so that |
141 // we close the minidump_fd we kept open. | 184 // we close the minidump_fd we kept open. |
142 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { | 185 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { |
143 content::RenderProcessHost* rph = | 186 content::RenderProcessHost* rph = |
144 content::Source<content::RenderProcessHost>(source).ptr(); | 187 content::Source<content::RenderProcessHost>(source).ptr(); |
145 OnChildExit(rph->GetID(), rph->GetHandle()); | 188 content::RenderProcessHost::RendererClosedDetails* process_details = |
189 content::Details<content::RenderProcessHost::RendererClosedDetails>( | |
190 details).ptr(); | |
191 OnChildExit(rph->GetID(), | |
192 rph->GetHandle(), | |
193 content::PROCESS_TYPE_RENDERER, | |
194 process_details->status, | |
195 base::android::ApplicationStatusListener::GetState()); | |
no sievers
2015/11/19 20:43:27
why pass GetState() and not call it where you are
Peter Wen
2015/11/19 21:01:26
We want the application state as close to when the
| |
146 break; | 196 break; |
147 } | 197 } |
148 default: | 198 default: |
149 NOTREACHED(); | 199 NOTREACHED(); |
150 return; | 200 return; |
151 } | 201 } |
152 } | 202 } |
153 | 203 |
154 void CrashDumpManager::OnChildExit(int child_process_id, | 204 void CrashDumpManager::OnChildExit(int child_process_id, |
155 base::ProcessHandle pid) { | 205 base::ProcessHandle pid, |
206 content::ProcessType process_type, | |
207 base::TerminationStatus exit_status, | |
208 int app_state) { | |
156 base::FilePath minidump_path; | 209 base::FilePath minidump_path; |
157 { | 210 { |
158 base::AutoLock auto_lock(child_process_id_to_minidump_path_lock_); | 211 base::AutoLock auto_lock(child_process_id_to_minidump_path_lock_); |
159 ChildProcessIDToMinidumpPath::iterator iter = | 212 ChildProcessIDToMinidumpPath::iterator iter = |
160 child_process_id_to_minidump_path_.find(child_process_id); | 213 child_process_id_to_minidump_path_.find(child_process_id); |
161 if (iter == child_process_id_to_minidump_path_.end()) { | 214 if (iter == child_process_id_to_minidump_path_.end()) { |
162 // We might get a NOTIFICATION_RENDERER_PROCESS_TERMINATED and a | 215 // We might get a NOTIFICATION_RENDERER_PROCESS_TERMINATED and a |
163 // NOTIFICATION_RENDERER_PROCESS_CLOSED. | 216 // NOTIFICATION_RENDERER_PROCESS_CLOSED. |
164 return; | 217 return; |
165 } | 218 } |
166 minidump_path = iter->second; | 219 minidump_path = iter->second; |
167 child_process_id_to_minidump_path_.erase(iter); | 220 child_process_id_to_minidump_path_.erase(iter); |
168 } | 221 } |
169 BrowserThread::PostTask( | 222 BrowserThread::PostTask( |
170 BrowserThread::FILE, FROM_HERE, | 223 BrowserThread::FILE, FROM_HERE, |
171 base::Bind(&CrashDumpManager::ProcessMinidump, minidump_path, pid)); | 224 base::Bind(&CrashDumpManager::ProcessMinidump, |
225 minidump_path, | |
226 pid, | |
227 process_type, | |
228 exit_status, | |
229 app_state)); | |
172 } | 230 } |
173 | 231 |
174 } // namespace breakpad | 232 } // namespace breakpad |
OLD | NEW |