michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set sw=2 ts=8 et ft=cpp : */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_PreallocatedProcessManager_h michael@0: #define mozilla_PreallocatedProcessManager_h michael@0: michael@0: #include "base/basictypes.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsIObserver.h" michael@0: michael@0: class nsIRunnable; michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: class ContentParent; michael@0: } michael@0: michael@0: /** michael@0: * This class manages a ContentParent that it starts up ahead of any particular michael@0: * need. You can then call Take() to get this process and use it. Since we michael@0: * already started it up, it should be ready for use faster than if you'd michael@0: * created the process when you needed it. michael@0: * michael@0: * This class watches the dom.ipc.processPrelaunch.enabled pref. If it changes michael@0: * from false to true, it preallocates a process. If it changes from true to michael@0: * false, it kills the preallocated process, if any. michael@0: * michael@0: * We don't expect this pref to flip between true and false in production, but michael@0: * flipping the pref is important for tests. michael@0: * michael@0: * The static methods here are implemented by forwarding calls on to a michael@0: * PreallocatedProcessManagerImpl singleton class, so if you add a new static michael@0: * method here, you'll need to write a corresponding public method on the michael@0: * singleton. michael@0: */ michael@0: class PreallocatedProcessManager MOZ_FINAL michael@0: { michael@0: typedef mozilla::dom::ContentParent ContentParent; michael@0: michael@0: public: michael@0: /** michael@0: * Create a process after a delay. We wait for a period of time (specified michael@0: * by the dom.ipc.processPrelaunch.delayMs pref), then wait for this process michael@0: * to go idle, then allocate the new process. michael@0: * michael@0: * If the dom.ipc.processPrelaunch.enabled pref is false, or if we already michael@0: * have a preallocated process, this function does nothing. michael@0: */ michael@0: static void AllocateAfterDelay(); michael@0: michael@0: /** michael@0: * Create a process once this process goes idle. michael@0: * michael@0: * If the dom.ipc.processPrelaunch.enabled pref is false, or if we already michael@0: * have a preallocated process, this function does nothing. michael@0: */ michael@0: static void AllocateOnIdle(); michael@0: michael@0: /** michael@0: * Create a process right now. michael@0: * michael@0: * If the dom.ipc.processPrelaunch.enabled pref is false, or if we already michael@0: * have a preallocated process, this function does nothing. michael@0: */ michael@0: static void AllocateNow(); michael@0: michael@0: /** michael@0: * Take the preallocated process, if we have one. If we don't have one, this michael@0: * returns null. michael@0: * michael@0: * If you call Take() twice in a row, the second call is guaranteed to return michael@0: * null. michael@0: * michael@0: * After you Take() the preallocated process, you need to call one of the michael@0: * Allocate* functions (or change the dom.ipc.processPrelaunch pref from michael@0: * false to true) before we'll create a new process. michael@0: */ michael@0: static already_AddRefed Take(); michael@0: michael@0: #ifdef MOZ_NUWA_PROCESS michael@0: static void PublishSpareProcess(ContentParent* aContent); michael@0: static void MaybeForgetSpare(ContentParent* aContent); michael@0: static void OnNuwaReady(); michael@0: static bool PreallocatedProcessReady(); michael@0: static void RunAfterPreallocatedProcessReady(nsIRunnable* aRunnable); michael@0: #endif michael@0: michael@0: private: michael@0: PreallocatedProcessManager(); michael@0: DISALLOW_EVIL_CONSTRUCTORS(PreallocatedProcessManager); michael@0: }; michael@0: michael@0: } // namespace mozilla michael@0: michael@0: #endif // defined mozilla_PreallocatedProcessManager_h