diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:29 +0000 |
commit | 59203c63bb777a3bacec32fb8830fba33540e809 (patch) | |
tree | 58298e711c0ff0575818c30485b44a2f21bf28a0 /netwerk/cache2 | |
parent | Adding upstream version 126.0.1. (diff) | |
download | firefox-59203c63bb777a3bacec32fb8830fba33540e809.tar.xz firefox-59203c63bb777a3bacec32fb8830fba33540e809.zip |
Adding upstream version 127.0.upstream/127.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'netwerk/cache2')
-rw-r--r-- | netwerk/cache2/CacheFileIOManager.cpp | 44 | ||||
-rw-r--r-- | netwerk/cache2/CacheFileIOManager.h | 8 | ||||
-rw-r--r-- | netwerk/cache2/CacheFileInputStream.cpp | 1 | ||||
-rw-r--r-- | netwerk/cache2/CacheFileMetadata.cpp | 6 | ||||
-rw-r--r-- | netwerk/cache2/CacheFileOutputStream.cpp | 2 | ||||
-rw-r--r-- | netwerk/cache2/CacheIndex.cpp | 14 |
6 files changed, 50 insertions, 25 deletions
diff --git a/netwerk/cache2/CacheFileIOManager.cpp b/netwerk/cache2/CacheFileIOManager.cpp index 8cff1c1cd9..89cd4497ad 100644 --- a/netwerk/cache2/CacheFileIOManager.cpp +++ b/netwerk/cache2/CacheFileIOManager.cpp @@ -2026,26 +2026,46 @@ nsresult CacheFileIOManager::Write(CacheFileHandle* aHandle, int64_t aOffset, "validate=%d, truncate=%d, listener=%p]", aHandle, aOffset, aCount, aValidate, aTruncate, aCallback)); - nsresult rv; + MOZ_ASSERT(aCallback); + RefPtr<CacheFileIOManager> ioMan = gInstance; - if (aHandle->IsClosed() || (aCallback && aCallback->IsKilled()) || !ioMan) { - if (!aCallback) { - // When no callback is provided, CacheFileIOManager is responsible for - // releasing the buffer. We must release it even in case of failure. - free(const_cast<char*>(aBuf)); - } + if (aHandle->IsClosed() || aCallback->IsKilled() || !ioMan) { return NS_ERROR_NOT_INITIALIZED; } RefPtr<WriteEvent> ev = new WriteEvent(aHandle, aOffset, aBuf, aCount, aValidate, aTruncate, aCallback); - rv = ioMan->mIOThread->Dispatch(ev, aHandle->mPriority - ? CacheIOThread::WRITE_PRIORITY - : CacheIOThread::WRITE); - NS_ENSURE_SUCCESS(rv, rv); + return ioMan->mIOThread->Dispatch(ev, aHandle->mPriority + ? CacheIOThread::WRITE_PRIORITY + : CacheIOThread::WRITE); +} - return NS_OK; +// static +nsresult CacheFileIOManager::WriteWithoutCallback(CacheFileHandle* aHandle, + int64_t aOffset, char* aBuf, + int32_t aCount, + bool aValidate, + bool aTruncate) { + LOG(("CacheFileIOManager::WriteWithoutCallback() [handle=%p, offset=%" PRId64 + ", count=%d, " + "validate=%d, truncate=%d]", + aHandle, aOffset, aCount, aValidate, aTruncate)); + + RefPtr<CacheFileIOManager> ioMan = gInstance; + + if (aHandle->IsClosed() || !ioMan) { + // When no callback is provided, CacheFileIOManager is responsible for + // releasing the buffer. We must release it even in case of failure. + free(aBuf); + return NS_ERROR_NOT_INITIALIZED; + } + + RefPtr<WriteEvent> ev = new WriteEvent(aHandle, aOffset, aBuf, aCount, + aValidate, aTruncate, nullptr); + return ioMan->mIOThread->Dispatch(ev, aHandle->mPriority + ? CacheIOThread::WRITE_PRIORITY + : CacheIOThread::WRITE); } static nsresult TruncFile(PRFileDesc* aFD, int64_t aEOF) { diff --git a/netwerk/cache2/CacheFileIOManager.h b/netwerk/cache2/CacheFileIOManager.h index 5be21c8db8..67c67e718d 100644 --- a/netwerk/cache2/CacheFileIOManager.h +++ b/netwerk/cache2/CacheFileIOManager.h @@ -287,9 +287,17 @@ class CacheFileIOManager final : public nsITimerCallback, public nsINamed { CacheFileIOListener* aCallback); static nsresult Read(CacheFileHandle* aHandle, int64_t aOffset, char* aBuf, int32_t aCount, CacheFileIOListener* aCallback); + // This function must be called with a callback. The caller is responsible for + // releasing |aBuf|. static nsresult Write(CacheFileHandle* aHandle, int64_t aOffset, const char* aBuf, int32_t aCount, bool aValidate, bool aTruncate, CacheFileIOListener* aCallback); + // Similar to the above, but without the callback. Note that |aBuf| will be + // released by CacheFileIOManager. + static nsresult WriteWithoutCallback(CacheFileHandle* aHandle, + int64_t aOffset, char* aBuf, + int32_t aCount, bool aValidate, + bool aTruncate); // PinningDoomRestriction: // NO_RESTRICTION // no restriction is checked, the file is simply always doomed diff --git a/netwerk/cache2/CacheFileInputStream.cpp b/netwerk/cache2/CacheFileInputStream.cpp index 99302baf54..564a08fd2b 100644 --- a/netwerk/cache2/CacheFileInputStream.cpp +++ b/netwerk/cache2/CacheFileInputStream.cpp @@ -8,6 +8,7 @@ #include "CacheFile.h" #include "nsStreamUtils.h" #include "nsThreadUtils.h" +#include "mozilla/IntegerPrintfMacros.h" #include <algorithm> namespace mozilla::net { diff --git a/netwerk/cache2/CacheFileMetadata.cpp b/netwerk/cache2/CacheFileMetadata.cpp index 68d55b1988..5e299a7852 100644 --- a/netwerk/cache2/CacheFileMetadata.cpp +++ b/netwerk/cache2/CacheFileMetadata.cpp @@ -257,14 +257,16 @@ nsresult CacheFileMetadata::WriteMetadata( char* writeBuffer = mWriteBuf; if (aListener) { mListener = aListener; + rv = CacheFileIOManager::Write(mHandle, aOffset, writeBuffer, + p - writeBuffer, true, true, this); } else { // We are not going to pass |this| as a callback so the buffer will be // released by CacheFileIOManager. Just null out mWriteBuf here. mWriteBuf = nullptr; + rv = CacheFileIOManager::WriteWithoutCallback(mHandle, aOffset, writeBuffer, + p - writeBuffer, true, true); } - rv = CacheFileIOManager::Write(mHandle, aOffset, writeBuffer, p - writeBuffer, - true, true, aListener ? this : nullptr); if (NS_FAILED(rv)) { LOG( ("CacheFileMetadata::WriteMetadata() - CacheFileIOManager::Write() " diff --git a/netwerk/cache2/CacheFileOutputStream.cpp b/netwerk/cache2/CacheFileOutputStream.cpp index 985082efba..b541132bd9 100644 --- a/netwerk/cache2/CacheFileOutputStream.cpp +++ b/netwerk/cache2/CacheFileOutputStream.cpp @@ -9,7 +9,7 @@ #include "CacheEntry.h" #include "nsStreamUtils.h" #include "nsThreadUtils.h" -#include "mozilla/DebugOnly.h" +#include "mozilla/IntegerPrintfMacros.h" #include <algorithm> namespace mozilla::net { diff --git a/netwerk/cache2/CacheIndex.cpp b/netwerk/cache2/CacheIndex.cpp index c0cb63ef6d..34931087c0 100644 --- a/netwerk/cache2/CacheIndex.cpp +++ b/netwerk/cache2/CacheIndex.cpp @@ -2213,16 +2213,10 @@ void CacheIndex::ParseRecords(const StaticMutexAutoLock& aProofOfLock) { reinterpret_cast<uint32_t*>(moz_xmalloc(sizeof(uint32_t))); NetworkEndian::writeUint32(isDirty, 1); - // Mark index dirty. The buffer is freed by CacheFileIOManager when - // nullptr is passed as the listener and the call doesn't fail - // synchronously. - rv = CacheFileIOManager::Write(mIndexHandle, 2 * sizeof(uint32_t), - reinterpret_cast<char*>(isDirty), - sizeof(uint32_t), true, false, nullptr); - if (NS_FAILED(rv)) { - // This is not fatal, just free the memory - free(isDirty); - } + // Mark index dirty. The buffer will be freed by CacheFileIOManager. + CacheFileIOManager::WriteWithoutCallback( + mIndexHandle, 2 * sizeof(uint32_t), reinterpret_cast<char*>(isDirty), + sizeof(uint32_t), true, false); } pos += sizeof(uint32_t); |