tor-browser

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

VRProcessParent.h (2793B)


      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 
      7 #ifndef GFX_VR_PROCESS_PARENT_H
      8 #define GFX_VR_PROCESS_PARENT_H
      9 
     10 #include "mozilla/UniquePtr.h"
     11 
     12 #include "mozilla/ipc/GeckoChildProcessHost.h"
     13 #include "mozilla/ipc/TaskFactory.h"
     14 
     15 namespace mozilla {
     16 namespace ipc {
     17 class SharedPreferenceSerializer;
     18 }
     19 namespace gfx {
     20 
     21 class VRChild;
     22 
     23 class VRProcessParent final : public mozilla::ipc::GeckoChildProcessHost {
     24 public:
     25  class Listener {
     26   public:
     27    virtual void OnProcessLaunchComplete(VRProcessParent* aParent) {}
     28 
     29    // Follow GPU and RDD process manager, adding this to avoid
     30    // unexpectedly shutdown or had its connection severed.
     31    // This is not called if an error occurs after calling Shutdown().
     32    virtual void OnProcessUnexpectedShutdown(VRProcessParent* aParent) {}
     33  };
     34 
     35  explicit VRProcessParent(Listener* aListener);
     36 
     37  // Launch the subprocess asynchronously. On failure, false is returned.
     38  // Otherwise, true is returned, and the OnProcessLaunchComplete listener
     39  // callback will be invoked either when a connection has been established, or
     40  // if a connection could not be established due to an asynchronous error.
     41  bool Launch();
     42  // If the process is being launched, block until it has launched and
     43  // connected. If a launch task is pending, it will fire immediately.
     44  //
     45  // Returns true if the process is successfully connected; false otherwise.
     46  bool WaitForLaunch();
     47  void Shutdown();
     48  void DestroyProcess();
     49  bool CanShutdown() override { return true; }
     50 
     51  void OnChannelConnected(base::ProcessId peer_pid) override;
     52  void OnChannelConnectedTask();
     53  void OnChannelErrorTask();
     54  void OnChannelClosed();
     55  bool IsConnected() const;
     56 
     57  VRChild* GetActor() const { return mVRChild.get(); }
     58  // Return a unique id for this process, guaranteed not to be shared with any
     59  // past or future instance of VRProcessParent.
     60  uint64_t GetProcessToken() const;
     61 
     62 private:
     63  ~VRProcessParent();
     64 
     65  DISALLOW_COPY_AND_ASSIGN(VRProcessParent);
     66 
     67  bool InitAfterConnect(bool aSucceeded);
     68  void KillHard(const char* aReason);
     69 
     70  RefPtr<VRChild> mVRChild;
     71  mozilla::ipc::TaskFactory<VRProcessParent> mTaskFactory;
     72  nsCOMPtr<nsIThread> mLaunchThread;
     73  Listener* mListener;
     74 
     75  enum class LaunchPhase { Unlaunched, Waiting, Complete };
     76  LaunchPhase mLaunchPhase;
     77  bool mChannelClosed;
     78  bool mShutdownRequested;
     79  UniquePtr<mozilla::ipc::SharedPreferenceSerializer> mPrefSerializer;
     80 };
     81 
     82 }  // namespace gfx
     83 }  // namespace mozilla
     84 
     85 #endif  // ifndef GFX_VR_PROCESS_PARENT_H