2015-03-02 16:20:00 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* 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 "mozilla/dom/cache/CacheStorageChild.h"
|
|
|
|
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2015-03-02 16:20:00 +03:00
|
|
|
#include "mozilla/dom/cache/CacheChild.h"
|
2015-04-16 22:00:15 +03:00
|
|
|
#include "mozilla/dom/cache/CacheOpChild.h"
|
2015-03-02 16:20:00 +03:00
|
|
|
#include "mozilla/dom/cache/CacheStorage.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
namespace cache {
|
|
|
|
|
|
|
|
// declared in ActorUtils.h
|
|
|
|
void
|
|
|
|
DeallocPCacheStorageChild(PCacheStorageChild* aActor)
|
|
|
|
{
|
|
|
|
delete aActor;
|
|
|
|
}
|
|
|
|
|
2016-06-23 11:53:14 +03:00
|
|
|
CacheStorageChild::CacheStorageChild(CacheStorage* aListener,
|
|
|
|
CacheWorkerHolder* aWorkerHolder)
|
2015-03-02 16:20:00 +03:00
|
|
|
: mListener(aListener)
|
2015-04-16 22:00:15 +03:00
|
|
|
, mNumChildActors(0)
|
2015-05-01 18:13:36 +03:00
|
|
|
, mDelayedDestroy(false)
|
2015-03-02 16:20:00 +03:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(cache::CacheStorageChild);
|
2017-01-06 23:41:15 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mListener);
|
2015-03-02 16:20:00 +03:00
|
|
|
|
2016-06-23 11:53:14 +03:00
|
|
|
SetWorkerHolder(aWorkerHolder);
|
2015-03-02 16:20:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CacheStorageChild::~CacheStorageChild()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(cache::CacheStorageChild);
|
|
|
|
NS_ASSERT_OWNINGTHREAD(CacheStorageChild);
|
2017-01-06 23:41:15 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mListener);
|
2015-03-02 16:20:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CacheStorageChild::ClearListener()
|
|
|
|
{
|
|
|
|
NS_ASSERT_OWNINGTHREAD(CacheStorageChild);
|
2017-01-06 23:41:15 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mListener);
|
2015-03-02 16:20:00 +03:00
|
|
|
mListener = nullptr;
|
|
|
|
}
|
|
|
|
|
2015-04-16 22:00:15 +03:00
|
|
|
void
|
|
|
|
CacheStorageChild::ExecuteOp(nsIGlobalObject* aGlobal, Promise* aPromise,
|
2015-05-01 18:13:36 +03:00
|
|
|
nsISupports* aParent, const CacheOpArgs& aArgs)
|
2015-04-16 22:00:15 +03:00
|
|
|
{
|
|
|
|
mNumChildActors += 1;
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << SendPCacheOpConstructor(
|
2016-06-23 11:53:14 +03:00
|
|
|
new CacheOpChild(GetWorkerHolder(), aGlobal, aParent, aPromise), aArgs);
|
2015-05-01 18:13:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CacheStorageChild::StartDestroyFromListener()
|
|
|
|
{
|
|
|
|
NS_ASSERT_OWNINGTHREAD(CacheStorageChild);
|
|
|
|
|
|
|
|
// The listener should be held alive by any async operations, so if it
|
|
|
|
// is going away then there must not be any child actors. This in turn
|
|
|
|
// ensures that StartDestroy() will not trigger the delayed path.
|
2017-01-06 23:41:15 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mNumChildActors);
|
2015-05-01 18:13:36 +03:00
|
|
|
|
|
|
|
StartDestroy();
|
2015-04-16 22:00:15 +03:00
|
|
|
}
|
|
|
|
|
2015-03-02 16:20:00 +03:00
|
|
|
void
|
|
|
|
CacheStorageChild::StartDestroy()
|
|
|
|
{
|
|
|
|
NS_ASSERT_OWNINGTHREAD(CacheStorageChild);
|
|
|
|
|
2015-05-01 18:13:36 +03:00
|
|
|
// If we have outstanding child actors, then don't destroy ourself yet.
|
|
|
|
// The child actors should be short lived and we should allow them to complete
|
|
|
|
// if possible. NoteDeletedActor() will call back into this Shutdown()
|
|
|
|
// method when the last child actor is gone.
|
|
|
|
if (mNumChildActors) {
|
|
|
|
mDelayedDestroy = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<CacheStorage> listener = mListener;
|
2015-03-02 16:20:00 +03:00
|
|
|
|
2016-06-23 11:53:14 +03:00
|
|
|
// StartDestroy() can get called from either CacheStorage or the
|
|
|
|
// CacheWorkerHolder.
|
2015-03-02 16:20:00 +03:00
|
|
|
// Theoretically we can get double called if the right race happens. Handle
|
|
|
|
// that by just ignoring the second StartDestroy() call.
|
|
|
|
if (!listener) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
listener->DestroyInternal(this);
|
|
|
|
|
|
|
|
// CacheStorage listener should call ClearListener() in DestroyInternal()
|
2017-01-06 23:41:15 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mListener);
|
2015-03-02 16:20:00 +03:00
|
|
|
|
|
|
|
// Start actor destruction from parent process
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << SendTeardown();
|
2015-03-02 16:20:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CacheStorageChild::ActorDestroy(ActorDestroyReason aReason)
|
|
|
|
{
|
|
|
|
NS_ASSERT_OWNINGTHREAD(CacheStorageChild);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<CacheStorage> listener = mListener;
|
2015-03-02 16:20:00 +03:00
|
|
|
if (listener) {
|
|
|
|
listener->DestroyInternal(this);
|
|
|
|
// CacheStorage listener should call ClearListener() in DestroyInternal()
|
2017-01-06 23:41:15 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mListener);
|
2015-03-02 16:20:00 +03:00
|
|
|
}
|
|
|
|
|
2016-06-23 11:53:14 +03:00
|
|
|
RemoveWorkerHolder();
|
2015-03-02 16:20:00 +03:00
|
|
|
}
|
|
|
|
|
2015-04-16 22:00:15 +03:00
|
|
|
PCacheOpChild*
|
|
|
|
CacheStorageChild::AllocPCacheOpChild(const CacheOpArgs& aOpArgs)
|
2015-04-15 01:27:48 +03:00
|
|
|
{
|
2015-04-16 22:00:15 +03:00
|
|
|
MOZ_CRASH("CacheOpChild should be manually constructed.");
|
|
|
|
return nullptr;
|
2015-04-15 10:55:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-04-16 22:00:15 +03:00
|
|
|
CacheStorageChild::DeallocPCacheOpChild(PCacheOpChild* aActor)
|
2015-04-15 10:55:53 +03:00
|
|
|
{
|
2015-04-16 22:00:15 +03:00
|
|
|
delete aActor;
|
2015-04-16 22:00:15 +03:00
|
|
|
NoteDeletedActor();
|
2015-03-02 16:20:00 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-04-16 22:00:15 +03:00
|
|
|
void
|
|
|
|
CacheStorageChild::NoteDeletedActor()
|
|
|
|
{
|
2017-01-06 23:41:15 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mNumChildActors);
|
2015-04-16 22:00:15 +03:00
|
|
|
mNumChildActors -= 1;
|
2015-05-01 18:13:36 +03:00
|
|
|
if (!mNumChildActors && mDelayedDestroy) {
|
|
|
|
StartDestroy();
|
2015-04-16 22:00:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-02 16:20:00 +03:00
|
|
|
} // namespace cache
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|