Bug 1527256 - P2: Get DNSCacheEntries from socket process r=dragana

Differential Revision: https://phabricator.services.mozilla.com/D20355
This commit is contained in:
Kershaw Chang 2020-07-08 10:29:03 +00:00
parent 907a9dedd4
commit 3a97f39f6d
5 changed files with 78 additions and 0 deletions

View File

@ -633,6 +633,27 @@ Dashboard::RequestDNSInfo(nsINetDashboardCallback* aCallback) {
}
}
if (nsIOService::UseSocketProcess()) {
if (!gIOService->SocketProcessReady()) {
return NS_ERROR_NOT_AVAILABLE;
}
RefPtr<Dashboard> self(this);
SocketProcessParent::GetSingleton()->SendGetDNSCacheEntries()->Then(
GetMainThreadSerialEventTarget(), __func__,
[self{std::move(self)},
dnsData{std::move(dnsData)}](nsTArray<DNSCacheEntries>&& entries) {
dnsData->mData.Assign(std::move(entries));
dnsData->mEventTarget->Dispatch(
NewRunnableMethod<RefPtr<DnsData>>(
"net::Dashboard::GetDNSCacheEntries", self,
&Dashboard::GetDNSCacheEntries, dnsData),
NS_DISPATCH_NORMAL);
},
[self](const mozilla::ipc::ResponseRejectReason) {});
return NS_OK;
}
gSocketTransportService->Dispatch(
NewRunnableMethod<RefPtr<DnsData>>("net::Dashboard::GetDnsInfoDispatch",
this, &Dashboard::GetDnsInfoDispatch,

View File

@ -89,6 +89,30 @@ struct ParamTraits<mozilla::net::SocketInfo> {
}
};
template <>
struct ParamTraits<mozilla::net::DNSCacheEntries> {
typedef mozilla::net::DNSCacheEntries paramType;
static void Write(Message* aMsg, const paramType& aParam) {
WriteParam(aMsg, aParam.hostname);
WriteParam(aMsg, aParam.hostaddr);
WriteParam(aMsg, aParam.family);
WriteParam(aMsg, aParam.expiration);
WriteParam(aMsg, aParam.netInterface);
WriteParam(aMsg, aParam.TRR);
}
static bool Read(const Message* aMsg, PickleIterator* aIter,
paramType* aResult) {
return ReadParam(aMsg, aIter, &aResult->hostname) &&
ReadParam(aMsg, aIter, &aResult->hostaddr) &&
ReadParam(aMsg, aIter, &aResult->family) &&
ReadParam(aMsg, aIter, &aResult->expiration) &&
ReadParam(aMsg, aIter, &aResult->netInterface) &&
ReadParam(aMsg, aIter, &aResult->TRR);
}
};
} // namespace IPC
#endif // mozilla_net_DashboardTypes_h_

View File

@ -40,6 +40,7 @@ using PRTime from "prtime.h";
using refcounted class nsIURI from "mozilla/ipc/URIUtils.h";
using struct nsID from "nsID.h";
using mozilla::net::SocketInfo from "mozilla/net/DashboardTypes.h";
using mozilla::net::DNSCacheEntries from "mozilla/net/DashboardTypes.h";
namespace mozilla {
namespace net {
@ -156,6 +157,8 @@ child:
async GetSocketData()
returns (SocketDataArgs data);
async GetDNSCacheEntries()
returns (DNSCacheEntries[] entries);
both:
async PFileDescriptorSet(FileDescriptor fd);

View File

@ -536,5 +536,33 @@ mozilla::ipc::IPCResult SocketProcessChild::RecvGetSocketData(
return IPC_OK();
}
mozilla::ipc::IPCResult SocketProcessChild::RecvGetDNSCacheEntries(
GetDNSCacheEntriesResolver&& aResolve) {
nsresult rv = NS_OK;
nsCOMPtr<nsIDNSService> dns =
do_GetService("@mozilla.org/network/dns-service;1", &rv);
if (NS_FAILED(rv)) {
aResolve(nsTArray<DNSCacheEntries>());
return IPC_OK();
}
RefPtr<DataResolver<nsTArray<DNSCacheEntries>,
SocketProcessChild::GetDNSCacheEntriesResolver>>
resolver =
new DataResolver<nsTArray<DNSCacheEntries>,
SocketProcessChild::GetDNSCacheEntriesResolver>(
std::move(aResolve));
gSocketTransportService->Dispatch(
NS_NewRunnableFunction(
"net::SocketProcessChild::RecvGetDNSCacheEntries",
[resolver{std::move(resolver)}, dns{std::move(dns)}]() {
nsTArray<DNSCacheEntries> entries;
dns->GetDNSCacheEntries(&entries);
resolver->OnResolve(std::move(entries));
}),
NS_DISPATCH_NORMAL);
return IPC_OK();
}
} // namespace net
} // namespace mozilla

View File

@ -127,6 +127,8 @@ class SocketProcessChild final
AllocPRemoteLazyInputStreamChild(const nsID& aID, const uint64_t& aSize);
mozilla::ipc::IPCResult RecvGetSocketData(GetSocketDataResolver&& aResolve);
mozilla::ipc::IPCResult RecvGetDNSCacheEntries(
GetDNSCacheEntriesResolver&& aResolve);
protected:
friend class SocketProcessImpl;