Bug 1400001 - Use AwaitingCacheCallbacks when deciding if racing instead of mCacheAsyncOpenCalled r=michal

MozReview-Commit-ID: 5VRRXrkNo9Y

--HG--
extra : rebase_source : f4eb8349627f12ccf638f1d42c7c8a0aecb00fe7
This commit is contained in:
Valentin Gosu 2017-09-15 02:47:41 +02:00
parent e24b0006df
commit 1b3f9ab5d6
2 changed files with 3 additions and 18 deletions

View File

@ -344,10 +344,8 @@ nsHttpChannel::nsHttpChannel()
, mWarningReporter(nullptr)
, mIsReadingFromCache(false)
, mFirstResponseSource(RESPONSE_PENDING)
, mOnCacheAvailableCalled(false)
, mRaceCacheWithNetwork(false)
, mRaceDelay(0)
, mCacheAsyncOpenCalled(false)
, mIgnoreCacheEntry(false)
, mRCWNLock("nsHttpChannel.mRCWNLock")
, mDidReval(false)
@ -1108,7 +1106,7 @@ nsHttpChannel::SetupTransaction()
// could be added in OnCacheEntryCheck. We cannot send conditional request
// without having the entry, so we need to remove the headers here and
// ignore the cache entry in OnCacheEntryAvailable.
if (mRaceCacheWithNetwork && !mOnCacheAvailableCalled) {
if (mRaceCacheWithNetwork && AwaitingCacheCallbacks()) {
if (mDidReval) {
LOG((" Removing conditional request headers"));
UntieValidationRequest();
@ -3983,28 +3981,19 @@ nsHttpChannel::OpenCacheEntry(bool isHttps)
if (!mCacheOpenDelay) {
MOZ_ASSERT(NS_IsMainThread(), "Should be called on the main thread");
mCacheAsyncOpenCalled = true;
if (mNetworkTriggered) {
mRaceCacheWithNetwork = sRCWNEnabled;
}
rv = cacheStorage->AsyncOpenURI(openURI, extension, cacheEntryOpenFlags, this);
if (NS_FAILED(rv)) {
// Drop the flag since the cache open failed
mCacheAsyncOpenCalled = false;
}
} else {
// We pass `this` explicitly as a parameter due to the raw pointer
// to refcounted object in lambda analysis.
mCacheOpenFunc = [openURI, extension, cacheEntryOpenFlags, cacheStorage] (nsHttpChannel* self) -> void {
MOZ_ASSERT(NS_IsMainThread(), "Should be called on the main thread");
self->mCacheAsyncOpenCalled = true;
if (self->mNetworkTriggered) {
self->mRaceCacheWithNetwork = true;
}
nsresult rv = cacheStorage->AsyncOpenURI(openURI, extension, cacheEntryOpenFlags, self);
if (NS_FAILED(rv)) {
self->mCacheAsyncOpenCalled = false;
}
cacheStorage->AsyncOpenURI(openURI, extension, cacheEntryOpenFlags, self);
};
mCacheOpenTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
@ -4434,7 +4423,6 @@ nsHttpChannel::OnCacheEntryAvailable(nsICacheEntry *entry,
nsresult status)
{
MOZ_ASSERT(NS_IsMainThread());
mOnCacheAvailableCalled = true;
nsresult rv;
@ -9404,7 +9392,7 @@ nsHttpChannel::TriggerNetwork()
return NS_OK;
}
if (mCacheAsyncOpenCalled && !mOnCacheAvailableCalled) {
if (AwaitingCacheCallbacks()) {
mRaceCacheWithNetwork = sRCWNEnabled;
}

View File

@ -731,13 +731,10 @@ private:
// Is true if the network request has been triggered.
bool mNetworkTriggered = false;
bool mWaitingForProxy = false;
// Is true if the onCacheEntryAvailable callback has been called.
bool mOnCacheAvailableCalled;
// Will be true if the onCacheEntryAvailable callback is not called by the
// time we send the network request
Atomic<bool> mRaceCacheWithNetwork;
uint32_t mRaceDelay;
bool mCacheAsyncOpenCalled;
// If true then OnCacheEntryAvailable should ignore the entry, because
// SetupTransaction removed conditional headers and decisions made in
// OnCacheEntryCheck are no longer valid.