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-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);
|
2017-01-06 23:41:15 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mManager);
|
2015-03-02 16:20:00 +03:00
|
|
|
mManager->AddRefCacheId(mCacheId);
|
|
|
|
}
|
|
|
|
|
|
|
|
CacheParent::~CacheParent()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(cache::CacheParent);
|
2017-01-06 23:41:15 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mManager);
|
2015-03-02 16:20:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CacheParent::ActorDestroy(ActorDestroyReason aReason)
|
|
|
|
{
|
2017-01-06 23:41:15 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mManager);
|
2015-03-02 16:20:00 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
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);
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-03-02 16:20:00 +03:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
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
|
|
|
}
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-03-02 16:20:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace cache
|
|
|
|
} // namespace dom
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|