dom/ipc/ProcessPriorityManager.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/ipc/ProcessPriorityManager.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,96 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set sw=2 ts=8 et ft=cpp : */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef mozilla_ProcessPriorityManager_h_
    1.11 +#define mozilla_ProcessPriorityManager_h_
    1.12 +
    1.13 +#include "mozilla/HalTypes.h"
    1.14 +
    1.15 +namespace mozilla {
    1.16 +namespace dom {
    1.17 +class ContentParent;
    1.18 +}
    1.19 +
    1.20 +/**
    1.21 + * This class sets the priority of subprocesses in response to explicit
    1.22 + * requests and events in the system.
    1.23 + *
    1.24 + * A process's priority changes e.g. when it goes into the background via
    1.25 + * mozbrowser's setVisible(false).  Process priority affects CPU scheduling and
    1.26 + * also which processes get killed when we run out of memory.
    1.27 + *
    1.28 + * After you call Initialize(), the only thing you probably have to do is call
    1.29 + * SetProcessPriority on processes immediately after creating them in order to
    1.30 + * set their initial priority.  The ProcessPriorityManager takes care of the
    1.31 + * rest.
    1.32 + */
    1.33 +class ProcessPriorityManager MOZ_FINAL
    1.34 +{
    1.35 +public:
    1.36 +  /**
    1.37 +   * Initialize the ProcessPriorityManager machinery, causing the
    1.38 +   * ProcessPriorityManager to actively manage the priorities of all
    1.39 +   * subprocesses.  You should call this before creating any subprocesses.
    1.40 +   *
    1.41 +   * You should also call this function even if you're in a child process,
    1.42 +   * since it will initialize ProcessPriorityManagerChild.
    1.43 +   */
    1.44 +  static void Init();
    1.45 +
    1.46 +  /**
    1.47 +   * Set the process priority of a given ContentParent's process.
    1.48 +   *
    1.49 +   * Note that because this method takes a ContentParent*, you can only set the
    1.50 +   * priority of your subprocesses.  In fact, because we don't support nested
    1.51 +   * content processes (bug 761935), you can only call this method from the
    1.52 +   * main process.
    1.53 +   *
    1.54 +   * It probably only makes sense to call this function immediately after a
    1.55 +   * process is created.  At this point, the process priority manager doesn't
    1.56 +   * have enough context about the processs to know what its priority should
    1.57 +   * be.
    1.58 +   *
    1.59 +   * Eventually whatever priority you set here can and probably will be
    1.60 +   * overwritten by the process priority manager.
    1.61 +   */
    1.62 +  static void SetProcessPriority(dom::ContentParent* aContentParent,
    1.63 +                                 hal::ProcessPriority aPriority);
    1.64 +
    1.65 +  /**
    1.66 +   * Returns true iff this process's priority is FOREGROUND*.
    1.67 +   *
    1.68 +   * Note that because process priorities are set in the main process, it's
    1.69 +   * possible for this method to return a stale value.  So be careful about
    1.70 +   * what you use this for.
    1.71 +   */
    1.72 +  static bool CurrentProcessIsForeground();
    1.73 +
    1.74 +  /**
    1.75 +   * Returns true if one or more processes with FOREGROUND_HIGH priority are
    1.76 +   * present, false otherwise.
    1.77 +   */
    1.78 +  static bool AnyProcessHasHighPriority();
    1.79 +
    1.80 +  /**
    1.81 +   * Used to remove a ContentParent from background LRU pool when
    1.82 +   * it is destroyed or its priority changed from BACKGROUND to others.
    1.83 +   */
    1.84 +  static void RemoveFromBackgroundLRUPool(dom::ContentParent* aContentParent);
    1.85 +
    1.86 +  /**
    1.87 +   * Used to add a ContentParent into background LRU pool when
    1.88 +   * its priority changed to BACKGROUND from others.
    1.89 +   */
    1.90 +  static void AddIntoBackgroundLRUPool(dom::ContentParent* aContentParent);
    1.91 +
    1.92 +private:
    1.93 +  ProcessPriorityManager();
    1.94 +  DISALLOW_EVIL_CONSTRUCTORS(ProcessPriorityManager);
    1.95 +};
    1.96 +
    1.97 +} // namespace mozilla
    1.98 +
    1.99 +#endif

mercurial