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_H_ | 5 #ifndef BASE_PROCESS_H_ |
6 #define BASE_PROCESS_H_ | 6 #define BASE_PROCESS_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/base_export.h" | 9 #include "base/base_export.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 const ProcessHandle kNullProcessHandle = NULL; | 27 const ProcessHandle kNullProcessHandle = NULL; |
28 const ProcessId kNullProcessId = 0; | 28 const ProcessId kNullProcessId = 0; |
29 #elif defined(OS_POSIX) | 29 #elif defined(OS_POSIX) |
30 // On POSIX, our ProcessHandle will just be the PID. | 30 // On POSIX, our ProcessHandle will just be the PID. |
31 typedef pid_t ProcessHandle; | 31 typedef pid_t ProcessHandle; |
32 typedef pid_t ProcessId; | 32 typedef pid_t ProcessId; |
33 const ProcessHandle kNullProcessHandle = 0; | 33 const ProcessHandle kNullProcessHandle = 0; |
34 const ProcessId kNullProcessId = 0; | 34 const ProcessId kNullProcessId = 0; |
35 #endif // defined(OS_WIN) | 35 #endif // defined(OS_WIN) |
36 | 36 |
37 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
38 // saved_priority_ will be set to this to indicate that it's not holding | |
39 // a valid value. -20 to 19 are valid process priorities. | |
40 const int kUnsetProcessPriority = 256; | |
41 #endif | |
42 | |
43 class BASE_EXPORT Process { | 37 class BASE_EXPORT Process { |
44 public: | 38 public: |
45 Process() : process_(kNullProcessHandle) { | 39 Process() : process_(kNullProcessHandle) { |
46 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
47 saved_priority_ = kUnsetProcessPriority; | |
48 #endif | |
49 } | 40 } |
50 | 41 |
51 explicit Process(ProcessHandle handle) : process_(handle) { | 42 explicit Process(ProcessHandle handle) : process_(handle) { |
52 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
53 saved_priority_ = kUnsetProcessPriority; | |
54 #endif | |
55 } | 43 } |
56 | 44 |
57 // A handle to the current process. | 45 // A handle to the current process. |
58 static Process Current(); | 46 static Process Current(); |
59 | 47 |
| 48 static bool CanBackgroundProcesses(); |
| 49 |
60 // Get/Set the handle for this process. The handle will be 0 if the process | 50 // Get/Set the handle for this process. The handle will be 0 if the process |
61 // is no longer running. | 51 // is no longer running. |
62 ProcessHandle handle() const { return process_; } | 52 ProcessHandle handle() const { return process_; } |
63 void set_handle(ProcessHandle handle) { | 53 void set_handle(ProcessHandle handle) { |
64 process_ = handle; | 54 process_ = handle; |
65 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
66 saved_priority_ = kUnsetProcessPriority; | |
67 #endif | |
68 } | 55 } |
69 | 56 |
70 // Get the PID for this process. | 57 // Get the PID for this process. |
71 ProcessId pid() const; | 58 ProcessId pid() const; |
72 | 59 |
73 // Is the this process the current process. | 60 // Is the this process the current process. |
74 bool is_current() const; | 61 bool is_current() const; |
75 | 62 |
76 // Close the process handle. This will not terminate the process. | 63 // Close the process handle. This will not terminate the process. |
77 void Close(); | 64 void Close(); |
(...skipping 13 matching lines...) Expand all Loading... |
91 // process priority. | 78 // process priority. |
92 // Returns true if the priority was changed, false otherwise. | 79 // Returns true if the priority was changed, false otherwise. |
93 bool SetProcessBackgrounded(bool value); | 80 bool SetProcessBackgrounded(bool value); |
94 | 81 |
95 // Returns an integer representing the priority of a process. The meaning | 82 // Returns an integer representing the priority of a process. The meaning |
96 // of this value is OS dependent. | 83 // of this value is OS dependent. |
97 int GetPriority() const; | 84 int GetPriority() const; |
98 | 85 |
99 private: | 86 private: |
100 ProcessHandle process_; | 87 ProcessHandle process_; |
101 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
102 // Holds the priority that the process was set to when it was backgrounded. | |
103 // If the process wasn't backgrounded it will be kUnsetProcessPriority. | |
104 int saved_priority_; | |
105 #endif | |
106 }; | 88 }; |
107 | 89 |
108 } // namespace base | 90 } // namespace base |
109 | 91 |
110 #endif // BASE_PROCESS_H_ | 92 #endif // BASE_PROCESS_H_ |
OLD | NEW |