netwerk/dns/DNSListenerProxy.h

Wed, 31 Dec 2014 06:55:46 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:46 +0100
changeset 1
ca08bd8f51b2
permissions
-rw-r--r--

Added tag TORBROWSER_REPLICA for changeset 6474c204b198

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     2 /* vim: set sw=4 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 class DNSListenerProxy MOZ_FINAL : public nsIDNSListener
    22 {
    23 public:
    24   DNSListenerProxy(nsIDNSListener* aListener, nsIEventTarget* aTargetThread)
    25     // Sometimes aListener is a main-thread only object like XPCWrappedJS, and
    26     // sometimes it's a threadsafe object like nsSOCKSSocketInfo. Use a main-
    27     // thread pointer holder, but disable strict enforcement of thread invariants.
    28     // The AddRef implementation of XPCWrappedJS will assert if we go wrong here.
    29     : mListener(new nsMainThreadPtrHolder<nsIDNSListener>(aListener, false))
    30     , mTargetThread(aTargetThread)
    31   { }
    33   NS_DECL_THREADSAFE_ISUPPORTS
    34   NS_DECL_NSIDNSLISTENER
    36   class OnLookupCompleteRunnable : public nsRunnable
    37   {
    38   public:
    39     OnLookupCompleteRunnable(const nsMainThreadPtrHandle<nsIDNSListener>& aListener,
    40                              nsICancelable* aRequest,
    41                              nsIDNSRecord* aRecord,
    42                              nsresult aStatus)
    43       : mListener(aListener)
    44       , mRequest(aRequest)
    45       , mRecord(aRecord)
    46       , mStatus(aStatus)
    47     { }
    49     NS_DECL_NSIRUNNABLE
    51   private:
    52     nsMainThreadPtrHandle<nsIDNSListener> mListener;
    53     nsCOMPtr<nsICancelable> mRequest;
    54     nsCOMPtr<nsIDNSRecord> mRecord;
    55     nsresult mStatus;
    56   };
    58 private:
    59   nsMainThreadPtrHandle<nsIDNSListener> mListener;
    60   nsCOMPtr<nsIEventTarget> mTargetThread;
    61 };
    64 } // namespace net
    65 } // namespace mozilla
    66 #endif // DNSListenerProxy_h__

mercurial