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"
9 #include "mozilla/Unused.h"
10 #include "nsComponentManagerUtils.h"
14 extern LogModule
* GetGMPLog();
19 #define __CLASS__ "GMPTimerParent"
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,
31 MOZ_ASSERT(mGMPEventTarget
->IsOnCurrentThread());
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",
44 NS_ENSURE_SUCCESS(rv
, IPC_OK());
49 mTimers
.Insert(ctx
.release());
54 void GMPTimerParent::Shutdown() {
55 GMP_LOG_DEBUG("%s::%s: %p mIsOpen=%d", __CLASS__
, __FUNCTION__
, this,
58 MOZ_ASSERT(mGMPEventTarget
->IsOnCurrentThread());
60 for (Context
* context
: mTimers
) {
61 context
->mTimer
->Cancel();
69 void GMPTimerParent::ActorDestroy(ActorDestroyReason aWhy
) {
70 GMP_LOG_DEBUG("%s::%s: %p mIsOpen=%d", __CLASS__
, __FUNCTION__
, this,
77 void GMPTimerParent::GMPTimerExpired(nsITimer
* aTimer
, void* aClosure
) {
79 UniquePtr
<Context
> ctx(static_cast<Context
*>(aClosure
));
80 MOZ_ASSERT(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,
89 MOZ_ASSERT(mGMPEventTarget
->IsOnCurrentThread());
95 uint32_t id
= aContext
->mId
;
96 mTimers
.Remove(aContext
);
98 Unused
<< SendTimerExpired(id
);
103 } // namespace mozilla