--- a/toolkit/components/downloads/ApplicationReputation.cpp
+++ b/toolkit/components/downloads/ApplicationReputation.cpp
@@ -49,20 +49,18 @@
#include "nsString.h"
#include "nsTArray.h"
#include "nsThreadUtils.h"
#include "nsIContentPolicy.h"
#include "nsILoadInfo.h"
#include "nsContentUtils.h"
#include "nsWeakReference.h"
-#include "nsCharSeparatedTokenizer.h"
#include "nsIRedirectHistoryEntry.h"
-using namespace mozilla::downloads;
using mozilla::ArrayLength;
using mozilla::BasePrincipal;
using mozilla::OriginAttributes;
using mozilla::Preferences;
using mozilla::TimeStamp;
using mozilla::Telemetry::Accumulate;
using mozilla::intl::LocaleService;
using safe_browsing::ClientDownloadRequest;
@@ -85,108 +83,16 @@ using safe_browsing::ClientDownloadReque
#define PREF_BLOCK_POTENTIALLY_UNWANTED "browser.safebrowsing.downloads.remote.block_potentially_unwanted"
#define PREF_BLOCK_UNCOMMON "browser.safebrowsing.downloads.remote.block_uncommon"
// MOZ_LOG=ApplicationReputation:5
mozilla::LazyLogModule ApplicationReputationService::prlog("ApplicationReputation");
#define LOG(args) MOZ_LOG(ApplicationReputationService::prlog, mozilla::LogLevel::Debug, args)
#define LOG_ENABLED() MOZ_LOG_TEST(ApplicationReputationService::prlog, mozilla::LogLevel::Debug)
-namespace mozilla {
-namespace downloads {
-
-enum class TelemetryMatchInfo : uint8_t
-{
- eNoMatch = 0x00,
- eV2Match = 0x01,
- eV4Match = 0x02,
- eBothMatch = eV2Match | eV4Match,
-};
-
-MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(TelemetryMatchInfo)
-
-// Given a comma-separated list of tables which matched a URL, check to see if
-// at least one of these tables is present in the given pref.
-bool
-LookupTablesInPrefs(const nsACString& tables, const char* aPref)
-{
- nsAutoCString prefList;
- Preferences::GetCString(aPref, &prefList);
- if (prefList.IsEmpty()) {
- return false;
- }
-
- // Check if V2 and V4 are enabled in preference
- // If V2 and V4 are both enabled, then we should do a telemetry record
- // Both V2 and V4 begin with "goog" but V4 ends with "-proto"
- nsCCharSeparatedTokenizer prefTokens(prefList, ',');
- nsCString prefToken;
- bool isV4Enabled = false;
- bool isV2Enabled = false;
-
- while (prefTokens.hasMoreTokens()) {
- prefToken = prefTokens.nextToken();
- if (StringBeginsWith(prefToken, NS_LITERAL_CSTRING("goog"))) {
- if (StringEndsWith(prefToken, NS_LITERAL_CSTRING("-proto"))) {
- isV4Enabled = true;
- } else {
- isV2Enabled = true;
- }
- }
- }
-
- bool shouldRecordTelemetry = isV2Enabled && isV4Enabled;
- TelemetryMatchInfo telemetryInfo = TelemetryMatchInfo::eNoMatch;
-
- // Parsed tables separated by "," into tokens then lookup each token
- // in preference list
- nsCCharSeparatedTokenizer tokens(tables, ',');
- nsCString table;
- bool found = false;
-
- while (tokens.hasMoreTokens()) {
- table = tokens.nextToken();
- if (table.IsEmpty()) {
- continue;
- }
-
- if (!FindInReadable(table, prefList)) {
- continue;
- }
- found = true;
-
- if (!shouldRecordTelemetry) {
- return found;
- }
-
- // We are checking if the table found is V2 or V4 to record telemetry
- // Both V2 and V4 begin with "goog" but V4 ends with "-proto"
- if (StringBeginsWith(table, NS_LITERAL_CSTRING("goog"))) {
- if (StringEndsWith(table, NS_LITERAL_CSTRING("-proto"))) {
- telemetryInfo |= TelemetryMatchInfo::eV4Match;
- } else {
- telemetryInfo |= TelemetryMatchInfo::eV2Match;
- }
- }
- }
-
- // Record telemetry for matching allow list and block list
- if (!strcmp(aPref, PREF_DOWNLOAD_BLOCK_TABLE)) {
- Accumulate(mozilla::Telemetry::APPLICATION_REPUTATION_BLOCKLIST_MATCH,
- static_cast<uint8_t>(telemetryInfo));
- } else if (!strcmp(aPref, PREF_DOWNLOAD_ALLOW_TABLE)) {
- Accumulate(mozilla::Telemetry::APPLICATION_REPUTATION_ALLOWLIST_MATCH,
- static_cast<uint8_t>(telemetryInfo));
- }
-
- return found;
-}
-} // namespace downloads
-} // namespace mozilla
-
class PendingDBLookup;
// A single use class private to ApplicationReputationService encapsulating an
// nsIApplicationReputationQuery and an nsIApplicationReputationCallback. Once
// created by ApplicationReputationService, it is guaranteed to call mCallback.
// This class is private to ApplicationReputationService.
class PendingLookup final : public nsIStreamListener,
public nsITimerCallback,
@@ -438,25 +344,29 @@ PendingDBLookup::LookupSpecInternal(cons
NS_IMETHODIMP
PendingDBLookup::HandleEvent(const nsACString& tables)
{
// HandleEvent is guaranteed to call either:
// 1) PendingLookup::OnComplete if the URL matches the blocklist, or
// 2) PendingLookup::LookupNext if the URL does not match the blocklist.
// Blocklisting trumps allowlisting.
- if (!mAllowlistOnly && LookupTablesInPrefs(tables, PREF_DOWNLOAD_BLOCK_TABLE)) {
+ nsAutoCString blockList;
+ Preferences::GetCString(PREF_DOWNLOAD_BLOCK_TABLE, &blockList);
+ if (!mAllowlistOnly && FindInReadable(blockList, tables)) {
mPendingLookup->mBlocklistCount++;
Accumulate(mozilla::Telemetry::APPLICATION_REPUTATION_LOCAL, BLOCK_LIST);
LOG(("Found principal %s on blocklist [this = %p]", mSpec.get(), this));
return mPendingLookup->OnComplete(true, NS_OK,
nsIApplicationReputationService::VERDICT_DANGEROUS);
}
- if (LookupTablesInPrefs(tables, PREF_DOWNLOAD_ALLOW_TABLE)) {
+ nsAutoCString allowList;
+ Preferences::GetCString(PREF_DOWNLOAD_ALLOW_TABLE, &allowList);
+ if (FindInReadable(allowList, tables)) {
mPendingLookup->mAllowlistCount++;
Accumulate(mozilla::Telemetry::APPLICATION_REPUTATION_LOCAL, ALLOW_LIST);
LOG(("Found principal %s on allowlist [this = %p]", mSpec.get(), this));
// Don't call onComplete, since blocklisting trumps allowlisting
} else {
LOG(("Didn't find principal %s on any list [this = %p]", mSpec.get(),
this));
Accumulate(mozilla::Telemetry::APPLICATION_REPUTATION_LOCAL, NO_LIST);
--- a/toolkit/components/downloads/ApplicationReputation.h
+++ b/toolkit/components/downloads/ApplicationReputation.h
@@ -15,24 +15,16 @@
#include "nsCOMPtr.h"
#include "nsString.h"
#include "mozilla/Logging.h"
class nsIRequest;
class PendingDBLookup;
class PendingLookup;
-namespace mozilla {
-namespace downloads {
-
-bool LookupTablesInPrefs(const nsACString& tables, const char* aPref);
-
-} // namespace downloads
-} // namespace mozilla
-
class ApplicationReputationService final :
public nsIApplicationReputationService {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIAPPLICATIONREPUTATIONSERVICE
public:
static ApplicationReputationService* GetSingleton();
--- a/toolkit/components/downloads/moz.build
+++ b/toolkit/components/downloads/moz.build
@@ -14,17 +14,17 @@ with Files('chromium/*'):
BUG_COMPONENT = ('Toolkit', 'Safe Browsing')
with Files('generate_csd.sh'):
BUG_COMPONENT = ('Toolkit', 'Safe Browsing')
with Files('nsIApplicationReputation.idl'):
BUG_COMPONENT = ('Toolkit', 'Safe Browsing')
-TEST_DIRS += ['test']
+XPCSHELL_TESTS_MANIFESTS += ['test/unit/xpcshell.ini']
XPIDL_SOURCES += [
'nsIApplicationReputation.idl',
'nsIDownload.idl',
'nsIDownloadManager.idl',
'nsIDownloadManagerUI.idl',
'nsIDownloadProgressListener.idl',
]
deleted file mode 100644
--- a/toolkit/components/downloads/test/gtest/TestLookupTable.cpp
+++ /dev/null
@@ -1,47 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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 "gtest/gtest.h"
-#include "ApplicationReputation.h"
-#include "mozilla/Preferences.h"
-#include "nsLiteralString.h"
-
-using namespace mozilla;
-using namespace mozilla::downloads;
-
-TEST(PendingLookup, LookupTablesInPrefs)
-{
- EXPECT_EQ(NS_OK, Preferences::SetCString("gtest.test", "goog-badbinurl-proto,goog-downloadwhite-proto,goog-badbinurl-shavar"));
-
- bool result;
- result = LookupTablesInPrefs(NS_LITERAL_CSTRING("goog-phish-proto,adafaf,,daf,goog-badbinurl-proto"), "gtest.test");
- ASSERT_TRUE(result);
-
- result = LookupTablesInPrefs(NS_LITERAL_CSTRING("goog-phish-proto,adafaf,,daf,goog-downloadwhite-proto"), "gtest.test");
- ASSERT_TRUE(result);
-
- result = LookupTablesInPrefs(NS_LITERAL_CSTRING("goog-phish-proto"), "gtest.test");
- ASSERT_FALSE(result);
-
- result = LookupTablesInPrefs(NS_LITERAL_CSTRING("goog-phish-proto,goog-badbinurl-proto,goog-phish-shavar"), "gtest.test");
- ASSERT_TRUE(result);
-
- EXPECT_EQ(NS_OK, Preferences::SetCString("gtest.test", "goog-badbinurl-proto"));
-
- result = LookupTablesInPrefs(NS_LITERAL_CSTRING("goog-badbinurl-proto"), "gtest.test");
- ASSERT_TRUE(result);
-
- result = LookupTablesInPrefs(NS_LITERAL_CSTRING("goog-phish-proto,goog-badbinurl-proto,goog-phish-shavar"), "gtest.test");
- ASSERT_TRUE(result);
-
- // Empty prefrence
- EXPECT_EQ(NS_OK, Preferences::SetCString("gtest.test", ""));
-
- result = LookupTablesInPrefs(NS_LITERAL_CSTRING("goog-phish-proto,goog-badbinurl-proto,goog-phish-shavar"), "gtest.test");
- ASSERT_FALSE(result);
-
- Preferences::ClearUser("gtest.test");
-}
-
deleted file mode 100644
--- a/toolkit/components/downloads/test/gtest/moz.build
+++ /dev/null
@@ -1,15 +0,0 @@
-# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
-# vim: set filetype=python:
-# 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/.
-
-LOCAL_INCLUDES += [
- '../..',
-]
-
-UNIFIED_SOURCES += [
- 'TestLookupTable.cpp',
-]
-
-FINAL_LIBRARY = 'xul-gtest'
deleted file mode 100644
--- a/toolkit/components/downloads/test/moz.build
+++ /dev/null
@@ -1,10 +0,0 @@
-# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
-# vim: set filetype=python:
-# 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/.
-
-XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini']
-
-if CONFIG['ENABLE_TESTS']:
- DIRS += ['gtest']
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -124,34 +124,16 @@
"APPLICATION_REPUTATION_REMOTE_LOOKUP_TIMEOUT": {
"record_in_processes": ["main", "content"],
"alert_emails": ["safebrowsing-telemetry@mozilla.org"],
"expires_in_version": "56",
"kind": "boolean",
"bug_numbers": [1172689],
"description": "Recorded when application reputation remote lookup is performed, `true` is recorded if the lookup times out."
},
- "APPLICATION_REPUTATION_BLOCKLIST_MATCH": {
- "record_in_processes": ["main", "content"],
- "alert_emails": ["safebrowsing-telemetry@mozilla.org"],
- "expires_in_version": "60",
- "kind": "enumerated",
- "n_values": 4,
- "bug_numbers": [1331139],
- "description": "For each Application Reputation lookup against both the V2 and V4 Google lists, note which version of block list returned a match (0 = no match, 1 = match only V2, 2 = match only V4, 3 = match both V2 and V4)"
- },
- "APPLICATION_REPUTATION_ALLOWLIST_MATCH": {
- "record_in_processes": ["main", "content"],
- "alert_emails": ["safebrowsing-telemetry@mozilla.org"],
- "expires_in_version": "60",
- "kind": "enumerated",
- "n_values": 4,
- "bug_numbers": [1331139],
- "description": "For each Application Reputation lookup against both the V2 and V4 Google lists, note which version of the allow list returned a match (0 = no match, 1 = match only V2, 2 = match only V4, 3 = match both V2 and V4)"
- },
"ASYNC_ANIMATION_CONTENT_TOO_LARGE_FRAME_SIZE": {
"record_in_processes": ["main", "content"],
"alert_emails": ["bbirtles@mozilla.com"],
"expires_in_version": "59",
"kind": "exponential",
"high": 80000000,
"n_buckets": 100,
"bug_numbers": [1100357, 1349808],
@@ -4945,35 +4927,16 @@
"alert_emails": ["safebrowsing-telemetry@mozilla.org"],
"expires_in_version": "59",
"kind": "enumerated",
"keyed": true,
"n_values": 16,
"bug_numbers": [1311910],
"description": "Whether or not an error was encountered while processing a Safe Browsing update (0 = success, 1 = unspecified error, 2 = addition of an already existing prefix, 3 = parser got into an infinite loop, 4 = removal index out of bounds, 5 = checksum mismatch, 6 = missing checksum, 7 = update while shutdown, 8 = cannot find table, 9 = build prefix failure, 10 = write disk failure, 11 = protocol parser error). Keyed by provider"
},
- "URLCLASSIFIER_MATCH_RESULT": {
- "record_in_processes": ["main", "content"],
- "alert_emails": ["safebrowsing-telemetry@mozilla.org"],
- "expires_in_version": "60",
- "kind": "enumerated",
- "n_values": 16,
- "bug_numbers": [1311931],
- "description": "The result of each URL lookup against both google and google4 lists. (0 = no match, 1 = V2 prefix only, 2 = V4 prefix only, 3 = V2 and V4 prefixes, 4 = V2 and V4 completions, 5 = V2 completion only, 6 = V4 completion only, 7 = V2 completion and v4 prefix, 8 = V2 prefix and V4 completion, 9 = unexpected result)"
-
- },
- "URLCLASSIFIER_MATCH_THREAT_TYPE_RESULT" : {
- "record_in_processes": ["main", "content"],
- "alert_emails": ["safebrowsing-telemetry@mozilla.org"],
- "expires_in_version": "60",
- "kind": "enumerated",
- "n_values": 64,
- "bug_numbers": [1311933],
- "description": "Whether or not a full URL match is of the same threat type on V2 and V4. (0 = same, otherwise the value is a bit flag where 0x01 = V2 phishing, 0x02 = V2 malware, 0x04 = V2 unwanted, 0x08 = V4 phishing, 0x10 = V4 malware, 0x20 = V4 unwanted)"
- },
"URLCLASSIFIER_POSITIVE_CACHE_DURATION": {
"record_in_processes": ["main", "content"],
"alert_emails": ["safebrowsing-telemetry@mozilla.org"],
"expires_in_version": "60",
"kind": "exponential",
"high": 86400000,
"n_buckets": 50,
"bug_numbers": [1338082],
--- a/toolkit/components/url-classifier/Classifier.cpp
+++ b/toolkit/components/url-classifier/Classifier.cpp
@@ -462,28 +462,16 @@ Classifier::Check(const nsACString& aSpe
LookupCache *cache = GetLookupCache(activeTables[i]);
if (cache) {
cacheArray.AppendElement(cache);
} else {
return NS_ERROR_FAILURE;
}
}
- // Only record telemetry when both v2 and v4 have data.
- bool isV2Empty = true, isV4Empty = true;
- bool shouldDoTelemetry = false;
- for (auto&& cache : cacheArray) {
- bool& ref = LookupCache::Cast<LookupCacheV2>(cache) ? isV2Empty : isV4Empty;
- ref = ref ? cache->IsEmpty() : false;
- if (!isV2Empty && !isV4Empty) {
- shouldDoTelemetry = true;
- break;
- }
- }
-
// Now check each lookup fragment against the entries in the DB.
for (uint32_t i = 0; i < fragments.Length(); i++) {
Completion lookupHash;
lookupHash.FromPlaintext(fragments[i], mCryptoHash);
if (LOG_ENABLED()) {
nsAutoCString checking;
lookupHash.ToHexString(checking);
@@ -508,38 +496,20 @@ Classifier::Check(const nsACString& aSpe
cache->TableName().get(),
confirmed ? "confirmed." : "Not confirmed."));
result->hash.complete = lookupHash;
result->mConfirmed = confirmed;
result->mTableName.Assign(cache->TableName());
result->mPartialHashLength = confirmed ? COMPLETE_SIZE : matchLength;
result->mProtocolV2 = LookupCache::Cast<LookupCacheV2>(cache);
-
- // There are two cases we are going to ignore the result for telemetry:
- // 1. shouldDoTelemetry == false(when either v2 or v4 table is empty)
- // 2. When match was found in the table which is not provided by google.
- if (!shouldDoTelemetry ||
- !StringBeginsWith(result->mTableName, NS_LITERAL_CSTRING("goog"))) {
- continue;
- }
-
- result->mMatchResult = result->mProtocolV2 ?
- MatchResult::eV2Prefix : MatchResult::eV4Prefix;
}
}
}
- // If we cannot find the prefix in neither the v2 nor the v4 database, record the
- // telemetry here because we won't reach nsUrlClassifierLookupCallback:::HandleResult.
- if (shouldDoTelemetry && aResults.Length() == 0) {
- Telemetry::Accumulate(Telemetry::URLCLASSIFIER_MATCH_RESULT,
- static_cast<uint8_t>(MatchResult::eNoMatch));
- }
-
return NS_OK;
}
static nsresult
SwapDirectoryContent(nsIFile* aDir1,
nsIFile* aDir2,
nsIFile* aParentDir,
nsIFile* aTempDir)
--- a/toolkit/components/url-classifier/LookupCache.h
+++ b/toolkit/components/url-classifier/LookupCache.h
@@ -9,34 +9,32 @@
#include "Entries.h"
#include "nsString.h"
#include "nsTArray.h"
#include "nsCOMPtr.h"
#include "nsIFile.h"
#include "nsIFileStreams.h"
#include "mozilla/RefPtr.h"
#include "nsUrlClassifierPrefixSet.h"
-#include "SBTelemetryUtils.h"
#include "VariableLengthPrefixSet.h"
#include "mozilla/Logging.h"
#include "mozilla/TypedEnumBits.h"
#include "nsIUrlClassifierInfo.h"
namespace mozilla {
namespace safebrowsing {
#define MAX_HOST_COMPONENTS 5
#define MAX_PATH_COMPONENTS 4
class LookupResult {
public:
LookupResult() : mNoise(false), mProtocolConfirmed(false),
mPartialHashLength(0), mConfirmed(false),
- mProtocolV2(true),
- mMatchResult(MatchResult::eTelemetryDisabled) {}
+ mProtocolV2(true) {}
// The fragment that matched in the LookupCache
union {
Prefix fixedLengthPrefix;
Completion complete;
} hash;
const Completion &CompleteHash() {
@@ -73,20 +71,18 @@ public:
nsCString mTableName;
uint32_t mPartialHashLength;
// True as long as this lookup is complete and hasn't expired.
bool mConfirmed;
+ // TODO : Is this necessary
bool mProtocolV2;
-
- // This is only used by telemetry to record the match result.
- MatchResult mMatchResult;
};
typedef nsTArray<LookupResult> LookupResultArray;
class CacheResult {
public:
enum { V2, V4 };
deleted file mode 100644
--- a/toolkit/components/url-classifier/SBTelemetryUtils.cpp
+++ /dev/null
@@ -1,45 +0,0 @@
-/* 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
deleted file mode 100644
--- a/toolkit/components/url-classifier/SBTelemetryUtils.h
+++ /dev/null
@@ -1,63 +0,0 @@
-//* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/. */
-
-#ifndef SBTelemetryUtils_h__
-#define SBTelemetryUtils_h__
-
-#include "mozilla/TypedEnumBits.h"
-
-namespace mozilla {
-namespace safebrowsing {
-
-enum class MatchResult : uint8_t
-{
- eNoMatch = 0x00,
- eV2Prefix = 0x01,
- eV4Prefix = 0x02,
- eV2Completion = 0x04,
- eV4Completion = 0x08,
- eTelemetryDisabled = 0x10,
-
- eBothPrefix = eV2Prefix | eV4Prefix,
- eBothCompletion = eV2Completion | eV4Completion,
- eV2PreAndCom = eV2Prefix | eV2Completion,
- eV4PreAndCom = eV4Prefix | eV4Completion,
- eBothPreAndV2Com = eBothPrefix | eV2Completion,
- eBothPreAndV4Com = eBothPrefix | eV4Completion,
- eAll = eBothPrefix | eBothCompletion,
-};
-MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(MatchResult)
-
-enum class MatchThreatType : uint8_t
-{
- eIdentical = 0x00,
- eV2Phishing = 0x01,
- eV2Malware = 0x02,
- eV2Unwanted = 0x04,
- eV4Phishing = 0x08,
- eV4Malware = 0x10,
- eV4Unwanted = 0x20,
- ePhishingMask = eV2Phishing | eV4Phishing,
- eMalwareMask = eV2Malware | eV4Malware,
- eUnwantedMask = eV2Unwanted | eV4Unwanted,
-};
-MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(MatchThreatType)
-
-uint8_t
-MatchResultToUint(const MatchResult& aResult);
-
-MatchThreatType
-TableNameToThreatType(bool aIsV2, const nsACString& aTable);
-
-enum UpdateTimeout {
- eNoTimeout = 0,
- eResponseTimeout = 1,
- eDownloadTimeout = 2,
-};
-
-} // namespace safebrowsing
-} // namespace mozilla
-
-#endif //SBTelemetryUtils_h__
--- a/toolkit/components/url-classifier/moz.build
+++ b/toolkit/components/url-classifier/moz.build
@@ -32,17 +32,16 @@ UNIFIED_SOURCES += [
'nsCheckSummedOutputStream.cpp',
'nsUrlClassifierDBService.cpp',
'nsUrlClassifierInfo.cpp',
'nsUrlClassifierProxies.cpp',
'nsUrlClassifierUtils.cpp',
'protobuf/safebrowsing.pb.cc',
'ProtocolParser.cpp',
'RiceDeltaDecoder.cpp',
- 'SBTelemetryUtils.cpp',
]
# define conflicting LOG() macros
SOURCES += [
'nsUrlClassifierPrefixSet.cpp',
'nsUrlClassifierStreamUpdater.cpp',
'VariableLengthPrefixSet.cpp',
]
@@ -68,17 +67,16 @@ EXTRA_JS_MODULES += [
]
EXPORTS += [
'Entries.h',
'LookupCache.h',
'LookupCacheV4.h',
'nsUrlClassifierPrefixSet.h',
'protobuf/safebrowsing.pb.h',
- 'SBTelemetryUtils.h',
'VariableLengthPrefixSet.h',
]
FINAL_LIBRARY = 'xul'
LOCAL_INCLUDES += [
'../build',
]
--- a/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
@@ -49,17 +49,16 @@
#include "Classifier.h"
#include "ProtocolParser.h"
#include "nsContentUtils.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/PermissionMessageUtils.h"
#include "mozilla/dom/URLClassifierChild.h"
#include "mozilla/ipc/URIUtils.h"
#include "nsProxyRelease.h"
-#include "SBTelemetryUtils.h"
namespace mozilla {
namespace safebrowsing {
nsresult
TablesToResponse(const nsACString& tables)
{
if (tables.IsEmpty()) {
@@ -1266,48 +1265,31 @@ nsUrlClassifierLookupCallback::HandleRes
"called while there are pending completions");
LOG(("nsUrlClassifierLookupCallback::HandleResults [%p, %" PRIuSIZE " results]",
this, mResults->Length()));
nsCOMPtr<nsIUrlClassifierClassifyCallback> classifyCallback =
do_QueryInterface(mCallback);
- MatchResult matchResult = MatchResult::eTelemetryDisabled;
-
nsTArray<nsCString> tables;
// Build a stringified list of result tables.
for (uint32_t i = 0; i < mResults->Length(); i++) {
LookupResult& result = mResults->ElementAt(i);
// Leave out results that weren't confirmed, as their existence on
// the list can't be verified. Also leave out randomly-generated
// noise.
if (result.mNoise) {
LOG(("Skipping result %s from table %s (noise)",
result.PartialHashHex().get(), result.mTableName.get()));
continue;
}
- bool confirmed = result.Confirmed();
-
- // If mMatchResult is set to eTelemetryDisabled, then we don't need to
- // set |matchResult| for this lookup.
- if (result.mMatchResult != MatchResult::eTelemetryDisabled) {
- matchResult &= ~(MatchResult::eTelemetryDisabled);
- if (result.mProtocolV2) {
- matchResult |=
- confirmed ? MatchResult::eV2PreAndCom : MatchResult::eV2Prefix;
- } else {
- matchResult |=
- confirmed ? MatchResult::eV4PreAndCom : MatchResult::eV4Prefix;
- }
- }
-
- if (!confirmed) {
+ if (!result.Confirmed()) {
LOG(("Skipping result %s from table %s (not confirmed)",
result.PartialHashHex().get(), result.mTableName.get()));
continue;
}
if (StringEndsWith(result.mTableName, NS_LITERAL_CSTRING("-proto")) &&
!Preferences::GetBool(TAKE_V4_COMPLETION_RESULT_PREF,
TAKE_V4_COMPLETION_RESULT_DEFAULT)) {
@@ -1325,67 +1307,16 @@ nsUrlClassifierLookupCallback::HandleRes
if (classifyCallback) {
nsCString prefixString;
result.hash.fixedLengthPrefix.ToString(prefixString);
classifyCallback->HandleResult(result.mTableName, prefixString);
}
}
- // Only record threat type telemetry when completion is found in V2 & V4.
- if (matchResult == MatchResult::eAll && mCacheResults) {
- MatchThreatType types = MatchThreatType::eIdentical;
-
- // Check all the results because there may be multiple matches being returned.
- bool foundV2Result = false, foundV4Result = false;
- for (uint32_t i = 0; i < mCacheResults->Length(); i++) {
- CacheResult* c = mCacheResults->ElementAt(i).get();
- bool isV2 = CacheResult::V2 == c->Ver();
- if (isV2) {
- foundV2Result = true;
- } else {
- foundV4Result = true;
- }
- for (LookupResult& l : *(mResults.get())) {
- if (l.mProtocolV2 != isV2 || l.hash.fixedLengthPrefix != c->prefix) {
- continue;
- }
-
- // Ignore unconfirmed results.
- if (l.Confirmed()) {
- types |= TableNameToThreatType(CacheResult::V2 == c->Ver(), c->table);
- }
- break;
- }
- }
-
- // We don't want to record telemetry when one of the results is from cache
- // because finding an unexpired cache entry will prevent us from doing gethash
- // requests that would otherwise be required.
- if (foundV2Result && foundV4Result) {
- auto fnIsMatchSameThreatType = [&](const MatchThreatType& aTypeMask) {
- uint8_t val = static_cast<uint8_t>(types & aTypeMask);
- return val == 0 || val == static_cast<uint8_t>(aTypeMask);
- };
- if (fnIsMatchSameThreatType(MatchThreatType::ePhishingMask) &&
- fnIsMatchSameThreatType(MatchThreatType::eMalwareMask) &&
- fnIsMatchSameThreatType(MatchThreatType::eUnwantedMask)) {
- types = MatchThreatType::eIdentical;
- }
-
- Telemetry::Accumulate(Telemetry::URLCLASSIFIER_MATCH_THREAT_TYPE_RESULT,
- static_cast<uint8_t>(types));
- }
- }
-
- if (matchResult != MatchResult::eTelemetryDisabled) {
- Telemetry::Accumulate(Telemetry::URLCLASSIFIER_MATCH_RESULT,
- MatchResultToUint(matchResult));
- }
-
// Some parts of this gethash request generated no hits at all.
// Save the prefixes we checked to prevent repeated requests.
CacheMisses();
if (mCacheResults) {
// This hands ownership of the cache results array back to the worker
// thread.
mDBService->CacheCompletions(mCacheResults.forget());
--- a/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp
@@ -20,17 +20,16 @@
#include "mozilla/ErrorNames.h"
#include "mozilla/Logging.h"
#include "nsIInterfaceRequestor.h"
#include "mozilla/LoadContext.h"
#include "mozilla/Telemetry.h"
#include "nsContentUtils.h"
#include "nsIURLFormatter.h"
#include "Classifier.h"
-#include "SBTelemetryUtils.h"
using namespace mozilla::safebrowsing;
#define DEFAULT_RESPONSE_TIMEOUT_MS 15 * 1000
#define DEFAULT_TIMEOUT_MS 60 * 1000
static_assert(DEFAULT_TIMEOUT_MS > DEFAULT_RESPONSE_TIMEOUT_MS,
"General timeout must be greater than reponse timeout");
--- a/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.h
+++ b/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.h
@@ -63,16 +63,21 @@ private:
bool aIsPostRequest,
const nsACString &aTable);
// Fetches the next table, from mPendingUpdates.
nsresult FetchNext();
// Fetches the next request, from mPendingRequests
nsresult FetchNextRequest();
+ enum UpdateTimeout {
+ eNoTimeout = 0,
+ eResponseTimeout = 1,
+ eDownloadTimeout = 2,
+ };
bool mIsUpdating;
bool mInitialized;
bool mDownloadError;
bool mBeganStream;
nsCString mDownloadErrorStatusStr;