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 #ifndef BASE_PROCESS_PROCESS_PROCESS_H_ | 5 #ifndef BASE_PROCESS_PROCESS_PROCESS_H_ |
6 #define BASE_PROCESS_PROCESS_PROCESS_H_ | 6 #define BASE_PROCESS_PROCESS_PROCESS_H_ |
7 | 7 |
8 #include "base/base_export.h" | 8 #include "base/base_export.h" |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/move.h" | |
10 #include "base/process/process_handle.h" | 11 #include "base/process/process_handle.h" |
11 #include "build/build_config.h" | 12 #include "build/build_config.h" |
12 | 13 |
14 #if defined(OS_WIN) | |
15 #include "base/win/scoped_handle.h" | |
16 #endif | |
17 | |
13 namespace base { | 18 namespace base { |
14 | 19 |
20 // Provides a move-only implementation of Process. | |
21 // TODO(rvargas) crbug.com/417532: Reaname this class Process after switching | |
scottmg
2014/10/14 18:51:02
Any chance we could do that upfront? i.e. switch P
scottmg
2014/10/14 18:51:03
nit; "Rename"
rvargas (doing something else)
2014/10/14 19:56:54
I was trying to avoid a huge change right now, but
| |
22 // all users and deleting the old implementation. | |
23 class BASE_EXPORT ProcessObject { | |
24 MOVE_ONLY_TYPE_FOR_CPP_03(ProcessObject, RValue) | |
25 | |
26 public: | |
27 explicit ProcessObject(ProcessHandle handle = kNullProcessHandle); | |
scottmg
2014/10/14 18:51:02
nit; I think default args are against "the rules"
rvargas (doing something else)
2014/10/14 19:56:54
I though that too until some recent thread involvi
| |
28 | |
29 // Move constructor for C++03 move emulation of this type. | |
30 ProcessObject(RValue other); | |
31 | |
32 // The destructor does not terminate the process. | |
scottmg
2014/10/14 18:51:03
Is it possible the handle could be reused if Proce
rvargas (doing something else)
2014/10/14 19:56:54
That should not be the case. The handle should be
| |
33 ~ProcessObject() {} | |
34 | |
35 // Move operator= for C++03 move emulation of this type. | |
36 ProcessObject& operator=(RValue other); | |
37 | |
38 // Returns an object for the current process. | |
39 static ProcessObject Current(); | |
40 | |
41 // Returns true if processes can be backgrounded. | |
42 static bool CanBackgroundProcesses(); | |
43 | |
44 // Returns true if this objects represents a valid process. | |
45 bool IsValid() const; | |
46 | |
47 // Returns a handle for this process. There is no guarantee about when that | |
48 // handle becomes invalid because this object retains ownership. | |
49 ProcessHandle Handle() const; | |
50 | |
51 // Returns a second object that represents this process. | |
52 ProcessObject Duplicate() const; | |
53 | |
54 // Get the PID for this process. | |
55 ProcessId pid() const; | |
56 | |
57 // Returns true if this process is the current process. | |
58 bool is_current() const; | |
59 | |
60 // Close the process handle. This will not terminate the process. | |
61 void Close(); | |
62 | |
63 // Terminates the process with extreme prejudice. The given |result_code| will | |
64 // be the exit code of the process. | |
65 // NOTE: On POSIX |result_code| is ignored. | |
66 void Terminate(int result_code); | |
67 | |
68 // A process is backgrounded when it's priority is lower than normal. | |
69 // Return true if this process is backgrounded, false otherwise. | |
70 bool IsProcessBackgrounded() const; | |
71 | |
72 // Set a process as backgrounded. If value is true, the priority of the | |
73 // process will be lowered. If value is false, the priority of the process | |
74 // will be made "normal" - equivalent to default process priority. | |
75 // Returns true if the priority was changed, false otherwise. | |
76 bool SetProcessBackgrounded(bool value); | |
77 | |
78 // Returns an integer representing the priority of a process. The meaning | |
79 // of this value is OS dependent. | |
80 int GetPriority() const; | |
81 | |
82 private: | |
83 #if defined(OS_WIN) | |
84 bool is_current_process_; | |
scottmg
2014/10/14 18:51:03
nit; indent
| |
85 win::ScopedHandle process_; | |
scottmg
2014/10/14 18:51:03
Could you explain why we use Scoped on Windows, bu
rvargas (doing something else)
2014/10/14 19:56:54
I'be been back and forth about how to clean up thi
| |
86 #else | |
87 ProcessHandle process_; | |
88 #endif | |
89 }; | |
90 | |
91 // Deprecated!. Use ProcessObject instead. | |
15 class BASE_EXPORT Process { | 92 class BASE_EXPORT Process { |
16 public: | 93 public: |
17 Process() : process_(kNullProcessHandle) { | 94 Process() : process_(kNullProcessHandle) { |
18 } | 95 } |
19 | 96 |
20 explicit Process(ProcessHandle handle) : process_(handle) { | 97 explicit Process(ProcessHandle handle) : process_(handle) { |
21 } | 98 } |
22 | 99 |
23 // A handle to the current process. | 100 // A handle to the current process. |
24 static Process Current(); | 101 static Process Current(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 // of this value is OS dependent. | 138 // of this value is OS dependent. |
62 int GetPriority() const; | 139 int GetPriority() const; |
63 | 140 |
64 private: | 141 private: |
65 ProcessHandle process_; | 142 ProcessHandle process_; |
66 }; | 143 }; |
67 | 144 |
68 } // namespace base | 145 } // namespace base |
69 | 146 |
70 #endif // BASE_PROCESS_PROCESS_PROCESS_H_ | 147 #endif // BASE_PROCESS_PROCESS_PROCESS_H_ |
OLD | NEW |