Skip to content

Commit

Permalink
Bug 1569196 - Make ChildDNSService run on socket process r=dragana
Browse files Browse the repository at this point in the history
Differential Revision: https://phabricator.services.mozilla.com/D40592

--HG--
extra : moz-landing-system : lando
  • Loading branch information
KershawChang committed Aug 5, 2019
1 parent ea6fd45 commit 93e82cb
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 14 deletions.
2 changes: 2 additions & 0 deletions netwerk/base/nsIOService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ using mozilla::dom::ServiceWorkerDescriptor;
#define NETWORK_NOTIFY_CHANGED_PREF "network.notify.changed"
#define NETWORK_CAPTIVE_PORTAL_PREF "network.captive-portal-service.enabled"
#define WEBRTC_PREF_PREFIX "media.peerconnection."
#define NETWORK_DNS_PREF "network.dns."

#define MAX_RECURSION_COUNT 50

Expand Down Expand Up @@ -224,6 +225,7 @@ static const char* gCallbackPrefs[] = {

static const char* gCallbackPrefsForSocketProcess[] = {
WEBRTC_PREF_PREFIX,
NETWORK_DNS_PREF,
nullptr,
};

Expand Down
8 changes: 5 additions & 3 deletions netwerk/dns/ChildDNSService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static StaticRefPtr<ChildDNSService> gChildDNSService;
static const char kPrefNameDisablePrefetch[] = "network.dns.disablePrefetch";

already_AddRefed<ChildDNSService> ChildDNSService::GetSingleton() {
MOZ_ASSERT(XRE_IsContentProcess());
MOZ_ASSERT(XRE_IsContentProcess() || XRE_IsSocketProcess());

if (!gChildDNSService) {
gChildDNSService = new ChildDNSService();
Expand All @@ -45,7 +45,7 @@ ChildDNSService::ChildDNSService()
: mFirstTime(true),
mDisablePrefetch(false),
mPendingRequestsLock("DNSPendingRequestsLock") {
MOZ_ASSERT(XRE_IsContentProcess());
MOZ_ASSERT(XRE_IsContentProcess() || XRE_IsSocketProcess());
}

void ChildDNSService::GetDNSRecordHashKey(
Expand All @@ -67,7 +67,9 @@ nsresult ChildDNSService::AsyncResolveInternal(
const nsACString& hostname, uint16_t type, uint32_t flags,
nsIDNSListener* listener, nsIEventTarget* target_,
const OriginAttributes& aOriginAttributes, nsICancelable** result) {
NS_ENSURE_TRUE(gNeckoChild != nullptr, NS_ERROR_FAILURE);
if (XRE_IsContentProcess()) {
NS_ENSURE_TRUE(gNeckoChild != nullptr, NS_ERROR_FAILURE);
}

if (mDisablePrefetch && (flags & RESOLVE_SPECULATE)) {
return NS_ERROR_DNS_LOOKUP_QUEUE_FULL;
Expand Down
31 changes: 22 additions & 9 deletions netwerk/dns/DNSRequestChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "mozilla/net/ChildDNSService.h"
#include "mozilla/net/DNSRequestChild.h"
#include "mozilla/net/NeckoChild.h"
#include "mozilla/net/SocketProcessChild.h"
#include "mozilla/SystemGroup.h"
#include "mozilla/Unused.h"
#include "nsIDNSRecord.h"
Expand Down Expand Up @@ -237,20 +238,32 @@ void DNSRequestChild::StartRequest() {
return;
}

nsCOMPtr<nsIEventTarget> systemGroupEventTarget =
SystemGroup::EventTargetFor(TaskCategory::Other);
if (XRE_IsContentProcess()) {
nsCOMPtr<nsIEventTarget> systemGroupEventTarget =
SystemGroup::EventTargetFor(TaskCategory::Other);
gNeckoChild->SetEventTargetForActor(this, systemGroupEventTarget);

gNeckoChild->SetEventTargetForActor(this, systemGroupEventTarget);
mozilla::dom::ContentChild* cc =
static_cast<mozilla::dom::ContentChild*>(gNeckoChild->Manager());
if (cc->IsShuttingDown()) {
return;
}

// Send request to Parent process.
gNeckoChild->SendPDNSRequestConstructor(this, mHost, mOriginAttributes,
mFlags);
} else if (XRE_IsSocketProcess()) {
SocketProcessChild* child = SocketProcessChild::GetSingleton();
if (!child->CanSend()) {
return;
}

mozilla::dom::ContentChild* cc =
static_cast<mozilla::dom::ContentChild*>(gNeckoChild->Manager());
if (cc->IsShuttingDown()) {
child->SendPDNSRequestConstructor(this, mHost, mOriginAttributes, mFlags);
} else {
MOZ_ASSERT(false, "Wrong process");
return;
}

// Send request to Parent process.
gNeckoChild->SendPDNSRequestConstructor(this, mHost, mOriginAttributes,
mFlags);
mIPCOpen = true;

// IPDL holds a reference until IPDL channel gets destroyed
Expand Down
3 changes: 2 additions & 1 deletion netwerk/dns/PDNSRequest.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

include protocol PNecko;
include protocol PSocketProcess;

include PDNSRequestParams;

Expand All @@ -18,7 +19,7 @@ namespace net {

async protocol PDNSRequest
{
manager PNecko;
manager PNecko or PSocketProcess;

parent:
// constructor in PNecko takes AsyncResolve args that initialize request
Expand Down
2 changes: 1 addition & 1 deletion netwerk/dns/nsDNSService2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ NS_IMPL_ISUPPORTS(nsDNSService, nsIDNSService, nsPIDNSService, nsIObserver,
static StaticRefPtr<nsDNSService> gDNSService;

already_AddRefed<nsIDNSService> nsDNSService::GetXPCOMSingleton() {
if (XRE_IsContentProcess()) {
if (XRE_IsContentProcess() || XRE_IsSocketProcess()) {
return ChildDNSService::GetSingleton();
}

Expand Down
5 changes: 5 additions & 0 deletions netwerk/ipc/PSocketProcess.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* 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 protocol PDNSRequest;
include protocol PSocketProcessBridge;
include protocol PProfiler;
include protocol PWebrtcProxyChannel;
Expand All @@ -19,12 +20,14 @@ using mozilla::Telemetry::KeyedScalarAction from "mozilla/TelemetryComms.h";
using mozilla::Telemetry::ChildEventData from "mozilla/TelemetryComms.h";
using mozilla::Telemetry::DiscardedData from "mozilla/TelemetryComms.h";
using base::ProcessId from "base/process.h";
using mozilla::OriginAttributes from "mozilla/ipc/BackgroundUtils.h";

namespace mozilla {
namespace net {

protocol PSocketProcess
{
manages PDNSRequest;
manages PWebrtcProxyChannel;

parent:
Expand All @@ -40,6 +43,8 @@ parent:
async RecordDiscardedData(DiscardedData data);

async PWebrtcProxyChannel(TabId tabId);
async PDNSRequest(nsCString hostName, OriginAttributes originAttributes,
uint32_t flags);

child:
async PreferenceUpdate(Pref pref);
Expand Down
16 changes: 16 additions & 0 deletions netwerk/ipc/SocketProcessChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "mozilla/dom/MemoryReportRequest.h"
#include "mozilla/ipc/CrashReporterClient.h"
#include "mozilla/ipc/ProcessChild.h"
#include "mozilla/net/DNSRequestChild.h"
#include "mozilla/Preferences.h"
#include "nsDebugImpl.h"
#include "nsThreadManager.h"
Expand Down Expand Up @@ -212,5 +213,20 @@ bool SocketProcessChild::DeallocPWebrtcProxyChannelChild(
return true;
}

PDNSRequestChild* SocketProcessChild::AllocPDNSRequestChild(
const nsCString& aHost, const OriginAttributes& aOriginAttributes,
const uint32_t& aFlags) {
// We don't allocate here: instead we always use IPDL constructor that takes
// an existing object
MOZ_ASSERT_UNREACHABLE("AllocPDNSRequestChild should not be called on child");
return nullptr;
}

bool SocketProcessChild::DeallocPDNSRequestChild(PDNSRequestChild* aChild) {
DNSRequestChild* p = static_cast<DNSRequestChild*>(aChild);
p->ReleaseIPDLReference();
return true;
}

} // namespace net
} // namespace mozilla
4 changes: 4 additions & 0 deletions netwerk/ipc/SocketProcessChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ class SocketProcessChild final : public PSocketProcessChild {
PWebrtcProxyChannelChild* AllocPWebrtcProxyChannelChild(
const PBrowserOrId& browser);
bool DeallocPWebrtcProxyChannelChild(PWebrtcProxyChannelChild* aActor);
PDNSRequestChild* AllocPDNSRequestChild(
const nsCString& aHost, const OriginAttributes& aOriginAttributes,
const uint32_t& aFlags);
bool DeallocPDNSRequestChild(PDNSRequestChild*);

void CleanUp();
void DestroySocketProcessBridgeParent(ProcessId aId);
Expand Down
23 changes: 23 additions & 0 deletions netwerk/ipc/SocketProcessParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "SocketProcessHost.h"
#include "mozilla/ipc/CrashReporterHost.h"
#include "mozilla/net/DNSRequestParent.h"
#include "mozilla/Telemetry.h"
#include "mozilla/TelemetryIPC.h"
#ifdef MOZ_WEBRTC
Expand Down Expand Up @@ -153,6 +154,28 @@ bool SocketProcessParent::DeallocPWebrtcProxyChannelParent(
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:
Expand Down
8 changes: 8 additions & 0 deletions netwerk/ipc/SocketProcessParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ class SocketProcessParent final : public PSocketProcessParent {
PWebrtcProxyChannelParent* AllocPWebrtcProxyChannelParent(
const TabId& aTabId);
bool DeallocPWebrtcProxyChannelParent(PWebrtcProxyChannelParent* aActor);
PDNSRequestParent* AllocPDNSRequestParent(
const nsCString& aHost, const OriginAttributes& aOriginAttributes,
const uint32_t& aFlags);
virtual mozilla::ipc::IPCResult RecvPDNSRequestConstructor(
PDNSRequestParent* actor, const nsCString& hostName,
const OriginAttributes& aOriginAttributes,
const uint32_t& flags) override;
bool DeallocPDNSRequestParent(PDNSRequestParent*);

void ActorDestroy(ActorDestroyReason aWhy) override;
bool SendRequestMemoryReport(const uint32_t& aGeneration,
Expand Down

0 comments on commit 93e82cb

Please sign in to comment.