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/CacheStreamControlChild.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/ActorUtils.h"
|
2015-04-16 22:00:15 +03:00
|
|
|
#include "mozilla/dom/cache/CacheTypes.h"
|
2017-10-26 14:35:08 +03:00
|
|
|
#include "mozilla/dom/cache/CacheWorkerHolder.h"
|
2015-03-02 16:20:00 +03:00
|
|
|
#include "mozilla/dom/cache/ReadStream.h"
|
2015-03-20 21:01:57 +03:00
|
|
|
#include "mozilla/ipc/FileDescriptorSetChild.h"
|
2017-10-26 14:35:08 +03:00
|
|
|
#include "mozilla/ipc/IPCStreamUtils.h"
|
2015-03-20 21:01:57 +03:00
|
|
|
#include "mozilla/ipc/PBackgroundChild.h"
|
|
|
|
#include "mozilla/ipc/PFileDescriptorSetChild.h"
|
2015-03-02 16:20:00 +03:00
|
|
|
#include "nsISupportsImpl.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
namespace cache {
|
|
|
|
|
2016-05-18 01:01:25 +03:00
|
|
|
using mozilla::dom::OptionalFileDescriptorSet;
|
2016-05-15 20:32:09 +03:00
|
|
|
using mozilla::ipc::AutoIPCStream;
|
2015-03-20 21:01:57 +03:00
|
|
|
using mozilla::ipc::FileDescriptor;
|
|
|
|
using mozilla::ipc::FileDescriptorSetChild;
|
|
|
|
using mozilla::ipc::PFileDescriptorSetChild;
|
|
|
|
|
2015-03-02 16:20:00 +03:00
|
|
|
// declared in ActorUtils.h
|
|
|
|
PCacheStreamControlChild* AllocPCacheStreamControlChild() {
|
|
|
|
return new CacheStreamControlChild();
|
|
|
|
}
|
|
|
|
|
|
|
|
// declared in ActorUtils.h
|
|
|
|
void DeallocPCacheStreamControlChild(PCacheStreamControlChild* aActor) {
|
|
|
|
delete aActor;
|
|
|
|
}
|
|
|
|
|
|
|
|
CacheStreamControlChild::CacheStreamControlChild()
|
|
|
|
: mDestroyStarted(false), mDestroyDelayed(false) {
|
|
|
|
MOZ_COUNT_CTOR(cache::CacheStreamControlChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
CacheStreamControlChild::~CacheStreamControlChild() {
|
|
|
|
NS_ASSERT_OWNINGTHREAD(CacheStreamControlChild);
|
|
|
|
MOZ_COUNT_DTOR(cache::CacheStreamControlChild);
|
|
|
|
}
|
|
|
|
|
2015-03-20 21:01:57 +03:00
|
|
|
void CacheStreamControlChild::StartDestroy() {
|
2015-03-02 16:20:00 +03:00
|
|
|
NS_ASSERT_OWNINGTHREAD(CacheStreamControlChild);
|
2015-03-20 21:01:57 +03:00
|
|
|
// This can get called twice under some circumstances. For example, if the
|
2016-06-23 11:53:14 +03:00
|
|
|
// actor is added to a CacheWorkerHolder that has already been notified and
|
|
|
|
// the Cache actor has no mListener.
|
2015-03-20 21:01:57 +03:00
|
|
|
if (mDestroyStarted) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mDestroyStarted = true;
|
|
|
|
|
2015-04-16 22:00:15 +03:00
|
|
|
// If any of the streams have started to be read, then wait for them to close
|
|
|
|
// naturally.
|
|
|
|
if (HasEverBeenRead()) {
|
|
|
|
// Note that we are delaying so that we can re-check for active streams
|
|
|
|
// in NoteClosedAfterForget().
|
|
|
|
mDestroyDelayed = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, if the streams have not been touched then just pre-emptively
|
|
|
|
// close them now. This handles the case where someone retrieves a Response
|
|
|
|
// from the Cache, but never accesses the body. We should not keep the
|
|
|
|
// Worker alive until that Response is GC'd just because of its ignored
|
|
|
|
// body stream.
|
|
|
|
|
2015-03-20 21:01:57 +03:00
|
|
|
// Begin shutting down all streams. This is the same as if the parent had
|
|
|
|
// asked us to shutdown. So simulate the CloseAll IPC message.
|
|
|
|
RecvCloseAll();
|
2015-03-02 16:20:00 +03:00
|
|
|
}
|
|
|
|
|
2015-04-16 22:00:15 +03:00
|
|
|
void CacheStreamControlChild::SerializeControl(
|
|
|
|
CacheReadStream* aReadStreamOut) {
|
2015-03-02 16:20:00 +03:00
|
|
|
NS_ASSERT_OWNINGTHREAD(CacheStreamControlChild);
|
2017-01-06 23:41:15 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aReadStreamOut);
|
2015-03-20 21:01:57 +03:00
|
|
|
aReadStreamOut->controlParent() = nullptr;
|
|
|
|
aReadStreamOut->controlChild() = this;
|
2015-03-02 16:20:00 +03:00
|
|
|
}
|
|
|
|
|
2016-05-15 20:32:09 +03:00
|
|
|
void CacheStreamControlChild::SerializeStream(
|
|
|
|
CacheReadStream* aReadStreamOut, nsIInputStream* aStream,
|
|
|
|
nsTArray<UniquePtr<AutoIPCStream>>& aStreamCleanupList) {
|
2015-03-02 16:20:00 +03:00
|
|
|
NS_ASSERT_OWNINGTHREAD(CacheStreamControlChild);
|
2017-01-06 23:41:15 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aReadStreamOut);
|
2016-05-15 20:32:09 +03:00
|
|
|
UniquePtr<AutoIPCStream> autoStream(
|
|
|
|
new AutoIPCStream(aReadStreamOut->stream()));
|
|
|
|
autoStream->Serialize(aStream, Manager());
|
2018-05-30 22:15:35 +03:00
|
|
|
aStreamCleanupList.AppendElement(std::move(autoStream));
|
2015-03-20 21:01:57 +03:00
|
|
|
}
|
2015-03-02 16:20:00 +03:00
|
|
|
|
2017-09-15 22:25:41 +03:00
|
|
|
void CacheStreamControlChild::OpenStream(const nsID& aId,
|
|
|
|
InputStreamResolver&& aResolver) {
|
|
|
|
NS_ASSERT_OWNINGTHREAD(CacheStreamControlChild);
|
|
|
|
|
|
|
|
if (mDestroyStarted) {
|
|
|
|
aResolver(nullptr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-25 20:45:58 +03:00
|
|
|
// If we are on a worker, then we need to hold it alive until the async
|
|
|
|
// IPC operation below completes. While the IPC layer will trigger a
|
|
|
|
// rejection here in many cases, we must handle the case where the
|
|
|
|
// MozPromise resolve runnable is already in the event queue when the
|
|
|
|
// worker wants to shut down.
|
|
|
|
RefPtr<CacheWorkerHolder> holder = GetWorkerHolder();
|
|
|
|
|
2017-09-15 22:25:41 +03:00
|
|
|
SendOpenStream(aId)->Then(
|
|
|
|
GetCurrentThreadSerialEventTarget(), __func__,
|
Bug 1443954 - Part 3: Add support for RefCounted types to IPDL, r=bz,froydnj,baku
This patch was reviewed in parts, however the intermediate states would not build:
Bug 1443954 - Part 3A: Strip pointers from the argument to WriteParam and WriteIPDLParam before selecting the ParamTraits impl, r=froydnj
Bug 1443954 - Part 3B: Move nsIAlertNotification serialization to the refcounted system, r=bz
Bug 1443954 - Part 3C: Move geolocation serialization to the refcounted system, r=bz
Bug 1443954 - Part 3D: Move nsIInputStream serialization to the refcounted system, r=baku
Bug 1443954 - Part 3E: Move BlobImpl serialization to the refcounted system, r=baku
Bug 1443954 - Part 3F: Correctly implement ParamTraits for actors after the ParamTraits changes, r=froydnj
2018-03-07 04:14:59 +03:00
|
|
|
[aResolver, holder](const RefPtr<nsIInputStream>& aOptionalStream) {
|
2018-02-23 23:28:11 +03:00
|
|
|
aResolver(nsCOMPtr<nsIInputStream>(aOptionalStream));
|
2017-11-16 23:12:06 +03:00
|
|
|
},
|
|
|
|
[aResolver, holder](ResponseRejectReason aReason) {
|
2017-09-15 22:25:41 +03:00
|
|
|
aResolver(nullptr);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-03-20 21:01:57 +03:00
|
|
|
void CacheStreamControlChild::NoteClosedAfterForget(const nsID& aId) {
|
2015-03-20 21:01:57 +03:00
|
|
|
NS_ASSERT_OWNINGTHREAD(CacheStreamControlChild);
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << SendNoteClosed(aId);
|
2015-04-16 22:00:15 +03:00
|
|
|
|
|
|
|
// A stream has closed. If we delayed StartDestry() due to this stream
|
|
|
|
// being read, then we should check to see if any of the remaining streams
|
|
|
|
// are active. If none of our other streams have been read, then we can
|
|
|
|
// proceed with the shutdown now.
|
|
|
|
if (mDestroyDelayed && !HasEverBeenRead()) {
|
|
|
|
mDestroyDelayed = false;
|
|
|
|
RecvCloseAll();
|
|
|
|
}
|
2015-03-20 21:01:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void CacheStreamControlChild::AssertOwningThread() {
|
|
|
|
NS_ASSERT_OWNINGTHREAD(CacheStreamControlChild);
|
|
|
|
}
|
|
|
|
#endif
|
2015-03-21 00:03:27 +03:00
|
|
|
|
2015-03-20 21:01:57 +03:00
|
|
|
void CacheStreamControlChild::ActorDestroy(ActorDestroyReason aReason) {
|
|
|
|
NS_ASSERT_OWNINGTHREAD(CacheStreamControlChild);
|
|
|
|
CloseAllReadStreamsWithoutReporting();
|
2016-06-23 11:53:14 +03:00
|
|
|
RemoveWorkerHolder();
|
2015-03-02 16:20:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult CacheStreamControlChild::RecvClose(const nsID& aId) {
|
|
|
|
NS_ASSERT_OWNINGTHREAD(CacheStreamControlChild);
|
2015-03-20 21:01:57 +03:00
|
|
|
CloseReadStreams(aId);
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-03-02 16:20:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult CacheStreamControlChild::RecvCloseAll() {
|
|
|
|
NS_ASSERT_OWNINGTHREAD(CacheStreamControlChild);
|
2015-03-20 21:01:57 +03:00
|
|
|
CloseAllReadStreams();
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-03-02 16:20:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace cache
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|