| 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/numerics/safe_conversions.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 process_(handle) { | 25 process_(handle) { |
| 26 CHECK_NE(handle, ::GetCurrentProcess()); | 26 CHECK_NE(handle, ::GetCurrentProcess()); |
| 27 } | 27 } |
| 28 | 28 |
| 29 Process::Process(RValue other) | 29 Process::Process(RValue other) |
| 30 : is_current_process_(other.object->is_current_process_), | 30 : is_current_process_(other.object->is_current_process_), |
| 31 process_(other.object->process_.Take()) { | 31 process_(other.object->process_.Take()) { |
| 32 other.object->Close(); | 32 other.object->Close(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 Process::~Process() { |
| 36 } |
| 37 |
| 35 Process& Process::operator=(RValue other) { | 38 Process& Process::operator=(RValue other) { |
| 36 if (this != other.object) { | 39 if (this != other.object) { |
| 37 process_.Set(other.object->process_.Take()); | 40 process_.Set(other.object->process_.Take()); |
| 38 is_current_process_ = other.object->is_current_process_; | 41 is_current_process_ = other.object->is_current_process_; |
| 39 other.object->Close(); | 42 other.object->Close(); |
| 40 } | 43 } |
| 41 return *this; | 44 return *this; |
| 42 } | 45 } |
| 43 | 46 |
| 44 // static | 47 // static |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 } | 119 } |
| 117 | 120 |
| 118 void Process::Close() { | 121 void Process::Close() { |
| 119 is_current_process_ = false; | 122 is_current_process_ = false; |
| 120 if (!process_.IsValid()) | 123 if (!process_.IsValid()) |
| 121 return; | 124 return; |
| 122 | 125 |
| 123 process_.Close(); | 126 process_.Close(); |
| 124 } | 127 } |
| 125 | 128 |
| 126 bool Process::Terminate(int result_code, bool wait) const { | 129 bool Process::Terminate(int exit_code, bool wait) const { |
| 127 DCHECK(IsValid()); | 130 DCHECK(IsValid()); |
| 128 // TODO(rvargas) crbug/417532: Move the implementation here. | 131 bool result = (::TerminateProcess(Handle(), exit_code) != FALSE); |
| 129 return KillProcess(Handle(), result_code, wait); | 132 if (result && wait) { |
| 133 // The process may not end immediately due to pending I/O |
| 134 if (::WaitForSingleObject(Handle(), 60 * 1000) != WAIT_OBJECT_0) |
| 135 DPLOG(ERROR) << "Error waiting for process exit"; |
| 136 } else if (!result) { |
| 137 DPLOG(ERROR) << "Unable to terminate process"; |
| 138 } |
| 139 return result; |
| 130 } | 140 } |
| 131 | 141 |
| 132 bool Process::WaitForExit(int* exit_code) { | 142 bool Process::WaitForExit(int* exit_code) { |
| 133 return WaitForExitWithTimeout(TimeDelta::FromMilliseconds(INFINITE), | 143 return WaitForExitWithTimeout(TimeDelta::FromMilliseconds(INFINITE), |
| 134 exit_code); | 144 exit_code); |
| 135 } | 145 } |
| 136 | 146 |
| 137 bool Process::WaitForExitWithTimeout(TimeDelta timeout, int* exit_code) { | 147 bool Process::WaitForExitWithTimeout(TimeDelta timeout, int* exit_code) { |
| 138 // Limit timeout to INFINITE. | 148 // Limit timeout to INFINITE. |
| 139 DWORD timeout_ms = saturated_cast<DWORD>(timeout.InMilliseconds()); | 149 DWORD timeout_ms = saturated_cast<DWORD>(timeout.InMilliseconds()); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 | 196 |
| 187 return (::SetPriorityClass(Handle(), priority) != 0); | 197 return (::SetPriorityClass(Handle(), priority) != 0); |
| 188 } | 198 } |
| 189 | 199 |
| 190 int Process::GetPriority() const { | 200 int Process::GetPriority() const { |
| 191 DCHECK(IsValid()); | 201 DCHECK(IsValid()); |
| 192 return ::GetPriorityClass(Handle()); | 202 return ::GetPriorityClass(Handle()); |
| 193 } | 203 } |
| 194 | 204 |
| 195 } // namespace base | 205 } // namespace base |
| OLD | NEW |