Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/media/gmp/GMPTimerChild.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 "GMPTimerChild.h"
7
#include "GMPPlatform.h"
8
#include "GMPChild.h"
9
10
0
#define MAX_NUM_TIMERS 1000
11
12
namespace mozilla {
13
namespace gmp {
14
15
GMPTimerChild::GMPTimerChild(GMPChild* aPlugin)
16
  : mTimerCount(1)
17
  , mPlugin(aPlugin)
18
0
{
19
0
  MOZ_ASSERT(mPlugin->GMPMessageLoop() == MessageLoop::current());
20
0
}
21
22
GMPTimerChild::~GMPTimerChild()
23
0
{
24
0
  MOZ_ASSERT(mPlugin->GMPMessageLoop() == MessageLoop::current());
25
0
}
26
27
GMPErr
28
GMPTimerChild::SetTimer(GMPTask* aTask, int64_t aTimeoutMS)
29
0
{
30
0
  if (!aTask) {
31
0
    NS_WARNING("Tried to set timer with null task!");
32
0
    return GMPGenericErr;
33
0
  }
34
0
35
0
  if (mPlugin->GMPMessageLoop() != MessageLoop::current()) {
36
0
    NS_WARNING("Tried to set GMP timer on non-main thread.");
37
0
    return GMPGenericErr;
38
0
  }
39
0
40
0
  if (mTimers.Count() > MAX_NUM_TIMERS) {
41
0
    return GMPQuotaExceededErr;
42
0
  }
43
0
  uint32_t timerId = mTimerCount;
44
0
  mTimers.Put(timerId, aTask);
45
0
  mTimerCount++;
46
0
47
0
  if (!SendSetTimer(timerId, aTimeoutMS)) {
48
0
    return GMPGenericErr;
49
0
  }
50
0
  return GMPNoErr;
51
0
}
52
53
mozilla::ipc::IPCResult
54
GMPTimerChild::RecvTimerExpired(const uint32_t& aTimerId)
55
0
{
56
0
  MOZ_ASSERT(mPlugin->GMPMessageLoop() == MessageLoop::current());
57
0
58
0
  GMPTask* task = mTimers.Get(aTimerId);
59
0
  mTimers.Remove(aTimerId);
60
0
  if (task) {
61
0
    RunOnMainThread(task);
62
0
  }
63
0
  return IPC_OK();
64
0
}
65
66
} // namespace gmp
67
} // namespace mozilla