From 85e6362a96c7f7b694d001e84da25e2da120395c Mon Sep 17 00:00:00 2001 From: Honza Bambas Date: Mon, 30 May 2016 04:48:00 +0200 Subject: [PATCH] Bug 1274585 - Push HTTP cache index build when asked for disk cache size, r=michal --- netwerk/cache2/CacheIndex.cpp | 51 ++++++++++++++++++++++++++--------- netwerk/cache2/CacheIndex.h | 1 + 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/netwerk/cache2/CacheIndex.cpp b/netwerk/cache2/CacheIndex.cpp index 13a075e597ea..3aacfc93331e 100644 --- a/netwerk/cache2/CacheIndex.cpp +++ b/netwerk/cache2/CacheIndex.cpp @@ -1369,6 +1369,20 @@ CacheIndex::AsyncGetDiskConsumption(nsICacheStorageConsumptionObserver* aObserve // Will be called when the index get to the READY state. index->mDiskConsumptionObservers.AppendElement(observer); + // Move forward with index re/building if it is pending + RefPtr ioThread = CacheFileIOManager::IOThread(); + if (ioThread) { + ioThread->Dispatch(NS_NewRunnableFunction([]() -> void { + StaticMutexAutoLock lock(sLock); + + RefPtr index = gInstance; + if (index && index->mUpdateTimer) { + index->mUpdateTimer->Cancel(); + index->DelayedUpdateLocked(); + } + }), CacheIOThread::INDEX); + } + return NS_OK; } @@ -2500,30 +2514,41 @@ CacheIndex::DelayedUpdate(nsITimer *aTimer, void *aClosure) { LOG(("CacheIndex::DelayedUpdate()")); - nsresult rv; StaticMutexAutoLock lock(sLock); - RefPtr index = gInstance; if (!index) { return; } - index->mUpdateTimer = nullptr; + index->DelayedUpdateLocked(); +} - if (!index->IsIndexUsable()) { +// static +void +CacheIndex::DelayedUpdateLocked() +{ + LOG(("CacheIndex::DelayedUpdateLocked()")); + + sLock.AssertCurrentThreadOwns(); + + nsresult rv; + + mUpdateTimer = nullptr; + + if (!IsIndexUsable()) { return; } - if (index->mState == READY && index->mShuttingDown) { + if (mState == READY && mShuttingDown) { return; } // mUpdateEventPending must be false here since StartUpdatingIndex() won't // schedule timer if it is true. - MOZ_ASSERT(!index->mUpdateEventPending); - if (index->mState != BUILDING && index->mState != UPDATING) { - LOG(("CacheIndex::DelayedUpdate() - Update was canceled")); + MOZ_ASSERT(!mUpdateEventPending); + if (mState != BUILDING && mState != UPDATING) { + LOG(("CacheIndex::DelayedUpdateLocked() - Update was canceled")); return; } @@ -2531,13 +2556,13 @@ CacheIndex::DelayedUpdate(nsITimer *aTimer, void *aClosure) RefPtr ioThread = CacheFileIOManager::IOThread(); MOZ_ASSERT(ioThread); - index->mUpdateEventPending = true; - rv = ioThread->Dispatch(index, CacheIOThread::INDEX); + mUpdateEventPending = true; + rv = ioThread->Dispatch(this, CacheIOThread::INDEX); if (NS_FAILED(rv)) { - index->mUpdateEventPending = false; - NS_WARNING("CacheIndex::DelayedUpdate() - Can't dispatch event"); + mUpdateEventPending = false; + NS_WARNING("CacheIndex::DelayedUpdateLocked() - Can't dispatch event"); LOG(("CacheIndex::DelayedUpdate() - Can't dispatch event" )); - index->FinishUpdate(false); + FinishUpdate(false); } } diff --git a/netwerk/cache2/CacheIndex.h b/netwerk/cache2/CacheIndex.h index ec6dd771e6f9..97c2e319609b 100644 --- a/netwerk/cache2/CacheIndex.h +++ b/netwerk/cache2/CacheIndex.h @@ -835,6 +835,7 @@ private: // Following methods perform updating and building of the index. // Timer callback that starts update or build process. static void DelayedUpdate(nsITimer *aTimer, void *aClosure); + void DelayedUpdateLocked(); // Posts timer event that start update or build process. nsresult ScheduleUpdateTimer(uint32_t aDelay); nsresult SetupDirectoryEnumerator();