tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

DNSListenerProxy.h (1644B)


      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/. */
      6 
      7 #ifndef DNSListenerProxy_h__
      8 #define DNSListenerProxy_h__
      9 
     10 #include "nsIDNSListener.h"
     11 #include "nsIDNSRecord.h"
     12 #include "nsProxyRelease.h"
     13 #include "nsThreadUtils.h"
     14 
     15 class nsIEventTarget;
     16 class nsICancelable;
     17 
     18 namespace mozilla {
     19 namespace net {
     20 
     21 #define DNS_LISTENER_PROXY_IID \
     22  {0x8f172ca3, 0x7a7f, 0x4941, {0xa7, 0x0b, 0xbc, 0x72, 0x80, 0x2e, 0x9d, 0x9b}}
     23 
     24 class DNSListenerProxy final : public nsIDNSListener {
     25 public:
     26  DNSListenerProxy(nsIDNSListener* aListener, nsIEventTarget* aTargetThread)
     27      // We want to make sure that |aListener| is only accessed on the target
     28      // thread.
     29      : mListener(aListener),
     30        mTargetThread(aTargetThread),
     31        mListenerAddress(reinterpret_cast<uintptr_t>(aListener)) {
     32    MOZ_ASSERT(mListener);
     33    MOZ_ASSERT(mTargetThread);
     34  }
     35 
     36  NS_DECL_THREADSAFE_ISUPPORTS
     37  NS_DECL_NSIDNSLISTENER
     38  NS_INLINE_DECL_STATIC_IID(DNS_LISTENER_PROXY_IID)
     39 
     40  uintptr_t GetOriginalListenerAddress() const { return mListenerAddress; }
     41 
     42 private:
     43  ~DNSListenerProxy() {
     44    NS_ProxyRelease("DNSListenerProxy::mListener", mTargetThread,
     45                    mListener.forget());
     46  }
     47 
     48  nsCOMPtr<nsIDNSListener> mListener;
     49  nsCOMPtr<nsIEventTarget> mTargetThread;
     50  uintptr_t mListenerAddress;
     51 };
     52 
     53 }  // namespace net
     54 }  // namespace mozilla
     55 
     56 #endif  // DNSListenerProxy_h__