Bumping manifests a=b2g-bump
[gecko.git] / xpcom / base / nsInterfaceRequestorAgg.cpp
blob6e777f5613cdd568339c1c8ae35de9361eb7fb91
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 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 #include "nsInterfaceRequestorAgg.h"
8 #include "nsIInterfaceRequestor.h"
9 #include "nsCOMPtr.h"
10 #include "mozilla/Attributes.h"
11 #include "nsThreadUtils.h"
12 #include "nsProxyRelease.h"
14 class nsInterfaceRequestorAgg MOZ_FINAL : public nsIInterfaceRequestor
16 public:
17 // XXX This needs to support threadsafe refcounting until we fix bug 243591.
18 NS_DECL_THREADSAFE_ISUPPORTS
19 NS_DECL_NSIINTERFACEREQUESTOR
21 nsInterfaceRequestorAgg(nsIInterfaceRequestor* aFirst,
22 nsIInterfaceRequestor* aSecond,
23 nsIEventTarget* aConsumerTarget = nullptr)
24 : mFirst(aFirst)
25 , mSecond(aSecond)
26 , mConsumerTarget(aConsumerTarget)
28 if (!mConsumerTarget) {
29 mConsumerTarget = NS_GetCurrentThread();
33 private:
34 ~nsInterfaceRequestorAgg();
36 nsCOMPtr<nsIInterfaceRequestor> mFirst, mSecond;
37 nsCOMPtr<nsIEventTarget> mConsumerTarget;
40 NS_IMPL_ISUPPORTS(nsInterfaceRequestorAgg, nsIInterfaceRequestor)
42 NS_IMETHODIMP
43 nsInterfaceRequestorAgg::GetInterface(const nsIID& aIID, void** aResult)
45 nsresult rv = NS_ERROR_NO_INTERFACE;
46 if (mFirst) {
47 rv = mFirst->GetInterface(aIID, aResult);
49 if (mSecond && NS_FAILED(rv)) {
50 rv = mSecond->GetInterface(aIID, aResult);
52 return rv;
55 nsInterfaceRequestorAgg::~nsInterfaceRequestorAgg()
57 nsIInterfaceRequestor* iir = nullptr;
58 mFirst.swap(iir);
59 if (iir) {
60 NS_ProxyRelease(mConsumerTarget, iir);
62 iir = nullptr;
63 mSecond.swap(iir);
64 if (iir) {
65 NS_ProxyRelease(mConsumerTarget, iir);
69 nsresult
70 NS_NewInterfaceRequestorAggregation(nsIInterfaceRequestor* aFirst,
71 nsIInterfaceRequestor* aSecond,
72 nsIInterfaceRequestor** aResult)
74 *aResult = new nsInterfaceRequestorAgg(aFirst, aSecond);
75 if (!*aResult) {
76 return NS_ERROR_OUT_OF_MEMORY;
78 NS_ADDREF(*aResult);
79 return NS_OK;
82 nsresult
83 NS_NewInterfaceRequestorAggregation(nsIInterfaceRequestor* aFirst,
84 nsIInterfaceRequestor* aSecond,
85 nsIEventTarget* aTarget,
86 nsIInterfaceRequestor** aResult)
88 *aResult = new nsInterfaceRequestorAgg(aFirst, aSecond, aTarget);
89 if (!*aResult) {
90 return NS_ERROR_OUT_OF_MEMORY;
92 NS_ADDREF(*aResult);
93 return NS_OK;