Bug 1359299 - Copy fullhash cache when update. r=hchang

After adopting the new thread model for safebrowsing, we will create a new
lookup cache for update so we can still check lookup cache at the same time.

Prefix set, completions will be generated when we open the new lookup cache
but it won't include cache, so we will loss cache after that.

This patch will copy cache data from old lookup cache to new lookup
cache while update.

MozReview-Commit-ID: L0WpiHOGIGm
This commit is contained in:
DimiL
2017-05-23 09:19:06 +08:00
parent 5d5ab83b9d
commit ecf67ffc51
7 changed files with 62 additions and 59 deletions

View File

@@ -627,6 +627,19 @@ Classifier::RemoveUpdateIntermediaries()
}
}
void
Classifier::CopyFullHashCacheToNewLookupCache(LookupCache* aNewLookupCache)
{
MOZ_ASSERT(aNewLookupCache);
for (auto c: mLookupCaches) {
if (c->TableName() == aNewLookupCache->TableName()) {
aNewLookupCache->CopyFullHashCache(c);
return;
}
}
}
void
Classifier::MergeNewLookupCaches()
{
@@ -1465,6 +1478,13 @@ Classifier::GetLookupCache(const nsACString& aTable, bool aForUpdate)
}
rv = cache->Open();
if (NS_SUCCEEDED(rv)) {
if (aForUpdate) {
// Since update algorithm will invalidate expired cache entries, we need
// to copy fullhash cache in "old LookupCache" to "update Lookupcache" before
// applying an update.
CopyFullHashCacheToNewLookupCache(cache.get());
}
lookupCaches.AppendElement(cache.get());
return cache.release();
}