xpcom/base/nsInterfaceRequestorAgg.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #include "nsInterfaceRequestorAgg.h"
michael@0 6 #include "nsIInterfaceRequestor.h"
michael@0 7 #include "nsCOMPtr.h"
michael@0 8 #include "mozilla/Attributes.h"
michael@0 9 #include "nsThreadUtils.h"
michael@0 10 #include "nsProxyRelease.h"
michael@0 11
michael@0 12 class nsInterfaceRequestorAgg MOZ_FINAL : public nsIInterfaceRequestor
michael@0 13 {
michael@0 14 public:
michael@0 15 // XXX This needs to support threadsafe refcounting until we fix bug 243591.
michael@0 16 NS_DECL_THREADSAFE_ISUPPORTS
michael@0 17 NS_DECL_NSIINTERFACEREQUESTOR
michael@0 18
michael@0 19 nsInterfaceRequestorAgg(nsIInterfaceRequestor *aFirst,
michael@0 20 nsIInterfaceRequestor *aSecond,
michael@0 21 nsIEventTarget *aConsumerTarget = nullptr)
michael@0 22 : mFirst(aFirst)
michael@0 23 , mSecond(aSecond)
michael@0 24 , mConsumerTarget(aConsumerTarget)
michael@0 25 {
michael@0 26 if (!mConsumerTarget) {
michael@0 27 mConsumerTarget = NS_GetCurrentThread();
michael@0 28 }
michael@0 29 }
michael@0 30 ~nsInterfaceRequestorAgg();
michael@0 31
michael@0 32 private:
michael@0 33 nsCOMPtr<nsIInterfaceRequestor> mFirst, mSecond;
michael@0 34 nsCOMPtr<nsIEventTarget> mConsumerTarget;
michael@0 35 };
michael@0 36
michael@0 37 NS_IMPL_ISUPPORTS(nsInterfaceRequestorAgg, nsIInterfaceRequestor)
michael@0 38
michael@0 39 NS_IMETHODIMP
michael@0 40 nsInterfaceRequestorAgg::GetInterface(const nsIID &aIID, void **aResult)
michael@0 41 {
michael@0 42 nsresult rv = NS_ERROR_NO_INTERFACE;
michael@0 43 if (mFirst)
michael@0 44 rv = mFirst->GetInterface(aIID, aResult);
michael@0 45 if (mSecond && NS_FAILED(rv))
michael@0 46 rv = mSecond->GetInterface(aIID, aResult);
michael@0 47 return rv;
michael@0 48 }
michael@0 49
michael@0 50 nsInterfaceRequestorAgg::~nsInterfaceRequestorAgg()
michael@0 51 {
michael@0 52 nsIInterfaceRequestor* iir = nullptr;
michael@0 53 mFirst.swap(iir);
michael@0 54 if (iir) {
michael@0 55 NS_ProxyRelease(mConsumerTarget, iir);
michael@0 56 }
michael@0 57 iir = nullptr;
michael@0 58 mSecond.swap(iir);
michael@0 59 if (iir) {
michael@0 60 NS_ProxyRelease(mConsumerTarget, iir);
michael@0 61 }
michael@0 62 }
michael@0 63
michael@0 64 nsresult
michael@0 65 NS_NewInterfaceRequestorAggregation(nsIInterfaceRequestor *aFirst,
michael@0 66 nsIInterfaceRequestor *aSecond,
michael@0 67 nsIInterfaceRequestor **aResult)
michael@0 68 {
michael@0 69 *aResult = new nsInterfaceRequestorAgg(aFirst, aSecond);
michael@0 70 if (!*aResult)
michael@0 71 return NS_ERROR_OUT_OF_MEMORY;
michael@0 72 NS_ADDREF(*aResult);
michael@0 73 return NS_OK;
michael@0 74 }
michael@0 75
michael@0 76 nsresult
michael@0 77 NS_NewInterfaceRequestorAggregation(nsIInterfaceRequestor *aFirst,
michael@0 78 nsIInterfaceRequestor *aSecond,
michael@0 79 nsIEventTarget* aTarget,
michael@0 80 nsIInterfaceRequestor **aResult)
michael@0 81 {
michael@0 82 *aResult = new nsInterfaceRequestorAgg(aFirst, aSecond, aTarget);
michael@0 83 if (!*aResult)
michael@0 84 return NS_ERROR_OUT_OF_MEMORY;
michael@0 85 NS_ADDREF(*aResult);
michael@0 86 return NS_OK;
michael@0 87 }

mercurial