no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / dom / media / ipc / RDDChild.cpp
blobfb2e14bb4fb8910fdc63085c95848442d8be9d57
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 #include "RDDChild.h"
8 #include "mozilla/FOGIPC.h"
9 #include "mozilla/RDDProcessManager.h"
10 #include "mozilla/dom/ContentParent.h"
11 #include "mozilla/dom/MemoryReportRequest.h"
12 #include "mozilla/gfx/GPUProcessManager.h"
13 #include "mozilla/gfx/gfxVars.h"
14 #include "mozilla/ipc/CrashReporterHost.h"
15 #include "mozilla/ipc/Endpoint.h"
17 #if defined(XP_LINUX) && defined(MOZ_SANDBOX)
18 # include "mozilla/SandboxBroker.h"
19 # include "mozilla/SandboxBrokerPolicyFactory.h"
20 #endif
22 #include "mozilla/Telemetry.h"
23 #include "mozilla/TelemetryIPC.h"
25 #if defined(XP_WIN)
26 # include "mozilla/WinDllServices.h"
27 #endif
29 #include "ProfilerParent.h"
30 #include "RDDProcessHost.h"
32 namespace mozilla {
34 using namespace layers;
35 using namespace gfx;
37 RDDChild::RDDChild(RDDProcessHost* aHost) : mHost(aHost) {}
39 RDDChild::~RDDChild() = default;
41 bool RDDChild::Init() {
42 Maybe<FileDescriptor> brokerFd;
44 #if defined(XP_LINUX) && defined(MOZ_SANDBOX)
45 auto policy = SandboxBrokerPolicyFactory::GetRDDPolicy(OtherPid());
46 if (policy != nullptr) {
47 brokerFd = Some(FileDescriptor());
48 mSandboxBroker =
49 SandboxBroker::Create(std::move(policy), OtherPid(), brokerFd.ref());
50 // This is unlikely to fail and probably indicates OS resource
51 // exhaustion, but we can at least try to recover.
52 if (NS_WARN_IF(mSandboxBroker == nullptr)) {
53 return false;
55 MOZ_ASSERT(brokerFd.ref().IsValid());
57 #endif // XP_LINUX && MOZ_SANDBOX
59 nsTArray<GfxVarUpdate> updates = gfxVars::FetchNonDefaultVars();
61 bool isReadyForBackgroundProcessing = false;
62 #if defined(XP_WIN)
63 RefPtr<DllServices> dllSvc(DllServices::Get());
64 isReadyForBackgroundProcessing = dllSvc->IsReadyForBackgroundProcessing();
65 #endif
67 SendInit(updates, brokerFd, Telemetry::CanRecordReleaseData(),
68 isReadyForBackgroundProcessing);
70 Unused << SendInitProfiler(ProfilerParent::CreateForProcess(OtherPid()));
72 gfxVars::AddReceiver(this);
73 auto* gpm = gfx::GPUProcessManager::Get();
74 if (gpm) {
75 gpm->AddListener(this);
78 return true;
81 bool RDDChild::SendRequestMemoryReport(const uint32_t& aGeneration,
82 const bool& aAnonymize,
83 const bool& aMinimizeMemoryUsage,
84 const Maybe<FileDescriptor>& aDMDFile) {
85 mMemoryReportRequest = MakeUnique<MemoryReportRequestHost>(aGeneration);
87 PRDDChild::SendRequestMemoryReport(
88 aGeneration, aAnonymize, aMinimizeMemoryUsage, aDMDFile,
89 [&](const uint32_t& aGeneration2) {
90 if (RDDProcessManager* rddpm = RDDProcessManager::Get()) {
91 if (RDDChild* child = rddpm->GetRDDChild()) {
92 if (child->mMemoryReportRequest) {
93 child->mMemoryReportRequest->Finish(aGeneration2);
94 child->mMemoryReportRequest = nullptr;
99 [&](mozilla::ipc::ResponseRejectReason) {
100 if (RDDProcessManager* rddpm = RDDProcessManager::Get()) {
101 if (RDDChild* child = rddpm->GetRDDChild()) {
102 child->mMemoryReportRequest = nullptr;
107 return true;
110 void RDDChild::OnCompositorUnexpectedShutdown() {
111 auto* rddm = RDDProcessManager::Get();
112 if (rddm) {
113 rddm->CreateVideoBridge();
117 void RDDChild::OnVarChanged(const GfxVarUpdate& aVar) { SendUpdateVar(aVar); }
119 mozilla::ipc::IPCResult RDDChild::RecvAddMemoryReport(
120 const MemoryReport& aReport) {
121 if (mMemoryReportRequest) {
122 mMemoryReportRequest->RecvReport(aReport);
124 return IPC_OK();
127 #if defined(XP_WIN)
128 mozilla::ipc::IPCResult RDDChild::RecvGetModulesTrust(
129 ModulePaths&& aModPaths, bool aRunAtNormalPriority,
130 GetModulesTrustResolver&& aResolver) {
131 RefPtr<DllServices> dllSvc(DllServices::Get());
132 dllSvc->GetModulesTrust(std::move(aModPaths), aRunAtNormalPriority)
133 ->Then(
134 GetMainThreadSerialEventTarget(), __func__,
135 [aResolver](ModulesMapResult&& aResult) {
136 aResolver(Some(ModulesMapResult(std::move(aResult))));
138 [aResolver](nsresult aRv) { aResolver(Nothing()); });
139 return IPC_OK();
141 #endif // defined(XP_WIN)
143 mozilla::ipc::IPCResult RDDChild::RecvUpdateMediaCodecsSupported(
144 const media::MediaCodecsSupported& aSupported) {
145 dom::ContentParent::BroadcastMediaCodecsSupportedUpdate(
146 RemoteDecodeIn::RddProcess, aSupported);
147 return IPC_OK();
150 mozilla::ipc::IPCResult RDDChild::RecvAccumulateChildHistograms(
151 nsTArray<HistogramAccumulation>&& aAccumulations) {
152 TelemetryIPC::AccumulateChildHistograms(Telemetry::ProcessID::Rdd,
153 aAccumulations);
154 return IPC_OK();
157 mozilla::ipc::IPCResult RDDChild::RecvAccumulateChildKeyedHistograms(
158 nsTArray<KeyedHistogramAccumulation>&& aAccumulations) {
159 TelemetryIPC::AccumulateChildKeyedHistograms(Telemetry::ProcessID::Rdd,
160 aAccumulations);
161 return IPC_OK();
164 mozilla::ipc::IPCResult RDDChild::RecvUpdateChildScalars(
165 nsTArray<ScalarAction>&& aScalarActions) {
166 TelemetryIPC::UpdateChildScalars(Telemetry::ProcessID::Rdd, aScalarActions);
167 return IPC_OK();
170 mozilla::ipc::IPCResult RDDChild::RecvUpdateChildKeyedScalars(
171 nsTArray<KeyedScalarAction>&& aScalarActions) {
172 TelemetryIPC::UpdateChildKeyedScalars(Telemetry::ProcessID::Rdd,
173 aScalarActions);
174 return IPC_OK();
177 mozilla::ipc::IPCResult RDDChild::RecvRecordChildEvents(
178 nsTArray<mozilla::Telemetry::ChildEventData>&& aEvents) {
179 TelemetryIPC::RecordChildEvents(Telemetry::ProcessID::Rdd, aEvents);
180 return IPC_OK();
183 mozilla::ipc::IPCResult RDDChild::RecvRecordDiscardedData(
184 const mozilla::Telemetry::DiscardedData& aDiscardedData) {
185 TelemetryIPC::RecordDiscardedData(Telemetry::ProcessID::Rdd, aDiscardedData);
186 return IPC_OK();
189 mozilla::ipc::IPCResult RDDChild::RecvFOGData(ByteBuf&& aBuf) {
190 glean::FOGData(std::move(aBuf));
191 return IPC_OK();
194 void RDDChild::ActorDestroy(ActorDestroyReason aWhy) {
195 if (aWhy == AbnormalShutdown) {
196 GenerateCrashReport(OtherPid());
199 auto* gpm = gfx::GPUProcessManager::Get();
200 if (gpm) {
201 // Note: the manager could have shutdown already.
202 gpm->RemoveListener(this);
205 gfxVars::RemoveReceiver(this);
206 mHost->OnChannelClosed();
209 class DeferredDeleteRDDChild : public Runnable {
210 public:
211 explicit DeferredDeleteRDDChild(RefPtr<RDDChild>&& aChild)
212 : Runnable("gfx::DeferredDeleteRDDChild"), mChild(std::move(aChild)) {}
214 NS_IMETHODIMP Run() override { return NS_OK; }
216 private:
217 RefPtr<RDDChild> mChild;
220 /* static */
221 void RDDChild::Destroy(RefPtr<RDDChild>&& aChild) {
222 NS_DispatchToMainThread(new DeferredDeleteRDDChild(std::move(aChild)));
225 } // namespace mozilla