diff --git a/toolkit/components/url-classifier/Classifier.cpp b/toolkit/components/url-classifier/Classifier.cpp index d16b235c3ec6..129f20cf09cc 100644 --- a/toolkit/components/url-classifier/Classifier.cpp +++ b/toolkit/components/url-classifier/Classifier.cpp @@ -498,8 +498,10 @@ Classifier::Check(const nsACString& aSpec, if (LookupCache::Cast(cache)) { matchingStatistics |= PrefixMatch::eMatchV4Prefix; + result->mProtocolV2 = false; } else { matchingStatistics |= PrefixMatch::eMatchV2Prefix; + result->mProtocolV2 = true; } } } diff --git a/toolkit/components/url-classifier/LookupCache.h b/toolkit/components/url-classifier/LookupCache.h index 752c0c695d41..730bae02135e 100644 --- a/toolkit/components/url-classifier/LookupCache.h +++ b/toolkit/components/url-classifier/LookupCache.h @@ -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 LookupResultArray; diff --git a/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp b/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp index 94ef6c5958f8..346cdc42834e 100644 --- a/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp +++ b/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp @@ -281,8 +281,12 @@ nsUrlClassifierDBServiceWorker::DoLookup(const nsACString& spec, nsAutoPtr 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); } }