| 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 <sys/resource.h> | 7 #include <sys/resource.h> |
| 8 #include <sys/time.h> | 8 #include <sys/time.h> |
| 9 #include <sys/types.h> | 9 #include <sys/types.h> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/process/kill.h" | 12 #include "base/process/kill.h" |
| 13 | 13 |
| 14 namespace base { | 14 namespace base { |
| 15 | 15 |
| 16 Process::Process(ProcessHandle handle) : process_(handle) { | 16 Process::Process(ProcessHandle handle) : process_(handle) { |
| 17 CHECK_NE(handle, GetCurrentProcessHandle()); | |
| 18 } | 17 } |
| 19 | 18 |
| 20 Process::Process(RValue other) | 19 Process::Process(RValue other) |
| 21 : process_(other.object->process_) { | 20 : process_(other.object->process_) { |
| 22 other.object->Close(); | 21 other.object->Close(); |
| 23 } | 22 } |
| 24 | 23 |
| 25 Process& Process::operator=(RValue other) { | 24 Process& Process::operator=(RValue other) { |
| 26 if (this != other.object) { | 25 if (this != other.object) { |
| 27 process_ = other.object->process_; | 26 process_ = other.object->process_; |
| 28 other.object->Close(); | 27 other.object->Close(); |
| 29 } | 28 } |
| 30 return *this; | 29 return *this; |
| 31 } | 30 } |
| 32 | 31 |
| 33 // static | 32 // static |
| 34 Process Process::Current() { | 33 Process Process::Current() { |
| 35 Process process; | 34 return Process(GetCurrentProcessHandle()); |
| 36 process.process_ = GetCurrentProcessHandle(); | |
| 37 return process.Pass(); | |
| 38 } | 35 } |
| 39 | 36 |
| 40 // static | 37 // static |
| 41 Process Process::OpenWithExtraPriviles(ProcessId pid) { | 38 Process Process::OpenWithExtraPriviles(ProcessId pid) { |
| 42 if (pid == GetCurrentProcId()) | 39 if (pid == GetCurrentProcId()) |
| 43 return Current(); | 40 return Current(); |
| 44 | 41 |
| 45 // On POSIX process handles are the same as PIDs, and there are no privileges | 42 // On POSIX process handles are the same as PIDs, and there are no privileges |
| 46 // to set. | 43 // to set. |
| 47 return Process(pid); | 44 return Process(pid); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 return false; | 123 return false; |
| 127 } | 124 } |
| 128 #endif // !defined(OS_LINUX) | 125 #endif // !defined(OS_LINUX) |
| 129 | 126 |
| 130 int Process::GetPriority() const { | 127 int Process::GetPriority() const { |
| 131 DCHECK(IsValid()); | 128 DCHECK(IsValid()); |
| 132 return getpriority(PRIO_PROCESS, process_); | 129 return getpriority(PRIO_PROCESS, process_); |
| 133 } | 130 } |
| 134 | 131 |
| 135 } // namspace base | 132 } // namspace base |
| OLD | NEW |