Bug 1319286 - Cache nsIUrlClassifierDBService.getTables result until next update. r=francois.

MozReview-Commit-ID: ItjTQNzCVED
This commit is contained in:
Henry Chang
2016-11-22 10:39:58 +08:00
parent 4c2c3750d2
commit acfb7674fb
3 changed files with 45 additions and 3 deletions

View File

@@ -22,6 +22,7 @@
#include "mozilla/Unused.h"
#include "mozilla/TypedEnumBits.h"
#include "nsIUrlClassifierUtils.h"
#include "nsUrlClassifierDBService.h"
// MOZ_LOG=UrlClassifierDbService:5
extern mozilla::LazyLogModule gUrlClassifierDbServiceLog;
@@ -144,6 +145,7 @@ Classifier::GetPrivateStoreDirectory(nsIFile* aRootStoreDirectory,
}
Classifier::Classifier()
: mIsTableRequestResultOutdated(true)
{
}
@@ -348,6 +350,16 @@ Classifier::AbortUpdateAndReset(const nsCString& aTable)
void
Classifier::TableRequest(nsACString& aResult)
{
MOZ_ASSERT(!NS_IsMainThread(),
"TableRequest must be called on the classifier worker thread.");
// This function and all disk I/O are guaranteed to occur
// on the same thread so we don't need to add a lock around.
if (!mIsTableRequestResultOutdated) {
aResult = mTableRequestResult;
return;
}
// Generating v2 table info.
nsTArray<nsCString> tables;
ActiveTables(tables);
@@ -387,8 +399,13 @@ Classifier::TableRequest(nsACString& aResult)
// Specifically for v4 tables.
nsCString metadata;
nsresult rv = LoadMetadata(mRootStoreDirectory, metadata);
NS_ENSURE_SUCCESS_VOID(rv);
aResult.Append(metadata);
if (NS_SUCCEEDED(rv)) {
aResult.Append(metadata);
}
// Update the TableRequest result in-memory cache.
mTableRequestResult = aResult;
mIsTableRequestResultOutdated = false;
}
// This is used to record the matching statistics for v2 and v4.
@@ -534,6 +551,10 @@ Classifier::ApplyUpdates(nsTArray<TableUpdate*>* aUpdates)
rv = UpdateTableV4(aUpdates, updateTable);
}
// We mark the table associated info outdated no matter the
// update is successful to avoid any possibile non-atomic update.
mIsTableRequestResultOutdated = true;
if (NS_FAILED(rv)) {
if (rv != NS_ERROR_OUT_OF_MEMORY) {
#ifdef MOZ_SAFEBROWSING_DUMP_FAILED_UPDATES
@@ -1009,6 +1030,9 @@ nsresult
Classifier::UpdateTableV4(nsTArray<TableUpdate*>* aUpdates,
const nsACString& aTable)
{
MOZ_ASSERT(!NS_IsMainThread(),
"UpdateTableV4 must be called on the classifier worker thread.");
LOG(("Classifier::UpdateTableV4(%s)", PromiseFlatCString(aTable).get()));
if (!CheckValidUpdate(aUpdates, aTable)) {