Bug 1694662 - Remove nsICachingChannel r=necko-reviewers,dragana

Differential Revision: https://phabricator.services.mozilla.com/D106432
This commit is contained in:
Valentin Gosu 2021-04-30 07:20:14 +00:00
parent 87d676a1e4
commit 6e7f34c437
4 changed files with 7 additions and 131 deletions

View File

@ -36,15 +36,6 @@ interface nsICachingChannel : nsICacheInfoChannel
*/ */
attribute nsISupports cacheToken; 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 * Instructs the channel to only store the metadata of the entry, and not
* the content. When reading an existing entry, this automatically sets * the content. When reading an existing entry, this automatically sets

View File

@ -304,7 +304,6 @@ nsHttpChannel::nsHttpChannel()
mLogicalOffset(0), mLogicalOffset(0),
mPostID(0), mPostID(0),
mRequestTime(0), mRequestTime(0),
mOfflineCacheLastModifiedTime(0),
mSuspendTotalTime(0), mSuspendTotalTime(0),
mRedirectType(0), mRedirectType(0),
mCacheOpenWithPriority(false), mCacheOpenWithPriority(false),
@ -3226,11 +3225,6 @@ nsresult nsHttpChannel::ProcessPartialContent(
rv = InstallCacheListener(mLogicalOffset); rv = InstallCacheListener(mLogicalOffset);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
if (mOfflineCacheEntry) {
rv = InstallOfflineCacheListener(mLogicalOffset);
if (NS_FAILED(rv)) return rv;
}
} else { } else {
// suspend the current transaction // suspend the current transaction
rv = mTransactionPump->Suspend(); rv = mTransactionPump->Suspend();
@ -4302,47 +4296,9 @@ nsresult nsHttpChannel::UpdateExpirationTime() {
expirationTime); expirationTime);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
if (mOfflineCacheEntry) {
rv = mOfflineCacheEntry->SetExpirationTime(expirationTime);
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK; 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, nsresult nsHttpChannel::OpenCacheInputStream(nsICacheEntry* cacheEntry,
bool startBuffering, bool startBuffering,
bool checkingAppCacheEntry) { bool checkingAppCacheEntry) {
@ -4627,25 +4583,13 @@ nsresult nsHttpChannel::ReadFromCache(bool alreadyMarkedValid) {
} }
if ((mLoadFlags & LOAD_ONLY_IF_MODIFIED) && !LoadCachedContentIsPartial()) { if ((mLoadFlags & LOAD_ONLY_IF_MODIFIED) && !LoadCachedContentIsPartial()) {
if (!mApplicationCacheForWrite) { LOG(
LOG( ("Skipping read from cache based on LOAD_ONLY_IF_MODIFIED "
("Skipping read from cache based on LOAD_ONLY_IF_MODIFIED " "load flag\n"));
"load flag\n")); MOZ_ASSERT(!mCacheInputStream);
MOZ_ASSERT(!mCacheInputStream); // TODO: Bug 759040 - We should call HandleAsyncNotModified directly
// TODO: Bug 759040 - We should call HandleAsyncNotModified directly // here, to avoid event dispatching latency.
// here, to avoid event dispatching latency. return AsyncCall(&nsHttpChannel::HandleAsyncNotModified);
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);
}
} }
MOZ_ASSERT(mCacheInputStream); MOZ_ASSERT(mCacheInputStream);
@ -5097,31 +5041,6 @@ nsresult nsHttpChannel::InstallCacheListener(int64_t offset) {
return NS_OK; 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<nsIOutputStream> out;
rv = mOfflineCacheEntry->OpenOutputStream(offset, -1, getter_AddRefs(out));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIStreamListenerTee> 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() { void nsHttpChannel::ClearBogusContentEncodingIfNeeded() {
// For .gz files, apache sends both a Content-Type: application/x-gzip // For .gz files, apache sends both a Content-Type: application/x-gzip
// as well as Content-Encoding: gzip, which is completely wrong. In // as well as Content-Encoding: gzip, which is completely wrong. In
@ -8161,18 +8080,6 @@ nsHttpChannel::SetCacheToken(nsISupports* token) {
return NS_ERROR_NOT_IMPLEMENTED; 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 NS_IMETHODIMP
nsHttpChannel::GetCacheKey(uint32_t* key) { nsHttpChannel::GetCacheKey(uint32_t* key) {
NS_ENSURE_ARG_POINTER(key); NS_ENSURE_ARG_POINTER(key);

View File

@ -381,7 +381,6 @@ class nsHttpChannel final : public HttpBaseChannel,
[[nodiscard]] nsresult OnNormalCacheEntryAvailable(nsICacheEntry* aEntry, [[nodiscard]] nsresult OnNormalCacheEntryAvailable(nsICacheEntry* aEntry,
bool aNew, bool aNew,
nsresult aResult); nsresult aResult);
[[nodiscard]] nsresult OpenOfflineCacheEntryForWriting();
[[nodiscard]] nsresult OnCacheEntryAvailableInternal( [[nodiscard]] nsresult OnCacheEntryAvailableInternal(
nsICacheEntry* entry, bool aNew, nsIApplicationCache* aAppCache, nsICacheEntry* entry, bool aNew, nsIApplicationCache* aAppCache,
nsresult status); nsresult status);
@ -389,7 +388,6 @@ 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);
bool ShouldUpdateOfflineCacheEntry();
[[nodiscard]] nsresult ReadFromCache(bool alreadyMarkedValid); [[nodiscard]] nsresult ReadFromCache(bool alreadyMarkedValid);
void CloseCacheEntry(bool doomOnFailure); void CloseCacheEntry(bool doomOnFailure);
[[nodiscard]] nsresult InitCacheEntry(); [[nodiscard]] nsresult InitCacheEntry();
@ -397,7 +395,6 @@ class nsHttpChannel final : public HttpBaseChannel,
[[nodiscard]] nsresult AddCacheEntryHeaders(nsICacheEntry* entry); [[nodiscard]] nsresult AddCacheEntryHeaders(nsICacheEntry* entry);
[[nodiscard]] nsresult FinalizeCacheEntry(); [[nodiscard]] nsresult FinalizeCacheEntry();
[[nodiscard]] nsresult InstallCacheListener(int64_t offset = 0); [[nodiscard]] nsresult InstallCacheListener(int64_t offset = 0);
[[nodiscard]] nsresult InstallOfflineCacheListener(int64_t offset = 0);
void MaybeInvalidateCacheEntryForSubsequentGet(); void MaybeInvalidateCacheEntryForSubsequentGet();
void AsyncOnExamineCachedResponse(); void AsyncOnExamineCachedResponse();
@ -590,9 +587,6 @@ class nsHttpChannel final : public HttpBaseChannel,
uint32_t mPostID; uint32_t mPostID;
uint32_t mRequestTime; uint32_t mRequestTime;
nsCOMPtr<nsICacheEntry> mOfflineCacheEntry;
uint32_t mOfflineCacheLastModifiedTime;
nsTArray<StreamFilterRequest> mStreamFilterRequests; nsTArray<StreamFilterRequest> mStreamFilterRequests;
mozilla::TimeStamp mOnStartRequestTimestamp; mozilla::TimeStamp mOnStartRequestTimestamp;

View File

@ -1000,22 +1000,6 @@ nsresult nsOfflineManifestItem::CheckNewManifestContentHash(
mNeedsUpdate = false; mNeedsUpdate = false;
} }
// Store the manifest content hash value to the new
// offline cache token
nsCOMPtr<nsICachingChannel> cachingChannel = do_QueryInterface(aRequest, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsISupports> cacheToken;
cachingChannel->GetOfflineCacheToken(getter_AddRefs(cacheToken));
if (cacheToken) {
nsCOMPtr<nsICacheEntry> 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; return NS_OK;
} }