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