2014-08-05 11:56:05 +04:00
|
|
|
/* -*- 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 "nsComponentManagerUtils.h"
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2016-06-07 23:10:18 +03:00
|
|
|
#include "nsAutoPtr.h"
|
2014-08-05 11:56:05 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2014-08-18 01:41:53 +04:00
|
|
|
|
|
|
|
#ifdef LOG
|
|
|
|
# undef LOG
|
|
|
|
#endif
|
|
|
|
|
2015-11-15 16:49:01 +03:00
|
|
|
extern LogModule* GetGMPLog();
|
2014-08-18 01:41:53 +04:00
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
#define LOGD(msg) MOZ_LOG(GetGMPLog(), mozilla::LogLevel::Debug, msg)
|
2015-05-21 23:22:04 +03:00
|
|
|
#define LOG(level, msg) MOZ_LOG(GetGMPLog(), (level), msg)
|
2014-08-18 01:41:53 +04:00
|
|
|
|
|
|
|
#ifdef __CLASS__
|
|
|
|
# undef __CLASS__
|
|
|
|
#endif
|
|
|
|
#define __CLASS__ "GMPParent"
|
|
|
|
|
2014-08-05 11:56:05 +04:00
|
|
|
namespace gmp {
|
|
|
|
|
2017-06-01 23:41:18 +03:00
|
|
|
GMPTimerParent::GMPTimerParent(nsISerialEventTarget* aGMPEventTarget)
|
|
|
|
: mGMPEventTarget(aGMPEventTarget), mIsOpen(true) {}
|
2014-08-05 11:56:05 +04:00
|
|
|
|
|
|
|
mozilla::ipc::IPCResult GMPTimerParent::RecvSetTimer(
|
|
|
|
const uint32_t& aTimerId, const uint32_t& aTimeoutMs) {
|
2014-08-18 01:41:53 +04:00
|
|
|
LOGD(("%s::%s: %p mIsOpen=%d", __CLASS__, __FUNCTION__, this, mIsOpen));
|
|
|
|
|
2017-06-01 23:41:18 +03:00
|
|
|
MOZ_ASSERT(mGMPEventTarget->IsOnCurrentThread());
|
2014-08-05 11:56:05 +04:00
|
|
|
|
2014-08-18 01:41:53 +04:00
|
|
|
if (!mIsOpen) {
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2014-08-18 01:41:53 +04:00
|
|
|
}
|
|
|
|
|
2014-08-05 11:56:05 +04:00
|
|
|
nsresult rv;
|
|
|
|
nsAutoPtr<Context> ctx(new Context());
|
2017-10-16 09:15:40 +03:00
|
|
|
|
|
|
|
rv = NS_NewTimerWithFuncCallback(
|
|
|
|
getter_AddRefs(ctx->mTimer), &GMPTimerParent::GMPTimerExpired, ctx,
|
|
|
|
aTimeoutMs, nsITimer::TYPE_ONE_SHOT, "gmp::GMPTimerParent::RecvSetTimer",
|
|
|
|
mGMPEventTarget);
|
2016-11-15 06:26:00 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, IPC_OK());
|
2014-08-05 11:56:05 +04:00
|
|
|
|
|
|
|
ctx->mId = aTimerId;
|
|
|
|
ctx->mParent = this;
|
|
|
|
|
|
|
|
mTimers.PutEntry(ctx.forget());
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2014-08-05 11:56:05 +04:00
|
|
|
}
|
|
|
|
|
2014-08-18 01:41:53 +04:00
|
|
|
void GMPTimerParent::Shutdown() {
|
|
|
|
LOGD(("%s::%s: %p mIsOpen=%d", __CLASS__, __FUNCTION__, this, mIsOpen));
|
|
|
|
|
2017-06-01 23:41:18 +03:00
|
|
|
MOZ_ASSERT(mGMPEventTarget->IsOnCurrentThread());
|
2015-07-16 20:59:41 +03:00
|
|
|
|
|
|
|
for (auto iter = mTimers.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
Context* context = iter.Get()->GetKey();
|
|
|
|
context->mTimer->Cancel();
|
|
|
|
delete context;
|
|
|
|
}
|
|
|
|
|
2014-08-18 01:41:53 +04:00
|
|
|
mTimers.Clear();
|
|
|
|
mIsOpen = false;
|
|
|
|
}
|
|
|
|
|
2014-08-05 11:56:05 +04:00
|
|
|
void GMPTimerParent::ActorDestroy(ActorDestroyReason aWhy) {
|
2014-08-18 01:41:53 +04:00
|
|
|
LOGD(("%s::%s: %p mIsOpen=%d", __CLASS__, __FUNCTION__, this, mIsOpen));
|
|
|
|
|
|
|
|
Shutdown();
|
2014-08-05 11:56:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
void GMPTimerParent::GMPTimerExpired(nsITimer* aTimer, void* aClosure) {
|
|
|
|
MOZ_ASSERT(aClosure);
|
|
|
|
nsAutoPtr<Context> ctx(static_cast<Context*>(aClosure));
|
|
|
|
MOZ_ASSERT(ctx->mParent);
|
|
|
|
if (ctx->mParent) {
|
|
|
|
ctx->mParent->TimerExpired(ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GMPTimerParent::TimerExpired(Context* aContext) {
|
2014-08-18 01:41:53 +04:00
|
|
|
LOGD(("%s::%s: %p mIsOpen=%d", __CLASS__, __FUNCTION__, this, mIsOpen));
|
2017-06-01 23:41:18 +03:00
|
|
|
MOZ_ASSERT(mGMPEventTarget->IsOnCurrentThread());
|
2014-08-05 11:56:05 +04:00
|
|
|
|
2014-08-18 01:41:53 +04:00
|
|
|
if (!mIsOpen) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-05 11:56:05 +04:00
|
|
|
uint32_t id = aContext->mId;
|
|
|
|
mTimers.RemoveEntry(aContext);
|
|
|
|
if (id) {
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << SendTimerExpired(id);
|
2014-08-05 11:56:05 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace gmp
|
|
|
|
} // namespace mozilla
|