Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(343)

Side by Side Diff: base/process/process.h

Issue 2454073003: Allow backgrounding processes on Mac (Closed)
Patch Set: Address review comments Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/BUILD.gn ('k') | base/process/process_mac.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/feature_list.h"
20 #include "base/process/port_provider_mac.h"
21 #endif
22
18 namespace base { 23 namespace base {
19 24
25 #if defined(OS_MACOSX)
26 extern const Feature kMacAllowBackgroundingProcesses;
27 #endif
28
20 // Provides a move-only encapsulation of a process. 29 // Provides a move-only encapsulation of a process.
21 // 30 //
22 // This object is not tied to the lifetime of the underlying process: the 31 // 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 32 // 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: 33 // claim to be valid. The actual behavior in that case is OS dependent like so:
25 // 34 //
26 // Windows: The underlying ProcessHandle will be valid after the process dies 35 // 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 36 // and can be used to gather some information about that process, but most
28 // methods will obviously fail. 37 // methods will obviously fail.
29 // 38 //
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 // any process. 108 // any process.
100 // NOTE: |exit_code| is optional, nullptr can be passed if the exit code is 109 // NOTE: |exit_code| is optional, nullptr can be passed if the exit code is
101 // not required. 110 // not required.
102 bool WaitForExit(int* exit_code); 111 bool WaitForExit(int* exit_code);
103 112
104 // Same as WaitForExit() but only waits for up to |timeout|. 113 // Same as WaitForExit() but only waits for up to |timeout|.
105 // NOTE: |exit_code| is optional, nullptr can be passed if the exit code 114 // NOTE: |exit_code| is optional, nullptr can be passed if the exit code
106 // is not required. 115 // is not required.
107 bool WaitForExitWithTimeout(TimeDelta timeout, int* exit_code); 116 bool WaitForExitWithTimeout(TimeDelta timeout, int* exit_code);
108 117
118 #if defined(OS_MACOSX)
119 // The Mac needs a Mach port in order to manipulate a process's priority,
120 // and there's no good way to get that from base given the pid. These Mac
121 // variants of the IsProcessBackgrounded and SetProcessBackgrounded API take
122 // a port provider for this reason. See crbug.com/460102
123 //
124 // A process is backgrounded when its task priority is
125 // |TASK_BACKGROUND_APPLICATION|.
126 //
127 // Returns true if the port_provider can locate a task port for the process
128 // and it is backgrounded. If port_provider is null, returns false.
129 bool IsProcessBackgrounded(PortProvider* port_provider) const;
130
131 // Set the process as backgrounded. If value is
132 // true, the priority of the associated task will be set to
133 // TASK_BACKGROUND_APPLICATION. If value is false, the
134 // priority of the process will be set to TASK_FOREGROUND_APPLICATION.
135 //
136 // Returns true if the priority was changed, false otherwise. If
137 // |port_provider| is null, this is a no-op and it returns false.
138 bool SetProcessBackgrounded(PortProvider* port_provider, bool value);
139 #else
109 // A process is backgrounded when it's priority is lower than normal. 140 // A process is backgrounded when it's priority is lower than normal.
110 // Return true if this process is backgrounded, false otherwise. 141 // Return true if this process is backgrounded, false otherwise.
111 bool IsProcessBackgrounded() const; 142 bool IsProcessBackgrounded() const;
112 143
113 // Set a process as backgrounded. If value is true, the priority of the 144 // 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 145 // process will be lowered. If value is false, the priority of the process
115 // will be made "normal" - equivalent to default process priority. 146 // will be made "normal" - equivalent to default process priority.
116 // Returns true if the priority was changed, false otherwise. 147 // Returns true if the priority was changed, false otherwise.
117 bool SetProcessBackgrounded(bool value); 148 bool SetProcessBackgrounded(bool value);
118 149 #endif // defined(OS_MACOSX)
119 // Returns an integer representing the priority of a process. The meaning 150 // Returns an integer representing the priority of a process. The meaning
120 // of this value is OS dependent. 151 // of this value is OS dependent.
121 int GetPriority() const; 152 int GetPriority() const;
122 153
123 #if defined(OS_CHROMEOS) 154 #if defined(OS_CHROMEOS)
124 // Get the PID in its PID namespace. 155 // Get the PID in its PID namespace.
125 // If the process is not in a PID namespace or /proc/<pid>/status does not 156 // If the process is not in a PID namespace or /proc/<pid>/status does not
126 // report NSpid, kNullProcessId is returned. 157 // report NSpid, kNullProcessId is returned.
127 ProcessId GetPidInNamespace() const; 158 ProcessId GetPidInNamespace() const;
128 #endif 159 #endif
(...skipping 13 matching lines...) Expand all
142 // Exposed for testing. 173 // Exposed for testing.
143 // Given the contents of the /proc/<pid>/cgroup file, determine whether the 174 // Given the contents of the /proc/<pid>/cgroup file, determine whether the
144 // process is backgrounded or not. 175 // process is backgrounded or not.
145 BASE_EXPORT bool IsProcessBackgroundedCGroup( 176 BASE_EXPORT bool IsProcessBackgroundedCGroup(
146 const StringPiece& cgroup_contents); 177 const StringPiece& cgroup_contents);
147 #endif // defined(OS_CHROMEOS) 178 #endif // defined(OS_CHROMEOS)
148 179
149 } // namespace base 180 } // namespace base
150 181
151 #endif // BASE_PROCESS_PROCESS_H_ 182 #endif // BASE_PROCESS_PROCESS_H_
OLDNEW
« no previous file with comments | « base/BUILD.gn ('k') | base/process/process_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698