tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

VRProcessManager.h (2936B)


      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
      8 
      9 #include "VRProcessParent.h"
     10 
     11 #include "mozilla/ipc/ProtocolUtils.h"
     12 #include "nsIObserver.h"
     13 
     14 namespace mozilla {
     15 class MemoryReportingProcess;
     16 namespace ipc {
     17 template <typename T>
     18 class Endpoint;
     19 }
     20 namespace gfx {
     21 
     22 class VRManagerChild;
     23 class PVRGPUChild;
     24 class VRChild;
     25 
     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 {
     29 public:
     30  static VRProcessManager* Get();
     31  static void Initialize();
     32  static void Shutdown();
     33 
     34  ~VRProcessManager();
     35 
     36  // If not using a VR process, launch a new VR process asynchronously.
     37  void LaunchVRProcess();
     38 
     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.
     42  bool EnsureVRReady();
     43 
     44  bool CreateGPUBridges(mozilla::ipc::EndpointProcInfo aOtherProcess,
     45                        mozilla::ipc::Endpoint<PVRGPUChild>* aOutVRBridge);
     46 
     47  VRChild* GetVRChild();
     48  // If a VR process is present, create a MemoryReportingProcess object.
     49  // Otherwise, return null.
     50  RefPtr<MemoryReportingProcess> GetProcessMemoryReporter();
     51 
     52  virtual void OnProcessLaunchComplete(VRProcessParent* aParent) override;
     53  virtual void OnProcessUnexpectedShutdown(VRProcessParent* aParent) override;
     54 
     55 private:
     56  VRProcessManager();
     57 
     58  DISALLOW_COPY_AND_ASSIGN(VRProcessManager);
     59 
     60  bool CreateGPUVRManager(mozilla::ipc::EndpointProcInfo aOtherProcess,
     61                          mozilla::ipc::Endpoint<PVRGPUChild>* aOutEndpoint);
     62  void OnXPCOMShutdown();
     63  void OnPreferenceChange(const char16_t* aData);
     64  void CleanShutdown();
     65  void DestroyProcess();
     66 
     67  // Permanently disable the VR process and record a message why.
     68  void DisableVRProcess(const char* aMessage);
     69 
     70  class Observer final : public nsIObserver {
     71   public:
     72    NS_DECL_ISUPPORTS
     73    NS_DECL_NSIOBSERVER
     74    explicit Observer(VRProcessManager* aManager);
     75 
     76   protected:
     77    ~Observer() = default;
     78 
     79    VRProcessManager* mManager;
     80  };
     81  friend class Observer;
     82 
     83  RefPtr<Observer> mObserver;
     84  VRProcessParent* mProcess;
     85  VRChild* mVRChild;
     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;
     90 };
     91 
     92 }  // namespace gfx
     93 }  // namespace mozilla
     94 
     95 #endif  // GFX_VR_PROCESS_MANAGER_H