From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- dom/media/gmp/GMPTimerParent.cpp | 105 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 dom/media/gmp/GMPTimerParent.cpp (limited to 'dom/media/gmp/GMPTimerParent.cpp') diff --git a/dom/media/gmp/GMPTimerParent.cpp b/dom/media/gmp/GMPTimerParent.cpp new file mode 100644 index 0000000000..31b17ef214 --- /dev/null +++ b/dom/media/gmp/GMPTimerParent.cpp @@ -0,0 +1,105 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "GMPTimerParent.h" + +#include "GMPLog.h" +#include "mozilla/Unused.h" +#include "nsComponentManagerUtils.h" + +namespace mozilla { + +extern LogModule* GetGMPLog(); + +#ifdef __CLASS__ +# undef __CLASS__ +#endif +#define __CLASS__ "GMPTimerParent" + +namespace gmp { + +GMPTimerParent::GMPTimerParent(nsISerialEventTarget* aGMPEventTarget) + : mGMPEventTarget(aGMPEventTarget), mIsOpen(true) {} + +mozilla::ipc::IPCResult GMPTimerParent::RecvSetTimer( + const uint32_t& aTimerId, const uint32_t& aTimeoutMs) { + GMP_LOG_DEBUG("%s::%s: %p mIsOpen=%d", __CLASS__, __FUNCTION__, this, + mIsOpen); + + MOZ_ASSERT(mGMPEventTarget->IsOnCurrentThread()); + + if (!mIsOpen) { + return IPC_OK(); + } + + nsresult rv; + UniquePtr ctx(new Context()); + + rv = NS_NewTimerWithFuncCallback( + getter_AddRefs(ctx->mTimer), &GMPTimerParent::GMPTimerExpired, ctx.get(), + aTimeoutMs, nsITimer::TYPE_ONE_SHOT, "gmp::GMPTimerParent::RecvSetTimer", + mGMPEventTarget); + NS_ENSURE_SUCCESS(rv, IPC_OK()); + + ctx->mId = aTimerId; + ctx->mParent = this; + + mTimers.Insert(ctx.release()); + + return IPC_OK(); +} + +void GMPTimerParent::Shutdown() { + GMP_LOG_DEBUG("%s::%s: %p mIsOpen=%d", __CLASS__, __FUNCTION__, this, + mIsOpen); + + MOZ_ASSERT(mGMPEventTarget->IsOnCurrentThread()); + + for (Context* context : mTimers) { + context->mTimer->Cancel(); + delete context; + } + + mTimers.Clear(); + mIsOpen = false; +} + +void GMPTimerParent::ActorDestroy(ActorDestroyReason aWhy) { + GMP_LOG_DEBUG("%s::%s: %p mIsOpen=%d", __CLASS__, __FUNCTION__, this, + mIsOpen); + + Shutdown(); +} + +/* static */ +void GMPTimerParent::GMPTimerExpired(nsITimer* aTimer, void* aClosure) { + MOZ_ASSERT(aClosure); + UniquePtr ctx(static_cast(aClosure)); + MOZ_ASSERT(ctx->mParent); + if (ctx->mParent) { + ctx->mParent->TimerExpired(ctx.get()); + } +} + +void GMPTimerParent::TimerExpired(Context* aContext) { + GMP_LOG_DEBUG("%s::%s: %p mIsOpen=%d", __CLASS__, __FUNCTION__, this, + mIsOpen); + MOZ_ASSERT(mGMPEventTarget->IsOnCurrentThread()); + + if (!mIsOpen) { + return; + } + + uint32_t id = aContext->mId; + mTimers.Remove(aContext); + if (id) { + Unused << SendTimerExpired(id); + } +} + +} // namespace gmp +} // namespace mozilla + +#undef __CLASS__ -- cgit v1.2.3