tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ProcessPriorityManager.h (3394B)


      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/. */
      6 
      7 #ifndef mozilla_ProcessPriorityManager_h_
      8 #define mozilla_ProcessPriorityManager_h_
      9 
     10 #include "mozilla/HalTypes.h"
     11 
     12 class nsFrameLoader;
     13 
     14 namespace mozilla {
     15 namespace dom {
     16 class BrowserParent;
     17 class CanonicalBrowsingContext;
     18 class ContentParent;
     19 }  // namespace dom
     20 
     21 /**
     22 * This class sets the priority of subprocesses in response to explicit
     23 * requests and events in the system.
     24 *
     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.
     28 *
     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.
     33 */
     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.
     40   *
     41   * You should also call this function even if you're in a child process,
     42   * since it will initialize ProcessPriorityManagerChild.
     43   */
     44  static void Init();
     45 
     46  /**
     47   * Set the process priority of a given ContentParent's process.
     48   *
     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.
     53   *
     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.
     58   *
     59   * Eventually whatever priority you set here can and probably will be
     60   * overwritten by the process priority manager.
     61   */
     62  static void SetProcessPriority(dom::ContentParent* aContentParent,
     63                                 hal::ProcessPriority aPriority);
     64 
     65  /**
     66   * Returns true iff this process's priority is FOREGROUND*.
     67   *
     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.
     71   */
     72  static bool CurrentProcessIsForeground();
     73 
     74  /**
     75   * Updates the contents of mHighPriorityBrowserParents to keep track of
     76   * the list of TabIds for this process that are high priority.
     77   */
     78  static void BrowserPriorityChanged(dom::CanonicalBrowsingContext* aBC,
     79                                     bool aPriority);
     80  static void BrowserPriorityChanged(dom::BrowserParent* aBrowserParent,
     81                                     bool aPriority);
     82 
     83 private:
     84  ProcessPriorityManager();
     85  ProcessPriorityManager(const ProcessPriorityManager&) = delete;
     86 
     87  const ProcessPriorityManager& operator=(const ProcessPriorityManager&) =
     88      delete;
     89 };
     90 
     91 }  // namespace mozilla
     92 
     93 #endif