xref: /aosp_15_r20/external/cronet/base/process/process_priority_delegate.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2024 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BASE_PROCESS_PROCESS_PRIORITY_DELEGATE_H_
6 #define BASE_PROCESS_PROCESS_PRIORITY_DELEGATE_H_
7 
8 #include "base/base_export.h"
9 #include "base/process/process.h"
10 
11 namespace base {
12 
13 // A ProcessPriorityDelegate can intercept process priority changes. This can be
14 // used to adjust process properties via another process (e.g. resourced on
15 // ChromeOS).
16 // Methods are thread-safe.
17 class BASE_EXPORT ProcessPriorityDelegate {
18  public:
19   ProcessPriorityDelegate() = default;
20 
21   ProcessPriorityDelegate(const ProcessPriorityDelegate&) = delete;
22   ProcessPriorityDelegate& operator=(const ProcessPriorityDelegate&) = delete;
23 
24   virtual ~ProcessPriorityDelegate() = default;
25 
26   // Returns true if changing the priority of processes through
27   // `base::Process::SetPriority()` is possible.
28   virtual bool CanSetProcessPriority() = 0;
29 
30   // Initialize internal state for the process priority.
31   virtual void InitializeProcessPriority(ProcessId process_id) = 0;
32 
33   // Clears internal state for the process priority.
34   virtual void ForgetProcessPriority(ProcessId process_id) = 0;
35 
36   // Set process priotiry on behalf of base::Process::SetPriority().
37   virtual bool SetProcessPriority(ProcessId process_id,
38                                   Process::Priority priority) = 0;
39 
40   // Returns the process priority on behalf of base::Process::GetPriority().
41   virtual Process::Priority GetProcessPriority(ProcessId process_id) = 0;
42 };
43 
44 }  // namespace base
45 
46 #endif  // BASE_PROCESS_PROCESS_PRIORITY_DELEGATE_H_
47