netwerk/dns/DNSListenerProxy.h
author B2G Bumper Bot <release+b2gbumper@mozilla.com>
Thu, 17 Apr 2014 20:30:27 -0700
changeset 179678 da6ddd1630b6bb9bee239f6051d0a0862dd9ae8c
parent 160283 3072c9af15b309f1814d6e55f6a7768134c1eeb2
permissions -rw-r--r--
Bumping gaia.json for 2 gaia revision(s) a=gaia-bump ======== https://hg.mozilla.org/integration/gaia-central/rev/31acef1532cc Author: George <georgeiscoming@gmail.com> Desc: Merge pull request #18308 from cctuan/968661-3 Bug 968661 - Extract new build module webapp-shared.js from webapp-zip.j... ======== https://hg.mozilla.org/integration/gaia-central/rev/fb2f6723539a Author: cctuan <georgeiscoming@gmail.com> Desc: Bug 968661 - Extract new build module webapp-shared.js from webapp-zip.js

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim: set sw=4 ts=8 et tw=80 : */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef DNSListenerProxy_h__
#define DNSListenerProxy_h__

#include "nsIDNSListener.h"
#include "nsIDNSRecord.h"
#include "nsProxyRelease.h"
#include "nsThreadUtils.h"

class nsIEventTarget;
class nsICancelable;

namespace mozilla {
namespace net {

class DNSListenerProxy MOZ_FINAL : public nsIDNSListener
{
public:
  DNSListenerProxy(nsIDNSListener* aListener, nsIEventTarget* aTargetThread)
    // Sometimes aListener is a main-thread only object like XPCWrappedJS, and
    // sometimes it's a threadsafe object like nsSOCKSSocketInfo. Use a main-
    // thread pointer holder, but disable strict enforcement of thread invariants.
    // The AddRef implementation of XPCWrappedJS will assert if we go wrong here.
    : mListener(new nsMainThreadPtrHolder<nsIDNSListener>(aListener, false))
    , mTargetThread(aTargetThread)
  { }

  NS_DECL_THREADSAFE_ISUPPORTS
  NS_DECL_NSIDNSLISTENER

  class OnLookupCompleteRunnable : public nsRunnable
  {
  public:
    OnLookupCompleteRunnable(const nsMainThreadPtrHandle<nsIDNSListener>& aListener,
                             nsICancelable* aRequest,
                             nsIDNSRecord* aRecord,
                             nsresult aStatus)
      : mListener(aListener)
      , mRequest(aRequest)
      , mRecord(aRecord)
      , mStatus(aStatus)
    { }

    NS_DECL_NSIRUNNABLE

  private:
    nsMainThreadPtrHandle<nsIDNSListener> mListener;
    nsCOMPtr<nsICancelable> mRequest;
    nsCOMPtr<nsIDNSRecord> mRecord;
    nsresult mStatus;
  };

private:
  nsMainThreadPtrHandle<nsIDNSListener> mListener;
  nsCOMPtr<nsIEventTarget> mTargetThread;
};


} // namespace net
} // namespace mozilla
#endif // DNSListenerProxy_h__