Bug 1531354 - P5. Safe Browsing test entries are directly stored in LookupCache. r=gcp

Create test entries via update introduces performance overhead.
We can store them directly in LookupCache and do not save test entries
to disk.

Differential Revision: https://phabricator.services.mozilla.com/D34576
This commit is contained in:
dlee
2019-06-29 19:05:41 +00:00
parent 7a8ac63eb7
commit f59bb40e5d
35 changed files with 228 additions and 212 deletions

View File

@@ -177,10 +177,18 @@ LookupCache::LookupCache(const nsACString& aTableName,
nsresult LookupCache::Open() {
LOG(("Loading PrefixSet for %s", mTableName.get()));
nsresult rv = LoadPrefixSet();
NS_ENSURE_SUCCESS(rv, rv);
nsresult rv;
if (nsUrlClassifierUtils::IsMozTestTable(mTableName)) {
// For built-in test table, we don't load it from disk,
// test entries are directly added in memory.
rv = LoadMozEntries();
} else {
rv = LoadPrefixSet();
}
return NS_OK;
Unused << NS_WARN_IF(NS_FAILED(rv));
return rv;
}
nsresult LookupCache::Init() {
@@ -863,5 +871,61 @@ nsCString LookupCacheV2::GetPrefixSetSuffix() const {
return NS_LITERAL_CSTRING(".vlpset");
}
// Support creating built-in entries for phsihing, malware, unwanted, harmful,
// tracking/tracking whitelist and flash block tables.
//
nsresult LookupCacheV2::LoadMozEntries() {
// We already have the entries, return
if (!IsEmpty() || IsPrimed()) {
return NS_OK;
}
nsTArray<nsLiteralCString> entries;
if (mTableName.EqualsLiteral("moztest-phish-simple")) {
// Entries for phishing table
entries.AppendElement(
NS_LITERAL_CSTRING("itisatrap.org/firefox/its-a-trap.html"));
} else if (mTableName.EqualsLiteral("moztest-malware-simple")) {
// Entries for malware table
entries.AppendElement(
NS_LITERAL_CSTRING("itisatrap.org/firefox/its-an-attack.html"));
} else if (mTableName.EqualsLiteral("moztest-unwanted-simple")) {
// Entries for unwanted table
entries.AppendElement(
NS_LITERAL_CSTRING("itisatrap.org/firefox/unwanted.html"));
} else if (mTableName.EqualsLiteral("moztest-harmful-simple")) {
// Entries for harmfule tables
entries.AppendElement(
NS_LITERAL_CSTRING("itisatrap.org/firefox/harmful.html"));
} else if (mTableName.EqualsLiteral("moztest-track-simple")) {
// Entries for tracking table
entries.AppendElement(NS_LITERAL_CSTRING("trackertest.org/"));
entries.AppendElement(NS_LITERAL_CSTRING("itisatracker.org/"));
} else if (mTableName.EqualsLiteral("moztest-trackwhite-simple")) {
// Entries for tracking whitelist table
entries.AppendElement(
NS_LITERAL_CSTRING("itisatrap.org/?resource=itisatracker.org"));
} else if (mTableName.EqualsLiteral("moztest-block-simple")) {
// Entries for flash block table
entries.AppendElement(
NS_LITERAL_CSTRING("itisatrap.org/firefox/blocked.html"));
} else {
MOZ_ASSERT_UNREACHABLE();
}
AddPrefixArray prefix;
AddCompleteArray completes;
for (const auto& entry : entries) {
AddComplete add;
if (NS_FAILED(add.complete.FromPlaintext(entry))) {
continue;
}
completes.AppendElement(add, fallible);
}
return Build(prefix, completes);
}
} // namespace safebrowsing
} // namespace mozilla