Bug 616090 - Optimize timer in nsDOMStorageDBWrapper. r=honzab a=blocking-fennec

This commit is contained in:
Alon Zakai 2010-12-16 10:09:58 -08:00
Родитель 15de57bf72
Коммит e62810702b
4 изменённых файлов: 69 добавлений и 11 удалений

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

@ -441,6 +441,8 @@ nsDOMStorageManager::Observe(nsISupports *aSubject,
nsCOMPtr<nsIObserverService> obsserv = mozilla::services::GetObserverService();
if (obsserv)
obsserv->NotifyObservers(nsnull, NS_DOMSTORAGE_FLUSH_TIMER_OBSERVER, nsnull);
if (!UnflushedDataExists())
DOMStorageImpl::gStorageDB->StopTempTableFlushTimer();
} else if (!strcmp(aTopic, "browser:purge-domain-data")) {
// Convert the domain name to the ACE format
nsCAutoString aceDomain;
@ -537,6 +539,26 @@ nsDOMStorageManager::RemoveFromStoragesHash(DOMStorageImpl* aStorage)
mStorages.RemoveEntry(aStorage);
}
static PLDHashOperator
CheckUnflushedData(nsDOMStorageEntry* aEntry, void* userArg)
{
if (aEntry->mStorage->WasTemporaryTableLoaded()) {
PRBool *unflushedData = (PRBool*)userArg;
*unflushedData = PR_TRUE;
return PL_DHASH_STOP;
}
return PL_DHASH_NEXT;
}
PRBool
nsDOMStorageManager::UnflushedDataExists()
{
PRBool unflushedData = PR_FALSE;
mStorages.EnumerateEntries(CheckUnflushedData, &unflushedData);
return unflushedData;
}
//
// nsDOMStorage
//
@ -1055,6 +1077,8 @@ DOMStorageImpl::SetTemporaryTableLoaded(bool loaded)
mLastTemporaryTableAccessTime = TimeStamp::Now();
if (!mLoadedTemporaryTable)
mTemporaryTableAge = mLastTemporaryTableAccessTime;
gStorageDB->EnsureTempTableFlushTimer();
}
mLoadedTemporaryTable = loaded;

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

@ -136,6 +136,11 @@ public:
static nsDOMStorageManager* GetInstance();
static void Shutdown();
/**
* Checks whether there is any data waiting to be flushed from a temp table.
*/
PRBool UnflushedDataExists();
static nsDOMStorageManager* gStorageManager;
protected:

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

@ -75,9 +75,7 @@ nsDOMStorageDBWrapper::nsDOMStorageDBWrapper()
nsDOMStorageDBWrapper::~nsDOMStorageDBWrapper()
{
if (mFlushTimer) {
mFlushTimer->Cancel();
}
StopTempTableFlushTimer();
}
nsresult
@ -97,13 +95,6 @@ nsDOMStorageDBWrapper::Init()
rv = mPrivateBrowsingDB.Init();
NS_ENSURE_SUCCESS(rv, rv);
mFlushTimer = do_CreateInstance(NS_TIMER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = mFlushTimer->Init(nsDOMStorageManager::gStorageManager, 5000,
nsITimer::TYPE_REPEATING_SLACK);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
@ -452,3 +443,30 @@ nsDOMStorageDBWrapper::GetDomainFromScopeKey(const nsACString& aScope,
ReverseString(reverseDomain, aDomain);
return NS_OK;
}
void
nsDOMStorageDBWrapper::EnsureTempTableFlushTimer()
{
if (!mTempTableFlushTimer) {
nsresult rv;
mTempTableFlushTimer = do_CreateInstance(NS_TIMER_CONTRACTID, &rv);
if (!NS_SUCCEEDED(rv)) {
mTempTableFlushTimer = nsnull;
return;
}
mTempTableFlushTimer->Init(nsDOMStorageManager::gStorageManager, 5000,
nsITimer::TYPE_REPEATING_SLACK);
}
}
void
nsDOMStorageDBWrapper::StopTempTableFlushTimer()
{
if (mTempTableFlushTimer) {
mTempTableFlushTimer->Cancel();
mTempTableFlushTimer = nsnull;
}
}

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

@ -221,13 +221,24 @@ public:
static nsresult GetDomainFromScopeKey(const nsACString& aScope,
nsACString& aDomain);
/**
* Ensures the temp table flush timer is running. This is called when we add
* data that will need to be flushed.
*/
void EnsureTempTableFlushTimer();
/**
* Stops the temp table flush timer.
*/
void StopTempTableFlushTimer();
protected:
nsDOMStoragePersistentDB mChromePersistentDB;
nsDOMStoragePersistentDB mPersistentDB;
nsDOMStorageMemoryDB mSessionOnlyDB;
nsDOMStorageMemoryDB mPrivateBrowsingDB;
nsCOMPtr<nsITimer> mFlushTimer;
nsCOMPtr<nsITimer> mTempTableFlushTimer;
};
#endif /* nsDOMStorageDB_h___ */