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
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef GFX_VR_PROCESS_MANAGER_H
7 #define GFX_VR_PROCESS_MANAGER_H
9 #include "VRProcessParent.h"
11 #include "mozilla/ipc/ProtocolUtils.h"
12 #include "nsIObserver.h"
15 class MemoryReportingProcess
;
26 // The VRProcessManager is a singleton responsible for creating VR-bound
27 // objects that may live in another process.
28 class VRProcessManager final
: public VRProcessParent::Listener
{
30 static VRProcessManager
* Get();
31 static void Initialize();
32 static void Shutdown();
36 // If not using a VR process, launch a new VR process asynchronously.
37 void LaunchVRProcess();
39 // Ensure that VR-bound methods can be used. If no VR process is being
40 // used, or one is launched and ready, this function returns immediately.
41 // Otherwise it blocks until the VR process has finished launching.
44 bool CreateGPUBridges(mozilla::ipc::EndpointProcInfo aOtherProcess
,
45 mozilla::ipc::Endpoint
<PVRGPUChild
>* aOutVRBridge
);
47 VRChild
* GetVRChild();
48 // If a VR process is present, create a MemoryReportingProcess object.
49 // Otherwise, return null.
50 RefPtr
<MemoryReportingProcess
> GetProcessMemoryReporter();
52 virtual void OnProcessLaunchComplete(VRProcessParent
* aParent
) override
;
53 virtual void OnProcessUnexpectedShutdown(VRProcessParent
* aParent
) override
;
58 DISALLOW_COPY_AND_ASSIGN(VRProcessManager
);
60 bool CreateGPUVRManager(mozilla::ipc::EndpointProcInfo aOtherProcess
,
61 mozilla::ipc::Endpoint
<PVRGPUChild
>* aOutEndpoint
);
62 void OnXPCOMShutdown();
63 void OnPreferenceChange(const char16_t
* aData
);
65 void DestroyProcess();
67 // Permanently disable the VR process and record a message why.
68 void DisableVRProcess(const char* aMessage
);
70 class Observer final
: public nsIObserver
{
74 explicit Observer(VRProcessManager
* aManager
);
77 ~Observer() = default;
79 VRProcessManager
* mManager
;
81 friend class Observer
;
83 RefPtr
<Observer
> mObserver
;
84 VRProcessParent
* mProcess
;
86 // Collects any pref changes that occur during process launch (after
87 // the initial map is passed in command-line arguments) to be sent
88 // when the process can receive IPC messages.
89 nsTArray
<mozilla::dom::Pref
> mQueuedPrefs
;
93 } // namespace mozilla
95 #endif // GFX_VR_PROCESS_MANAGER_H