Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim: set sw=2 ts=8 et ft=cpp : */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 5 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef mozilla_ProcessPriorityManager_h_ |
michael@0 | 8 | #define mozilla_ProcessPriorityManager_h_ |
michael@0 | 9 | |
michael@0 | 10 | #include "mozilla/HalTypes.h" |
michael@0 | 11 | |
michael@0 | 12 | namespace mozilla { |
michael@0 | 13 | namespace dom { |
michael@0 | 14 | class ContentParent; |
michael@0 | 15 | } |
michael@0 | 16 | |
michael@0 | 17 | /** |
michael@0 | 18 | * This class sets the priority of subprocesses in response to explicit |
michael@0 | 19 | * requests and events in the system. |
michael@0 | 20 | * |
michael@0 | 21 | * A process's priority changes e.g. when it goes into the background via |
michael@0 | 22 | * mozbrowser's setVisible(false). Process priority affects CPU scheduling and |
michael@0 | 23 | * also which processes get killed when we run out of memory. |
michael@0 | 24 | * |
michael@0 | 25 | * After you call Initialize(), the only thing you probably have to do is call |
michael@0 | 26 | * SetProcessPriority on processes immediately after creating them in order to |
michael@0 | 27 | * set their initial priority. The ProcessPriorityManager takes care of the |
michael@0 | 28 | * rest. |
michael@0 | 29 | */ |
michael@0 | 30 | class ProcessPriorityManager MOZ_FINAL |
michael@0 | 31 | { |
michael@0 | 32 | public: |
michael@0 | 33 | /** |
michael@0 | 34 | * Initialize the ProcessPriorityManager machinery, causing the |
michael@0 | 35 | * ProcessPriorityManager to actively manage the priorities of all |
michael@0 | 36 | * subprocesses. You should call this before creating any subprocesses. |
michael@0 | 37 | * |
michael@0 | 38 | * You should also call this function even if you're in a child process, |
michael@0 | 39 | * since it will initialize ProcessPriorityManagerChild. |
michael@0 | 40 | */ |
michael@0 | 41 | static void Init(); |
michael@0 | 42 | |
michael@0 | 43 | /** |
michael@0 | 44 | * Set the process priority of a given ContentParent's process. |
michael@0 | 45 | * |
michael@0 | 46 | * Note that because this method takes a ContentParent*, you can only set the |
michael@0 | 47 | * priority of your subprocesses. In fact, because we don't support nested |
michael@0 | 48 | * content processes (bug 761935), you can only call this method from the |
michael@0 | 49 | * main process. |
michael@0 | 50 | * |
michael@0 | 51 | * It probably only makes sense to call this function immediately after a |
michael@0 | 52 | * process is created. At this point, the process priority manager doesn't |
michael@0 | 53 | * have enough context about the processs to know what its priority should |
michael@0 | 54 | * be. |
michael@0 | 55 | * |
michael@0 | 56 | * Eventually whatever priority you set here can and probably will be |
michael@0 | 57 | * overwritten by the process priority manager. |
michael@0 | 58 | */ |
michael@0 | 59 | static void SetProcessPriority(dom::ContentParent* aContentParent, |
michael@0 | 60 | hal::ProcessPriority aPriority); |
michael@0 | 61 | |
michael@0 | 62 | /** |
michael@0 | 63 | * Returns true iff this process's priority is FOREGROUND*. |
michael@0 | 64 | * |
michael@0 | 65 | * Note that because process priorities are set in the main process, it's |
michael@0 | 66 | * possible for this method to return a stale value. So be careful about |
michael@0 | 67 | * what you use this for. |
michael@0 | 68 | */ |
michael@0 | 69 | static bool CurrentProcessIsForeground(); |
michael@0 | 70 | |
michael@0 | 71 | /** |
michael@0 | 72 | * Returns true if one or more processes with FOREGROUND_HIGH priority are |
michael@0 | 73 | * present, false otherwise. |
michael@0 | 74 | */ |
michael@0 | 75 | static bool AnyProcessHasHighPriority(); |
michael@0 | 76 | |
michael@0 | 77 | /** |
michael@0 | 78 | * Used to remove a ContentParent from background LRU pool when |
michael@0 | 79 | * it is destroyed or its priority changed from BACKGROUND to others. |
michael@0 | 80 | */ |
michael@0 | 81 | static void RemoveFromBackgroundLRUPool(dom::ContentParent* aContentParent); |
michael@0 | 82 | |
michael@0 | 83 | /** |
michael@0 | 84 | * Used to add a ContentParent into background LRU pool when |
michael@0 | 85 | * its priority changed to BACKGROUND from others. |
michael@0 | 86 | */ |
michael@0 | 87 | static void AddIntoBackgroundLRUPool(dom::ContentParent* aContentParent); |
michael@0 | 88 | |
michael@0 | 89 | private: |
michael@0 | 90 | ProcessPriorityManager(); |
michael@0 | 91 | DISALLOW_EVIL_CONSTRUCTORS(ProcessPriorityManager); |
michael@0 | 92 | }; |
michael@0 | 93 | |
michael@0 | 94 | } // namespace mozilla |
michael@0 | 95 | |
michael@0 | 96 | #endif |