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

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
       3             : /* This Source Code Form is subject to the terms of the Mozilla Public
       4             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       5             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : #include "mozilla/dom/cache/CacheStorageChild.h"
       8             : 
       9             : #include "mozilla/Unused.h"
      10             : #include "mozilla/dom/cache/CacheChild.h"
      11             : #include "mozilla/dom/cache/CacheOpChild.h"
      12             : #include "mozilla/dom/cache/CacheStorage.h"
      13             : 
      14             : namespace mozilla {
      15             : namespace dom {
      16             : namespace cache {
      17             : 
      18             : // declared in ActorUtils.h
      19             : void
      20           0 : DeallocPCacheStorageChild(PCacheStorageChild* aActor)
      21             : {
      22           0 :   delete aActor;
      23           0 : }
      24             : 
      25           0 : CacheStorageChild::CacheStorageChild(CacheStorage* aListener,
      26           0 :                                      CacheWorkerHolder* aWorkerHolder)
      27             :   : mListener(aListener)
      28             :   , mNumChildActors(0)
      29           0 :   , mDelayedDestroy(false)
      30             : {
      31           0 :   MOZ_COUNT_CTOR(cache::CacheStorageChild);
      32           0 :   MOZ_DIAGNOSTIC_ASSERT(mListener);
      33             : 
      34           0 :   SetWorkerHolder(aWorkerHolder);
      35           0 : }
      36             : 
      37           0 : CacheStorageChild::~CacheStorageChild()
      38             : {
      39           0 :   MOZ_COUNT_DTOR(cache::CacheStorageChild);
      40           0 :   NS_ASSERT_OWNINGTHREAD(CacheStorageChild);
      41           0 :   MOZ_DIAGNOSTIC_ASSERT(!mListener);
      42           0 : }
      43             : 
      44             : void
      45           0 : CacheStorageChild::ClearListener()
      46             : {
      47           0 :   NS_ASSERT_OWNINGTHREAD(CacheStorageChild);
      48           0 :   MOZ_DIAGNOSTIC_ASSERT(mListener);
      49           0 :   mListener = nullptr;
      50           0 : }
      51             : 
      52             : void
      53           0 : CacheStorageChild::ExecuteOp(nsIGlobalObject* aGlobal, Promise* aPromise,
      54             :                              nsISupports* aParent, const CacheOpArgs& aArgs)
      55             : {
      56           0 :   mNumChildActors += 1;
      57           0 :   Unused << SendPCacheOpConstructor(
      58           0 :     new CacheOpChild(GetWorkerHolder(), aGlobal, aParent, aPromise), aArgs);
      59           0 : }
      60             : 
      61             : void
      62           0 : CacheStorageChild::StartDestroyFromListener()
      63             : {
      64           0 :   NS_ASSERT_OWNINGTHREAD(CacheStorageChild);
      65             : 
      66             :   // The listener should be held alive by any async operations, so if it
      67             :   // is going away then there must not be any child actors.  This in turn
      68             :   // ensures that StartDestroy() will not trigger the delayed path.
      69           0 :   MOZ_DIAGNOSTIC_ASSERT(!mNumChildActors);
      70             : 
      71           0 :   StartDestroy();
      72           0 : }
      73             : 
      74             : void
      75           0 : CacheStorageChild::StartDestroy()
      76             : {
      77           0 :   NS_ASSERT_OWNINGTHREAD(CacheStorageChild);
      78             : 
      79             :   // If we have outstanding child actors, then don't destroy ourself yet.
      80             :   // The child actors should be short lived and we should allow them to complete
      81             :   // if possible.  NoteDeletedActor() will call back into this Shutdown()
      82             :   // method when the last child actor is gone.
      83           0 :   if (mNumChildActors) {
      84           0 :     mDelayedDestroy = true;
      85           0 :     return;
      86             :   }
      87             : 
      88           0 :   RefPtr<CacheStorage> listener = mListener;
      89             : 
      90             :   // StartDestroy() can get called from either CacheStorage or the
      91             :   // CacheWorkerHolder.
      92             :   // Theoretically we can get double called if the right race happens.  Handle
      93             :   // that by just ignoring the second StartDestroy() call.
      94           0 :   if (!listener) {
      95           0 :     return;
      96             :   }
      97             : 
      98           0 :   listener->DestroyInternal(this);
      99             : 
     100             :   // CacheStorage listener should call ClearListener() in DestroyInternal()
     101           0 :   MOZ_DIAGNOSTIC_ASSERT(!mListener);
     102             : 
     103             :   // Start actor destruction from parent process
     104           0 :   Unused << SendTeardown();
     105             : }
     106             : 
     107             : void
     108           0 : CacheStorageChild::ActorDestroy(ActorDestroyReason aReason)
     109             : {
     110           0 :   NS_ASSERT_OWNINGTHREAD(CacheStorageChild);
     111           0 :   RefPtr<CacheStorage> listener = mListener;
     112           0 :   if (listener) {
     113           0 :     listener->DestroyInternal(this);
     114             :     // CacheStorage listener should call ClearListener() in DestroyInternal()
     115           0 :     MOZ_DIAGNOSTIC_ASSERT(!mListener);
     116             :   }
     117             : 
     118           0 :   RemoveWorkerHolder();
     119           0 : }
     120             : 
     121             : PCacheOpChild*
     122           0 : CacheStorageChild::AllocPCacheOpChild(const CacheOpArgs& aOpArgs)
     123             : {
     124           0 :   MOZ_CRASH("CacheOpChild should be manually constructed.");
     125             :   return nullptr;
     126             : }
     127             : 
     128             : bool
     129           0 : CacheStorageChild::DeallocPCacheOpChild(PCacheOpChild* aActor)
     130             : {
     131           0 :   delete aActor;
     132           0 :   NoteDeletedActor();
     133           0 :   return true;
     134             : }
     135             : 
     136             : void
     137           0 : CacheStorageChild::NoteDeletedActor()
     138             : {
     139           0 :   MOZ_DIAGNOSTIC_ASSERT(mNumChildActors);
     140           0 :   mNumChildActors -= 1;
     141           0 :   if (!mNumChildActors && mDelayedDestroy) {
     142           0 :     StartDestroy();
     143             :   }
     144           0 : }
     145             : 
     146             : } // namespace cache
     147             : } // namespace dom
     148             : } // namespace mozilla

Generated by: LCOV version 1.13