зеркало из https://github.com/mozilla/gecko-dev.git
188 строки
5.7 KiB
C++
188 строки
5.7 KiB
C++
/* -*- 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/net/DNSRequestParent.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/WebrtcTCPSocketParent.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;
|
|
}
|
|
|
|
void SocketProcessParent::ActorDestroy(ActorDestroyReason aWhy) {
|
|
if (aWhy == AbnormalShutdown) {
|
|
GenerateCrashReport(OtherPid());
|
|
}
|
|
|
|
if (mHost) {
|
|
mHost->OnChannelClosed();
|
|
}
|
|
}
|
|
|
|
bool SocketProcessParent::SendRequestMemoryReport(
|
|
const uint32_t& aGeneration, const bool& aAnonymize,
|
|
const bool& aMinimizeMemoryUsage,
|
|
const Maybe<ipc::FileDescriptor>& aDMDFile) {
|
|
mMemoryReportRequest = MakeUnique<dom::MemoryReportRequestHost>(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(
|
|
nsTArray<HistogramAccumulation>&& aAccumulations) {
|
|
TelemetryIPC::AccumulateChildHistograms(Telemetry::ProcessID::Socket,
|
|
aAccumulations);
|
|
return IPC_OK();
|
|
}
|
|
|
|
mozilla::ipc::IPCResult SocketProcessParent::RecvAccumulateChildKeyedHistograms(
|
|
nsTArray<KeyedHistogramAccumulation>&& aAccumulations) {
|
|
TelemetryIPC::AccumulateChildKeyedHistograms(Telemetry::ProcessID::Socket,
|
|
aAccumulations);
|
|
return IPC_OK();
|
|
}
|
|
|
|
mozilla::ipc::IPCResult SocketProcessParent::RecvUpdateChildScalars(
|
|
nsTArray<ScalarAction>&& aScalarActions) {
|
|
TelemetryIPC::UpdateChildScalars(Telemetry::ProcessID::Socket,
|
|
aScalarActions);
|
|
return IPC_OK();
|
|
}
|
|
|
|
mozilla::ipc::IPCResult SocketProcessParent::RecvUpdateChildKeyedScalars(
|
|
nsTArray<KeyedScalarAction>&& aScalarActions) {
|
|
TelemetryIPC::UpdateChildKeyedScalars(Telemetry::ProcessID::Socket,
|
|
aScalarActions);
|
|
return IPC_OK();
|
|
}
|
|
|
|
mozilla::ipc::IPCResult SocketProcessParent::RecvRecordChildEvents(
|
|
nsTArray<mozilla::Telemetry::ChildEventData>&& 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();
|
|
}
|
|
|
|
PWebrtcTCPSocketParent* SocketProcessParent::AllocPWebrtcTCPSocketParent(
|
|
const Maybe<TabId>& aTabId) {
|
|
#ifdef MOZ_WEBRTC
|
|
WebrtcTCPSocketParent* parent = new WebrtcTCPSocketParent(aTabId);
|
|
parent->AddRef();
|
|
return parent;
|
|
#else
|
|
return nullptr;
|
|
#endif
|
|
}
|
|
|
|
bool SocketProcessParent::DeallocPWebrtcTCPSocketParent(
|
|
PWebrtcTCPSocketParent* aActor) {
|
|
#ifdef MOZ_WEBRTC
|
|
WebrtcTCPSocketParent* parent = static_cast<WebrtcTCPSocketParent*>(aActor);
|
|
parent->Release();
|
|
#endif
|
|
return true;
|
|
}
|
|
|
|
PDNSRequestParent* SocketProcessParent::AllocPDNSRequestParent(
|
|
const nsCString& aHost, const OriginAttributes& aOriginAttributes,
|
|
const uint32_t& aFlags) {
|
|
DNSRequestParent* p = new DNSRequestParent();
|
|
p->AddRef();
|
|
return p;
|
|
}
|
|
|
|
mozilla::ipc::IPCResult SocketProcessParent::RecvPDNSRequestConstructor(
|
|
PDNSRequestParent* aActor, const nsCString& aHost,
|
|
const OriginAttributes& aOriginAttributes, const uint32_t& aFlags) {
|
|
static_cast<DNSRequestParent*>(aActor)->DoAsyncResolve(
|
|
aHost, aOriginAttributes, aFlags);
|
|
return IPC_OK();
|
|
}
|
|
|
|
bool SocketProcessParent::DeallocPDNSRequestParent(PDNSRequestParent* aParent) {
|
|
DNSRequestParent* p = static_cast<DNSRequestParent*>(aParent);
|
|
p->Release();
|
|
return true;
|
|
}
|
|
|
|
// To ensure that IPDL is finished before SocketParent gets deleted.
|
|
class DeferredDeleteSocketProcessParent : public Runnable {
|
|
public:
|
|
explicit DeferredDeleteSocketProcessParent(
|
|
UniquePtr<SocketProcessParent>&& aParent)
|
|
: Runnable("net::DeferredDeleteSocketProcessParent"),
|
|
mParent(std::move(aParent)) {}
|
|
|
|
NS_IMETHODIMP Run() override { return NS_OK; }
|
|
|
|
private:
|
|
UniquePtr<SocketProcessParent> mParent;
|
|
};
|
|
|
|
/* static */
|
|
void SocketProcessParent::Destroy(UniquePtr<SocketProcessParent>&& aParent) {
|
|
NS_DispatchToMainThread(
|
|
new DeferredDeleteSocketProcessParent(std::move(aParent)));
|
|
}
|
|
|
|
} // namespace net
|
|
} // namespace mozilla
|