File: RDDProcessManager.h

package info (click to toggle)
firefox 149.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,767,760 kB
  • sloc: cpp: 7,416,064; javascript: 6,752,859; ansic: 3,774,850; python: 1,250,473; xml: 641,578; asm: 439,191; java: 186,617; sh: 56,634; makefile: 18,856; objc: 13,092; perl: 12,763; pascal: 5,960; yacc: 4,583; cs: 3,846; lex: 1,720; ruby: 1,002; php: 436; lisp: 258; awk: 105; sql: 66; sed: 53; csh: 10; exp: 6
file content (130 lines) | stat: -rw-r--r-- 4,432 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef _include_dom_media_ipc_RDDProcessManager_h_
#define _include_dom_media_ipc_RDDProcessManager_h_
#include "mozilla/MozPromise.h"
#include "mozilla/PRDDChild.h"
#include "mozilla/PRemoteMediaManagerChild.h"
#include "mozilla/RDDProcessHost.h"
#include "mozilla/dom/ipc/IdType.h"
#include "mozilla/ipc/TaskFactory.h"
#include "nsIObserver.h"

namespace mozilla {

class MemoryReportingProcess;
class RDDChild;

// The RDDProcessManager is a singleton responsible for creating RDD-bound
// objects that may live in another process. Currently, it provides access
// to the RDD process via ContentParent.
class RDDProcessManager final : public RDDProcessHost::Listener {
  friend class RDDChild;

 public:
  static void Initialize();
  static void RDDProcessShutdown();
  static void Shutdown();
  static RDDProcessManager* Get();

  ~RDDProcessManager();

  using EnsureRDDPromise =
      MozPromise<ipc::Endpoint<PRemoteMediaManagerChild>, nsresult, true>;
  // Launch a new RDD process asynchronously
  RefPtr<GenericNonExclusivePromise> LaunchRDDProcess();
  // If not using a RDD process, launch a new RDD process asynchronously and
  // create a RemoteMediaManager bridge
  RefPtr<EnsureRDDPromise> EnsureRDDProcessAndCreateBridge(
      ipc::EndpointProcInfo aOtherProcess, dom::ContentParentId aParentId);

  void OnProcessUnexpectedShutdown(RDDProcessHost* aHost) override;

  // Notify the RDDProcessManager that a top-level PRDD protocol has been
  // terminated. This may be called from any thread.
  void NotifyRemoteActorDestroyed(const uint64_t& aProcessToken);

  // Returns -1 if there is no RDD process, or the platform pid for it.
  base::ProcessId RDDProcessPid();

  // Returns Invalid if there is no RDD process, or the proc info for it.
  ipc::EndpointProcInfo RDDEndpointProcInfo();

  // If a RDD process is present, create a MemoryReportingProcess object.
  // Otherwise, return null.
  RefPtr<MemoryReportingProcess> GetProcessMemoryReporter();

  // Returns access to the PRDD protocol if a RDD process is present.
  RDDChild* GetRDDChild() { return mRDDChild; }

  // Returns whether or not a RDD process was ever launched.
  bool AttemptedRDDProcess() const { return mNumProcessAttempts > 0; }

  // Returns the RDD Process
  RDDProcessHost* Process() { return mProcess; }

  /*
   * ** Test-only Method **
   *
   * Trigger RDD-process test metric instrumentation.
   */
  RefPtr<PRDDChild::TestTriggerMetricsPromise> TestTriggerMetrics();

 private:
  bool IsRDDProcessLaunching() const;
  bool IsRDDProcessAlive() const;

  // Called from our xpcom-shutdown observer.
  void OnXPCOMShutdown();
  void OnPreferenceChange(const char16_t* aData);

  RDDProcessManager();

  // Shutdown the RDD process.
  void DestroyProcess();

  bool IsShutdown() const;

  DISALLOW_COPY_AND_ASSIGN(RDDProcessManager);

  class Observer final : public nsIObserver {
   public:
    NS_DECL_ISUPPORTS
    NS_DECL_NSIOBSERVER
    explicit Observer(RDDProcessManager* aManager);

   protected:
    ~Observer() = default;

    RDDProcessManager* mManager;
  };
  friend class Observer;

  bool CreateContentBridge(
      ipc::EndpointProcInfo aOtherProcess, dom::ContentParentId aParentId,
      ipc::Endpoint<PRemoteMediaManagerChild>* aOutRemoteMediaManager);

  const RefPtr<Observer> mObserver;
  ipc::TaskFactory<RDDProcessManager> mTaskFactory;
  uint32_t mNumProcessAttempts = 0;
  uint32_t mNumUnexpectedCrashes = 0;

  // Fields that are associated with the current RDD process.
  RDDProcessHost* mProcess = nullptr;
  uint64_t mProcessToken = 0;
  RDDChild* mRDDChild = nullptr;
  // Collects any pref changes that occur during process launch (after
  // the initial map is passed in command-line arguments) to be sent
  // when the process can receive IPC messages.
  nsTArray<dom::Pref> mQueuedPrefs;
  // Promise will be resolved when the RDD process has been fully started and
  // VideoBridge configured. Only accessed on the main thread.
  RefPtr<GenericNonExclusivePromise> mLaunchRDDPromise;
};

}  // namespace mozilla

#endif  // _include_dom_media_ipc_RDDProcessManager_h_