dom/ipc/ProcessPriorityManager.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim: set sw=2 ts=8 et ft=cpp : */
     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 namespace mozilla {
    13 namespace dom {
    14 class ContentParent;
    15 }
    17 /**
    18  * This class sets the priority of subprocesses in response to explicit
    19  * requests and events in the system.
    20  *
    21  * A process's priority changes e.g. when it goes into the background via
    22  * mozbrowser's setVisible(false).  Process priority affects CPU scheduling and
    23  * also which processes get killed when we run out of memory.
    24  *
    25  * After you call Initialize(), the only thing you probably have to do is call
    26  * SetProcessPriority on processes immediately after creating them in order to
    27  * set their initial priority.  The ProcessPriorityManager takes care of the
    28  * rest.
    29  */
    30 class ProcessPriorityManager MOZ_FINAL
    31 {
    32 public:
    33   /**
    34    * Initialize the ProcessPriorityManager machinery, causing the
    35    * ProcessPriorityManager to actively manage the priorities of all
    36    * subprocesses.  You should call this before creating any subprocesses.
    37    *
    38    * You should also call this function even if you're in a child process,
    39    * since it will initialize ProcessPriorityManagerChild.
    40    */
    41   static void Init();
    43   /**
    44    * Set the process priority of a given ContentParent's process.
    45    *
    46    * Note that because this method takes a ContentParent*, you can only set the
    47    * priority of your subprocesses.  In fact, because we don't support nested
    48    * content processes (bug 761935), you can only call this method from the
    49    * main process.
    50    *
    51    * It probably only makes sense to call this function immediately after a
    52    * process is created.  At this point, the process priority manager doesn't
    53    * have enough context about the processs to know what its priority should
    54    * be.
    55    *
    56    * Eventually whatever priority you set here can and probably will be
    57    * overwritten by the process priority manager.
    58    */
    59   static void SetProcessPriority(dom::ContentParent* aContentParent,
    60                                  hal::ProcessPriority aPriority);
    62   /**
    63    * Returns true iff this process's priority is FOREGROUND*.
    64    *
    65    * Note that because process priorities are set in the main process, it's
    66    * possible for this method to return a stale value.  So be careful about
    67    * what you use this for.
    68    */
    69   static bool CurrentProcessIsForeground();
    71   /**
    72    * Returns true if one or more processes with FOREGROUND_HIGH priority are
    73    * present, false otherwise.
    74    */
    75   static bool AnyProcessHasHighPriority();
    77   /**
    78    * Used to remove a ContentParent from background LRU pool when
    79    * it is destroyed or its priority changed from BACKGROUND to others.
    80    */
    81   static void RemoveFromBackgroundLRUPool(dom::ContentParent* aContentParent);
    83   /**
    84    * Used to add a ContentParent into background LRU pool when
    85    * its priority changed to BACKGROUND from others.
    86    */
    87   static void AddIntoBackgroundLRUPool(dom::ContentParent* aContentParent);
    89 private:
    90   ProcessPriorityManager();
    91   DISALLOW_EVIL_CONSTRUCTORS(ProcessPriorityManager);
    92 };
    94 } // namespace mozilla
    96 #endif

mercurial