Chromium Code Reviews| 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/macros.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 #if defined(OS_MACOSX) | |
| 19 #include "base/process/port_provider_mac.h" | |
| 20 #endif | |
| 21 | |
| 18 namespace base { | 22 namespace base { |
| 19 | 23 |
| 20 // Provides a move-only encapsulation of a process. | 24 // Provides a move-only encapsulation of a process. |
| 21 // | 25 // |
| 22 // This object is not tied to the lifetime of the underlying process: the | 26 // 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 | 27 // 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: | 28 // claim to be valid. The actual behavior in that case is OS dependent like so: |
| 25 // | 29 // |
| 26 // Windows: The underlying ProcessHandle will be valid after the process dies | 30 // 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 | 31 // and can be used to gather some information about that process, but most |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 // any process. | 103 // any process. |
| 100 // NOTE: |exit_code| is optional, nullptr can be passed if the exit code is | 104 // NOTE: |exit_code| is optional, nullptr can be passed if the exit code is |
| 101 // not required. | 105 // not required. |
| 102 bool WaitForExit(int* exit_code); | 106 bool WaitForExit(int* exit_code); |
| 103 | 107 |
| 104 // Same as WaitForExit() but only waits for up to |timeout|. | 108 // Same as WaitForExit() but only waits for up to |timeout|. |
| 105 // NOTE: |exit_code| is optional, nullptr can be passed if the exit code | 109 // NOTE: |exit_code| is optional, nullptr can be passed if the exit code |
| 106 // is not required. | 110 // is not required. |
| 107 bool WaitForExitWithTimeout(TimeDelta timeout, int* exit_code); | 111 bool WaitForExitWithTimeout(TimeDelta timeout, int* exit_code); |
| 108 | 112 |
| 113 #if defined(OS_MACOSX) | |
| 114 // The Mac needs a Mach port in order to manipulate a process's priority, | |
| 115 // and there's no good way to get that from base given the pid. These Mac | |
| 116 // variants of the IsProcessBackgrounded and SetProcessBackgrounded API take | |
| 117 // a port provider for this reason. See crbug.com/460102 | |
| 118 // | |
| 119 // A process is backgrounded when its task priority is | |
| 120 // |TASK_BACKGROUND_APPLICATION|. | |
| 121 // Return true if the port_provider can locate a task port for the process and | |
| 122 // it | |
|
shrike
2016/10/31 17:26:04
Move straggler "it" to the next line?
lgrey
2016/10/31 19:22:01
Done.
| |
| 123 // is backgrounded. If port_provider is null, returns false. | |
| 124 bool IsProcessBackgrounded(PortProvider* port_provider) const; | |
| 125 | |
| 126 // Set the process as backgrounded. If value is | |
| 127 // true, the priority of the associated task will be set to | |
| 128 // TASK_BACKGROUND_APPLICATION. If value is false, the | |
| 129 // priority of the process will be set to TASK_FOREGROUND_APPLICATION. Returns | |
| 130 // true if the priority was changed, false | |
| 131 // otherwise. If |port_provider| is null, this is a no-op and it returns | |
| 132 // false. | |
| 133 bool SetProcessBackgrounded(PortProvider* port_provider, bool value); | |
| 134 #else | |
| 109 // A process is backgrounded when it's priority is lower than normal. | 135 // A process is backgrounded when it's priority is lower than normal. |
| 110 // Return true if this process is backgrounded, false otherwise. | 136 // Return true if this process is backgrounded, false otherwise. |
| 111 bool IsProcessBackgrounded() const; | 137 bool IsProcessBackgrounded() const; |
| 112 | 138 |
| 113 // Set a process as backgrounded. If value is true, the priority of the | 139 // Set a process as backgrounded. If value is true, the priority of the |
| 114 // process will be lowered. If value is false, the priority of the process | 140 // process will be lowered. If value is false, the priority of the process |
| 115 // will be made "normal" - equivalent to default process priority. | 141 // will be made "normal" - equivalent to default process priority. |
| 116 // Returns true if the priority was changed, false otherwise. | 142 // Returns true if the priority was changed, false otherwise. |
| 117 bool SetProcessBackgrounded(bool value); | 143 bool SetProcessBackgrounded(bool value); |
| 118 | 144 #endif // defined(OS_MACOSX) |
| 119 // Returns an integer representing the priority of a process. The meaning | 145 // Returns an integer representing the priority of a process. The meaning |
| 120 // of this value is OS dependent. | 146 // of this value is OS dependent. |
| 121 int GetPriority() const; | 147 int GetPriority() const; |
| 122 | 148 |
| 123 #if defined(OS_CHROMEOS) | 149 #if defined(OS_CHROMEOS) |
| 124 // Get the PID in its PID namespace. | 150 // Get the PID in its PID namespace. |
| 125 // If the process is not in a PID namespace or /proc/<pid>/status does not | 151 // If the process is not in a PID namespace or /proc/<pid>/status does not |
| 126 // report NSpid, kNullProcessId is returned. | 152 // report NSpid, kNullProcessId is returned. |
| 127 ProcessId GetPidInNamespace() const; | 153 ProcessId GetPidInNamespace() const; |
| 128 #endif | 154 #endif |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 142 // Exposed for testing. | 168 // Exposed for testing. |
| 143 // Given the contents of the /proc/<pid>/cgroup file, determine whether the | 169 // Given the contents of the /proc/<pid>/cgroup file, determine whether the |
| 144 // process is backgrounded or not. | 170 // process is backgrounded or not. |
| 145 BASE_EXPORT bool IsProcessBackgroundedCGroup( | 171 BASE_EXPORT bool IsProcessBackgroundedCGroup( |
| 146 const StringPiece& cgroup_contents); | 172 const StringPiece& cgroup_contents); |
| 147 #endif // defined(OS_CHROMEOS) | 173 #endif // defined(OS_CHROMEOS) |
| 148 | 174 |
| 149 } // namespace base | 175 } // namespace base |
| 150 | 176 |
| 151 #endif // BASE_PROCESS_PROCESS_H_ | 177 #endif // BASE_PROCESS_PROCESS_H_ |
| OLD | NEW |