michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set sw=2 ts=8 et ft=cpp : */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_ProcessPriorityManager_h_ michael@0: #define mozilla_ProcessPriorityManager_h_ michael@0: michael@0: #include "mozilla/HalTypes.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: class ContentParent; michael@0: } michael@0: michael@0: /** michael@0: * This class sets the priority of subprocesses in response to explicit michael@0: * requests and events in the system. michael@0: * michael@0: * A process's priority changes e.g. when it goes into the background via michael@0: * mozbrowser's setVisible(false). Process priority affects CPU scheduling and michael@0: * also which processes get killed when we run out of memory. michael@0: * michael@0: * After you call Initialize(), the only thing you probably have to do is call michael@0: * SetProcessPriority on processes immediately after creating them in order to michael@0: * set their initial priority. The ProcessPriorityManager takes care of the michael@0: * rest. michael@0: */ michael@0: class ProcessPriorityManager MOZ_FINAL michael@0: { michael@0: public: michael@0: /** michael@0: * Initialize the ProcessPriorityManager machinery, causing the michael@0: * ProcessPriorityManager to actively manage the priorities of all michael@0: * subprocesses. You should call this before creating any subprocesses. michael@0: * michael@0: * You should also call this function even if you're in a child process, michael@0: * since it will initialize ProcessPriorityManagerChild. michael@0: */ michael@0: static void Init(); michael@0: michael@0: /** michael@0: * Set the process priority of a given ContentParent's process. michael@0: * michael@0: * Note that because this method takes a ContentParent*, you can only set the michael@0: * priority of your subprocesses. In fact, because we don't support nested michael@0: * content processes (bug 761935), you can only call this method from the michael@0: * main process. michael@0: * michael@0: * It probably only makes sense to call this function immediately after a michael@0: * process is created. At this point, the process priority manager doesn't michael@0: * have enough context about the processs to know what its priority should michael@0: * be. michael@0: * michael@0: * Eventually whatever priority you set here can and probably will be michael@0: * overwritten by the process priority manager. michael@0: */ michael@0: static void SetProcessPriority(dom::ContentParent* aContentParent, michael@0: hal::ProcessPriority aPriority); michael@0: michael@0: /** michael@0: * Returns true iff this process's priority is FOREGROUND*. michael@0: * michael@0: * Note that because process priorities are set in the main process, it's michael@0: * possible for this method to return a stale value. So be careful about michael@0: * what you use this for. michael@0: */ michael@0: static bool CurrentProcessIsForeground(); michael@0: michael@0: /** michael@0: * Returns true if one or more processes with FOREGROUND_HIGH priority are michael@0: * present, false otherwise. michael@0: */ michael@0: static bool AnyProcessHasHighPriority(); michael@0: michael@0: /** michael@0: * Used to remove a ContentParent from background LRU pool when michael@0: * it is destroyed or its priority changed from BACKGROUND to others. michael@0: */ michael@0: static void RemoveFromBackgroundLRUPool(dom::ContentParent* aContentParent); michael@0: michael@0: /** michael@0: * Used to add a ContentParent into background LRU pool when michael@0: * its priority changed to BACKGROUND from others. michael@0: */ michael@0: static void AddIntoBackgroundLRUPool(dom::ContentParent* aContentParent); michael@0: michael@0: private: michael@0: ProcessPriorityManager(); michael@0: DISALLOW_EVIL_CONSTRUCTORS(ProcessPriorityManager); michael@0: }; michael@0: michael@0: } // namespace mozilla michael@0: michael@0: #endif