Bug 1866777 - Disable test_race_cache_with_network.js on windows opt for frequent...
[gecko.git] / netwerk / dns / DNSListenerProxy.h
blob5baddfd8e7c342b558c21b30f0af16e85cd43235
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 DNSListenerProxy_h__
8 #define DNSListenerProxy_h__
10 #include "nsIDNSListener.h"
11 #include "nsIDNSRecord.h"
12 #include "nsProxyRelease.h"
13 #include "nsThreadUtils.h"
15 class nsIEventTarget;
16 class nsICancelable;
18 namespace mozilla {
19 namespace net {
21 #define DNS_LISTENER_PROXY_IID \
22 { \
23 0x8f172ca3, 0x7a7f, 0x4941, { \
24 0xa7, 0x0b, 0xbc, 0x72, 0x80, 0x2e, 0x9d, 0x9b \
25 } \
28 class DNSListenerProxy final : public nsIDNSListener {
29 public:
30 DNSListenerProxy(nsIDNSListener* aListener, nsIEventTarget* aTargetThread)
31 // We want to make sure that |aListener| is only accessed on the target
32 // thread.
33 : mListener(aListener),
34 mTargetThread(aTargetThread),
35 mListenerAddress(reinterpret_cast<uintptr_t>(aListener)) {
36 MOZ_ASSERT(mListener);
37 MOZ_ASSERT(mTargetThread);
40 NS_DECL_THREADSAFE_ISUPPORTS
41 NS_DECL_NSIDNSLISTENER
42 NS_DECLARE_STATIC_IID_ACCESSOR(DNS_LISTENER_PROXY_IID)
44 uintptr_t GetOriginalListenerAddress() const { return mListenerAddress; }
46 private:
47 ~DNSListenerProxy() {
48 NS_ProxyRelease("DNSListenerProxy::mListener", mTargetThread,
49 mListener.forget());
52 nsCOMPtr<nsIDNSListener> mListener;
53 nsCOMPtr<nsIEventTarget> mTargetThread;
54 uintptr_t mListenerAddress;
57 NS_DEFINE_STATIC_IID_ACCESSOR(DNSListenerProxy, DNS_LISTENER_PROXY_IID)
59 } // namespace net
60 } // namespace mozilla
62 #endif // DNSListenerProxy_h__