LCOV - code coverage report
Current view: top level - dom/media/gmp - GMPTimerParent.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 51 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 6 0.0 %
Legend: Lines: hit not hit

          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 "GMPTimerParent.h"
       7             : #include "nsComponentManagerUtils.h"
       8             : #include "mozilla/Unused.h"
       9             : #include "nsAutoPtr.h"
      10             : 
      11             : namespace mozilla {
      12             : 
      13             : #ifdef LOG
      14             : #undef LOG
      15             : #endif
      16             : 
      17             : extern LogModule* GetGMPLog();
      18             : 
      19             : #define LOGD(msg) MOZ_LOG(GetGMPLog(), mozilla::LogLevel::Debug, msg)
      20             : #define LOG(level, msg) MOZ_LOG(GetGMPLog(), (level), msg)
      21             : 
      22             : #ifdef __CLASS__
      23             : #undef __CLASS__
      24             : #endif
      25             : #define __CLASS__ "GMPParent"
      26             : 
      27             : namespace gmp {
      28             : 
      29           0 : GMPTimerParent::GMPTimerParent(nsISerialEventTarget* aGMPEventTarget)
      30             :   : mGMPEventTarget(aGMPEventTarget)
      31           0 :   , mIsOpen(true)
      32             : {
      33           0 : }
      34             : 
      35             : mozilla::ipc::IPCResult
      36           0 : GMPTimerParent::RecvSetTimer(const uint32_t& aTimerId,
      37             :                              const uint32_t& aTimeoutMs)
      38             : {
      39           0 :   LOGD(("%s::%s: %p mIsOpen=%d", __CLASS__, __FUNCTION__, this, mIsOpen));
      40             : 
      41           0 :   MOZ_ASSERT(mGMPEventTarget->IsOnCurrentThread());
      42             : 
      43           0 :   if (!mIsOpen) {
      44           0 :     return IPC_OK();
      45             :   }
      46             : 
      47             :   nsresult rv;
      48           0 :   nsAutoPtr<Context> ctx(new Context());
      49           0 :   ctx->mTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
      50           0 :   NS_ENSURE_SUCCESS(rv, IPC_OK());
      51             : 
      52           0 :   ctx->mId = aTimerId;
      53           0 :   rv = ctx->mTimer->SetTarget(mGMPEventTarget);
      54           0 :   NS_ENSURE_SUCCESS(rv, IPC_OK());
      55           0 :   ctx->mParent = this;
      56             : 
      57           0 :   rv =
      58           0 :     ctx->mTimer->InitWithNamedFuncCallback(&GMPTimerParent::GMPTimerExpired,
      59             :                                            ctx,
      60             :                                            aTimeoutMs,
      61             :                                            nsITimer::TYPE_ONE_SHOT,
      62           0 :                                            "gmp::GMPTimerParent::RecvSetTimer");
      63           0 :   NS_ENSURE_SUCCESS(rv, IPC_OK());
      64             : 
      65           0 :   mTimers.PutEntry(ctx.forget());
      66             : 
      67           0 :   return IPC_OK();
      68             : }
      69             : 
      70             : void
      71           0 : GMPTimerParent::Shutdown()
      72             : {
      73           0 :   LOGD(("%s::%s: %p mIsOpen=%d", __CLASS__, __FUNCTION__, this, mIsOpen));
      74             : 
      75           0 :   MOZ_ASSERT(mGMPEventTarget->IsOnCurrentThread());
      76             : 
      77           0 :   for (auto iter = mTimers.Iter(); !iter.Done(); iter.Next()) {
      78           0 :     Context* context = iter.Get()->GetKey();
      79           0 :     context->mTimer->Cancel();
      80           0 :     delete context;
      81             :   }
      82             : 
      83           0 :   mTimers.Clear();
      84           0 :   mIsOpen = false;
      85           0 : }
      86             : 
      87             : void
      88           0 : GMPTimerParent::ActorDestroy(ActorDestroyReason aWhy)
      89             : {
      90           0 :   LOGD(("%s::%s: %p mIsOpen=%d", __CLASS__, __FUNCTION__, this, mIsOpen));
      91             : 
      92           0 :   Shutdown();
      93           0 : }
      94             : 
      95             : /* static */
      96             : void
      97           0 : GMPTimerParent::GMPTimerExpired(nsITimer *aTimer, void *aClosure)
      98             : {
      99           0 :   MOZ_ASSERT(aClosure);
     100           0 :   nsAutoPtr<Context> ctx(static_cast<Context*>(aClosure));
     101           0 :   MOZ_ASSERT(ctx->mParent);
     102           0 :   if (ctx->mParent) {
     103           0 :     ctx->mParent->TimerExpired(ctx);
     104             :   }
     105           0 : }
     106             : 
     107             : void
     108           0 : GMPTimerParent::TimerExpired(Context* aContext)
     109             : {
     110           0 :   LOGD(("%s::%s: %p mIsOpen=%d", __CLASS__, __FUNCTION__, this, mIsOpen));
     111           0 :   MOZ_ASSERT(mGMPEventTarget->IsOnCurrentThread());
     112             : 
     113           0 :   if (!mIsOpen) {
     114           0 :     return;
     115             :   }
     116             : 
     117           0 :   uint32_t id = aContext->mId;
     118           0 :   mTimers.RemoveEntry(aContext);
     119           0 :   if (id) {
     120           0 :     Unused << SendTimerExpired(id);
     121             :   }
     122             : }
     123             : 
     124             : } // namespace gmp
     125             : } // namespace mozilla

Generated by: LCOV version 1.13