Backed out changeset 9866ca157a60 (bug 1894995) for causing several xpcshell failures.

This commit is contained in:
Cosmin Sabou 2024-05-23 00:35:42 +03:00
parent 8f3c74abcb
commit 86c3cf58d6
5 changed files with 99 additions and 10 deletions

View file

@ -1546,6 +1546,26 @@ nsresult CacheEntry::GetAltDataType(nsACString& aType) {
return mFile->GetAltDataType(aType); return mFile->GetAltDataType(aType);
} }
nsresult CacheEntry::MarkValid() {
// NOT IMPLEMENTED ACTUALLY
return NS_OK;
}
nsresult CacheEntry::MaybeMarkValid() {
// NOT IMPLEMENTED ACTUALLY
return NS_OK;
}
nsresult CacheEntry::HasWriteAccess(bool aWriteAllowed, bool* aWriteAccess) {
*aWriteAccess = aWriteAllowed;
return NS_OK;
}
nsresult CacheEntry::Close() {
// NOT IMPLEMENTED ACTUALLY
return NS_OK;
}
nsresult CacheEntry::GetDiskStorageSizeInKB(uint32_t* aDiskStorageSize) { nsresult CacheEntry::GetDiskStorageSizeInKB(uint32_t* aDiskStorageSize) {
if (NS_FAILED(mFileStatus)) { if (NS_FAILED(mFileStatus)) {
return NS_ERROR_NOT_AVAILABLE; return NS_ERROR_NOT_AVAILABLE;

View file

@ -103,6 +103,10 @@ class CacheEntry final : public nsIRunnable,
nsresult OpenAlternativeInputStream(const nsACString& type, nsresult OpenAlternativeInputStream(const nsACString& type,
nsIInputStream** _retval); nsIInputStream** _retval);
nsresult GetLoadContextInfo(nsILoadContextInfo** aInfo); nsresult GetLoadContextInfo(nsILoadContextInfo** aInfo);
nsresult Close(void);
nsresult MarkValid(void);
nsresult MaybeMarkValid(void);
nsresult HasWriteAccess(bool aWriteAllowed, bool* aWriteAccess);
public: public:
uint32_t GetMetadataMemoryConsumption(); uint32_t GetMetadataMemoryConsumption();
@ -542,6 +546,12 @@ class CacheEntryHandle final : public nsICacheEntry {
nsILoadContextInfo** aLoadContextInfo) override { nsILoadContextInfo** aLoadContextInfo) override {
return mEntry->GetLoadContextInfo(aLoadContextInfo); return mEntry->GetLoadContextInfo(aLoadContextInfo);
} }
NS_IMETHOD Close(void) override { return mEntry->Close(); }
NS_IMETHOD MarkValid(void) override { return mEntry->MarkValid(); }
NS_IMETHOD MaybeMarkValid(void) override { return mEntry->MaybeMarkValid(); }
NS_IMETHOD HasWriteAccess(bool aWriteAllowed, bool* _retval) override {
return mEntry->HasWriteAccess(aWriteAllowed, _retval);
}
// Specific implementation: // Specific implementation:
NS_IMETHOD Dismiss() override; NS_IMETHOD Dismiss() override;

View file

@ -309,6 +309,50 @@ interface nsICacheEntry : nsISupports
* Get the nsILoadContextInfo of the cache entry * Get the nsILoadContextInfo of the cache entry
*/ */
readonly attribute nsILoadContextInfo loadContextInfo; readonly attribute nsILoadContextInfo loadContextInfo;
/****************************************************************************
* The following methods might be added to some nsICacheEntryInternal
* interface since we want to remove them as soon as the old cache backend is
* completely removed.
*/
/**
* @deprecated
* FOR BACKWARD COMPATIBILITY ONLY
* When the old cache backend is eventually removed, this method
* can be removed too.
*
* In the new backend: this method is no-op
* In the old backend: this method delegates to nsICacheEntryDescriptor.close()
*/
void close();
/**
* @deprecated
* FOR BACKWARD COMPATIBILITY ONLY
* Marks the entry as valid so that others can use it and get only readonly
* access when the entry is held by the 1st writer.
*/
void markValid();
/**
* @deprecated
* FOR BACKWARD COMPATIBILITY ONLY
* Marks the entry as valid when write access is acquired.
*/
void maybeMarkValid();
/**
* @deprecated
* FOR BACKWARD COMPATIBILITY ONLY / KINDA HACK
* @param aWriteAllowed
* Consumer indicates whether write to the entry is allowed for it.
* Depends on implementation how the flag is handled.
* @returns
* true when write access is acquired for this entry,
* false otherwise
*/
boolean hasWriteAccess(in boolean aWriteAllowed);
}; };
/** /**

View file

@ -955,7 +955,7 @@ nsresult nsHttpChannel::ConnectOnTailUnblock() {
// If the content is valid, we should attempt to do so, as technically the // If the content is valid, we should attempt to do so, as technically the
// cache has won the race. // cache has won the race.
if (mRaceCacheWithNetwork && mCachedContentIsValid) { if (mRaceCacheWithNetwork && mCachedContentIsValid) {
Unused << ReadFromCache(); Unused << ReadFromCache(true);
} }
return TriggerNetwork(); return TriggerNetwork();
@ -987,7 +987,7 @@ nsresult nsHttpChannel::ContinueConnect() {
LOG((" AsyncCall failed (%08x)", static_cast<uint32_t>(rv))); LOG((" AsyncCall failed (%08x)", static_cast<uint32_t>(rv)));
} }
} }
rv = ReadFromCache(); rv = ReadFromCache(true);
if (NS_FAILED(rv) && event) { if (NS_FAILED(rv) && event) {
event->Revoke(); event->Revoke();
} }
@ -3601,7 +3601,7 @@ nsresult nsHttpChannel::ProcessPartialContent(
// the cached content is valid, although incomplete. // the cached content is valid, although incomplete.
mCachedContentIsValid = true; mCachedContentIsValid = true;
return CallOrWaitForResume([aContinueProcessResponseFunc](auto* self) { return CallOrWaitForResume([aContinueProcessResponseFunc](auto* self) {
nsresult rv = self->ReadFromCache(); nsresult rv = self->ReadFromCache(false);
return aContinueProcessResponseFunc(self, rv); return aContinueProcessResponseFunc(self, rv);
}); });
} }
@ -3742,7 +3742,7 @@ nsresult nsHttpChannel::ProcessNotModified(
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
return CallOrWaitForResume([aContinueProcessResponseFunc](auto* self) { return CallOrWaitForResume([aContinueProcessResponseFunc](auto* self) {
nsresult rv = self->ReadFromCache(); nsresult rv = self->ReadFromCache(false);
return aContinueProcessResponseFunc(self, rv); return aContinueProcessResponseFunc(self, rv);
}); });
} }
@ -4077,6 +4077,7 @@ nsHttpChannel::OnCacheEntryCheck(nsICacheEntry* entry, uint32_t* aResult) {
rv = OpenCacheInputStream(entry, true); rv = OpenCacheInputStream(entry, true);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
mCachedContentIsValid = true; mCachedContentIsValid = true;
entry->MaybeMarkValid();
} }
return rv; return rv;
} }
@ -4351,6 +4352,10 @@ nsHttpChannel::OnCacheEntryCheck(nsICacheEntry* entry, uint32_t* aResult) {
} }
} }
if (mCachedContentIsValid) {
entry->MaybeMarkValid();
}
LOG( LOG(
("nsHTTPChannel::OnCacheEntryCheck exit [this=%p doValidation=%d " ("nsHTTPChannel::OnCacheEntryCheck exit [this=%p doValidation=%d "
"result=%d]\n", "result=%d]\n",
@ -4444,7 +4449,7 @@ nsresult nsHttpChannel::OnCacheEntryAvailableInternal(nsICacheEntry* entry,
} }
if (mRaceCacheWithNetwork && mCachedContentIsValid) { if (mRaceCacheWithNetwork && mCachedContentIsValid) {
Unused << ReadFromCache(); Unused << ReadFromCache(true);
} }
return TriggerNetwork(); return TriggerNetwork();
@ -4794,7 +4799,7 @@ nsresult nsHttpChannel::OpenCacheInputStream(nsICacheEntry* cacheEntry,
// Actually process the cached response that we started to handle in CheckCache // Actually process the cached response that we started to handle in CheckCache
// and/or StartBufferingCachedEntity. // and/or StartBufferingCachedEntity.
nsresult nsHttpChannel::ReadFromCache(void) { nsresult nsHttpChannel::ReadFromCache(bool alreadyMarkedValid) {
NS_ENSURE_TRUE(mCacheEntry, NS_ERROR_FAILURE); NS_ENSURE_TRUE(mCacheEntry, NS_ERROR_FAILURE);
NS_ENSURE_TRUE(mCachedContentIsValid, NS_ERROR_FAILURE); NS_ENSURE_TRUE(mCachedContentIsValid, NS_ERROR_FAILURE);
NS_ENSURE_TRUE(!mCachePump, NS_OK); // already opened NS_ENSURE_TRUE(!mCachePump, NS_OK); // already opened
@ -4860,6 +4865,16 @@ nsresult nsHttpChannel::ReadFromCache(void) {
// in which case we could have security info from a socket transport. // in which case we could have security info from a socket transport.
if (!mSecurityInfo) mSecurityInfo = mCachedSecurityInfo; if (!mSecurityInfo) mSecurityInfo = mCachedSecurityInfo;
if (!alreadyMarkedValid && !LoadCachedContentIsPartial()) {
// We validated the entry, and we have write access to the cache, so
// mark the cache entry as valid in order to allow others access to
// this cache entry.
//
// TODO: This should be done asynchronously so we don't take the cache
// service lock on the main thread.
mCacheEntry->MaybeMarkValid();
}
nsresult rv; nsresult rv;
// Keep the conditions below in sync with the conditions in // Keep the conditions below in sync with the conditions in
@ -8291,12 +8306,12 @@ nsresult nsHttpChannel::ContinueOnStopRequest(nsresult aStatus, bool aIsFromNet,
// perform any final cache operations before we close the cache entry. // perform any final cache operations before we close the cache entry.
if (mCacheEntry && LoadRequestTimeInitialized()) { if (mCacheEntry && LoadRequestTimeInitialized()) {
bool writeAccess;
// New implementation just returns value of the !LoadCacheEntryIsReadOnly() // New implementation just returns value of the !LoadCacheEntryIsReadOnly()
// flag passed in. Old implementation checks on nsICache::ACCESS_WRITE // flag passed in. Old implementation checks on nsICache::ACCESS_WRITE
// flag. // flag.
mCacheEntry->HasWriteAccess(!LoadCacheEntryIsReadOnly(), &writeAccess);
// Assume that write access is granted if (writeAccess) {
if (!LoadCacheEntryIsReadOnly()) {
nsresult rv = FinalizeCacheEntry(); nsresult rv = FinalizeCacheEntry();
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
LOG(("FinalizeCacheEntry failed (%08x)", static_cast<uint32_t>(rv))); LOG(("FinalizeCacheEntry failed (%08x)", static_cast<uint32_t>(rv)));

View file

@ -401,7 +401,7 @@ class nsHttpChannel final : public HttpBaseChannel,
[[nodiscard]] nsresult UpdateExpirationTime(); [[nodiscard]] nsresult UpdateExpirationTime();
[[nodiscard]] nsresult CheckPartial(nsICacheEntry* aEntry, int64_t* aSize, [[nodiscard]] nsresult CheckPartial(nsICacheEntry* aEntry, int64_t* aSize,
int64_t* aContentLength); int64_t* aContentLength);
[[nodiscard]] nsresult ReadFromCache(void); [[nodiscard]] nsresult ReadFromCache(bool alreadyMarkedValid);
void CloseCacheEntry(bool doomOnFailure); void CloseCacheEntry(bool doomOnFailure);
[[nodiscard]] nsresult InitCacheEntry(); [[nodiscard]] nsresult InitCacheEntry();
void UpdateInhibitPersistentCachingFlag(); void UpdateInhibitPersistentCachingFlag();