void CacheFileOutputStream::EnsureCorrectChunk(bool aReleaseOnly) { mFile->AssertOwnsLock(); LOG(("CacheFileOutputStream::EnsureCorrectChunk() [this=%p, releaseOnly=%d]", this, aReleaseOnly)); uint32_t chunkIdx = mPos / kChunkSize; if (mChunk) { if (mChunk->Index() == chunkIdx) { // we have a correct chunk LOG(("CacheFileOutputStream::EnsureCorrectChunk() - Have correct chunk " "[this=%p, idx=%d]", this, chunkIdx)); return; } else { ReleaseChunk(); } } if (aReleaseOnly) return; nsresult rv; rv = mFile->GetChunkLocked(chunkIdx, CacheFile::WRITER, nullptr, getter_AddRefs(mChunk)); if (NS_FAILED(rv)) { LOG(("CacheFileOutputStream::EnsureCorrectChunk() - GetChunkLocked failed. " "[this=%p, idx=%d, rv=0x%08x]", this, chunkIdx, rv)); CloseWithStatusLocked(rv); } }
nsresult CacheFileOutputStream::CloseWithStatusLocked(nsresult aStatus) { LOG(("CacheFileOutputStream::CloseWithStatusLocked() [this=%p, " "aStatus=0x%08x]", this, aStatus)); if (mClosed) { MOZ_ASSERT(!mCallback); return NS_OK; } mClosed = true; mStatus = NS_FAILED(aStatus) ? aStatus : NS_BASE_STREAM_CLOSED; if (mChunk) { ReleaseChunk(); } if (mCallback) { NotifyListener(); } mFile->RemoveOutput(this, mStatus); return NS_OK; }
// nsIAsyncInputStream NS_IMETHODIMP CacheFileInputStream::CloseWithStatus(nsresult aStatus) { CacheFileAutoLock lock(mFile); MOZ_ASSERT(!mInReadSegments); LOG(("CacheFileInputStream::CloseWithStatus() [this=%p, aStatus=0x%08x]", this, aStatus)); if (mClosed) { MOZ_ASSERT(!mCallback); return NS_OK; } mClosed = true; mStatus = NS_FAILED(aStatus) ? aStatus : NS_BASE_STREAM_CLOSED; if (mChunk) ReleaseChunk(); // TODO propagate error from input stream to other streams ??? MaybeNotifyListener(); return NS_OK; }
nsresult CacheFileInputStream::CloseWithStatusLocked(nsresult aStatus) { LOG(("CacheFileInputStream::CloseWithStatusLocked() [this=%p, " "aStatus=0x%08x]", this, aStatus)); if (mClosed) { MOZ_ASSERT(!mCallback); return NS_OK; } mClosed = true; mStatus = NS_FAILED(aStatus) ? aStatus : NS_BASE_STREAM_CLOSED; if (mChunk) { ReleaseChunk(); } // TODO propagate error from input stream to other streams ??? MaybeNotifyListener(); mFile->ReleaseOutsideLock(mCacheEntryHandle.forget()); return NS_OK; }
void CacheFileInputStream::EnsureCorrectChunk(bool aReleaseOnly) { mFile->AssertOwnsLock(); LOG(("CacheFileInputStream::EnsureCorrectChunk() [this=%p, releaseOnly=%d]", this, aReleaseOnly)); nsresult rv; uint32_t chunkIdx = mPos / kChunkSize; if (mChunk) { if (mChunk->Index() == chunkIdx) { // we have a correct chunk LOG(("CacheFileInputStream::EnsureCorrectChunk() - Have correct chunk " "[this=%p, idx=%d]", this, chunkIdx)); return; } else { ReleaseChunk(); } } MOZ_ASSERT(!mWaitingForUpdate); if (aReleaseOnly) return; if (mListeningForChunk == static_cast<int64_t>(chunkIdx)) { // We're already waiting for this chunk LOG(("CacheFileInputStream::EnsureCorrectChunk() - Already listening for " "chunk %lld [this=%p]", mListeningForChunk, this)); return; } rv = mFile->GetChunkLocked(chunkIdx, CacheFile::READER, this, getter_AddRefs(mChunk)); if (NS_FAILED(rv)) { LOG(("CacheFileInputStream::EnsureCorrectChunk() - GetChunkLocked failed. " "[this=%p, idx=%d, rv=0x%08x]", this, chunkIdx, rv)); if (rv != NS_ERROR_NOT_AVAILABLE) { // Close the stream with error. The consumer will receive this error later // in Read(), Available() etc. We need to handle NS_ERROR_NOT_AVAILABLE // differently since it is returned when the requested chunk is not // available and there is no writer that could create it, i.e. it means // that we've reached the end of the file. CloseWithStatusLocked(rv); return; } } else if (!mChunk) { mListeningForChunk = static_cast<int64_t>(chunkIdx); } MaybeNotifyListener(); }
void CacheFileInputStream::EnsureCorrectChunk(bool aReleaseOnly) { mFile->AssertOwnsLock(); LOG(("CacheFileInputStream::EnsureCorrectChunk() [this=%p, releaseOnly=%d]", this, aReleaseOnly)); nsresult rv; uint32_t chunkIdx = mPos / kChunkSize; if (mChunk) { if (mChunk->Index() == chunkIdx) { // we have a correct chunk LOG(("CacheFileInputStream::EnsureCorrectChunk() - Have correct chunk " "[this=%p, idx=%d]", this, chunkIdx)); return; } else { ReleaseChunk(); } } MOZ_ASSERT(!mWaitingForUpdate); if (aReleaseOnly) return; if (mListeningForChunk == static_cast<int64_t>(chunkIdx)) { // We're already waiting for this chunk LOG(("CacheFileInputStream::EnsureCorrectChunk() - Already listening for " "chunk %lld [this=%p]", mListeningForChunk, this)); return; } rv = mFile->GetChunkLocked(chunkIdx, false, this, getter_AddRefs(mChunk)); if (NS_FAILED(rv)) { LOG(("CacheFileInputStream::EnsureCorrectChunk() - GetChunkLocked failed. " "[this=%p, idx=%d, rv=0x%08x]", this, chunkIdx, rv)); } else if (!mChunk) { mListeningForChunk = static_cast<int64_t>(chunkIdx); } MaybeNotifyListener(); }