netwerk/dns/DNSListenerProxy.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/dns/DNSListenerProxy.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,66 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* vim: set sw=4 ts=8 et tw=80 : */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef DNSListenerProxy_h__
    1.11 +#define DNSListenerProxy_h__
    1.12 +
    1.13 +#include "nsIDNSListener.h"
    1.14 +#include "nsIDNSRecord.h"
    1.15 +#include "nsProxyRelease.h"
    1.16 +#include "nsThreadUtils.h"
    1.17 +
    1.18 +class nsIEventTarget;
    1.19 +class nsICancelable;
    1.20 +
    1.21 +namespace mozilla {
    1.22 +namespace net {
    1.23 +
    1.24 +class DNSListenerProxy MOZ_FINAL : public nsIDNSListener
    1.25 +{
    1.26 +public:
    1.27 +  DNSListenerProxy(nsIDNSListener* aListener, nsIEventTarget* aTargetThread)
    1.28 +    // Sometimes aListener is a main-thread only object like XPCWrappedJS, and
    1.29 +    // sometimes it's a threadsafe object like nsSOCKSSocketInfo. Use a main-
    1.30 +    // thread pointer holder, but disable strict enforcement of thread invariants.
    1.31 +    // The AddRef implementation of XPCWrappedJS will assert if we go wrong here.
    1.32 +    : mListener(new nsMainThreadPtrHolder<nsIDNSListener>(aListener, false))
    1.33 +    , mTargetThread(aTargetThread)
    1.34 +  { }
    1.35 +
    1.36 +  NS_DECL_THREADSAFE_ISUPPORTS
    1.37 +  NS_DECL_NSIDNSLISTENER
    1.38 +
    1.39 +  class OnLookupCompleteRunnable : public nsRunnable
    1.40 +  {
    1.41 +  public:
    1.42 +    OnLookupCompleteRunnable(const nsMainThreadPtrHandle<nsIDNSListener>& aListener,
    1.43 +                             nsICancelable* aRequest,
    1.44 +                             nsIDNSRecord* aRecord,
    1.45 +                             nsresult aStatus)
    1.46 +      : mListener(aListener)
    1.47 +      , mRequest(aRequest)
    1.48 +      , mRecord(aRecord)
    1.49 +      , mStatus(aStatus)
    1.50 +    { }
    1.51 +
    1.52 +    NS_DECL_NSIRUNNABLE
    1.53 +
    1.54 +  private:
    1.55 +    nsMainThreadPtrHandle<nsIDNSListener> mListener;
    1.56 +    nsCOMPtr<nsICancelable> mRequest;
    1.57 +    nsCOMPtr<nsIDNSRecord> mRecord;
    1.58 +    nsresult mStatus;
    1.59 +  };
    1.60 +
    1.61 +private:
    1.62 +  nsMainThreadPtrHandle<nsIDNSListener> mListener;
    1.63 +  nsCOMPtr<nsIEventTarget> mTargetThread;
    1.64 +};
    1.65 +
    1.66 +
    1.67 +} // namespace net
    1.68 +} // namespace mozilla
    1.69 +#endif // DNSListenerProxy_h__

mercurial