Bug 1867190 - Initialise the PHC allocate delay later r=glandium
[gecko.git] / dom / ipc / ProcessPriorityManager.h
blob8153a609935a772fce9c0bdec029e34f4778e328
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_ProcessPriorityManager_h_
8 #define mozilla_ProcessPriorityManager_h_
10 #include "mozilla/HalTypes.h"
12 class nsFrameLoader;
14 namespace mozilla {
15 namespace dom {
16 class BrowserParent;
17 class CanonicalBrowsingContext;
18 class ContentParent;
19 } // namespace dom
21 /**
22 * This class sets the priority of subprocesses in response to explicit
23 * requests and events in the system.
25 * A process's priority changes e.g. when it goes into the background via
26 * mozbrowser's setVisible(false). Process priority affects CPU scheduling and
27 * also which processes get killed when we run out of memory.
29 * After you call Initialize(), the only thing you probably have to do is call
30 * SetProcessPriority on processes immediately after creating them in order to
31 * set their initial priority. The ProcessPriorityManager takes care of the
32 * rest.
34 class ProcessPriorityManager final {
35 public:
36 /**
37 * Initialize the ProcessPriorityManager machinery, causing the
38 * ProcessPriorityManager to actively manage the priorities of all
39 * subprocesses. You should call this before creating any subprocesses.
41 * You should also call this function even if you're in a child process,
42 * since it will initialize ProcessPriorityManagerChild.
44 static void Init();
46 /**
47 * Set the process priority of a given ContentParent's process.
49 * Note that because this method takes a ContentParent*, you can only set the
50 * priority of your subprocesses. In fact, because we don't support nested
51 * content processes (bug 761935), you can only call this method from the
52 * main process.
54 * It probably only makes sense to call this function immediately after a
55 * process is created. At this point, the process priority manager doesn't
56 * have enough context about the processs to know what its priority should
57 * be.
59 * Eventually whatever priority you set here can and probably will be
60 * overwritten by the process priority manager.
62 static void SetProcessPriority(dom::ContentParent* aContentParent,
63 hal::ProcessPriority aPriority);
65 /**
66 * Returns true iff this process's priority is FOREGROUND*.
68 * Note that because process priorities are set in the main process, it's
69 * possible for this method to return a stale value. So be careful about
70 * what you use this for.
72 static bool CurrentProcessIsForeground();
74 /**
75 * Updates the contents of mHighPriorityBrowserParents to keep track of
76 * the list of TabIds for this process that are high priority.
78 static void BrowserPriorityChanged(dom::CanonicalBrowsingContext* aBC,
79 bool aPriority);
80 static void BrowserPriorityChanged(dom::BrowserParent* aBrowserParent,
81 bool aPriority);
83 static void RemoteBrowserFrameShown(nsFrameLoader* aFrameLoader);
85 private:
86 ProcessPriorityManager();
87 ProcessPriorityManager(const ProcessPriorityManager&) = delete;
89 const ProcessPriorityManager& operator=(const ProcessPriorityManager&) =
90 delete;
93 } // namespace mozilla
95 #endif