2015-03-02 05:20:00 -08: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/AutoUtils.h"
|
|
|
|
|
|
|
|
#include "mozilla/unused.h"
|
2015-04-13 14:05:57 -07:00
|
|
|
#include "mozilla/dom/cache/CacheParent.h"
|
2015-03-21 23:52:12 -07:00
|
|
|
#include "mozilla/dom/cache/CachePushStreamChild.h"
|
2015-03-02 05:20:00 -08:00
|
|
|
#include "mozilla/dom/cache/CacheStreamControlParent.h"
|
|
|
|
#include "mozilla/dom/cache/ReadStream.h"
|
|
|
|
#include "mozilla/dom/cache/SavedTypes.h"
|
|
|
|
#include "mozilla/dom/cache/StreamList.h"
|
|
|
|
#include "mozilla/dom/cache/TypeUtils.h"
|
|
|
|
#include "mozilla/ipc/FileDescriptorSetChild.h"
|
|
|
|
#include "mozilla/ipc/FileDescriptorSetParent.h"
|
|
|
|
#include "mozilla/ipc/PBackgroundParent.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
using mozilla::unused;
|
2015-03-21 23:52:12 -07:00
|
|
|
using mozilla::dom::cache::CachePushStreamChild;
|
2015-03-02 05:20:00 -08:00
|
|
|
using mozilla::dom::cache::PCacheReadStream;
|
|
|
|
using mozilla::dom::cache::PCacheReadStreamOrVoid;
|
|
|
|
using mozilla::ipc::FileDescriptor;
|
|
|
|
using mozilla::ipc::FileDescriptorSetChild;
|
|
|
|
using mozilla::ipc::FileDescriptorSetParent;
|
|
|
|
using mozilla::ipc::OptionalFileDescriptorSet;
|
|
|
|
|
|
|
|
enum CleanupAction
|
|
|
|
{
|
2015-03-21 23:52:12 -07:00
|
|
|
Forget,
|
|
|
|
Delete
|
2015-03-02 05:20:00 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
CleanupChildFds(PCacheReadStream& aReadStream, CleanupAction aAction)
|
|
|
|
{
|
|
|
|
if (aReadStream.fds().type() !=
|
|
|
|
OptionalFileDescriptorSet::TPFileDescriptorSetChild) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoTArray<FileDescriptor, 4> fds;
|
|
|
|
|
|
|
|
FileDescriptorSetChild* fdSetActor =
|
|
|
|
static_cast<FileDescriptorSetChild*>(aReadStream.fds().get_PFileDescriptorSetChild());
|
|
|
|
MOZ_ASSERT(fdSetActor);
|
|
|
|
|
2015-03-21 23:52:12 -07:00
|
|
|
if (aAction == Delete) {
|
2015-03-02 05:20:00 -08:00
|
|
|
unused << fdSetActor->Send__delete__(fdSetActor);
|
|
|
|
}
|
|
|
|
|
|
|
|
// FileDescriptorSet doesn't clear its fds in its ActorDestroy, so we
|
|
|
|
// unconditionally forget them here. The fds themselves are auto-closed in
|
|
|
|
// ~FileDescriptor since they originated in this process.
|
|
|
|
fdSetActor->ForgetFileDescriptors(fds);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-03-21 23:52:12 -07:00
|
|
|
CleanupChildPushStream(PCacheReadStream& aReadStream, CleanupAction aAction)
|
|
|
|
{
|
|
|
|
if (!aReadStream.pushStreamChild()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto pushStream =
|
|
|
|
static_cast<CachePushStreamChild*>(aReadStream.pushStreamChild());
|
|
|
|
|
|
|
|
if (aAction == Delete) {
|
|
|
|
pushStream->StartDestroy();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we send the stream, then we need to start it before forgetting about it.
|
|
|
|
pushStream->Start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CleanupChild(PCacheReadStream& aReadStream, CleanupAction aAction)
|
|
|
|
{
|
|
|
|
CleanupChildFds(aReadStream, aAction);
|
|
|
|
CleanupChildPushStream(aReadStream, aAction);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CleanupChild(PCacheReadStreamOrVoid& aReadStreamOrVoid, CleanupAction aAction)
|
2015-03-02 05:20:00 -08:00
|
|
|
{
|
|
|
|
if (aReadStreamOrVoid.type() == PCacheReadStreamOrVoid::Tvoid_t) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-21 23:52:12 -07:00
|
|
|
CleanupChild(aReadStreamOrVoid.get_PCacheReadStream(), aAction);
|
2015-03-02 05:20:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CleanupParentFds(PCacheReadStream& aReadStream, CleanupAction aAction)
|
|
|
|
{
|
|
|
|
if (aReadStream.fds().type() !=
|
|
|
|
OptionalFileDescriptorSet::TPFileDescriptorSetParent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoTArray<FileDescriptor, 4> fds;
|
|
|
|
|
|
|
|
FileDescriptorSetParent* fdSetActor =
|
|
|
|
static_cast<FileDescriptorSetParent*>(aReadStream.fds().get_PFileDescriptorSetParent());
|
|
|
|
MOZ_ASSERT(fdSetActor);
|
|
|
|
|
2015-03-21 23:52:12 -07:00
|
|
|
if (aAction == Delete) {
|
2015-03-02 05:20:00 -08:00
|
|
|
unused << fdSetActor->Send__delete__(fdSetActor);
|
|
|
|
}
|
|
|
|
|
|
|
|
// FileDescriptorSet doesn't clear its fds in its ActorDestroy, so we
|
|
|
|
// unconditionally forget them here. The fds themselves are auto-closed in
|
|
|
|
// ~FileDescriptor since they originated in this process.
|
|
|
|
fdSetActor->ForgetFileDescriptors(fds);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CleanupParentFds(PCacheReadStreamOrVoid& aReadStreamOrVoid, CleanupAction aAction)
|
|
|
|
{
|
|
|
|
if (aReadStreamOrVoid.type() == PCacheReadStreamOrVoid::Tvoid_t) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CleanupParentFds(aReadStreamOrVoid.get_PCacheReadStream(), aAction);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
namespace cache {
|
|
|
|
|
|
|
|
using mozilla::ipc::PBackgroundParent;
|
|
|
|
|
2015-04-13 14:05:57 -07:00
|
|
|
// --------------------------------------------
|
|
|
|
|
|
|
|
AutoChildOpArgs::AutoChildOpArgs(TypeUtils* aTypeUtils,
|
|
|
|
const CacheOpArgs& aOpArgs)
|
2015-03-02 05:20:00 -08:00
|
|
|
: mTypeUtils(aTypeUtils)
|
2015-04-13 14:05:57 -07:00
|
|
|
, mOpArgs(aOpArgs)
|
2015-03-02 05:20:00 -08:00
|
|
|
, mSent(false)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mTypeUtils);
|
|
|
|
}
|
|
|
|
|
2015-04-13 14:05:57 -07:00
|
|
|
AutoChildOpArgs::~AutoChildOpArgs()
|
2015-03-02 05:20:00 -08:00
|
|
|
{
|
2015-04-13 14:05:57 -07:00
|
|
|
CleanupAction action = mSent ? Forget : Delete;
|
2015-03-02 05:20:00 -08:00
|
|
|
|
2015-04-13 14:05:57 -07:00
|
|
|
switch(mOpArgs.type()) {
|
|
|
|
case CacheOpArgs::TCacheMatchArgs:
|
|
|
|
{
|
|
|
|
CacheMatchArgs& args = mOpArgs.get_CacheMatchArgs();
|
|
|
|
CleanupChild(args.request().body(), action);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CacheOpArgs::TCacheMatchAllArgs:
|
|
|
|
{
|
|
|
|
CacheMatchAllArgs& args = mOpArgs.get_CacheMatchAllArgs();
|
|
|
|
if (args.requestOrVoid().type() == PCacheRequestOrVoid::Tvoid_t) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
CleanupChild(args.requestOrVoid().get_PCacheRequest().body(), action);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CacheOpArgs::TCacheAddAllArgs:
|
|
|
|
{
|
|
|
|
CacheAddAllArgs& args = mOpArgs.get_CacheAddAllArgs();
|
|
|
|
auto& list = args.requestList();
|
|
|
|
for (uint32_t i = 0; i < list.Length(); ++i) {
|
|
|
|
CleanupChild(list[i].body(), action);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CacheOpArgs::TCachePutAllArgs:
|
|
|
|
{
|
|
|
|
CachePutAllArgs& args = mOpArgs.get_CachePutAllArgs();
|
|
|
|
auto& list = args.requestResponseList();
|
|
|
|
for (uint32_t i = 0; i < list.Length(); ++i) {
|
|
|
|
CleanupChild(list[i].request().body(), action);
|
|
|
|
CleanupChild(list[i].response().body(), action);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CacheOpArgs::TCacheDeleteArgs:
|
|
|
|
{
|
|
|
|
CacheDeleteArgs& args = mOpArgs.get_CacheDeleteArgs();
|
|
|
|
CleanupChild(args.request().body(), action);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CacheOpArgs::TCacheKeysArgs:
|
|
|
|
{
|
|
|
|
CacheKeysArgs& args = mOpArgs.get_CacheKeysArgs();
|
|
|
|
if (args.requestOrVoid().type() == PCacheRequestOrVoid::Tvoid_t) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
CleanupChild(args.requestOrVoid().get_PCacheRequest().body(), action);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CacheOpArgs::TStorageMatchArgs:
|
|
|
|
{
|
|
|
|
StorageMatchArgs& args = mOpArgs.get_StorageMatchArgs();
|
|
|
|
CleanupChild(args.request().body(), action);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
// Other types do not need cleanup
|
|
|
|
break;
|
2015-03-02 05:20:00 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-04-13 14:05:57 -07:00
|
|
|
AutoChildOpArgs::Add(InternalRequest* aRequest, BodyAction aBodyAction,
|
|
|
|
ReferrerAction aReferrerAction, SchemeAction aSchemeAction,
|
|
|
|
ErrorResult& aRv)
|
2015-03-02 05:20:00 -08:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mSent);
|
|
|
|
|
2015-04-13 14:05:57 -07:00
|
|
|
switch(mOpArgs.type()) {
|
|
|
|
case CacheOpArgs::TCacheMatchArgs:
|
|
|
|
{
|
|
|
|
CacheMatchArgs& args = mOpArgs.get_CacheMatchArgs();
|
|
|
|
mTypeUtils->ToPCacheRequest(args.request(), aRequest, aBodyAction,
|
|
|
|
aReferrerAction, aSchemeAction, aRv);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CacheOpArgs::TCacheMatchAllArgs:
|
|
|
|
{
|
|
|
|
CacheMatchAllArgs& args = mOpArgs.get_CacheMatchAllArgs();
|
|
|
|
MOZ_ASSERT(args.requestOrVoid().type() == PCacheRequestOrVoid::Tvoid_t);
|
|
|
|
args.requestOrVoid() = PCacheRequest();
|
|
|
|
mTypeUtils->ToPCacheRequest(args.requestOrVoid().get_PCacheRequest(),
|
|
|
|
aRequest, aBodyAction, aReferrerAction,
|
|
|
|
aSchemeAction, aRv);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CacheOpArgs::TCacheAddAllArgs:
|
|
|
|
{
|
|
|
|
CacheAddAllArgs& args = mOpArgs.get_CacheAddAllArgs();
|
|
|
|
|
|
|
|
// The FileDescriptorSetChild asserts in its destructor that all fds have
|
|
|
|
// been removed. The copy constructor, however, simply duplicates the
|
|
|
|
// fds without removing any. This means each temporary and copy must be
|
|
|
|
// explicitly cleaned up.
|
|
|
|
//
|
|
|
|
// Avoid a lot of this hassle by making sure we only create one here. On
|
|
|
|
// error we remove it.
|
|
|
|
PCacheRequest& request = *args.requestList().AppendElement();
|
|
|
|
|
|
|
|
mTypeUtils->ToPCacheRequest(request, aRequest, aBodyAction,
|
|
|
|
aReferrerAction, aSchemeAction, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
args.requestList().RemoveElementAt(args.requestList().Length() - 1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CacheOpArgs::TCacheDeleteArgs:
|
|
|
|
{
|
|
|
|
CacheDeleteArgs& args = mOpArgs.get_CacheDeleteArgs();
|
|
|
|
mTypeUtils->ToPCacheRequest(args.request(), aRequest, aBodyAction,
|
|
|
|
aReferrerAction, aSchemeAction, aRv);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CacheOpArgs::TCacheKeysArgs:
|
|
|
|
{
|
|
|
|
CacheKeysArgs& args = mOpArgs.get_CacheKeysArgs();
|
|
|
|
MOZ_ASSERT(args.requestOrVoid().type() == PCacheRequestOrVoid::Tvoid_t);
|
|
|
|
args.requestOrVoid() = PCacheRequest();
|
|
|
|
mTypeUtils->ToPCacheRequest(args.requestOrVoid().get_PCacheRequest(),
|
|
|
|
aRequest, aBodyAction, aReferrerAction,
|
|
|
|
aSchemeAction, aRv);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CacheOpArgs::TStorageMatchArgs:
|
|
|
|
{
|
|
|
|
StorageMatchArgs& args = mOpArgs.get_StorageMatchArgs();
|
|
|
|
mTypeUtils->ToPCacheRequest(args.request(), aRequest, aBodyAction,
|
|
|
|
aReferrerAction, aSchemeAction, aRv);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Cache args type cannot send a Request!");
|
2015-03-02 05:20:00 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-04-13 14:05:57 -07:00
|
|
|
AutoChildOpArgs::Add(InternalRequest* aRequest, BodyAction aBodyAction,
|
|
|
|
ReferrerAction aReferrerAction, SchemeAction aSchemeAction,
|
|
|
|
Response& aResponse, ErrorResult& aRv)
|
2015-03-02 05:20:00 -08:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mSent);
|
|
|
|
|
2015-04-13 14:05:57 -07:00
|
|
|
switch(mOpArgs.type()) {
|
|
|
|
case CacheOpArgs::TCachePutAllArgs:
|
|
|
|
{
|
|
|
|
CachePutAllArgs& args = mOpArgs.get_CachePutAllArgs();
|
|
|
|
|
|
|
|
// The FileDescriptorSetChild asserts in its destructor that all fds have
|
|
|
|
// been removed. The copy constructor, however, simply duplicates the
|
|
|
|
// fds without removing any. This means each temporary and copy must be
|
|
|
|
// explicitly cleaned up.
|
|
|
|
//
|
|
|
|
// Avoid a lot of this hassle by making sure we only create one here. On
|
|
|
|
// error we remove it.
|
|
|
|
CacheRequestResponse& pair = *args.requestResponseList().AppendElement();
|
|
|
|
pair.request().body() = void_t();
|
|
|
|
pair.response().body() = void_t();
|
|
|
|
|
|
|
|
mTypeUtils->ToPCacheRequest(pair.request(), aRequest, aBodyAction,
|
|
|
|
aReferrerAction, aSchemeAction, aRv);
|
|
|
|
if (!aRv.Failed()) {
|
|
|
|
mTypeUtils->ToPCacheResponse(pair.response(), aResponse, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
CleanupChild(pair.request().body(), Delete);
|
|
|
|
args.requestResponseList().RemoveElementAt(
|
|
|
|
args.requestResponseList().Length() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Cache args type cannot send a Request/Response pair!");
|
2015-03-02 05:20:00 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-13 14:05:57 -07:00
|
|
|
const CacheOpArgs&
|
|
|
|
AutoChildOpArgs::SendAsOpArgs()
|
2015-03-02 05:20:00 -08:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mSent);
|
|
|
|
mSent = true;
|
2015-04-13 14:05:57 -07:00
|
|
|
return mOpArgs;
|
2015-03-02 05:20:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------
|
|
|
|
|
2015-04-13 14:05:57 -07:00
|
|
|
AutoParentOpResult::AutoParentOpResult(mozilla::ipc::PBackgroundParent* aManager,
|
|
|
|
const CacheOpResult& aOpResult)
|
|
|
|
: mManager(aManager)
|
|
|
|
, mOpResult(aOpResult)
|
|
|
|
, mStreamControl(nullptr)
|
|
|
|
, mSent(false)
|
2015-03-02 05:20:00 -08:00
|
|
|
{
|
2015-04-13 14:05:57 -07:00
|
|
|
MOZ_ASSERT(mManager);
|
2015-03-02 05:20:00 -08:00
|
|
|
}
|
|
|
|
|
2015-04-13 14:05:57 -07:00
|
|
|
AutoParentOpResult::~AutoParentOpResult()
|
2015-03-02 05:20:00 -08:00
|
|
|
{
|
2015-03-21 23:52:12 -07:00
|
|
|
CleanupAction action = mSent ? Forget : Delete;
|
2015-04-13 14:05:57 -07:00
|
|
|
|
|
|
|
switch (mOpResult.type()) {
|
|
|
|
case CacheOpResult::TCacheMatchResult:
|
|
|
|
{
|
|
|
|
CacheMatchResult& result = mOpResult.get_CacheMatchResult();
|
|
|
|
if (result.responseOrVoid().type() == PCacheResponseOrVoid::Tvoid_t) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
CleanupParentFds(result.responseOrVoid().get_PCacheResponse().body(),
|
|
|
|
action);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CacheOpResult::TCacheMatchAllResult:
|
|
|
|
{
|
|
|
|
CacheMatchAllResult& result = mOpResult.get_CacheMatchAllResult();
|
|
|
|
for (uint32_t i = 0; i < result.responseList().Length(); ++i) {
|
|
|
|
CleanupParentFds(result.responseList()[i].body(), action);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CacheOpResult::TCacheKeysResult:
|
|
|
|
{
|
|
|
|
CacheKeysResult& result = mOpResult.get_CacheKeysResult();
|
|
|
|
for (uint32_t i = 0; i < result.requestList().Length(); ++i) {
|
|
|
|
CleanupParentFds(result.requestList()[i].body(), action);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CacheOpResult::TStorageMatchResult:
|
|
|
|
{
|
|
|
|
StorageMatchResult& result = mOpResult.get_StorageMatchResult();
|
|
|
|
if (result.responseOrVoid().type() == PCacheResponseOrVoid::Tvoid_t) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
CleanupParentFds(result.responseOrVoid().get_PCacheResponse().body(),
|
|
|
|
action);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CacheOpResult::TStorageOpenResult:
|
|
|
|
{
|
|
|
|
StorageOpenResult& result = mOpResult.get_StorageOpenResult();
|
|
|
|
if (action == Forget || result.actorParent() == nullptr) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
unused << PCacheParent::Send__delete__(result.actorParent());
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
// other types do not need clean up
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action == Delete && mStreamControl) {
|
|
|
|
unused << PCacheStreamControlParent::Send__delete__(mStreamControl);
|
|
|
|
}
|
2015-03-02 05:20:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-04-13 14:05:57 -07:00
|
|
|
AutoParentOpResult::Add(CacheId aOpenedCacheId, Manager* aManager)
|
2015-03-02 05:20:00 -08:00
|
|
|
{
|
2015-04-13 14:05:57 -07:00
|
|
|
MOZ_ASSERT(mOpResult.type() == CacheOpResult::TStorageOpenResult);
|
|
|
|
MOZ_ASSERT(mOpResult.get_StorageOpenResult().actorParent() == nullptr);
|
|
|
|
mOpResult.get_StorageOpenResult().actorParent() =
|
|
|
|
mManager->SendPCacheConstructor(new CacheParent(aManager, aOpenedCacheId));
|
2015-03-02 05:20:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-04-13 14:05:57 -07:00
|
|
|
AutoParentOpResult::Add(const SavedResponse& aSavedResponse,
|
|
|
|
StreamList* aStreamList)
|
2015-03-02 05:20:00 -08:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mSent);
|
2015-04-13 14:05:57 -07:00
|
|
|
|
|
|
|
switch (mOpResult.type()) {
|
|
|
|
case CacheOpResult::TCacheMatchResult:
|
|
|
|
{
|
|
|
|
CacheMatchResult& result = mOpResult.get_CacheMatchResult();
|
|
|
|
MOZ_ASSERT(result.responseOrVoid().type() == PCacheResponseOrVoid::Tvoid_t);
|
|
|
|
result.responseOrVoid() = aSavedResponse.mValue;
|
|
|
|
SerializeResponseBody(aSavedResponse, aStreamList,
|
|
|
|
&result.responseOrVoid().get_PCacheResponse());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CacheOpResult::TCacheMatchAllResult:
|
|
|
|
{
|
|
|
|
CacheMatchAllResult& result = mOpResult.get_CacheMatchAllResult();
|
|
|
|
result.responseList().AppendElement(aSavedResponse.mValue);
|
|
|
|
SerializeResponseBody(aSavedResponse, aStreamList,
|
|
|
|
&result.responseList().LastElement());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CacheOpResult::TStorageMatchResult:
|
|
|
|
{
|
|
|
|
StorageMatchResult& result = mOpResult.get_StorageMatchResult();
|
|
|
|
MOZ_ASSERT(result.responseOrVoid().type() == PCacheResponseOrVoid::Tvoid_t);
|
|
|
|
result.responseOrVoid() = aSavedResponse.mValue;
|
|
|
|
SerializeResponseBody(aSavedResponse, aStreamList,
|
|
|
|
&result.responseOrVoid().get_PCacheResponse());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Cache result type cannot handle returning a Response!");
|
|
|
|
}
|
2015-03-02 05:20:00 -08:00
|
|
|
}
|
|
|
|
|
2015-04-13 14:05:57 -07:00
|
|
|
void
|
|
|
|
AutoParentOpResult::Add(const SavedRequest& aSavedRequest,
|
|
|
|
StreamList* aStreamList)
|
2015-03-02 05:20:00 -08:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mSent);
|
|
|
|
|
2015-04-13 14:05:57 -07:00
|
|
|
switch (mOpResult.type()) {
|
|
|
|
case CacheOpResult::TCacheKeysResult:
|
|
|
|
{
|
|
|
|
CacheKeysResult& result = mOpResult.get_CacheKeysResult();
|
|
|
|
result.requestList().AppendElement(aSavedRequest.mValue);
|
|
|
|
PCacheRequest& request = result.requestList().LastElement();
|
|
|
|
|
|
|
|
if (!aSavedRequest.mHasBodyId) {
|
|
|
|
request.body() = void_t();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
request.body() = PCacheReadStream();
|
|
|
|
SerializeReadStream(aSavedRequest.mBodyId, aStreamList,
|
|
|
|
&request.body().get_PCacheReadStream());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Cache result type cannot handle returning a Request!");
|
|
|
|
}
|
|
|
|
}
|
2015-03-02 05:20:00 -08:00
|
|
|
|
2015-04-13 14:05:57 -07:00
|
|
|
const CacheOpResult&
|
|
|
|
AutoParentOpResult::SendAsOpResult()
|
2015-03-02 05:20:00 -08:00
|
|
|
{
|
2015-04-13 14:05:57 -07:00
|
|
|
MOZ_ASSERT(!mSent);
|
|
|
|
mSent = true;
|
|
|
|
return mOpResult;
|
2015-03-02 05:20:00 -08:00
|
|
|
}
|
|
|
|
|
2015-04-13 14:05:57 -07:00
|
|
|
void
|
|
|
|
AutoParentOpResult::SerializeResponseBody(const SavedResponse& aSavedResponse,
|
|
|
|
StreamList* aStreamList,
|
|
|
|
PCacheResponse* aResponseOut)
|
2015-03-02 05:20:00 -08:00
|
|
|
{
|
2015-04-13 14:05:57 -07:00
|
|
|
MOZ_ASSERT(aResponseOut);
|
|
|
|
|
|
|
|
if (!aSavedResponse.mHasBodyId) {
|
|
|
|
aResponseOut->body() = void_t();
|
|
|
|
return;
|
2015-03-02 05:20:00 -08:00
|
|
|
}
|
2015-04-13 14:05:57 -07:00
|
|
|
|
|
|
|
aResponseOut->body() = PCacheReadStream();
|
|
|
|
SerializeReadStream(aSavedResponse.mBodyId, aStreamList,
|
|
|
|
&aResponseOut->body().get_PCacheReadStream());
|
2015-03-02 05:20:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-04-13 14:05:57 -07:00
|
|
|
AutoParentOpResult::SerializeReadStream(const nsID& aId, StreamList* aStreamList,
|
|
|
|
PCacheReadStream* aReadStreamOut)
|
2015-03-02 05:20:00 -08:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aStreamList);
|
|
|
|
MOZ_ASSERT(aReadStreamOut);
|
|
|
|
MOZ_ASSERT(!mSent);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIInputStream> stream = aStreamList->Extract(aId);
|
|
|
|
MOZ_ASSERT(stream);
|
|
|
|
|
|
|
|
if (!mStreamControl) {
|
|
|
|
mStreamControl = static_cast<CacheStreamControlParent*>(
|
|
|
|
mManager->SendPCacheStreamControlConstructor(new CacheStreamControlParent()));
|
|
|
|
|
|
|
|
// If this failed, then the child process is gone. Warn and allow actor
|
|
|
|
// cleanup to proceed as normal.
|
|
|
|
if (!mStreamControl) {
|
|
|
|
NS_WARNING("Cache failed to create stream control actor.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aStreamList->SetStreamControl(mStreamControl);
|
|
|
|
|
|
|
|
nsRefPtr<ReadStream> readStream = ReadStream::Create(mStreamControl,
|
|
|
|
aId, stream);
|
|
|
|
readStream->Serialize(aReadStreamOut);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace cache
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|