Bug 1333257 - Only cache V2 misses when doing Safe Browsing lookups. r=francois

MozReview-Commit-ID: 6kvM6z5OnPw

--HG--
extra : rebase_source : c180ac1b6c840a6112f72abe3b7984503fad7082
This commit is contained in:
Dimi Lee 2017-01-26 11:36:52 +08:00
Родитель 4711cdb9fd
Коммит c6aec3beb1
3 изменённых файлов: 14 добавлений и 4 удалений

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

@ -498,8 +498,10 @@ Classifier::Check(const nsACString& aSpec,
if (LookupCache::Cast<LookupCacheV4>(cache)) {
matchingStatistics |= PrefixMatch::eMatchV4Prefix;
result->mProtocolV2 = false;
} else {
matchingStatistics |= PrefixMatch::eMatchV2Prefix;
result->mProtocolV2 = true;
}
}
}

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

@ -26,7 +26,8 @@ namespace safebrowsing {
class LookupResult {
public:
LookupResult() : mNoise(false), mProtocolConfirmed(false),
mPartialHashLength(0), mConfirmed(false) {}
mPartialHashLength(0), mConfirmed(false),
mProtocolV2(true) {}
// The fragment that matched in the LookupCache
union {
@ -72,6 +73,8 @@ public:
// True as long as this lookup is complete and hasn't expired.
bool mConfirmed;
bool mProtocolV2;
};
typedef nsTArray<LookupResult> LookupResultArray;

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

@ -281,8 +281,12 @@ nsUrlClassifierDBServiceWorker::DoLookup(const nsACString& spec,
nsAutoPtr<LookupResultArray> completes(new LookupResultArray());
for (uint32_t i = 0; i < results->Length(); i++) {
if (!mMissCache.Contains(results->ElementAt(i).hash.fixedLengthPrefix)) {
completes->AppendElement(results->ElementAt(i));
const LookupResult& lookupResult = results->ElementAt(i);
// mMissCache should only be used in V2.
if (!lookupResult.mProtocolV2 ||
!mMissCache.Contains(lookupResult.hash.fixedLengthPrefix)) {
completes->AppendElement(lookupResult);
}
}
@ -1141,6 +1145,7 @@ nsUrlClassifierLookupCallback::HandleResults()
}
}
// TODO: Bug 1333328, Refactor cache miss mechanism for v2.
// Some parts of this gethash request generated no hits at all.
// Prefixes must have been removed from the database since our last update.
// Save the prefixes we checked to prevent repeated requests
@ -1149,7 +1154,7 @@ nsUrlClassifierLookupCallback::HandleResults()
if (cacheMisses) {
for (uint32_t i = 0; i < mResults->Length(); i++) {
LookupResult &result = mResults->ElementAt(i);
if (!result.Confirmed() && !result.mNoise) {
if (result.mProtocolV2 && !result.Confirmed() && !result.mNoise) {
cacheMisses->AppendElement(result.hash.fixedLengthPrefix);
}
}