зеркало из https://github.com/mozilla/gecko-dev.git
219 строки
6.5 KiB
C++
219 строки
6.5 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/ProxyConfigLookupParent.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;
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
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<WebrtcProxyChannelParent*>(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;
|
|
}
|
|
|
|
PProxyConfigLookupParent* SocketProcessParent::AllocPProxyConfigLookupParent() {
|
|
#ifdef MOZ_WEBRTC
|
|
RefPtr<ProxyConfigLookupParent> actor = new ProxyConfigLookupParent();
|
|
return actor.forget().take();
|
|
#else
|
|
return nullptr;
|
|
#endif
|
|
}
|
|
|
|
mozilla::ipc::IPCResult SocketProcessParent::RecvPProxyConfigLookupConstructor(
|
|
PProxyConfigLookupParent* aActor) {
|
|
#ifdef MOZ_WEBRTC
|
|
ProxyConfigLookupParent* actor =
|
|
static_cast<ProxyConfigLookupParent*>(aActor);
|
|
actor->DoProxyLookup();
|
|
#endif
|
|
return IPC_OK();
|
|
}
|
|
|
|
bool SocketProcessParent::DeallocPProxyConfigLookupParent(
|
|
PProxyConfigLookupParent* aActor) {
|
|
#ifdef MOZ_WEBRTC
|
|
RefPtr<ProxyConfigLookupParent> actor =
|
|
dont_AddRef(static_cast<ProxyConfigLookupParent*>(aActor));
|
|
MOZ_ASSERT(actor);
|
|
#endif
|
|
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
|