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