tor-browser

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

BackgroundParent.h (3578B)


      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/. */
      6 
      7 #ifndef mozilla_ipc_backgroundparent_h__
      8 #define mozilla_ipc_backgroundparent_h__
      9 
     10 #include "base/process.h"
     11 #include "mozilla/dom/ContentParent.h"
     12 #include "nsStringFwd.h"
     13 #include "nsTArrayForwardDeclare.h"
     14 
     15 #ifdef DEBUG
     16 #  include "nsXULAppAPI.h"
     17 #endif
     18 
     19 template <class>
     20 struct already_AddRefed;
     21 
     22 namespace mozilla {
     23 
     24 namespace net {
     25 
     26 class SocketProcessBridgeParent;
     27 class SocketProcessParent;
     28 
     29 }  // namespace net
     30 
     31 namespace dom {
     32 
     33 class BlobImpl;
     34 class ContentParent;
     35 
     36 }  // namespace dom
     37 
     38 namespace ipc {
     39 
     40 class BackgroundStarterParent;
     41 class PBackgroundParent;
     42 class PBackgroundStarterParent;
     43 
     44 template <class PFooSide>
     45 class Endpoint;
     46 
     47 // This class is not designed for public consumption beyond the few static
     48 // member functions.
     49 class BackgroundParent final {
     50  friend class mozilla::ipc::BackgroundStarterParent;
     51  friend class mozilla::dom::ContentParent;
     52  friend class mozilla::net::SocketProcessBridgeParent;
     53  friend class mozilla::net::SocketProcessParent;
     54 
     55  using ProcessId = base::ProcessId;
     56  using BlobImpl = mozilla::dom::BlobImpl;
     57  using ContentParent = mozilla::dom::ContentParent;
     58  using ThreadsafeContentParentHandle =
     59      mozilla::dom::ThreadsafeContentParentHandle;
     60 
     61 public:
     62  // Get the nsISerialEventTarget used to handle messages from BackgroundParent
     63  // actors, if it is running.
     64  //
     65  // This function may only be called on the background or main thread.
     66  static already_AddRefed<nsISerialEventTarget> GetBackgroundThread();
     67 
     68  // This function allows the caller to determine if the given parent actor
     69  // corresponds to a child actor from another process or a child actor from a
     70  // different thread in the same process.
     71  // This function may only be called on the background thread.
     72  static bool IsOtherProcessActor(PBackgroundParent* aBackgroundActor);
     73 
     74  // This function returns a handle to the ContentParent associated with the
     75  // parent actor if the parent actor corresponds to a child actor from another
     76  // content process. If the parent actor corresponds to a child actor from a
     77  // different thread in the same process then this function returns null.
     78  //
     79  // This function may only be called on the background thread.
     80  static ThreadsafeContentParentHandle* GetContentParentHandle(
     81      PBackgroundParent* aBackgroundActor);
     82 
     83  static uint64_t GetChildID(PBackgroundParent* aBackgroundActor);
     84 
     85  static void KillHardAsync(PBackgroundParent* aBackgroundActor,
     86                            const nsACString& aReason);
     87 
     88 private:
     89  // Only called by ContentParent for cross-process actors.
     90  static bool AllocStarter(ContentParent* aContent,
     91                           Endpoint<PBackgroundStarterParent>&& aEndpoint);
     92 
     93  // Called by SocketProcessBridgeParent and SocketProcessParent for
     94  // cross-process actors.
     95  static bool AllocStarter(Endpoint<PBackgroundStarterParent>&& aEndpoint);
     96 };
     97 
     98 // Implemented in BackgroundImpl.cpp.
     99 bool IsOnBackgroundThread();
    100 
    101 #ifdef DEBUG
    102 
    103 // Implemented in BackgroundImpl.cpp.
    104 void AssertIsOnBackgroundThread();
    105 
    106 #else
    107 
    108 inline void AssertIsOnBackgroundThread() {}
    109 
    110 #endif  // DEBUG
    111 
    112 inline void AssertIsInMainProcess() { MOZ_ASSERT(XRE_IsParentProcess()); }
    113 
    114 }  // namespace ipc
    115 }  // namespace mozilla
    116 
    117 #endif  // mozilla_ipc_backgroundparent_h__