1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/ipc/PreallocatedProcessManager.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,98 @@ 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_PreallocatedProcessManager_h 1.11 +#define mozilla_PreallocatedProcessManager_h 1.12 + 1.13 +#include "base/basictypes.h" 1.14 +#include "nsCOMPtr.h" 1.15 +#include "nsIObserver.h" 1.16 + 1.17 +class nsIRunnable; 1.18 + 1.19 +namespace mozilla { 1.20 +namespace dom { 1.21 +class ContentParent; 1.22 +} 1.23 + 1.24 +/** 1.25 + * This class manages a ContentParent that it starts up ahead of any particular 1.26 + * need. You can then call Take() to get this process and use it. Since we 1.27 + * already started it up, it should be ready for use faster than if you'd 1.28 + * created the process when you needed it. 1.29 + * 1.30 + * This class watches the dom.ipc.processPrelaunch.enabled pref. If it changes 1.31 + * from false to true, it preallocates a process. If it changes from true to 1.32 + * false, it kills the preallocated process, if any. 1.33 + * 1.34 + * We don't expect this pref to flip between true and false in production, but 1.35 + * flipping the pref is important for tests. 1.36 + * 1.37 + * The static methods here are implemented by forwarding calls on to a 1.38 + * PreallocatedProcessManagerImpl singleton class, so if you add a new static 1.39 + * method here, you'll need to write a corresponding public method on the 1.40 + * singleton. 1.41 + */ 1.42 +class PreallocatedProcessManager MOZ_FINAL 1.43 +{ 1.44 + typedef mozilla::dom::ContentParent ContentParent; 1.45 + 1.46 +public: 1.47 + /** 1.48 + * Create a process after a delay. We wait for a period of time (specified 1.49 + * by the dom.ipc.processPrelaunch.delayMs pref), then wait for this process 1.50 + * to go idle, then allocate the new process. 1.51 + * 1.52 + * If the dom.ipc.processPrelaunch.enabled pref is false, or if we already 1.53 + * have a preallocated process, this function does nothing. 1.54 + */ 1.55 + static void AllocateAfterDelay(); 1.56 + 1.57 + /** 1.58 + * Create a process once this process goes idle. 1.59 + * 1.60 + * If the dom.ipc.processPrelaunch.enabled pref is false, or if we already 1.61 + * have a preallocated process, this function does nothing. 1.62 + */ 1.63 + static void AllocateOnIdle(); 1.64 + 1.65 + /** 1.66 + * Create a process right now. 1.67 + * 1.68 + * If the dom.ipc.processPrelaunch.enabled pref is false, or if we already 1.69 + * have a preallocated process, this function does nothing. 1.70 + */ 1.71 + static void AllocateNow(); 1.72 + 1.73 + /** 1.74 + * Take the preallocated process, if we have one. If we don't have one, this 1.75 + * returns null. 1.76 + * 1.77 + * If you call Take() twice in a row, the second call is guaranteed to return 1.78 + * null. 1.79 + * 1.80 + * After you Take() the preallocated process, you need to call one of the 1.81 + * Allocate* functions (or change the dom.ipc.processPrelaunch pref from 1.82 + * false to true) before we'll create a new process. 1.83 + */ 1.84 + static already_AddRefed<ContentParent> Take(); 1.85 + 1.86 +#ifdef MOZ_NUWA_PROCESS 1.87 + static void PublishSpareProcess(ContentParent* aContent); 1.88 + static void MaybeForgetSpare(ContentParent* aContent); 1.89 + static void OnNuwaReady(); 1.90 + static bool PreallocatedProcessReady(); 1.91 + static void RunAfterPreallocatedProcessReady(nsIRunnable* aRunnable); 1.92 +#endif 1.93 + 1.94 +private: 1.95 + PreallocatedProcessManager(); 1.96 + DISALLOW_EVIL_CONSTRUCTORS(PreallocatedProcessManager); 1.97 +}; 1.98 + 1.99 +} // namespace mozilla 1.100 + 1.101 +#endif // defined mozilla_PreallocatedProcessManager_h