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