Bug 1842773 - Part 5: Add ArrayBuffer.prototype.{maxByteLength,resizable} getters...
[gecko.git] / dom / media / gmp / GMPTimerParent.cpp
blob31b17ef2146b473e6ba81feb6f4b6e29be8c1dd6
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/. */
6 #include "GMPTimerParent.h"
8 #include "GMPLog.h"
9 #include "mozilla/Unused.h"
10 #include "nsComponentManagerUtils.h"
12 namespace mozilla {
14 extern LogModule* GetGMPLog();
16 #ifdef __CLASS__
17 # undef __CLASS__
18 #endif
19 #define __CLASS__ "GMPTimerParent"
21 namespace gmp {
23 GMPTimerParent::GMPTimerParent(nsISerialEventTarget* aGMPEventTarget)
24 : mGMPEventTarget(aGMPEventTarget), mIsOpen(true) {}
26 mozilla::ipc::IPCResult GMPTimerParent::RecvSetTimer(
27 const uint32_t& aTimerId, const uint32_t& aTimeoutMs) {
28 GMP_LOG_DEBUG("%s::%s: %p mIsOpen=%d", __CLASS__, __FUNCTION__, this,
29 mIsOpen);
31 MOZ_ASSERT(mGMPEventTarget->IsOnCurrentThread());
33 if (!mIsOpen) {
34 return IPC_OK();
37 nsresult rv;
38 UniquePtr<Context> ctx(new Context());
40 rv = NS_NewTimerWithFuncCallback(
41 getter_AddRefs(ctx->mTimer), &GMPTimerParent::GMPTimerExpired, ctx.get(),
42 aTimeoutMs, nsITimer::TYPE_ONE_SHOT, "gmp::GMPTimerParent::RecvSetTimer",
43 mGMPEventTarget);
44 NS_ENSURE_SUCCESS(rv, IPC_OK());
46 ctx->mId = aTimerId;
47 ctx->mParent = this;
49 mTimers.Insert(ctx.release());
51 return IPC_OK();
54 void GMPTimerParent::Shutdown() {
55 GMP_LOG_DEBUG("%s::%s: %p mIsOpen=%d", __CLASS__, __FUNCTION__, this,
56 mIsOpen);
58 MOZ_ASSERT(mGMPEventTarget->IsOnCurrentThread());
60 for (Context* context : mTimers) {
61 context->mTimer->Cancel();
62 delete context;
65 mTimers.Clear();
66 mIsOpen = false;
69 void GMPTimerParent::ActorDestroy(ActorDestroyReason aWhy) {
70 GMP_LOG_DEBUG("%s::%s: %p mIsOpen=%d", __CLASS__, __FUNCTION__, this,
71 mIsOpen);
73 Shutdown();
76 /* static */
77 void GMPTimerParent::GMPTimerExpired(nsITimer* aTimer, void* aClosure) {
78 MOZ_ASSERT(aClosure);
79 UniquePtr<Context> ctx(static_cast<Context*>(aClosure));
80 MOZ_ASSERT(ctx->mParent);
81 if (ctx->mParent) {
82 ctx->mParent->TimerExpired(ctx.get());
86 void GMPTimerParent::TimerExpired(Context* aContext) {
87 GMP_LOG_DEBUG("%s::%s: %p mIsOpen=%d", __CLASS__, __FUNCTION__, this,
88 mIsOpen);
89 MOZ_ASSERT(mGMPEventTarget->IsOnCurrentThread());
91 if (!mIsOpen) {
92 return;
95 uint32_t id = aContext->mId;
96 mTimers.Remove(aContext);
97 if (id) {
98 Unused << SendTimerExpired(id);
102 } // namespace gmp
103 } // namespace mozilla
105 #undef __CLASS__