Backed out changeset 8abbf422db5c (bug 1894995) for causing bustage on nsHttpChannel.cpp CLOSED TREE

This commit is contained in:
Natalia Csoregi 2024-05-17 12:52:02 +03:00
parent f7797d93fe
commit 173d5cf3e7
5 changed files with 94 additions and 5 deletions

View file

@ -1546,6 +1546,26 @@ nsresult CacheEntry::GetAltDataType(nsACString& 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) {
if (NS_FAILED(mFileStatus)) {
return NS_ERROR_NOT_AVAILABLE;

View file

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

View file

@ -309,6 +309,50 @@ interface nsICacheEntry : nsISupports
* Get the nsILoadContextInfo of the cache entry
*/
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

@ -4070,6 +4070,7 @@ nsHttpChannel::OnCacheEntryCheck(nsICacheEntry* entry, uint32_t* aResult) {
rv = OpenCacheInputStream(entry, true);
if (NS_SUCCEEDED(rv)) {
mCachedContentIsValid = true;
entry->MaybeMarkValid();
}
return rv;
}
@ -4344,6 +4345,10 @@ nsHttpChannel::OnCacheEntryCheck(nsICacheEntry* entry, uint32_t* aResult) {
}
}
if (mCachedContentIsValid) {
entry->MaybeMarkValid();
}
LOG(
("nsHTTPChannel::OnCacheEntryCheck exit [this=%p doValidation=%d "
"result=%d]\n",
@ -4787,7 +4792,7 @@ nsresult nsHttpChannel::OpenCacheInputStream(nsICacheEntry* cacheEntry,
// Actually process the cached response that we started to handle in CheckCache
// and/or StartBufferingCachedEntity.
nsresult nsHttpChannel::ReadFromCache(void) {
nsresult nsHttpChannel::ReadFromCache(bool alreadyMarkedValid) {
NS_ENSURE_TRUE(mCacheEntry, NS_ERROR_FAILURE);
NS_ENSURE_TRUE(mCachedContentIsValid, NS_ERROR_FAILURE);
NS_ENSURE_TRUE(!mCachePump, NS_OK); // already opened
@ -4853,6 +4858,16 @@ nsresult nsHttpChannel::ReadFromCache(void) {
// in which case we could have security info from a socket transport.
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;
// Keep the conditions below in sync with the conditions in
@ -8272,12 +8287,12 @@ nsresult nsHttpChannel::ContinueOnStopRequest(nsresult aStatus, bool aIsFromNet,
// perform any final cache operations before we close the cache entry.
if (mCacheEntry && LoadRequestTimeInitialized()) {
bool writeAccess;
// New implementation just returns value of the !LoadCacheEntryIsReadOnly()
// flag passed in. Old implementation checks on nsICache::ACCESS_WRITE
// flag.
// Assume that write access is granted
if (!LoadCacheEntryIsReadOnly()) {
mCacheEntry->HasWriteAccess(!LoadCacheEntryIsReadOnly(), &writeAccess);
if (writeAccess) {
nsresult rv = FinalizeCacheEntry();
if (NS_FAILED(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 CheckPartial(nsICacheEntry* aEntry, int64_t* aSize,
int64_t* aContentLength);
[[nodiscard]] nsresult ReadFromCache(void);
[[nodiscard]] nsresult ReadFromCache(bool alreadyMarkedValid);
void CloseCacheEntry(bool doomOnFailure);
[[nodiscard]] nsresult InitCacheEntry();
void UpdateInhibitPersistentCachingFlag();