| 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/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/numerics/safe_conversions.h" |
| 10 #include "base/process/kill.h" | 11 #include "base/process/kill.h" |
| 11 #include "base/win/windows_version.h" | 12 #include "base/win/windows_version.h" |
| 12 | 13 |
| 13 namespace { | 14 namespace { |
| 14 | 15 |
| 15 DWORD kBasicProcessAccess = | 16 DWORD kBasicProcessAccess = |
| 16 PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION | SYNCHRONIZE; | 17 PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION | SYNCHRONIZE; |
| 17 | 18 |
| 18 } // namespace | 19 } // namespace |
| 19 | 20 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 GetProcAddress(module, "NtTerminateProcess")); | 135 GetProcAddress(module, "NtTerminateProcess")); |
| 135 terminate_process(Handle(), result_code); | 136 terminate_process(Handle(), result_code); |
| 136 } | 137 } |
| 137 | 138 |
| 138 bool Process::WaitForExit(int* exit_code) { | 139 bool Process::WaitForExit(int* exit_code) { |
| 139 return WaitForExitWithTimeout(TimeDelta::FromMilliseconds(INFINITE), | 140 return WaitForExitWithTimeout(TimeDelta::FromMilliseconds(INFINITE), |
| 140 exit_code); | 141 exit_code); |
| 141 } | 142 } |
| 142 | 143 |
| 143 bool Process::WaitForExitWithTimeout(TimeDelta timeout, int* exit_code) { | 144 bool Process::WaitForExitWithTimeout(TimeDelta timeout, int* exit_code) { |
| 144 // TODO(rvargas) crbug.com/417532: Move the implementation here. | 145 // Limit timeout to INFINITE. |
| 145 if (timeout > TimeDelta::FromMilliseconds(INFINITE)) | 146 DWORD timeout_ms = saturated_cast<DWORD>(timeout.InMilliseconds()); |
| 146 timeout = TimeDelta::FromMilliseconds(INFINITE); | 147 if (::WaitForSingleObject(Handle(), timeout_ms) != WAIT_OBJECT_0) |
| 147 return base::WaitForExitCodeWithTimeout(Handle(), exit_code, timeout); | 148 return false; |
| 149 |
| 150 DWORD temp_code; // Don't clobber out-parameters in case of failure. |
| 151 if (!::GetExitCodeProcess(Handle(), &temp_code)) |
| 152 return false; |
| 153 |
| 154 *exit_code = temp_code; |
| 155 return true; |
| 148 } | 156 } |
| 149 | 157 |
| 150 bool Process::IsProcessBackgrounded() const { | 158 bool Process::IsProcessBackgrounded() const { |
| 151 DCHECK(IsValid()); | 159 DCHECK(IsValid()); |
| 152 DWORD priority = GetPriority(); | 160 DWORD priority = GetPriority(); |
| 153 if (priority == 0) | 161 if (priority == 0) |
| 154 return false; // Failure case. | 162 return false; // Failure case. |
| 155 return ((priority == BELOW_NORMAL_PRIORITY_CLASS) || | 163 return ((priority == BELOW_NORMAL_PRIORITY_CLASS) || |
| 156 (priority == IDLE_PRIORITY_CLASS)); | 164 (priority == IDLE_PRIORITY_CLASS)); |
| 157 } | 165 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 185 | 193 |
| 186 return (::SetPriorityClass(Handle(), priority) != 0); | 194 return (::SetPriorityClass(Handle(), priority) != 0); |
| 187 } | 195 } |
| 188 | 196 |
| 189 int Process::GetPriority() const { | 197 int Process::GetPriority() const { |
| 190 DCHECK(IsValid()); | 198 DCHECK(IsValid()); |
| 191 return ::GetPriorityClass(Handle()); | 199 return ::GetPriorityClass(Handle()); |
| 192 } | 200 } |
| 193 | 201 |
| 194 } // namespace base | 202 } // namespace base |
| OLD | NEW |