From 6e7f34c43756a8893b9a7a9f12786a8fb8e546f8 Mon Sep 17 00:00:00 2001 From: Valentin Gosu Date: Fri, 30 Apr 2021 07:20:14 +0000 Subject: [PATCH] Bug 1694662 - Remove nsICachingChannel r=necko-reviewers,dragana Differential Revision: https://phabricator.services.mozilla.com/D106432 --- netwerk/base/nsICachingChannel.idl | 9 -- netwerk/protocol/http/nsHttpChannel.cpp | 107 ++------------------ netwerk/protocol/http/nsHttpChannel.h | 6 -- uriloader/prefetch/nsOfflineCacheUpdate.cpp | 16 --- 4 files changed, 7 insertions(+), 131 deletions(-) diff --git a/netwerk/base/nsICachingChannel.idl b/netwerk/base/nsICachingChannel.idl index 1828f153076c..e06425f2d054 100644 --- a/netwerk/base/nsICachingChannel.idl +++ b/netwerk/base/nsICachingChannel.idl @@ -36,15 +36,6 @@ interface nsICachingChannel : nsICacheInfoChannel */ attribute nsISupports cacheToken; - /** - * The same as above but accessing the offline app cache token if there - * is any. - * - * @throws - * NS_ERROR_NOT_AVAILABLE when there is not offline cache token - */ - attribute nsISupports offlineCacheToken; - /** * Instructs the channel to only store the metadata of the entry, and not * the content. When reading an existing entry, this automatically sets diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp index 7dc736b20504..c3734bcac3a6 100644 --- a/netwerk/protocol/http/nsHttpChannel.cpp +++ b/netwerk/protocol/http/nsHttpChannel.cpp @@ -304,7 +304,6 @@ nsHttpChannel::nsHttpChannel() mLogicalOffset(0), mPostID(0), mRequestTime(0), - mOfflineCacheLastModifiedTime(0), mSuspendTotalTime(0), mRedirectType(0), mCacheOpenWithPriority(false), @@ -3226,11 +3225,6 @@ nsresult nsHttpChannel::ProcessPartialContent( rv = InstallCacheListener(mLogicalOffset); if (NS_FAILED(rv)) return rv; - - if (mOfflineCacheEntry) { - rv = InstallOfflineCacheListener(mLogicalOffset); - if (NS_FAILED(rv)) return rv; - } } else { // suspend the current transaction rv = mTransactionPump->Suspend(); @@ -4302,47 +4296,9 @@ nsresult nsHttpChannel::UpdateExpirationTime() { expirationTime); NS_ENSURE_SUCCESS(rv, rv); - if (mOfflineCacheEntry) { - rv = mOfflineCacheEntry->SetExpirationTime(expirationTime); - NS_ENSURE_SUCCESS(rv, rv); - } - return NS_OK; } -bool nsHttpChannel::ShouldUpdateOfflineCacheEntry() { - if (!mApplicationCacheForWrite || !mOfflineCacheEntry) { - return false; - } - - // if we're updating the cache entry, update the offline cache entry too - if (mCacheEntry && LoadCacheEntryIsWriteOnly()) { - return true; - } - - // if there's nothing in the offline cache, add it - if (mOfflineCacheEntry) { - return true; - } - - // if the document is newer than the offline entry, update it - uint32_t docLastModifiedTime; - nsresult rv = mResponseHead->GetLastModifiedValue(&docLastModifiedTime); - if (NS_FAILED(rv)) { - return true; - } - - if (mOfflineCacheLastModifiedTime == 0) { - return false; - } - - if (docLastModifiedTime > mOfflineCacheLastModifiedTime) { - return true; - } - - return false; -} - nsresult nsHttpChannel::OpenCacheInputStream(nsICacheEntry* cacheEntry, bool startBuffering, bool checkingAppCacheEntry) { @@ -4627,25 +4583,13 @@ nsresult nsHttpChannel::ReadFromCache(bool alreadyMarkedValid) { } if ((mLoadFlags & LOAD_ONLY_IF_MODIFIED) && !LoadCachedContentIsPartial()) { - if (!mApplicationCacheForWrite) { - LOG( - ("Skipping read from cache based on LOAD_ONLY_IF_MODIFIED " - "load flag\n")); - MOZ_ASSERT(!mCacheInputStream); - // TODO: Bug 759040 - We should call HandleAsyncNotModified directly - // here, to avoid event dispatching latency. - return AsyncCall(&nsHttpChannel::HandleAsyncNotModified); - } - - if (!ShouldUpdateOfflineCacheEntry()) { - LOG( - ("Skipping read from cache based on LOAD_ONLY_IF_MODIFIED " - "load flag (mApplicationCacheForWrite not null case)\n")); - mCacheInputStream.CloseAndRelease(); - // TODO: Bug 759040 - We should call HandleAsyncNotModified directly - // here, to avoid event dispatching latency. - return AsyncCall(&nsHttpChannel::HandleAsyncNotModified); - } + LOG( + ("Skipping read from cache based on LOAD_ONLY_IF_MODIFIED " + "load flag\n")); + MOZ_ASSERT(!mCacheInputStream); + // TODO: Bug 759040 - We should call HandleAsyncNotModified directly + // here, to avoid event dispatching latency. + return AsyncCall(&nsHttpChannel::HandleAsyncNotModified); } MOZ_ASSERT(mCacheInputStream); @@ -5097,31 +5041,6 @@ nsresult nsHttpChannel::InstallCacheListener(int64_t offset) { return NS_OK; } -nsresult nsHttpChannel::InstallOfflineCacheListener(int64_t offset) { - nsresult rv; - - LOG(("Preparing to write data into the offline cache [uri=%s]\n", - mSpec.get())); - - MOZ_ASSERT(mOfflineCacheEntry); - MOZ_ASSERT(mListener); - - nsCOMPtr out; - rv = mOfflineCacheEntry->OpenOutputStream(offset, -1, getter_AddRefs(out)); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr tee = - do_CreateInstance(kStreamListenerTeeCID, &rv); - if (NS_FAILED(rv)) return rv; - - rv = tee->Init(mListener, out, nullptr); - if (NS_FAILED(rv)) return rv; - - mListener = tee; - - return NS_OK; -} - void nsHttpChannel::ClearBogusContentEncodingIfNeeded() { // For .gz files, apache sends both a Content-Type: application/x-gzip // as well as Content-Encoding: gzip, which is completely wrong. In @@ -8161,18 +8080,6 @@ nsHttpChannel::SetCacheToken(nsISupports* token) { return NS_ERROR_NOT_IMPLEMENTED; } -NS_IMETHODIMP -nsHttpChannel::GetOfflineCacheToken(nsISupports** token) { - NS_ENSURE_ARG_POINTER(token); - if (!mOfflineCacheEntry) return NS_ERROR_NOT_AVAILABLE; - return CallQueryInterface(mOfflineCacheEntry, token); -} - -NS_IMETHODIMP -nsHttpChannel::SetOfflineCacheToken(nsISupports* token) { - return NS_ERROR_NOT_IMPLEMENTED; -} - NS_IMETHODIMP nsHttpChannel::GetCacheKey(uint32_t* key) { NS_ENSURE_ARG_POINTER(key); diff --git a/netwerk/protocol/http/nsHttpChannel.h b/netwerk/protocol/http/nsHttpChannel.h index f55fe1112645..53280a23e482 100644 --- a/netwerk/protocol/http/nsHttpChannel.h +++ b/netwerk/protocol/http/nsHttpChannel.h @@ -381,7 +381,6 @@ class nsHttpChannel final : public HttpBaseChannel, [[nodiscard]] nsresult OnNormalCacheEntryAvailable(nsICacheEntry* aEntry, bool aNew, nsresult aResult); - [[nodiscard]] nsresult OpenOfflineCacheEntryForWriting(); [[nodiscard]] nsresult OnCacheEntryAvailableInternal( nsICacheEntry* entry, bool aNew, nsIApplicationCache* aAppCache, nsresult status); @@ -389,7 +388,6 @@ class nsHttpChannel final : public HttpBaseChannel, [[nodiscard]] nsresult UpdateExpirationTime(); [[nodiscard]] nsresult CheckPartial(nsICacheEntry* aEntry, int64_t* aSize, int64_t* aContentLength); - bool ShouldUpdateOfflineCacheEntry(); [[nodiscard]] nsresult ReadFromCache(bool alreadyMarkedValid); void CloseCacheEntry(bool doomOnFailure); [[nodiscard]] nsresult InitCacheEntry(); @@ -397,7 +395,6 @@ class nsHttpChannel final : public HttpBaseChannel, [[nodiscard]] nsresult AddCacheEntryHeaders(nsICacheEntry* entry); [[nodiscard]] nsresult FinalizeCacheEntry(); [[nodiscard]] nsresult InstallCacheListener(int64_t offset = 0); - [[nodiscard]] nsresult InstallOfflineCacheListener(int64_t offset = 0); void MaybeInvalidateCacheEntryForSubsequentGet(); void AsyncOnExamineCachedResponse(); @@ -590,9 +587,6 @@ class nsHttpChannel final : public HttpBaseChannel, uint32_t mPostID; uint32_t mRequestTime; - nsCOMPtr mOfflineCacheEntry; - uint32_t mOfflineCacheLastModifiedTime; - nsTArray mStreamFilterRequests; mozilla::TimeStamp mOnStartRequestTimestamp; diff --git a/uriloader/prefetch/nsOfflineCacheUpdate.cpp b/uriloader/prefetch/nsOfflineCacheUpdate.cpp index 62561cdaa363..4c6d7524284a 100644 --- a/uriloader/prefetch/nsOfflineCacheUpdate.cpp +++ b/uriloader/prefetch/nsOfflineCacheUpdate.cpp @@ -1000,22 +1000,6 @@ nsresult nsOfflineManifestItem::CheckNewManifestContentHash( mNeedsUpdate = false; } - // Store the manifest content hash value to the new - // offline cache token - nsCOMPtr cachingChannel = do_QueryInterface(aRequest, &rv); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr cacheToken; - cachingChannel->GetOfflineCacheToken(getter_AddRefs(cacheToken)); - if (cacheToken) { - nsCOMPtr cacheDescriptor(do_QueryInterface(cacheToken, &rv)); - NS_ENSURE_SUCCESS(rv, rv); - - rv = cacheDescriptor->SetMetaDataElement("offline-manifest-hash", - mManifestHashValue.get()); - NS_ENSURE_SUCCESS(rv, rv); - } - return NS_OK; }