Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/media/gmp/GMPTimerParent.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this
4
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6
#include "GMPTimerParent.h"
7
#include "nsComponentManagerUtils.h"
8
#include "mozilla/Unused.h"
9
#include "nsAutoPtr.h"
10
11
namespace mozilla {
12
13
#ifdef LOG
14
#undef LOG
15
#endif
16
17
extern LogModule* GetGMPLog();
18
19
0
#define LOGD(msg) MOZ_LOG(GetGMPLog(), mozilla::LogLevel::Debug, msg)
20
#define LOG(level, msg) MOZ_LOG(GetGMPLog(), (level), msg)
21
22
#ifdef __CLASS__
23
#undef __CLASS__
24
#endif
25
#define __CLASS__ "GMPParent"
26
27
namespace gmp {
28
29
GMPTimerParent::GMPTimerParent(nsISerialEventTarget* aGMPEventTarget)
30
  : mGMPEventTarget(aGMPEventTarget)
31
  , mIsOpen(true)
32
0
{
33
0
}
34
35
mozilla::ipc::IPCResult
36
GMPTimerParent::RecvSetTimer(const uint32_t& aTimerId,
37
                             const uint32_t& aTimeoutMs)
38
0
{
39
0
  LOGD(("%s::%s: %p mIsOpen=%d", __CLASS__, __FUNCTION__, this, mIsOpen));
40
0
41
0
  MOZ_ASSERT(mGMPEventTarget->IsOnCurrentThread());
42
0
43
0
  if (!mIsOpen) {
44
0
    return IPC_OK();
45
0
  }
46
0
47
0
  nsresult rv;
48
0
  nsAutoPtr<Context> ctx(new Context());
49
0
50
0
  rv = NS_NewTimerWithFuncCallback(getter_AddRefs(ctx->mTimer),
51
0
                                   &GMPTimerParent::GMPTimerExpired,
52
0
                                   ctx,
53
0
                                   aTimeoutMs,
54
0
                                   nsITimer::TYPE_ONE_SHOT,
55
0
                                   "gmp::GMPTimerParent::RecvSetTimer",
56
0
                                   mGMPEventTarget);
57
0
  NS_ENSURE_SUCCESS(rv, IPC_OK());
58
0
59
0
  ctx->mId = aTimerId;
60
0
  ctx->mParent = this;
61
0
62
0
  mTimers.PutEntry(ctx.forget());
63
0
64
0
  return IPC_OK();
65
0
}
66
67
void
68
GMPTimerParent::Shutdown()
69
0
{
70
0
  LOGD(("%s::%s: %p mIsOpen=%d", __CLASS__, __FUNCTION__, this, mIsOpen));
71
0
72
0
  MOZ_ASSERT(mGMPEventTarget->IsOnCurrentThread());
73
0
74
0
  for (auto iter = mTimers.Iter(); !iter.Done(); iter.Next()) {
75
0
    Context* context = iter.Get()->GetKey();
76
0
    context->mTimer->Cancel();
77
0
    delete context;
78
0
  }
79
0
80
0
  mTimers.Clear();
81
0
  mIsOpen = false;
82
0
}
83
84
void
85
GMPTimerParent::ActorDestroy(ActorDestroyReason aWhy)
86
0
{
87
0
  LOGD(("%s::%s: %p mIsOpen=%d", __CLASS__, __FUNCTION__, this, mIsOpen));
88
0
89
0
  Shutdown();
90
0
}
91
92
/* static */
93
void
94
GMPTimerParent::GMPTimerExpired(nsITimer *aTimer, void *aClosure)
95
0
{
96
0
  MOZ_ASSERT(aClosure);
97
0
  nsAutoPtr<Context> ctx(static_cast<Context*>(aClosure));
98
0
  MOZ_ASSERT(ctx->mParent);
99
0
  if (ctx->mParent) {
100
0
    ctx->mParent->TimerExpired(ctx);
101
0
  }
102
0
}
103
104
void
105
GMPTimerParent::TimerExpired(Context* aContext)
106
0
{
107
0
  LOGD(("%s::%s: %p mIsOpen=%d", __CLASS__, __FUNCTION__, this, mIsOpen));
108
0
  MOZ_ASSERT(mGMPEventTarget->IsOnCurrentThread());
109
0
110
0
  if (!mIsOpen) {
111
0
    return;
112
0
  }
113
0
114
0
  uint32_t id = aContext->mId;
115
0
  mTimers.RemoveEntry(aContext);
116
0
  if (id) {
117
0
    Unused << SendTimerExpired(id);
118
0
  }
119
0
}
120
121
} // namespace gmp
122
} // namespace mozilla