OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/process/process.h" | 5 #include "base/process/process.h" |
6 | 6 |
7 #include "base/debug/activity_tracker.h" | 7 #include "base/debug/activity_tracker.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/numerics/safe_conversions.h" | 9 #include "base/numerics/safe_conversions.h" |
10 #include "base/process/kill.h" | 10 #include "base/process/kill.h" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 bool Process::Terminate(int exit_code, bool wait) const { | 132 bool Process::Terminate(int exit_code, bool wait) const { |
133 DCHECK(IsValid()); | 133 DCHECK(IsValid()); |
134 bool result = (::TerminateProcess(Handle(), exit_code) != FALSE); | 134 bool result = (::TerminateProcess(Handle(), exit_code) != FALSE); |
135 if (result && wait) { | 135 if (result && wait) { |
136 // The process may not end immediately due to pending I/O | 136 // The process may not end immediately due to pending I/O |
137 if (::WaitForSingleObject(Handle(), 60 * 1000) != WAIT_OBJECT_0) | 137 if (::WaitForSingleObject(Handle(), 60 * 1000) != WAIT_OBJECT_0) |
138 DPLOG(ERROR) << "Error waiting for process exit"; | 138 DPLOG(ERROR) << "Error waiting for process exit"; |
139 } else if (!result) { | 139 } else if (!result) { |
140 DPLOG(ERROR) << "Unable to terminate process"; | 140 DPLOG(ERROR) << "Unable to terminate process"; |
141 } | 141 } |
| 142 if (result) { |
| 143 base::debug::GlobalActivityTracker::RecordProcessExitIfEnabled(Pid(), |
| 144 exit_code); |
| 145 } |
142 return result; | 146 return result; |
143 } | 147 } |
144 | 148 |
145 bool Process::WaitForExit(int* exit_code) const { | 149 bool Process::WaitForExit(int* exit_code) const { |
146 return WaitForExitWithTimeout(TimeDelta::FromMilliseconds(INFINITE), | 150 return WaitForExitWithTimeout(TimeDelta::FromMilliseconds(INFINITE), |
147 exit_code); | 151 exit_code); |
148 } | 152 } |
149 | 153 |
150 bool Process::WaitForExitWithTimeout(TimeDelta timeout, int* exit_code) const { | 154 bool Process::WaitForExitWithTimeout(TimeDelta timeout, int* exit_code) const { |
151 // Record the event that this thread is blocking upon (for hang diagnosis). | 155 // Record the event that this thread is blocking upon (for hang diagnosis). |
152 base::debug::ScopedProcessWaitActivity process_activity(this); | 156 base::debug::ScopedProcessWaitActivity process_activity(this); |
153 | 157 |
154 // Limit timeout to INFINITE. | 158 // Limit timeout to INFINITE. |
155 DWORD timeout_ms = saturated_cast<DWORD>(timeout.InMilliseconds()); | 159 DWORD timeout_ms = saturated_cast<DWORD>(timeout.InMilliseconds()); |
156 if (::WaitForSingleObject(Handle(), timeout_ms) != WAIT_OBJECT_0) | 160 if (::WaitForSingleObject(Handle(), timeout_ms) != WAIT_OBJECT_0) |
157 return false; | 161 return false; |
158 | 162 |
159 DWORD temp_code; // Don't clobber out-parameters in case of failure. | 163 DWORD temp_code; // Don't clobber out-parameters in case of failure. |
160 if (!::GetExitCodeProcess(Handle(), &temp_code)) | 164 if (!::GetExitCodeProcess(Handle(), &temp_code)) |
161 return false; | 165 return false; |
162 | 166 |
163 if (exit_code) | 167 if (exit_code) |
164 *exit_code = temp_code; | 168 *exit_code = temp_code; |
| 169 |
| 170 base::debug::GlobalActivityTracker::RecordProcessExitIfEnabled( |
| 171 Pid(), static_cast<int>(temp_code)); |
165 return true; | 172 return true; |
166 } | 173 } |
167 | 174 |
168 bool Process::IsProcessBackgrounded() const { | 175 bool Process::IsProcessBackgrounded() const { |
169 DCHECK(IsValid()); | 176 DCHECK(IsValid()); |
170 DWORD priority = GetPriority(); | 177 DWORD priority = GetPriority(); |
171 if (priority == 0) | 178 if (priority == 0) |
172 return false; // Failure case. | 179 return false; // Failure case. |
173 return ((priority == BELOW_NORMAL_PRIORITY_CLASS) || | 180 return ((priority == BELOW_NORMAL_PRIORITY_CLASS) || |
174 (priority == IDLE_PRIORITY_CLASS)); | 181 (priority == IDLE_PRIORITY_CLASS)); |
(...skipping 14 matching lines...) Expand all Loading... |
189 | 196 |
190 return (::SetPriorityClass(Handle(), priority) != 0); | 197 return (::SetPriorityClass(Handle(), priority) != 0); |
191 } | 198 } |
192 | 199 |
193 int Process::GetPriority() const { | 200 int Process::GetPriority() const { |
194 DCHECK(IsValid()); | 201 DCHECK(IsValid()); |
195 return ::GetPriorityClass(Handle()); | 202 return ::GetPriorityClass(Handle()); |
196 } | 203 } |
197 | 204 |
198 } // namespace base | 205 } // namespace base |
OLD | NEW |