Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/media/mtransport/ipc/StunAddrsRequestParent.cpp
Line
Count
Source (jump to first uncovered line)
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3
 * You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5
#include "StunAddrsRequestParent.h"
6
7
#include "../runnable_utils.h"
8
#include "nsNetUtil.h"
9
10
#include "mtransport/nricectx.h"
11
#include "mtransport/nricemediastream.h" // needed only for including nricectx.h
12
#include "mtransport/nricestunaddr.h"
13
14
using namespace mozilla::ipc;
15
16
namespace mozilla {
17
namespace net {
18
19
StunAddrsRequestParent::StunAddrsRequestParent()
20
  : mIPCClosed(false)
21
0
{
22
0
  NS_GetMainThread(getter_AddRefs(mMainThread));
23
0
24
0
  nsresult res;
25
0
  mSTSThread = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &res);
26
0
  MOZ_ASSERT(mSTSThread);
27
0
}
28
29
mozilla::ipc::IPCResult
30
StunAddrsRequestParent::RecvGetStunAddrs()
31
0
{
32
0
  ASSERT_ON_THREAD(mMainThread);
33
0
34
0
  if (mIPCClosed) {
35
0
    return IPC_OK();
36
0
  }
37
0
38
0
  RUN_ON_THREAD(mSTSThread,
39
0
                WrapRunnable(RefPtr<StunAddrsRequestParent>(this),
40
0
                             &StunAddrsRequestParent::GetStunAddrs_s),
41
0
                NS_DISPATCH_NORMAL);
42
0
43
0
  return IPC_OK();
44
0
}
45
46
mozilla::ipc::IPCResult
47
StunAddrsRequestParent::Recv__delete__()
48
0
{
49
0
  // see note below in ActorDestroy
50
0
  mIPCClosed = true;
51
0
  return IPC_OK();
52
0
}
53
54
void
55
StunAddrsRequestParent::ActorDestroy(ActorDestroyReason why)
56
0
{
57
0
  // We may still have refcount>0 if we haven't made it through
58
0
  // GetStunAddrs_s and SendStunAddrs_m yet, but child process
59
0
  // has crashed.  We must not send any more msgs to child, or
60
0
  // IPDL will kill chrome process, too.
61
0
  mIPCClosed = true;
62
0
}
63
64
void
65
StunAddrsRequestParent::GetStunAddrs_s()
66
0
{
67
0
  ASSERT_ON_THREAD(mSTSThread);
68
0
69
0
  // get the stun addresses while on STS thread
70
0
  NrIceStunAddrArray addrs = NrIceCtx::GetStunAddrs();
71
0
72
0
  if (mIPCClosed) {
73
0
    return;
74
0
  }
75
0
76
0
  // in order to return the result over IPC, we need to be on main thread
77
0
  RUN_ON_THREAD(mMainThread,
78
0
                WrapRunnable(RefPtr<StunAddrsRequestParent>(this),
79
0
                             &StunAddrsRequestParent::SendStunAddrs_m,
80
0
                             std::move(addrs)),
81
0
                NS_DISPATCH_NORMAL);
82
0
}
83
84
void
85
StunAddrsRequestParent::SendStunAddrs_m(const NrIceStunAddrArray& addrs)
86
0
{
87
0
  ASSERT_ON_THREAD(mMainThread);
88
0
89
0
  if (mIPCClosed) {
90
0
    // nothing to do: child probably crashed
91
0
    return;
92
0
  }
93
0
94
0
  mIPCClosed = true;
95
0
  // send the new addresses back to the child
96
0
  Unused << SendOnStunAddrsAvailable(addrs);
97
0
}
98
99
NS_IMPL_ADDREF(StunAddrsRequestParent)
100
NS_IMPL_RELEASE(StunAddrsRequestParent)
101
102
} // namespace net
103
} // namespace mozilla