Bug 1311933 - P2. Add telemetry to measure if completion match type is the same for v2 and v4. r=francois

When full match is found in both v2 and v4, the threat types returned should also be the same.
If threat types are different, the telemetry record this by setting a bit flags which indicates
what threat types are being returned.

If threat types are the same, this telemetry will record 0.

MozReview-Commit-ID: Laz77yoCg00
This commit is contained in:
dimi
2017-04-12 09:11:18 +08:00
parent b19db734bc
commit 80b83c117c
6 changed files with 152 additions and 43 deletions

View File

@@ -0,0 +1,45 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* * License, v. 2.0. If a copy of the MPL was not distributed with this
* * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "SBTelemetryUtils.h"
#include "mozilla/Assertions.h"
namespace mozilla {
namespace safebrowsing {
uint8_t
MatchResultToUint(const MatchResult& aResult)
{
MOZ_ASSERT(!(aResult & MatchResult::eTelemetryDisabled));
switch (aResult) {
case MatchResult::eNoMatch: return 0;
case MatchResult::eV2Prefix: return 1;
case MatchResult::eV4Prefix: return 2;
case MatchResult::eBothPrefix: return 3;
case MatchResult::eAll: return 4;
case MatchResult::eV2PreAndCom: return 5;
case MatchResult::eV4PreAndCom: return 6;
case MatchResult::eBothPreAndV2Com: return 7;
case MatchResult::eBothPreAndV4Com: return 8;
default:
MOZ_ASSERT_UNREACHABLE("Unexpected match result");
return 9;
}
}
MatchThreatType
TableNameToThreatType(bool aIsV2, const nsACString& aTable)
{
if (FindInReadable(NS_LITERAL_CSTRING("-phish-"), aTable)) {
return aIsV2 ? MatchThreatType::eV2Phishing : MatchThreatType::eV4Phishing;
} else if (FindInReadable(NS_LITERAL_CSTRING("-malware-"), aTable)) {
return aIsV2 ? MatchThreatType::eV2Malware : MatchThreatType::eV4Malware;
} else if (FindInReadable(NS_LITERAL_CSTRING("-unwanted-"), aTable)) {
return aIsV2 ? MatchThreatType::eV2Unwanted : MatchThreatType::eV4Unwanted;
}
return MatchThreatType::eIdentical;
}
} // namespace safebrowsing
} // namespace mozilla