Bug 1395202 - Part 2: Expose CacheEntryId to nsICacheInfoChannel. r=michal, f=junior

This commit is contained in:
Ho-Pang Hsu 2017-10-12 02:25:00 -04:00
Родитель f56a0fb03f
Коммит 24a4dd8501
6 изменённых файлов: 55 добавлений и 2 удалений

Просмотреть файл

@ -38,6 +38,18 @@ interface nsICacheInfoChannel : nsISupports
*/
boolean isFromCache();
/**
* The unique ID of the corresponding nsICacheEntry from which the response is
* retrieved. By comparing the returned value, we can judge whether the data
* of two distinct nsICacheInfoChannels is from the same nsICacheEntry. This
* scenario could be useful when verifying whether the alternative data from
* one nsICacheInfochannel matches the main data from another one.
*
* Note: NS_ERROR_NOT_AVAILABLE is thrown when a nsICacheInfoChannel has no
* valid corresponding nsICacheEntry.
*/
uint64_t getCacheEntryId();
/**
* Set/get the cache key... uniquely identifies the data in the cache
* for this channel. Holding a reference to this key does NOT prevent

Просмотреть файл

@ -165,6 +165,7 @@ HttpChannelChild::HttpChannelChild()
, mSynthesizedStreamLength(0)
, mIsFromCache(false)
, mCacheEntryAvailable(false)
, mCacheEntryId(0)
, mAltDataCacheEntryAvailable(false)
, mCacheFetchCount(0)
, mCacheExpirationTime(nsICacheEntry::NO_EXPIRATION_TIME)
@ -413,6 +414,7 @@ class StartRequestEvent : public NeckoTargetChannelEvent<HttpChannelChild>
const nsHttpHeaderArray& aRequestHeaders,
const bool& aIsFromCache,
const bool& aCacheEntryAvailable,
const uint64_t& aCacheEntryId,
const int32_t& aCacheFetchCount,
const uint32_t& aCacheExpirationTime,
const nsCString& aCachedCharset,
@ -429,6 +431,7 @@ class StartRequestEvent : public NeckoTargetChannelEvent<HttpChannelChild>
, mUseResponseHead(aUseResponseHead)
, mIsFromCache(aIsFromCache)
, mCacheEntryAvailable(aCacheEntryAvailable)
, mCacheEntryId(aCacheEntryId)
, mCacheFetchCount(aCacheFetchCount)
, mCacheExpirationTime(aCacheExpirationTime)
, mCachedCharset(aCachedCharset)
@ -445,7 +448,8 @@ class StartRequestEvent : public NeckoTargetChannelEvent<HttpChannelChild>
LOG(("StartRequestEvent [this=%p]\n", mChild));
mChild->OnStartRequest(mChannelStatus, mResponseHead, mUseResponseHead,
mRequestHeaders, mIsFromCache, mCacheEntryAvailable,
mCacheFetchCount, mCacheExpirationTime, mCachedCharset,
mCacheEntryId, mCacheFetchCount,
mCacheExpirationTime, mCachedCharset,
mSecurityInfoSerialization, mSelfAddr, mPeerAddr,
mCacheKey, mAltDataType, mAltDataLen);
}
@ -457,6 +461,7 @@ class StartRequestEvent : public NeckoTargetChannelEvent<HttpChannelChild>
bool mUseResponseHead;
bool mIsFromCache;
bool mCacheEntryAvailable;
uint64_t mCacheEntryId;
int32_t mCacheFetchCount;
uint32_t mCacheExpirationTime;
nsCString mCachedCharset;
@ -475,6 +480,7 @@ HttpChannelChild::RecvOnStartRequest(const nsresult& channelStatus,
const nsHttpHeaderArray& requestHeaders,
const bool& isFromCache,
const bool& cacheEntryAvailable,
const uint64_t& cacheEntryId,
const int32_t& cacheFetchCount,
const uint32_t& cacheExpirationTime,
const nsCString& cachedCharset,
@ -500,7 +506,7 @@ HttpChannelChild::RecvOnStartRequest(const nsresult& channelStatus,
mEventQ->RunOrEnqueue(new StartRequestEvent(this, channelStatus, responseHead,
useResponseHead, requestHeaders,
isFromCache, cacheEntryAvailable,
cacheFetchCount,
cacheEntryId, cacheFetchCount,
cacheExpirationTime, cachedCharset,
securityInfoSerialization,
selfAddr, peerAddr, cacheKey,
@ -535,6 +541,7 @@ HttpChannelChild::OnStartRequest(const nsresult& channelStatus,
const nsHttpHeaderArray& requestHeaders,
const bool& isFromCache,
const bool& cacheEntryAvailable,
const uint64_t& cacheEntryId,
const int32_t& cacheFetchCount,
const uint32_t& cacheExpirationTime,
const nsCString& cachedCharset,
@ -568,6 +575,7 @@ HttpChannelChild::OnStartRequest(const nsresult& channelStatus,
mIsFromCache = isFromCache;
mCacheEntryAvailable = cacheEntryAvailable;
mCacheEntryId = cacheEntryId;
mCacheFetchCount = cacheFetchCount;
mCacheExpirationTime = cacheExpirationTime;
mCachedCharset = cachedCharset;
@ -2846,6 +2854,20 @@ HttpChannelChild::IsFromCache(bool *value)
return NS_OK;
}
NS_IMETHODIMP
HttpChannelChild::GetCacheEntryId(uint64_t *aCacheEntryId)
{
bool fromCache = false;
if (NS_FAILED(IsFromCache(&fromCache)) ||
!fromCache ||
!mCacheEntryAvailable) {
return NS_ERROR_NOT_AVAILABLE;
}
*aCacheEntryId = mCacheEntryId;
return NS_OK;
}
NS_IMETHODIMP
HttpChannelChild::GetCacheKey(nsISupports **cacheKey)
{

Просмотреть файл

@ -131,6 +131,7 @@ protected:
const nsHttpHeaderArray& requestHeaders,
const bool& isFromCache,
const bool& cacheEntryAvailable,
const uint64_t& cacheEntryId,
const int32_t& cacheFetchCount,
const uint32_t& cacheExpirationTime,
const nsCString& cachedCharset,
@ -289,6 +290,7 @@ private:
bool mIsFromCache;
bool mCacheEntryAvailable;
uint64_t mCacheEntryId;
bool mAltDataCacheEntryAvailable;
int32_t mCacheFetchCount;
uint32_t mCacheExpirationTime;
@ -385,6 +387,7 @@ private:
const nsHttpHeaderArray& requestHeaders,
const bool& isFromCache,
const bool& cacheEntryAvailable,
const uint64_t& cacheEntryId,
const int32_t& cacheFetchCount,
const uint32_t& cacheExpirationTime,
const nsCString& cachedCharset,

Просмотреть файл

@ -1443,6 +1443,7 @@ HttpChannelParent::OnStartRequest(nsIRequest *aRequest, nsISupports *aContext)
nsHttpResponseHead *responseHead = chan->GetResponseHead();
nsHttpRequestHead *requestHead = chan->GetRequestHead();
bool isFromCache = false;
uint64_t cacheEntryId = 0;
int32_t fetchCount = 0;
uint32_t expirationTime = nsICacheEntry::NO_EXPIRATION_TIME;
nsCString cachedCharset;
@ -1451,6 +1452,7 @@ HttpChannelParent::OnStartRequest(nsIRequest *aRequest, nsISupports *aContext)
if (httpChannelImpl) {
httpChannelImpl->IsFromCache(&isFromCache);
httpChannelImpl->GetCacheEntryId(&cacheEntryId);
httpChannelImpl->GetCacheTokenFetchCount(&fetchCount);
httpChannelImpl->GetCacheTokenExpirationTime(&expirationTime);
httpChannelImpl->GetCacheTokenCachedCharset(cachedCharset);
@ -1528,6 +1530,7 @@ HttpChannelParent::OnStartRequest(nsIRequest *aRequest, nsISupports *aContext)
requestHead->Headers(),
isFromCache,
mCacheEntry ? true : false,
cacheEntryId,
fetchCount, expirationTime,
cachedCharset, secInfoSerialization,
chan->GetSelfAddr(), chan->GetPeerAddr(),

Просмотреть файл

@ -99,6 +99,7 @@ child:
nsHttpHeaderArray requestHeaders,
bool isFromCache,
bool cacheEntryAvailable,
uint64_t cacheEntryId,
int32_t cacheFetchCount,
uint32_t cacheExpirationTime,
nsCString cachedCharset,

Просмотреть файл

@ -7851,6 +7851,18 @@ nsHttpChannel::IsFromCache(bool *value)
return NS_OK;
}
NS_IMETHODIMP
nsHttpChannel::GetCacheEntryId(uint64_t *aCacheEntryId)
{
bool fromCache = false;
if (NS_FAILED(IsFromCache(&fromCache)) || !fromCache || !mCacheEntry ||
NS_FAILED(mCacheEntry->GetCacheEntryId(aCacheEntryId))) {
return NS_ERROR_NOT_AVAILABLE;
}
return NS_OK;
}
NS_IMETHODIMP
nsHttpChannel::GetCacheTokenFetchCount(int32_t *_retval)
{