PreallocatedProcessManager.h (2567B)
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_PreallocatedProcessManager_h 8 #define mozilla_PreallocatedProcessManager_h 9 10 #include "base/basictypes.h" 11 #include "mozilla/dom/UniqueContentParentKeepAlive.h" 12 #include "nsStringFwd.h" 13 14 namespace mozilla { 15 16 /** 17 * This class manages a ContentParent that it starts up ahead of any particular 18 * need. You can then call Take() to get this process and use it. Since we 19 * already started it up, it should be ready for use faster than if you'd 20 * created the process when you needed it. 21 * 22 * This class watches the dom.ipc.processPrelaunch.enabled pref. If it changes 23 * from false to true, it preallocates a process. If it changes from true to 24 * false, it kills the preallocated process, if any. 25 * 26 * We don't expect this pref to flip between true and false in production, but 27 * flipping the pref is important for tests. 28 */ 29 class PreallocatedProcessManagerImpl; 30 31 class PreallocatedProcessManager final { 32 using ContentParent = mozilla::dom::ContentParent; 33 using UniqueContentParentKeepAlive = 34 mozilla::dom::UniqueContentParentKeepAlive; 35 36 public: 37 static PreallocatedProcessManagerImpl* GetPPMImpl(); 38 39 static bool Enabled(); 40 41 /** 42 * Before first paint we don't want to allocate any processes in the 43 * background. To avoid that, the PreallocatedProcessManager won't start up 44 * any processes while there is a blocker active. 45 */ 46 static void AddBlocker(const nsACString& aRemoteType, ContentParent* aParent); 47 static void RemoveBlocker(const nsACString& aRemoteType, 48 ContentParent* aParent); 49 50 /** 51 * Take a preallocated process, if we have one. If we don't have a 52 * preallocated process to return, this returns null. 53 * 54 * If we use a preallocated process, it will schedule the start of 55 * another on Idle (AllocateOnIdle()). 56 */ 57 static UniqueContentParentKeepAlive Take(const nsACString& aRemoteType); 58 59 /** 60 * Note that a process was shut down, and should no longer be tracked as a 61 * preallocated process. 62 */ 63 static void Erase(ContentParent* aParent); 64 65 private: 66 PreallocatedProcessManager(); 67 DISALLOW_EVIL_CONSTRUCTORS(PreallocatedProcessManager); 68 }; 69 70 } // namespace mozilla 71 72 #endif // defined mozilla_PreallocatedProcessManager_h