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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_cache_CacheChild_h
|
|
|
|
#define mozilla_dom_cache_CacheChild_h
|
|
|
|
|
|
|
|
#include "mozilla/dom/cache/ActorChild.h"
|
|
|
|
#include "mozilla/dom/cache/PCacheChild.h"
|
|
|
|
|
2015-04-16 22:00:15 +03:00
|
|
|
class nsIAsyncInputStream;
|
|
|
|
class nsIGlobalObject;
|
|
|
|
|
2015-03-02 16:20:00 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2015-04-16 22:00:15 +03:00
|
|
|
|
|
|
|
class Promise;
|
|
|
|
|
2015-03-02 16:20:00 +03:00
|
|
|
namespace cache {
|
|
|
|
|
|
|
|
class Cache;
|
2015-04-16 22:00:15 +03:00
|
|
|
class CacheOpArgs;
|
2015-03-02 16:20:00 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class CacheChild final : public PCacheChild, public ActorChild {
|
2019-02-06 18:57:37 +03:00
|
|
|
friend class PCacheChild;
|
|
|
|
|
2015-03-02 16:20:00 +03:00
|
|
|
public:
|
2016-01-04 23:03:11 +03:00
|
|
|
class MOZ_RAII AutoLock final {
|
|
|
|
CacheChild* mActor;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit AutoLock(CacheChild* aActor) : mActor(aActor) {
|
2017-01-06 23:41:15 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mActor);
|
2016-01-04 23:03:11 +03:00
|
|
|
mActor->Lock();
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoLock() { mActor->Unlock(); }
|
|
|
|
};
|
|
|
|
|
2015-03-02 16:20:00 +03:00
|
|
|
CacheChild();
|
|
|
|
~CacheChild();
|
|
|
|
|
|
|
|
void SetListener(Cache* aListener);
|
|
|
|
|
2015-05-01 18:13:36 +03:00
|
|
|
// Must be called by the associated Cache listener in its DestroyInternal()
|
|
|
|
// method. Also, Cache must call StartDestroyFromListener() on the actor in
|
|
|
|
// its destructor to trigger ActorDestroy() if it has not been called yet.
|
2015-03-02 16:20:00 +03:00
|
|
|
void ClearListener();
|
|
|
|
|
2015-04-16 22:00:15 +03:00
|
|
|
void 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
|
|
|
|
2015-05-01 18:13:36 +03:00
|
|
|
// Our parent Listener object has gone out of scope and is being destroyed.
|
|
|
|
void StartDestroyFromListener();
|
|
|
|
|
|
|
|
private:
|
2015-03-02 16:20:00 +03:00
|
|
|
// ActorChild methods
|
|
|
|
|
2019-07-12 14:17:59 +03:00
|
|
|
// WorkerRef is trying to destroy due to worker shutdown.
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void StartDestroy() override;
|
2015-03-02 16:20:00 +03:00
|
|
|
|
|
|
|
// PCacheChild methods
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void ActorDestroy(ActorDestroyReason aReason) override;
|
2015-03-02 16:20:00 +03:00
|
|
|
|
2019-02-06 18:58:07 +03:00
|
|
|
PCacheOpChild* AllocPCacheOpChild(const CacheOpArgs& aOpArgs);
|
2015-04-16 22:00:15 +03:00
|
|
|
|
2019-02-06 18:58:07 +03:00
|
|
|
bool DeallocPCacheOpChild(PCacheOpChild* aActor);
|
2015-04-16 22:00:15 +03:00
|
|
|
|
2015-04-16 22:00:15 +03:00
|
|
|
// utility methods
|
|
|
|
void NoteDeletedActor();
|
|
|
|
|
2016-01-04 23:03:11 +03:00
|
|
|
void MaybeFlushDelayedDestroy();
|
|
|
|
|
|
|
|
// Methods used to temporarily force the actor alive. Only called from
|
|
|
|
// AutoLock.
|
|
|
|
void Lock();
|
|
|
|
|
|
|
|
void Unlock();
|
|
|
|
|
2015-03-02 16:20:00 +03:00
|
|
|
// Use a weak ref so actor does not hold DOM object alive past content use.
|
|
|
|
// The Cache object must call ClearListener() to null this before its
|
|
|
|
// destroyed.
|
|
|
|
Cache* MOZ_NON_OWNING_REF mListener;
|
2015-04-16 22:00:15 +03:00
|
|
|
uint32_t mNumChildActors;
|
2015-05-01 18:13:36 +03:00
|
|
|
bool mDelayedDestroy;
|
2016-01-04 23:03:11 +03:00
|
|
|
bool mLocked;
|
2015-03-02 16:20:00 +03:00
|
|
|
|
|
|
|
NS_DECL_OWNINGTHREAD
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace cache
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_cache_CacheChild_h
|