Bug 1110485 P4 Keep Cache Actors alive during async operations. r=baku

This commit is contained in:
Ben Kelly
2015-04-16 12:00:15 -07:00
parent b143e5d19b
commit ccf34d901e
15 changed files with 194 additions and 32 deletions

View File

@@ -41,6 +41,7 @@ DeallocPCacheStreamControlChild(PCacheStreamControlChild* aActor)
CacheStreamControlChild::CacheStreamControlChild()
: mDestroyStarted(false)
, mDestroyDelayed(false)
{
MOZ_COUNT_CTOR(cache::CacheStreamControlChild);
}
@@ -63,6 +64,21 @@ CacheStreamControlChild::StartDestroy()
}
mDestroyStarted = true;
// 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.
// 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();
@@ -120,6 +136,15 @@ CacheStreamControlChild::NoteClosedAfterForget(const nsID& aId)
{
NS_ASSERT_OWNINGTHREAD(CacheStreamControlChild);
unused << SendNoteClosed(aId);
// 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();
}
}
#ifdef DEBUG