summaryrefslogtreecommitdiffstats
path: root/dom/media/webrtc/transport/ipc/StunAddrsRequestChild.h
blob: f487f52baf5d758ebb9ccca94e30ca7f3da9ae73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* 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 mozilla_net_StunAddrsRequestChild_h
#define mozilla_net_StunAddrsRequestChild_h

#include "mozilla/net/PStunAddrsRequestChild.h"

class nsISerialEventTarget;

namespace mozilla::net {

class StunAddrsListener {
 public:
  virtual void OnMDNSQueryComplete(const nsCString& hostname,
                                   const Maybe<nsCString>& address) = 0;
  virtual void OnStunAddrsAvailable(const NrIceStunAddrArray& addrs) = 0;

  NS_IMETHOD_(MozExternalRefCountType) AddRef();
  NS_IMETHOD_(MozExternalRefCountType) Release();

 protected:
  virtual ~StunAddrsListener() = default;

  ThreadSafeAutoRefCnt mRefCnt;
  NS_DECL_OWNINGTHREAD
};

class StunAddrsRequestChild final : public PStunAddrsRequestChild {
  friend class PStunAddrsRequestChild;

 public:
  explicit StunAddrsRequestChild(StunAddrsListener* listener);

  NS_IMETHOD_(MozExternalRefCountType) AddRef();
  NS_IMETHOD_(MozExternalRefCountType) Release();

  // Not sure why AddIPDLReference & ReleaseIPDLReference don't come
  // from PStunAddrsRequestChild since the IPC plumbing seem to
  // expect this.
  void AddIPDLReference() { AddRef(); }
  void ReleaseIPDLReference() { Release(); }

  void Cancel();

 protected:
  virtual ~StunAddrsRequestChild() = default;

  virtual mozilla::ipc::IPCResult RecvOnMDNSQueryComplete(
      const nsACString& aHostname, const Maybe<nsCString>& aAddress) override;

  virtual mozilla::ipc::IPCResult RecvOnStunAddrsAvailable(
      const NrIceStunAddrArray& addrs) override;

  RefPtr<StunAddrsListener> mListener;

  ThreadSafeAutoRefCnt mRefCnt;
  NS_DECL_OWNINGTHREAD
};

}  // namespace mozilla::net

#endif  // mozilla_net_StunAddrsRequestChild_h