dom/ipc/PreallocatedProcessManager.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.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set sw=2 ts=8 et ft=cpp : */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef mozilla_PreallocatedProcessManager_h
michael@0 8 #define mozilla_PreallocatedProcessManager_h
michael@0 9
michael@0 10 #include "base/basictypes.h"
michael@0 11 #include "nsCOMPtr.h"
michael@0 12 #include "nsIObserver.h"
michael@0 13
michael@0 14 class nsIRunnable;
michael@0 15
michael@0 16 namespace mozilla {
michael@0 17 namespace dom {
michael@0 18 class ContentParent;
michael@0 19 }
michael@0 20
michael@0 21 /**
michael@0 22 * This class manages a ContentParent that it starts up ahead of any particular
michael@0 23 * need. You can then call Take() to get this process and use it. Since we
michael@0 24 * already started it up, it should be ready for use faster than if you'd
michael@0 25 * created the process when you needed it.
michael@0 26 *
michael@0 27 * This class watches the dom.ipc.processPrelaunch.enabled pref. If it changes
michael@0 28 * from false to true, it preallocates a process. If it changes from true to
michael@0 29 * false, it kills the preallocated process, if any.
michael@0 30 *
michael@0 31 * We don't expect this pref to flip between true and false in production, but
michael@0 32 * flipping the pref is important for tests.
michael@0 33 *
michael@0 34 * The static methods here are implemented by forwarding calls on to a
michael@0 35 * PreallocatedProcessManagerImpl singleton class, so if you add a new static
michael@0 36 * method here, you'll need to write a corresponding public method on the
michael@0 37 * singleton.
michael@0 38 */
michael@0 39 class PreallocatedProcessManager MOZ_FINAL
michael@0 40 {
michael@0 41 typedef mozilla::dom::ContentParent ContentParent;
michael@0 42
michael@0 43 public:
michael@0 44 /**
michael@0 45 * Create a process after a delay. We wait for a period of time (specified
michael@0 46 * by the dom.ipc.processPrelaunch.delayMs pref), then wait for this process
michael@0 47 * to go idle, then allocate the new process.
michael@0 48 *
michael@0 49 * If the dom.ipc.processPrelaunch.enabled pref is false, or if we already
michael@0 50 * have a preallocated process, this function does nothing.
michael@0 51 */
michael@0 52 static void AllocateAfterDelay();
michael@0 53
michael@0 54 /**
michael@0 55 * Create a process once this process goes idle.
michael@0 56 *
michael@0 57 * If the dom.ipc.processPrelaunch.enabled pref is false, or if we already
michael@0 58 * have a preallocated process, this function does nothing.
michael@0 59 */
michael@0 60 static void AllocateOnIdle();
michael@0 61
michael@0 62 /**
michael@0 63 * Create a process right now.
michael@0 64 *
michael@0 65 * If the dom.ipc.processPrelaunch.enabled pref is false, or if we already
michael@0 66 * have a preallocated process, this function does nothing.
michael@0 67 */
michael@0 68 static void AllocateNow();
michael@0 69
michael@0 70 /**
michael@0 71 * Take the preallocated process, if we have one. If we don't have one, this
michael@0 72 * returns null.
michael@0 73 *
michael@0 74 * If you call Take() twice in a row, the second call is guaranteed to return
michael@0 75 * null.
michael@0 76 *
michael@0 77 * After you Take() the preallocated process, you need to call one of the
michael@0 78 * Allocate* functions (or change the dom.ipc.processPrelaunch pref from
michael@0 79 * false to true) before we'll create a new process.
michael@0 80 */
michael@0 81 static already_AddRefed<ContentParent> Take();
michael@0 82
michael@0 83 #ifdef MOZ_NUWA_PROCESS
michael@0 84 static void PublishSpareProcess(ContentParent* aContent);
michael@0 85 static void MaybeForgetSpare(ContentParent* aContent);
michael@0 86 static void OnNuwaReady();
michael@0 87 static bool PreallocatedProcessReady();
michael@0 88 static void RunAfterPreallocatedProcessReady(nsIRunnable* aRunnable);
michael@0 89 #endif
michael@0 90
michael@0 91 private:
michael@0 92 PreallocatedProcessManager();
michael@0 93 DISALLOW_EVIL_CONSTRUCTORS(PreallocatedProcessManager);
michael@0 94 };
michael@0 95
michael@0 96 } // namespace mozilla
michael@0 97
michael@0 98 #endif // defined mozilla_PreallocatedProcessManager_h

mercurial