Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/xpcom/base/nsInterfaceRequestorAgg.cpp
Line
Count
Source (jump to first uncovered line)
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/. */
6
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"
13
14
class nsInterfaceRequestorAgg final : public nsIInterfaceRequestor
15
{
16
public:
17
  // XXX This needs to support threadsafe refcounting until we fix bug 243591.
18
  NS_DECL_THREADSAFE_ISUPPORTS
19
  NS_DECL_NSIINTERFACEREQUESTOR
20
21
  nsInterfaceRequestorAgg(nsIInterfaceRequestor* aFirst,
22
                          nsIInterfaceRequestor* aSecond,
23
                          nsIEventTarget* aConsumerTarget = nullptr)
24
    : mFirst(aFirst)
25
    , mSecond(aSecond)
26
    , mConsumerTarget(aConsumerTarget)
27
0
  {
28
0
    if (!mConsumerTarget) {
29
0
      mConsumerTarget = GetCurrentThreadEventTarget();
30
0
    }
31
0
  }
32
33
private:
34
  ~nsInterfaceRequestorAgg();
35
36
  nsCOMPtr<nsIInterfaceRequestor> mFirst, mSecond;
37
  nsCOMPtr<nsIEventTarget> mConsumerTarget;
38
};
39
40
NS_IMPL_ISUPPORTS(nsInterfaceRequestorAgg, nsIInterfaceRequestor)
41
42
NS_IMETHODIMP
43
nsInterfaceRequestorAgg::GetInterface(const nsIID& aIID, void** aResult)
44
0
{
45
0
  nsresult rv = NS_ERROR_NO_INTERFACE;
46
0
  if (mFirst) {
47
0
    rv = mFirst->GetInterface(aIID, aResult);
48
0
  }
49
0
  if (mSecond && NS_FAILED(rv)) {
50
0
    rv = mSecond->GetInterface(aIID, aResult);
51
0
  }
52
0
  return rv;
53
0
}
54
55
nsInterfaceRequestorAgg::~nsInterfaceRequestorAgg()
56
0
{
57
0
  NS_ProxyRelease(
58
0
    "nsInterfaceRequestorAgg::mFirst", mConsumerTarget, mFirst.forget());
59
0
  NS_ProxyRelease(
60
0
    "nsInterfaceRequestorAgg::mSecond", mConsumerTarget, mSecond.forget());
61
0
}
62
63
nsresult
64
NS_NewInterfaceRequestorAggregation(nsIInterfaceRequestor* aFirst,
65
                                    nsIInterfaceRequestor* aSecond,
66
                                    nsIInterfaceRequestor** aResult)
67
0
{
68
0
  *aResult = new nsInterfaceRequestorAgg(aFirst, aSecond);
69
0
  if (!*aResult) {
70
0
    return NS_ERROR_OUT_OF_MEMORY;
71
0
  }
72
0
  NS_ADDREF(*aResult);
73
0
  return NS_OK;
74
0
}
75
76
nsresult
77
NS_NewInterfaceRequestorAggregation(nsIInterfaceRequestor* aFirst,
78
                                    nsIInterfaceRequestor* aSecond,
79
                                    nsIEventTarget* aTarget,
80
                                    nsIInterfaceRequestor** aResult)
81
0
{
82
0
  *aResult = new nsInterfaceRequestorAgg(aFirst, aSecond, aTarget);
83
0
  if (!*aResult) {
84
0
    return NS_ERROR_OUT_OF_MEMORY;
85
0
  }
86
0
  NS_ADDREF(*aResult);
87
0
  return NS_OK;
88
0
}