Bug 1936278 - Prevent search mode chiclet from being dismissed when clicking in page...
[gecko.git] / dom / ipc / PreallocatedProcessManager.h
blobbd62c97a8162d64f0519646f7ed12d647c93abfb
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/. */
7 #ifndef mozilla_PreallocatedProcessManager_h
8 #define mozilla_PreallocatedProcessManager_h
10 #include "base/basictypes.h"
11 #include "mozilla/dom/UniqueContentParentKeepAlive.h"
12 #include "nsStringFwd.h"
14 namespace mozilla {
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.
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.
26 * We don't expect this pref to flip between true and false in production, but
27 * flipping the pref is important for tests.
29 class PreallocatedProcessManagerImpl;
31 class PreallocatedProcessManager final {
32 using ContentParent = mozilla::dom::ContentParent;
33 using UniqueContentParentKeepAlive =
34 mozilla::dom::UniqueContentParentKeepAlive;
36 public:
37 static PreallocatedProcessManagerImpl* GetPPMImpl();
39 static bool Enabled();
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.
46 static void AddBlocker(const nsACString& aRemoteType, ContentParent* aParent);
47 static void RemoveBlocker(const nsACString& aRemoteType,
48 ContentParent* aParent);
50 /**
51 * Take a preallocated process, if we have one. If we don't have a
52 * preallocated process to return, this returns null.
54 * If we use a preallocated process, it will schedule the start of
55 * another on Idle (AllocateOnIdle()).
57 static UniqueContentParentKeepAlive Take(const nsACString& aRemoteType);
59 /**
60 * Note that a process was shut down, and should no longer be tracked as a
61 * preallocated process.
63 static void Erase(ContentParent* aParent);
65 private:
66 PreallocatedProcessManager();
67 DISALLOW_EVIL_CONSTRUCTORS(PreallocatedProcessManager);
70 } // namespace mozilla
72 #endif // defined mozilla_PreallocatedProcessManager_h