1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 ts=8 et tw=80 : */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_net_ChildDNSService_h
8 #define mozilla_net_ChildDNSService_h
10 #include "DNSServiceBase.h"
11 #include "nsPIDNSService.h"
12 #include "mozilla/Attributes.h"
13 #include "mozilla/Mutex.h"
14 #include "DNSRequestChild.h"
15 #include "DNSRequestParent.h"
16 #include "nsHashKeys.h"
17 #include "nsClassHashtable.h"
22 class TRRServiceParent
;
24 class ChildDNSService final
: public DNSServiceBase
, public nsPIDNSService
{
26 // AsyncResolve (and CancelAsyncResolve) can be called off-main
27 NS_DECL_ISUPPORTS_INHERITED
28 NS_DECL_NSPIDNSSERVICE
34 static already_AddRefed
<ChildDNSService
> GetSingleton();
36 void NotifyRequestDone(DNSRequestSender
* aDnsRequest
);
38 void SetTRRDomain(const nsACString
& aTRRDomain
);
39 void SetTRRModeInChild(nsIDNSService::ResolverMode mode
,
40 nsIDNSService::ResolverMode modeFromPref
);
43 virtual ~ChildDNSService() = default;
45 void MOZ_ALWAYS_INLINE
GetDNSRecordHashKey(
46 const nsACString
& aHost
, const nsACString
& aTrrServer
, int32_t aPort
,
47 uint16_t aType
, const OriginAttributes
& aOriginAttributes
,
48 nsIDNSService::DNSFlags aFlags
, uintptr_t aListenerAddr
,
49 nsACString
& aHashKey
);
50 nsresult
AsyncResolveInternal(const nsACString
& hostname
, uint16_t type
,
51 nsIDNSService::DNSFlags flags
,
52 nsIDNSAdditionalInfo
* aInfo
,
53 nsIDNSListener
* listener
,
54 nsIEventTarget
* target_
,
55 const OriginAttributes
& aOriginAttributes
,
56 nsICancelable
** result
);
57 nsresult
CancelAsyncResolveInternal(
58 const nsACString
& aHostname
, uint16_t aType
,
59 nsIDNSService::DNSFlags aFlags
, nsIDNSAdditionalInfo
* aInfo
,
60 nsIDNSListener
* aListener
, nsresult aReason
,
61 const OriginAttributes
& aOriginAttributes
);
63 // We need to remember pending dns requests to be able to cancel them.
64 nsClassHashtable
<nsCStringHashKey
, nsTArray
<RefPtr
<DNSRequestSender
>>>
66 Mutex mPendingRequestsLock MOZ_UNANNOTATED
{"DNSPendingRequestsLock"};
67 RefPtr
<TRRServiceParent
> mTRRServiceParent
;
70 // Only set in the content process.
71 nsIDNSService::ResolverMode mTRRMode
=
72 nsIDNSService::ResolverMode::MODE_NATIVEONLY
;
76 } // namespace mozilla
78 #endif // mozilla_net_ChildDNSService_h