/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* 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/. */ #include "SocketProcessParent.h" #include "SocketProcessHost.h" #include "mozilla/ipc/CrashReporterHost.h" #include "mozilla/Telemetry.h" #include "mozilla/TelemetryIPC.h" #ifdef MOZ_WEBRTC # include "mozilla/dom/ContentProcessManager.h" # include "mozilla/dom/BrowserParent.h" # include "mozilla/net/WebrtcProxyChannelParent.h" #endif namespace mozilla { namespace net { static SocketProcessParent* sSocketProcessParent; SocketProcessParent::SocketProcessParent(SocketProcessHost* aHost) : mHost(aHost) { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(mHost); MOZ_COUNT_CTOR(SocketProcessParent); sSocketProcessParent = this; } SocketProcessParent::~SocketProcessParent() { MOZ_ASSERT(NS_IsMainThread()); MOZ_COUNT_DTOR(SocketProcessParent); sSocketProcessParent = nullptr; } /* static */ SocketProcessParent* SocketProcessParent::GetSingleton() { MOZ_ASSERT(NS_IsMainThread()); return sSocketProcessParent; } mozilla::ipc::IPCResult SocketProcessParent::RecvInitCrashReporter( Shmem&& aShmem, const NativeThreadId& aThreadId) { mCrashReporter = MakeUnique(GeckoProcessType_Content, aShmem, aThreadId); return IPC_OK(); } void SocketProcessParent::ActorDestroy(ActorDestroyReason aWhy) { if (aWhy == AbnormalShutdown) { if (mCrashReporter) { mCrashReporter->GenerateCrashReport(OtherPid()); mCrashReporter = nullptr; } } if (mHost) { mHost->OnChannelClosed(); } } bool SocketProcessParent::SendRequestMemoryReport( const uint32_t& aGeneration, const bool& aAnonymize, const bool& aMinimizeMemoryUsage, const Maybe& aDMDFile) { mMemoryReportRequest = MakeUnique(aGeneration); Unused << PSocketProcessParent::SendRequestMemoryReport( aGeneration, aAnonymize, aMinimizeMemoryUsage, aDMDFile); return true; } mozilla::ipc::IPCResult SocketProcessParent::RecvAddMemoryReport( const MemoryReport& aReport) { if (mMemoryReportRequest) { mMemoryReportRequest->RecvReport(aReport); } return IPC_OK(); } mozilla::ipc::IPCResult SocketProcessParent::RecvFinishMemoryReport( const uint32_t& aGeneration) { if (mMemoryReportRequest) { mMemoryReportRequest->Finish(aGeneration); mMemoryReportRequest = nullptr; } return IPC_OK(); } mozilla::ipc::IPCResult SocketProcessParent::RecvAccumulateChildHistograms( InfallibleTArray&& aAccumulations) { TelemetryIPC::AccumulateChildHistograms(Telemetry::ProcessID::Socket, aAccumulations); return IPC_OK(); } mozilla::ipc::IPCResult SocketProcessParent::RecvAccumulateChildKeyedHistograms( InfallibleTArray&& aAccumulations) { TelemetryIPC::AccumulateChildKeyedHistograms(Telemetry::ProcessID::Socket, aAccumulations); return IPC_OK(); } mozilla::ipc::IPCResult SocketProcessParent::RecvUpdateChildScalars( InfallibleTArray&& aScalarActions) { TelemetryIPC::UpdateChildScalars(Telemetry::ProcessID::Socket, aScalarActions); return IPC_OK(); } mozilla::ipc::IPCResult SocketProcessParent::RecvUpdateChildKeyedScalars( InfallibleTArray&& aScalarActions) { TelemetryIPC::UpdateChildKeyedScalars(Telemetry::ProcessID::Socket, aScalarActions); return IPC_OK(); } mozilla::ipc::IPCResult SocketProcessParent::RecvRecordChildEvents( nsTArray&& aEvents) { TelemetryIPC::RecordChildEvents(Telemetry::ProcessID::Socket, aEvents); return IPC_OK(); } mozilla::ipc::IPCResult SocketProcessParent::RecvRecordDiscardedData( const mozilla::Telemetry::DiscardedData& aDiscardedData) { TelemetryIPC::RecordDiscardedData(Telemetry::ProcessID::Socket, aDiscardedData); return IPC_OK(); } PWebrtcProxyChannelParent* SocketProcessParent::AllocPWebrtcProxyChannelParent( const TabId& aTabId) { #ifdef MOZ_WEBRTC WebrtcProxyChannelParent* parent = new WebrtcProxyChannelParent(aTabId); parent->AddRef(); return parent; #else return nullptr; #endif } bool SocketProcessParent::DeallocPWebrtcProxyChannelParent( PWebrtcProxyChannelParent* aActor) { #ifdef MOZ_WEBRTC WebrtcProxyChannelParent* parent = static_cast(aActor); parent->Release(); #endif return true; } // To ensure that IPDL is finished before SocketParent gets deleted. class DeferredDeleteSocketProcessParent : public Runnable { public: explicit DeferredDeleteSocketProcessParent( UniquePtr&& aParent) : Runnable("net::DeferredDeleteSocketProcessParent"), mParent(std::move(aParent)) {} NS_IMETHODIMP Run() override { return NS_OK; } private: UniquePtr mParent; }; /* static */ void SocketProcessParent::Destroy(UniquePtr&& aParent) { NS_DispatchToMainThread( new DeferredDeleteSocketProcessParent(std::move(aParent))); } } // namespace net } // namespace mozilla