Bug 1358038 - "Add "Race Cache With Network" status to netmonitor" r=Honza

--HG--
extra : histedit_source : 6fd61c4cdc5b6fc1e48463dea15614f845d0ae7a
This commit is contained in:
Michal Novotny 2019-04-15 05:52:00 +03:00
Родитель 67808459ac
Коммит bd208195d9
8 изменённых файлов: 80 добавлений и 31 удалений

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

@ -55,6 +55,15 @@ interface nsICacheInfoChannel : nsISupports
*/
boolean isFromCache();
/**
* Returns true if the channel raced the cache and network requests.
* In order to determine if the response is coming from the cache or the
* network, the consumer can check isFromCache().
* The method can only be called after the channel fires its OnStartRequest
* notification.
*/
boolean isRacing();
/**
* The unique ID of the corresponding nsICacheEntry from which the response is
* retrieved. By comparing the returned value, we can judge whether the data

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

@ -174,6 +174,7 @@ HttpChannelChild::HttpChannelChild()
mDivertingToParent(false),
mFlushedForDiversion(false),
mIsFromCache(false),
mIsRacing(false),
mCacheNeedToReportBytesReadInitialized(false),
mNeedToReportBytesRead(true),
mCacheEntryAvailable(false),
@ -399,9 +400,10 @@ class StartRequestEvent : public NeckoTargetChannelEvent<HttpChannelChild> {
const nsHttpResponseHead& aResponseHead, const bool& aUseResponseHead,
const nsHttpHeaderArray& aRequestHeaders,
const ParentLoadInfoForwarderArgs& loadInfoForwarder,
const bool& aIsFromCache, const bool& aCacheEntryAvailable,
const uint64_t& aCacheEntryId, const int32_t& aCacheFetchCount,
const uint32_t& aCacheExpirationTime, const nsCString& aCachedCharset,
const bool& aIsFromCache, const bool& aIsRacing,
const bool& aCacheEntryAvailable, const uint64_t& aCacheEntryId,
const int32_t& aCacheFetchCount, const uint32_t& aCacheExpirationTime,
const nsCString& aCachedCharset,
const nsCString& aSecurityInfoSerialization, const NetAddr& aSelfAddr,
const NetAddr& aPeerAddr, const uint32_t& aCacheKey,
const nsCString& altDataType, const int64_t& altDataLen,
@ -414,6 +416,7 @@ class StartRequestEvent : public NeckoTargetChannelEvent<HttpChannelChild> {
mUseResponseHead(aUseResponseHead),
mApplyConversion(aApplyConversion),
mIsFromCache(aIsFromCache),
mIsRacing(aIsRacing),
mCacheEntryAvailable(aCacheEntryAvailable),
mCacheEntryId(aCacheEntryId),
mCacheFetchCount(aCacheFetchCount),
@ -433,8 +436,8 @@ class StartRequestEvent : public NeckoTargetChannelEvent<HttpChannelChild> {
LOG(("StartRequestEvent [this=%p]\n", mChild));
mChild->OnStartRequest(
mChannelStatus, mResponseHead, mUseResponseHead, mRequestHeaders,
mLoadInfoForwarder, mIsFromCache, mCacheEntryAvailable, mCacheEntryId,
mCacheFetchCount, mCacheExpirationTime, mCachedCharset,
mLoadInfoForwarder, mIsFromCache, mIsRacing, mCacheEntryAvailable,
mCacheEntryId, mCacheFetchCount, mCacheExpirationTime, mCachedCharset,
mSecurityInfoSerialization, mSelfAddr, mPeerAddr, mCacheKey,
mAltDataType, mAltDataLen, mDeliveringAltData, mApplyConversion,
mTiming);
@ -447,6 +450,7 @@ class StartRequestEvent : public NeckoTargetChannelEvent<HttpChannelChild> {
bool mUseResponseHead;
bool mApplyConversion;
bool mIsFromCache;
bool mIsRacing;
bool mCacheEntryAvailable;
uint64_t mCacheEntryId;
int32_t mCacheFetchCount;
@ -467,14 +471,15 @@ mozilla::ipc::IPCResult HttpChannelChild::RecvOnStartRequest(
const nsresult& channelStatus, const nsHttpResponseHead& responseHead,
const bool& useResponseHead, const nsHttpHeaderArray& requestHeaders,
const ParentLoadInfoForwarderArgs& loadInfoForwarder,
const bool& isFromCache, const bool& cacheEntryAvailable,
const uint64_t& cacheEntryId, const int32_t& cacheFetchCount,
const uint32_t& cacheExpirationTime, const nsCString& cachedCharset,
const nsCString& securityInfoSerialization, const NetAddr& selfAddr,
const NetAddr& peerAddr, const int16_t& redirectCount,
const uint32_t& cacheKey, const nsCString& altDataType,
const int64_t& altDataLen, const bool& deliveringAltData,
const bool& aApplyConversion, const ResourceTimingStruct& aTiming) {
const bool& isFromCache, const bool& isRacing,
const bool& cacheEntryAvailable, const uint64_t& cacheEntryId,
const int32_t& cacheFetchCount, const uint32_t& cacheExpirationTime,
const nsCString& cachedCharset, const nsCString& securityInfoSerialization,
const NetAddr& selfAddr, const NetAddr& peerAddr,
const int16_t& redirectCount, const uint32_t& cacheKey,
const nsCString& altDataType, const int64_t& altDataLen,
const bool& deliveringAltData, const bool& aApplyConversion,
const ResourceTimingStruct& aTiming) {
AUTO_PROFILER_LABEL("HttpChannelChild::RecvOnStartRequest", NETWORK);
LOG(("HttpChannelChild::RecvOnStartRequest [this=%p]\n", this));
// mFlushedForDiversion and mDivertingToParent should NEVER be set at this
@ -490,8 +495,8 @@ mozilla::ipc::IPCResult HttpChannelChild::RecvOnStartRequest(
mEventQ->RunOrEnqueue(new StartRequestEvent(
this, channelStatus, responseHead, useResponseHead, requestHeaders,
loadInfoForwarder, isFromCache, cacheEntryAvailable, cacheEntryId,
cacheFetchCount, cacheExpirationTime, cachedCharset,
loadInfoForwarder, isFromCache, isRacing, cacheEntryAvailable,
cacheEntryId, cacheFetchCount, cacheExpirationTime, cachedCharset,
securityInfoSerialization, selfAddr, peerAddr, cacheKey, altDataType,
altDataLen, deliveringAltData, aApplyConversion, aTiming));
@ -520,11 +525,11 @@ void HttpChannelChild::OnStartRequest(
const nsresult& channelStatus, const nsHttpResponseHead& responseHead,
const bool& useResponseHead, const nsHttpHeaderArray& requestHeaders,
const ParentLoadInfoForwarderArgs& loadInfoForwarder,
const bool& isFromCache, const bool& cacheEntryAvailable,
const uint64_t& cacheEntryId, const int32_t& cacheFetchCount,
const uint32_t& cacheExpirationTime, const nsCString& cachedCharset,
const nsCString& securityInfoSerialization, const NetAddr& selfAddr,
const NetAddr& peerAddr, const uint32_t& cacheKey,
const bool& isFromCache, const bool& isRacing,
const bool& cacheEntryAvailable, const uint64_t& cacheEntryId,
const int32_t& cacheFetchCount, const uint32_t& cacheExpirationTime,
const nsCString& cachedCharset, const nsCString& securityInfoSerialization,
const NetAddr& selfAddr, const NetAddr& peerAddr, const uint32_t& cacheKey,
const nsCString& altDataType, const int64_t& altDataLen,
const bool& deliveringAltData, const bool& aApplyConversion,
const ResourceTimingStruct& aTiming) {
@ -569,6 +574,7 @@ void HttpChannelChild::OnStartRequest(
ipc::MergeParentLoadInfoForwarder(loadInfoForwarder, mLoadInfo);
mIsFromCache = isFromCache;
mIsRacing = isRacing;
mCacheEntryAvailable = cacheEntryAvailable;
mCacheEntryId = cacheEntryId;
mCacheFetchCount = cacheFetchCount;
@ -3000,6 +3006,15 @@ HttpChannelChild::GetCacheEntryId(uint64_t* aCacheEntryId) {
return NS_OK;
}
NS_IMETHODIMP
HttpChannelChild::IsRacing(bool* aIsRacing) {
if (!mAfterOnStartRequestBegun) {
return NS_ERROR_NOT_AVAILABLE;
}
*aIsRacing = mIsRacing;
return NS_OK;
}
NS_IMETHODIMP
HttpChannelChild::GetCacheKey(uint32_t* cacheKey) {
MOZ_ASSERT(NS_IsMainThread());

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

@ -138,9 +138,10 @@ class HttpChannelChild final : public PHttpChannelChild,
const nsresult& channelStatus, const nsHttpResponseHead& responseHead,
const bool& useResponseHead, const nsHttpHeaderArray& requestHeaders,
const ParentLoadInfoForwarderArgs& loadInfoForwarder,
const bool& isFromCache, const bool& cacheEntryAvailable,
const uint64_t& cacheEntryId, const int32_t& cacheFetchCount,
const uint32_t& cacheExpirationTime, const nsCString& cachedCharset,
const bool& isFromCache, const bool& isRacing,
const bool& cacheEntryAvailable, const uint64_t& cacheEntryId,
const int32_t& cacheFetchCount, const uint32_t& cacheExpirationTime,
const nsCString& cachedCharset,
const nsCString& securityInfoSerialization, const NetAddr& selfAddr,
const NetAddr& peerAddr, const int16_t& redirectCount,
const uint32_t& cacheKey, const nsCString& altDataType,
@ -402,6 +403,7 @@ class HttpChannelChild final : public PHttpChannelChild,
Atomic<bool, ReleaseAcquire> mFlushedForDiversion;
Atomic<bool, SequentiallyConsistent> mIsFromCache;
Atomic<bool, SequentiallyConsistent> mIsRacing;
// Set if we get the result and cache |mNeedToReportBytesRead|
Atomic<bool, SequentiallyConsistent> mCacheNeedToReportBytesReadInitialized;
// True if we need to tell the parent the size of unreported received data
@ -463,9 +465,10 @@ class HttpChannelChild final : public PHttpChannelChild,
const nsresult& channelStatus, const nsHttpResponseHead& responseHead,
const bool& useResponseHead, const nsHttpHeaderArray& requestHeaders,
const ParentLoadInfoForwarderArgs& loadInfoForwarder,
const bool& isFromCache, const bool& cacheEntryAvailable,
const uint64_t& cacheEntryId, const int32_t& cacheFetchCount,
const uint32_t& cacheExpirationTime, const nsCString& cachedCharset,
const bool& isFromCache, const bool& isRacing,
const bool& cacheEntryAvailable, const uint64_t& cacheEntryId,
const int32_t& cacheFetchCount, const uint32_t& cacheExpirationTime,
const nsCString& cachedCharset,
const nsCString& securityInfoSerialization, const NetAddr& selfAddr,
const NetAddr& peerAddr, const uint32_t& cacheKey,
const nsCString& altDataType, const int64_t& altDataLen,

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

@ -1364,6 +1364,7 @@ HttpChannelParent::OnStartRequest(nsIRequest* aRequest) {
}
bool isFromCache = false;
bool isRacing = false;
uint64_t cacheEntryId = 0;
int32_t fetchCount = 0;
uint32_t expirationTime = nsICacheEntry::NO_EXPIRATION_TIME;
@ -1373,6 +1374,7 @@ HttpChannelParent::OnStartRequest(nsIRequest* aRequest) {
if (httpChannelImpl) {
httpChannelImpl->IsFromCache(&isFromCache);
httpChannelImpl->IsRacing(&isRacing);
httpChannelImpl->GetCacheEntryId(&cacheEntryId);
httpChannelImpl->GetCacheTokenFetchCount(&fetchCount);
httpChannelImpl->GetCacheTokenExpirationTime(&expirationTime);
@ -1473,11 +1475,11 @@ HttpChannelParent::OnStartRequest(nsIRequest* aRequest) {
!SendOnStartRequest(
channelStatus, *responseHead, useResponseHead,
cleanedUpRequest ? cleanedUpRequestHeaders : requestHead->Headers(),
loadInfoForwarderArg, isFromCache, mCacheEntry ? true : false,
cacheEntryId, fetchCount, expirationTime, cachedCharset,
secInfoSerialization, chan->GetSelfAddr(), chan->GetPeerAddr(),
redirectCount, cacheKey, altDataType, altDataLen, deliveringAltData,
applyConversion, timing)) {
loadInfoForwarderArg, isFromCache, isRacing,
mCacheEntry ? true : false, cacheEntryId, fetchCount, expirationTime,
cachedCharset, secInfoSerialization, chan->GetSelfAddr(),
chan->GetPeerAddr(), redirectCount, cacheKey, altDataType, altDataLen,
deliveringAltData, applyConversion, timing)) {
rv = NS_ERROR_UNEXPECTED;
}
requestHead->Exit();

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

@ -1175,6 +1175,15 @@ InterceptedHttpChannel::IsFromCache(bool* value) {
return NS_OK;
}
NS_IMETHODIMP
InterceptedHttpChannel::IsRacing(bool* value) {
if (mSynthesizedCacheInfo) {
return mSynthesizedCacheInfo->IsRacing(value);
}
*value = false;
return NS_OK;
}
NS_IMETHODIMP
InterceptedHttpChannel::GetCacheEntryId(uint64_t* aCacheEntryId) {
if (mSynthesizedCacheInfo) {

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

@ -112,6 +112,7 @@ child:
nsHttpHeaderArray requestHeaders,
ParentLoadInfoForwarderArgs loadInfoForwarder,
bool isFromCache,
bool isRacing,
bool cacheEntryAvailable,
uint64_t cacheEntryId,
int32_t cacheFetchCount,

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

@ -8662,6 +8662,15 @@ nsHttpChannel::GetAltDataInputStream(const nsACString &aType,
// nsHttpChannel::nsICachingChannel
//-----------------------------------------------------------------------------
NS_IMETHODIMP
nsHttpChannel::IsRacing(bool *aIsRacing) {
if (!mAfterOnStartRequestBegun) {
return NS_ERROR_NOT_AVAILABLE;
}
*aIsRacing = mRaceCacheWithNetwork;
return NS_OK;
}
NS_IMETHODIMP
nsHttpChannel::GetCacheToken(nsISupports **token) {
NS_ENSURE_ARG_POINTER(token);

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

@ -58,6 +58,7 @@ let gIsFromCache = 0;
function checkContent(request, buffer, context, isFromCache)
{
Assert.equal(buffer, gResponseBody);
info("isRacing: " + request.QueryInterface(Ci.nsICacheInfoChannel).isRacing() + "\n");
gResponseCounter++;
if (isFromCache) {
gIsFromCache++;