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/CacheParent.h"
|
|
|
|
|
2015-04-16 22:00:15 +03:00
|
|
|
#include "mozilla/dom/cache/CacheOpParent.h"
|
2015-03-22 09:52:12 +03:00
|
|
|
#include "mozilla/dom/cache/CachePushStreamParent.h"
|
2015-03-02 16:20:00 +03:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
namespace cache {
|
|
|
|
|
|
|
|
// Declared in ActorUtils.h
|
|
|
|
void
|
|
|
|
DeallocPCacheParent(PCacheParent* aActor)
|
|
|
|
{
|
|
|
|
delete aActor;
|
|
|
|
}
|
|
|
|
|
|
|
|
CacheParent::CacheParent(cache::Manager* aManager, CacheId aCacheId)
|
|
|
|
: mManager(aManager)
|
|
|
|
, mCacheId(aCacheId)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(cache::CacheParent);
|
|
|
|
MOZ_ASSERT(mManager);
|
|
|
|
mManager->AddRefCacheId(mCacheId);
|
|
|
|
}
|
|
|
|
|
|
|
|
CacheParent::~CacheParent()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(cache::CacheParent);
|
|
|
|
MOZ_ASSERT(!mManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CacheParent::ActorDestroy(ActorDestroyReason aReason)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mManager);
|
|
|
|
mManager->ReleaseCacheId(mCacheId);
|
|
|
|
mManager = nullptr;
|
|
|
|
}
|
|
|
|
|
2015-04-16 22:00:15 +03:00
|
|
|
PCacheOpParent*
|
|
|
|
CacheParent::AllocPCacheOpParent(const CacheOpArgs& aOpArgs)
|
2015-03-22 09:52:12 +03:00
|
|
|
{
|
2015-04-16 22:00:15 +03:00
|
|
|
if (aOpArgs.type() != CacheOpArgs::TCacheMatchArgs &&
|
|
|
|
aOpArgs.type() != CacheOpArgs::TCacheMatchAllArgs &&
|
|
|
|
aOpArgs.type() != CacheOpArgs::TCachePutAllArgs &&
|
|
|
|
aOpArgs.type() != CacheOpArgs::TCacheDeleteArgs &&
|
|
|
|
aOpArgs.type() != CacheOpArgs::TCacheKeysArgs)
|
|
|
|
{
|
|
|
|
MOZ_CRASH("Invalid operation sent to Cache actor!");
|
2015-03-02 16:20:00 +03:00
|
|
|
}
|
|
|
|
|
2015-04-16 22:00:15 +03:00
|
|
|
return new CacheOpParent(Manager(), mCacheId, aOpArgs);
|
2015-03-02 16:20:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-04-16 22:00:15 +03:00
|
|
|
CacheParent::DeallocPCacheOpParent(PCacheOpParent* aActor)
|
2015-03-02 16:20:00 +03:00
|
|
|
{
|
2015-04-16 22:00:15 +03:00
|
|
|
delete aActor;
|
2015-03-02 16:20:00 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-04-16 22:00:15 +03:00
|
|
|
CacheParent::RecvPCacheOpConstructor(PCacheOpParent* aActor,
|
|
|
|
const CacheOpArgs& aOpArgs)
|
2015-03-02 16:20:00 +03:00
|
|
|
{
|
2015-04-16 22:00:15 +03:00
|
|
|
auto actor = static_cast<CacheOpParent*>(aActor);
|
|
|
|
actor->Execute(mManager);
|
2015-03-02 16:20:00 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-04-16 22:00:15 +03:00
|
|
|
PCachePushStreamParent*
|
|
|
|
CacheParent::AllocPCachePushStreamParent()
|
2015-03-02 16:20:00 +03:00
|
|
|
{
|
2015-04-16 22:00:15 +03:00
|
|
|
return CachePushStreamParent::Create();
|
2015-03-02 16:20:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-04-16 22:00:15 +03:00
|
|
|
CacheParent::DeallocPCachePushStreamParent(PCachePushStreamParent* aActor)
|
2015-03-02 16:20:00 +03:00
|
|
|
{
|
2015-04-16 22:00:15 +03:00
|
|
|
delete aActor;
|
2015-03-02 16:20:00 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-04-16 22:00:15 +03:00
|
|
|
CacheParent::RecvTeardown()
|
2015-04-15 10:55:53 +03:00
|
|
|
{
|
2015-04-16 22:00:15 +03:00
|
|
|
if (!Send__delete__(this)) {
|
2015-04-15 10:55:53 +03:00
|
|
|
// child process is gone, warn and allow actor to clean up normally
|
2015-04-16 22:00:15 +03:00
|
|
|
NS_WARNING("Cache failed to send delete.");
|
2015-04-15 10:55:53 +03:00
|
|
|
}
|
2015-04-16 22:00:15 +03:00
|
|
|
return true;
|
2015-03-02 16:20:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace cache
|
|
|
|
} // namespace dom
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|