Bug 1110485 P4 Keep Cache Actors alive during async operations. r=baku
This commit is contained in:
25
dom/cache/ReadStream.cpp
vendored
25
dom/cache/ReadStream.cpp
vendored
@@ -50,6 +50,9 @@ public:
|
||||
virtual bool
|
||||
MatchId(const nsID& aId) const override;
|
||||
|
||||
virtual bool
|
||||
HasEverBeenRead() const override;
|
||||
|
||||
// Simulate nsIInputStream methods, but we don't actually inherit from it
|
||||
NS_METHOD
|
||||
Close();
|
||||
@@ -103,6 +106,7 @@ private:
|
||||
NumStates
|
||||
};
|
||||
Atomic<State> mState;
|
||||
Atomic<bool> mHasEverBeenRead;
|
||||
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(cache::ReadStream::Inner, override)
|
||||
};
|
||||
@@ -249,6 +253,13 @@ ReadStream::Inner::MatchId(const nsID& aId) const
|
||||
return mId.Equals(aId);
|
||||
}
|
||||
|
||||
bool
|
||||
ReadStream::Inner::HasEverBeenRead() const
|
||||
{
|
||||
MOZ_ASSERT(NS_GetCurrentThread() == mOwningThread);
|
||||
return mHasEverBeenRead;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ReadStream::Inner::Close()
|
||||
{
|
||||
@@ -284,6 +295,8 @@ ReadStream::Inner::Read(char* aBuf, uint32_t aCount, uint32_t* aNumReadOut)
|
||||
Close();
|
||||
}
|
||||
|
||||
mHasEverBeenRead = true;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -294,6 +307,10 @@ ReadStream::Inner::ReadSegments(nsWriteSegmentFun aWriter, void* aClosure,
|
||||
// stream ops can happen on any thread
|
||||
MOZ_ASSERT(aNumReadOut);
|
||||
|
||||
if (aCount) {
|
||||
mHasEverBeenRead = true;
|
||||
}
|
||||
|
||||
nsresult rv = mSnappyStream->ReadSegments(aWriter, aClosure, aCount,
|
||||
aNumReadOut);
|
||||
|
||||
@@ -302,6 +319,14 @@ ReadStream::Inner::ReadSegments(nsWriteSegmentFun aWriter, void* aClosure,
|
||||
Close();
|
||||
}
|
||||
|
||||
// Verify bytes were actually read before marking as being ever read. For
|
||||
// example, code can test if the stream supports ReadSegments() by calling
|
||||
// this method with a dummy callback which doesn't read anything. We don't
|
||||
// want to trigger on that.
|
||||
if (*aNumReadOut) {
|
||||
mHasEverBeenRead = true;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user