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/process/kill.h" | 9 #include "base/process/kill.h" |
10 #include "base/win/windows_version.h" | 10 #include "base/win/windows_version.h" |
11 | 11 |
| 12 namespace { |
| 13 |
| 14 DWORD kBasicProcessAccess = |
| 15 PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION | SYNCHRONIZE; |
| 16 |
| 17 } // namespace |
| 18 |
12 namespace base { | 19 namespace base { |
13 | 20 |
14 Process::Process(ProcessHandle handle) | 21 Process::Process(ProcessHandle handle) |
15 : is_current_process_(false), | 22 : is_current_process_(false), |
16 process_(handle) { | 23 process_(handle) { |
17 CHECK_NE(handle, ::GetCurrentProcess()); | 24 CHECK_NE(handle, ::GetCurrentProcess()); |
18 } | 25 } |
19 | 26 |
20 Process::Process(RValue other) | 27 Process::Process(RValue other) |
21 : is_current_process_(other.object->is_current_process_), | 28 : is_current_process_(other.object->is_current_process_), |
(...skipping 11 matching lines...) Expand all Loading... |
33 } | 40 } |
34 | 41 |
35 // static | 42 // static |
36 Process Process::Current() { | 43 Process Process::Current() { |
37 Process process; | 44 Process process; |
38 process.is_current_process_ = true; | 45 process.is_current_process_ = true; |
39 return process.Pass(); | 46 return process.Pass(); |
40 } | 47 } |
41 | 48 |
42 // static | 49 // static |
| 50 Process Process::OpenWithExtraPriviles(ProcessId pid) { |
| 51 DWORD access = kBasicProcessAccess | PROCESS_DUP_HANDLE | PROCESS_VM_READ; |
| 52 ProcessHandle handle = ::OpenProcess(access, FALSE, pid); |
| 53 return Process(handle); |
| 54 } |
| 55 |
| 56 // static |
43 Process Process::DeprecatedGetProcessFromHandle(ProcessHandle handle) { | 57 Process Process::DeprecatedGetProcessFromHandle(ProcessHandle handle) { |
44 DCHECK_NE(handle, ::GetCurrentProcess()); | 58 DCHECK_NE(handle, ::GetCurrentProcess()); |
45 ProcessHandle out_handle; | 59 ProcessHandle out_handle; |
46 if (!::DuplicateHandle(GetCurrentProcess(), handle, | 60 if (!::DuplicateHandle(GetCurrentProcess(), handle, |
47 GetCurrentProcess(), &out_handle, | 61 GetCurrentProcess(), &out_handle, |
48 0, FALSE, DUPLICATE_SAME_ACCESS)) { | 62 0, FALSE, DUPLICATE_SAME_ACCESS)) { |
49 return Process(); | 63 return Process(); |
50 } | 64 } |
51 return Process(out_handle); | 65 return Process(out_handle); |
52 } | 66 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 | 161 |
148 return (::SetPriorityClass(Handle(), priority) != 0); | 162 return (::SetPriorityClass(Handle(), priority) != 0); |
149 } | 163 } |
150 | 164 |
151 int Process::GetPriority() const { | 165 int Process::GetPriority() const { |
152 DCHECK(IsValid()); | 166 DCHECK(IsValid()); |
153 return ::GetPriorityClass(Handle()); | 167 return ::GetPriorityClass(Handle()); |
154 } | 168 } |
155 | 169 |
156 } // namespace base | 170 } // namespace base |
OLD | NEW |