cache fixes required for link prefetching (b=12274) r=dougt sr=rpotts

This commit is contained in:
darin%netscape.com 2002-09-02 00:17:00 +00:00
Родитель a358278e89
Коммит 4776d6f1e7
2 изменённых файлов: 29 добавлений и 5 удалений

31
netwerk/cache/src/nsDiskCacheStreams.cpp поставляемый
Просмотреть файл

@ -477,6 +477,14 @@ nsDiskCacheStreamIO::GetContentLength(PRInt32 *contentLength)
}
void
nsDiskCacheStreamIO::ClearBinding()
{
if (mBinding && mOutStream)
Flush();
mBinding = nsnull;
}
nsresult
nsDiskCacheStreamIO::CloseOutputStream(nsDiskCacheOutputStream * outputStream)
{
@ -490,13 +498,30 @@ nsDiskCacheStreamIO::CloseOutputStream(nsDiskCacheOutputStream * outputStream)
// output stream is closing
if (!mBinding) { // if we're severed, just clear member variables
NS_ASSERTION(!mBufDirty, "oops");
mOutStream = nsnull;
outputStream->mStreamIO = nsnull;
return NS_ERROR_NOT_AVAILABLE;
}
rv = Flush();
NS_ASSERTION(NS_SUCCEEDED(rv), "Flush() failed");
mOutStream = nsnull;
return rv;
}
nsresult
nsDiskCacheStreamIO::Flush()
{
NS_ASSERTION(mBinding, "oops");
if (!mBufDirty)
return NS_OK;
// write data to cache blocks, or flush mBuffer to file
nsDiskCacheMap * cacheMap = mDevice->CacheMap(); // get map reference
nsDiskCacheMap *cacheMap = mDevice->CacheMap(); // get map reference
nsresult rv;
if ((mStreamEnd > kMaxBufferSize) ||
(mBinding->mCacheEntry->StoragePolicy() == nsICache::STORE_ON_DISK_AS_FILE)) {
@ -522,7 +547,6 @@ nsDiskCacheStreamIO::CloseOutputStream(nsDiskCacheOutputStream * outputStream)
// delete existing storage
nsDiskCacheRecord * record = &mBinding->mRecord;
if (record->DataLocationInitialized()) {
rv = cacheMap->DeleteStorage(record, nsDiskCache::kData);
if (NS_FAILED(rv)) {
NS_WARNING("cacheMap->DeleteStorage() failed.");
@ -532,7 +556,7 @@ nsDiskCacheStreamIO::CloseOutputStream(nsDiskCacheOutputStream * outputStream)
// flush buffer to block files
if (mStreamEnd > 0) {
nsresult rv = cacheMap->WriteDataCacheBlocks(mBinding, mBuffer, mBufEnd);
rv = cacheMap->WriteDataCacheBlocks(mBinding, mBuffer, mBufEnd);
if (NS_FAILED(rv)) {
NS_WARNING("WriteDataCacheBlocks() failed.");
return rv; // XXX doom cache entry?
@ -553,7 +577,6 @@ nsDiskCacheStreamIO::CloseOutputStream(nsDiskCacheOutputStream * outputStream)
}
}
mOutStream = nsnull;
return NS_OK;
}

3
netwerk/cache/src/nsDiskCacheStreams.h поставляемый
Просмотреть файл

@ -62,7 +62,7 @@ public:
nsresult Tell(PRUint32 * position);
nsresult SetEOF();
void ClearBinding() { mBinding = nsnull; }
void ClearBinding();
void IncrementInputStreamCount() { PR_AtomicIncrement(&mInStreamCount); }
void DecrementInputStreamCount()
@ -83,6 +83,7 @@ private:
PRUint32 WriteToBuffer(const char * buffer, PRUint32 count);
nsresult UpdateFileSize();
void DeleteBuffer();
nsresult Flush();
nsDiskCacheBinding * mBinding;