Index: base/process/process_posix.cc |
diff --git a/base/process/process_posix.cc b/base/process/process_posix.cc |
index 3d8b31d0352e6c027a2d132255654ff3d8692e13..ea8fd8cea1e7d95e2c283fe72099dc0fd36ce8af 100644 |
--- a/base/process/process_posix.cc |
+++ b/base/process/process_posix.cc |
@@ -13,15 +13,54 @@ |
namespace base { |
+Process::Process(ProcessHandle handle) : process_(handle) { |
+ CHECK_NE(handle, GetCurrentProcessHandle()); |
+} |
+ |
+Process::Process(RValue other) |
+ : process_(other.object->process_) { |
+ other.object->Close(); |
+} |
+ |
+Process& Process::operator=(RValue other) { |
+ if (this != other.object) { |
+ process_ = other.object->process_; |
+ other.object->Close(); |
+ } |
+ return *this; |
+} |
+ |
// static |
Process Process::Current() { |
- return Process(GetCurrentProcessHandle()); |
+ Process process; |
+ process.process_ = GetCurrentProcessHandle(); |
+ return process.Pass(); |
} |
-ProcessId Process::pid() const { |
- if (process_ == 0) |
- return 0; |
+#if !defined(OS_LINUX) |
+// static |
+bool Process::CanBackgroundProcesses() { |
+ return false; |
+} |
+#endif // !defined(OS_LINUX) |
+ |
+bool Process::IsValid() const { |
+ return process_ != kNullProcessHandle; |
+} |
+ |
+ProcessHandle Process::Handle() const { |
+ return process_; |
+} |
+ |
+Process Process::Duplicate() const { |
+ if (is_current()) |
+ return Current(); |
+ return Process(process_); |
+} |
+ |
+ProcessId Process::pid() const { |
+ DCHECK(IsValid()); |
return GetProcId(process_); |
} |
@@ -30,7 +69,7 @@ bool Process::is_current() const { |
} |
void Process::Close() { |
- process_ = 0; |
+ process_ = kNullProcessHandle; |
// if the process wasn't terminated (so we waited) or the state |
// wasn't already collected w/ a wait from process_utils, we're gonna |
// end up w/ a zombie when it does finally exit. |
@@ -38,8 +77,7 @@ void Process::Close() { |
void Process::Terminate(int result_code) { |
// result_code isn't supportable. |
- if (!process_) |
- return; |
+ DCHECK(IsValid()); |
// We don't wait here. It's the responsibility of other code to reap the |
// child. |
KillProcess(process_, result_code, false); |
@@ -48,6 +86,7 @@ void Process::Terminate(int result_code) { |
#if !defined(OS_LINUX) |
bool Process::IsProcessBackgrounded() const { |
// See SetProcessBackgrounded(). |
+ DCHECK(IsValid()); |
return false; |
} |
@@ -55,18 +94,13 @@ bool Process::SetProcessBackgrounded(bool value) { |
// POSIX only allows lowering the priority of a process, so if we |
// were to lower it we wouldn't be able to raise it back to its initial |
// priority. |
+ DCHECK(IsValid()); |
return false; |
} |
- |
-// static |
-bool Process::CanBackgroundProcesses() { |
- return false; |
-} |
- |
-#endif |
+#endif // !defined(OS_LINUX) |
int Process::GetPriority() const { |
- DCHECK(process_); |
+ DCHECK(IsValid()); |
return getpriority(PRIO_PROCESS, process_); |
} |