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(); | 35 } |
37 return process.Pass(); | 36 |
| 37 // static |
| 38 Process Process::Open(ProcessId pid) { |
| 39 if (pid == GetCurrentProcId()) |
| 40 return Current(); |
| 41 |
| 42 // On POSIX process handles are the same as PIDs. |
| 43 return Process(pid); |
38 } | 44 } |
39 | 45 |
40 // static | 46 // static |
41 Process Process::OpenWithExtraPriviles(ProcessId pid) { | 47 Process Process::OpenWithExtraPriviles(ProcessId pid) { |
42 if (pid == GetCurrentProcId()) | 48 // On POSIX there are no privileges to set. |
43 return Current(); | 49 return Open(pid); |
44 | |
45 // On POSIX process handles are the same as PIDs, and there are no privileges | |
46 // to set. | |
47 return Process(pid); | |
48 } | 50 } |
49 | 51 |
50 // static | 52 // static |
51 Process Process::DeprecatedGetProcessFromHandle(ProcessHandle handle) { | 53 Process Process::DeprecatedGetProcessFromHandle(ProcessHandle handle) { |
52 DCHECK_NE(handle, GetCurrentProcessHandle()); | 54 DCHECK_NE(handle, GetCurrentProcessHandle()); |
53 return Process(handle); | 55 return Process(handle); |
54 } | 56 } |
55 | 57 |
56 #if !defined(OS_LINUX) | 58 #if !defined(OS_LINUX) |
57 // static | 59 // static |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 return false; | 128 return false; |
127 } | 129 } |
128 #endif // !defined(OS_LINUX) | 130 #endif // !defined(OS_LINUX) |
129 | 131 |
130 int Process::GetPriority() const { | 132 int Process::GetPriority() const { |
131 DCHECK(IsValid()); | 133 DCHECK(IsValid()); |
132 return getpriority(PRIO_PROCESS, process_); | 134 return getpriority(PRIO_PROCESS, process_); |
133 } | 135 } |
134 | 136 |
135 } // namspace base | 137 } // namspace base |
OLD | NEW |