OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #ifndef BASE_PROCESS_PROCESS_H_ | 5 #ifndef BASE_PROCESS_PROCESS_H_ |
6 #define BASE_PROCESS_PROCESS_H_ | 6 #define BASE_PROCESS_PROCESS_H_ |
7 | 7 |
8 #include "base/base_export.h" | 8 #include "base/base_export.h" |
9 #include "base/move.h" | 9 #include "base/macros.h" |
10 #include "base/process/process_handle.h" | 10 #include "base/process/process_handle.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 | 13 |
14 #if defined(OS_WIN) | 14 #if defined(OS_WIN) |
15 #include "base/win/scoped_handle.h" | 15 #include "base/win/scoped_handle.h" |
16 #endif | 16 #endif |
17 | 17 |
18 namespace base { | 18 namespace base { |
19 | 19 |
20 // Provides a move-only encapsulation of a process. | 20 // Provides a move-only encapsulation of a process. |
21 // | 21 // |
22 // This object is not tied to the lifetime of the underlying process: the | 22 // This object is not tied to the lifetime of the underlying process: the |
23 // process may be killed and this object may still around, and it will still | 23 // process may be killed and this object may still around, and it will still |
24 // claim to be valid. The actual behavior in that case is OS dependent like so: | 24 // claim to be valid. The actual behavior in that case is OS dependent like so: |
25 // | 25 // |
26 // Windows: The underlying ProcessHandle will be valid after the process dies | 26 // Windows: The underlying ProcessHandle will be valid after the process dies |
27 // and can be used to gather some information about that process, but most | 27 // and can be used to gather some information about that process, but most |
28 // methods will obviously fail. | 28 // methods will obviously fail. |
29 // | 29 // |
30 // POSIX: The underlying PorcessHandle is not guaranteed to remain valid after | 30 // POSIX: The underlying PorcessHandle is not guaranteed to remain valid after |
31 // the process dies, and it may be reused by the system, which means that it may | 31 // the process dies, and it may be reused by the system, which means that it may |
32 // end up pointing to the wrong process. | 32 // end up pointing to the wrong process. |
33 class BASE_EXPORT Process { | 33 class BASE_EXPORT Process { |
34 MOVE_ONLY_TYPE_FOR_CPP_03(Process) | |
35 | |
36 public: | 34 public: |
37 explicit Process(ProcessHandle handle = kNullProcessHandle); | 35 explicit Process(ProcessHandle handle = kNullProcessHandle); |
38 | 36 |
39 Process(Process&& other); | 37 Process(Process&& other); |
40 | 38 |
41 // The destructor does not terminate the process. | 39 // The destructor does not terminate the process. |
42 ~Process(); | 40 ~Process(); |
43 | 41 |
44 Process& operator=(Process&& other); | 42 Process& operator=(Process&& other); |
45 | 43 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 ProcessId GetPidInNamespace() const; | 127 ProcessId GetPidInNamespace() const; |
130 #endif | 128 #endif |
131 | 129 |
132 private: | 130 private: |
133 #if defined(OS_WIN) | 131 #if defined(OS_WIN) |
134 bool is_current_process_; | 132 bool is_current_process_; |
135 win::ScopedHandle process_; | 133 win::ScopedHandle process_; |
136 #else | 134 #else |
137 ProcessHandle process_; | 135 ProcessHandle process_; |
138 #endif | 136 #endif |
| 137 |
| 138 DISALLOW_COPY_AND_ASSIGN(Process); |
139 }; | 139 }; |
140 | 140 |
141 #if defined(OS_CHROMEOS) | 141 #if defined(OS_CHROMEOS) |
142 // Exposed for testing. | 142 // Exposed for testing. |
143 // Given the contents of the /proc/<pid>/cgroup file, determine whether the | 143 // Given the contents of the /proc/<pid>/cgroup file, determine whether the |
144 // process is backgrounded or not. | 144 // process is backgrounded or not. |
145 BASE_EXPORT bool IsProcessBackgroundedCGroup( | 145 BASE_EXPORT bool IsProcessBackgroundedCGroup( |
146 const StringPiece& cgroup_contents); | 146 const StringPiece& cgroup_contents); |
147 #endif // defined(OS_CHROMEOS) | 147 #endif // defined(OS_CHROMEOS) |
148 | 148 |
149 } // namespace base | 149 } // namespace base |
150 | 150 |
151 #endif // BASE_PROCESS_PROCESS_H_ | 151 #endif // BASE_PROCESS_PROCESS_H_ |
OLD | NEW |