Bug 1335974 - Add more error codes to URLCLASSIFIER_UPDATE_ERROR. r?francois
MozReview-Commit-ID: AAd6Yu0AuUO
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -4147,17 +4147,17 @@
},
"URLCLASSIFIER_UPDATE_ERROR": {
"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). Keyed by provider"
+ "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_PREFIX_MATCH": {
"alert_emails": ["safebrowsing-telemetry@mozilla.org"],
"expires_in_version": "58",
"kind": "enumerated",
"n_values": 4,
"bug_numbers": [1298257],
"description": "Classifier prefix matching result (0 = no match, 1 = match only V2, 2 = match only V4, 3 = match both V2 and V4)"
--- a/toolkit/components/url-classifier/Classifier.cpp
+++ b/toolkit/components/url-classifier/Classifier.cpp
@@ -952,17 +952,17 @@ Classifier::GetProvider(const nsACString
/*
* This will consume+delete updates from the passed nsTArray.
*/
nsresult
Classifier::UpdateHashStore(nsTArray<TableUpdate*>* aUpdates,
const nsACString& aTable)
{
if (nsUrlClassifierDBService::ShutdownHasStarted()) {
- return NS_ERROR_ABORT;
+ return NS_ERROR_UC_UPDATE_SHUTDOWNING;
}
LOG(("Classifier::UpdateHashStore(%s)", PromiseFlatCString(aTable).get()));
HashStore store(aTable, GetProvider(aTable), mRootStoreDirectory);
if (!CheckValidUpdate(aUpdates, store.TableName())) {
return NS_OK;
@@ -972,17 +972,17 @@ Classifier::UpdateHashStore(nsTArray<Tab
NS_ENSURE_SUCCESS(rv, rv);
rv = store.BeginUpdate();
NS_ENSURE_SUCCESS(rv, rv);
// Read the part of the store that is (only) in the cache
LookupCacheV2* lookupCache =
LookupCache::Cast<LookupCacheV2>(GetLookupCache(store.TableName()));
if (!lookupCache) {
- return NS_ERROR_FAILURE;
+ return NS_ERROR_UC_UPDATE_TABLE_NOT_FOUND;
}
// Clear cache when update
lookupCache->ClearCache();
FallibleTArray<uint32_t> AddPrefixHashes;
rv = lookupCache->GetPrefixes(AddPrefixHashes);
NS_ENSURE_SUCCESS(rv, rv);
@@ -1032,51 +1032,51 @@ Classifier::UpdateHashStore(nsTArray<Tab
LOG((" %" PRIuSIZE " sub completions", store.SubCompletes().Length()));
rv = store.WriteFile();
NS_ENSURE_SUCCESS(rv, rv);
// At this point the store is updated and written out to disk, but
// the data is still in memory. Build our quick-lookup table here.
rv = lookupCache->Build(store.AddPrefixes(), store.AddCompletes());
- NS_ENSURE_SUCCESS(rv, rv);
+ NS_ENSURE_SUCCESS(rv, NS_ERROR_UC_UPDATE_BUILD_PREFIX_FAILURE);
#if defined(DEBUG)
lookupCache->DumpCompletions();
#endif
rv = lookupCache->WriteFile();
- NS_ENSURE_SUCCESS(rv, rv);
+ NS_ENSURE_SUCCESS(rv, NS_ERROR_UC_UPDATE_FAIL_TO_WRITE_DISK);
int64_t now = (PR_Now() / PR_USEC_PER_SEC);
LOG(("Successfully updated %s", store.TableName().get()));
mTableFreshness.Put(store.TableName(), now);
return NS_OK;
}
nsresult
Classifier::UpdateTableV4(nsTArray<TableUpdate*>* aUpdates,
const nsACString& aTable)
{
MOZ_ASSERT(!NS_IsMainThread(),
"UpdateTableV4 must be called on the classifier worker thread.");
if (nsUrlClassifierDBService::ShutdownHasStarted()) {
- return NS_ERROR_ABORT;
+ return NS_ERROR_UC_UPDATE_SHUTDOWNING;
}
LOG(("Classifier::UpdateTableV4(%s)", PromiseFlatCString(aTable).get()));
if (!CheckValidUpdate(aUpdates, aTable)) {
return NS_OK;
}
LookupCacheV4* lookupCache =
LookupCache::Cast<LookupCacheV4>(GetLookupCache(aTable));
if (!lookupCache) {
- return NS_ERROR_FAILURE;
+ return NS_ERROR_UC_UPDATE_TABLE_NOT_FOUND;
}
nsresult rv = NS_OK;
// If there are multiple updates for the same table, prefixes1 & prefixes2
// will act as input and output in turn to reduce memory copy overhead.
PrefixStringMap prefixes1, prefixes2;
PrefixStringMap* input = &prefixes1;
@@ -1085,17 +1085,17 @@ Classifier::UpdateTableV4(nsTArray<Table
TableUpdateV4* lastAppliedUpdate = nullptr;
for (uint32_t i = 0; i < aUpdates->Length(); i++) {
TableUpdate *update = aUpdates->ElementAt(i);
if (!update || !update->TableName().Equals(aTable)) {
continue;
}
auto updateV4 = TableUpdate::Cast<TableUpdateV4>(update);
- NS_ENSURE_TRUE(updateV4, NS_ERROR_FAILURE);
+ NS_ENSURE_TRUE(updateV4, NS_ERROR_UC_UPDATE_TABLE_NOT_FOUND);
if (updateV4->IsFullUpdate()) {
input->Clear();
output->Clear();
rv = lookupCache->ApplyUpdate(updateV4, *input, *output);
if (NS_FAILED(rv)) {
return rv;
}
@@ -1125,25 +1125,25 @@ Classifier::UpdateTableV4(nsTArray<Table
// Keep track of the last applied update.
lastAppliedUpdate = updateV4;
aUpdates->ElementAt(i) = nullptr;
}
rv = lookupCache->Build(*output);
- NS_ENSURE_SUCCESS(rv, rv);
+ NS_ENSURE_SUCCESS(rv, NS_ERROR_UC_UPDATE_BUILD_PREFIX_FAILURE);
rv = lookupCache->WriteFile();
- NS_ENSURE_SUCCESS(rv, rv);
+ NS_ENSURE_SUCCESS(rv, NS_ERROR_UC_UPDATE_FAIL_TO_WRITE_DISK);
if (lastAppliedUpdate) {
LOG(("Write meta data of the last applied update."));
rv = lookupCache->WriteMetadata(lastAppliedUpdate);
- NS_ENSURE_SUCCESS(rv, rv);
+ NS_ENSURE_SUCCESS(rv, NS_ERROR_UC_UPDATE_FAIL_TO_WRITE_DISK);
}
int64_t now = (PR_Now() / PR_USEC_PER_SEC);
LOG(("Successfully updated %s\n", PromiseFlatCString(aTable).get()));
mTableFreshness.Put(aTable, now);
return NS_OK;
--- a/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
@@ -590,16 +590,18 @@ nsUrlClassifierDBServiceWorker::FinishSt
mUpdateStatus = mProtocolParser->Status();
}
mUpdateObserver->StreamFinished(mProtocolParser->Status(), 0);
if (NS_SUCCEEDED(mUpdateStatus)) {
if (mProtocolParser->ResetRequested()) {
mClassifier->ResetTables(Classifier::Clear_All, mUpdateTables);
}
+ } else {
+ mUpdateStatus = NS_ERROR_UC_UPDATE_PROTOCOL_PARSER_ERROR;
}
mProtocolParser = nullptr;
return NS_OK;
}
NS_IMETHODIMP
--- a/xpcom/base/ErrorList.h
+++ b/xpcom/base/ErrorList.h
@@ -984,22 +984,27 @@
/* Internal platform-related errors */
ERROR(NS_ERROR_DOM_MEDIA_CUBEB_INITIALIZATION_ERR, FAILURE(101)),
#undef MODULE
/* ======================================================================= */
/* 42: NS_ERROR_MODULE_URL_CLASSIFIER */
/* ======================================================================= */
#define MODULE NS_ERROR_MODULE_URL_CLASSIFIER
- ERROR(NS_ERROR_UC_UPDATE_UNKNOWN, FAILURE(1)),
- ERROR(NS_ERROR_UC_UPDATE_DUPLICATE_PREFIX, FAILURE(2)),
- ERROR(NS_ERROR_UC_UPDATE_INFINITE_LOOP, FAILURE(3)),
- ERROR(NS_ERROR_UC_UPDATE_WRONG_REMOVAL_INDICES, FAILURE(4)),
- ERROR(NS_ERROR_UC_UPDATE_CHECKSUM_MISMATCH, FAILURE(5)),
- ERROR(NS_ERROR_UC_UPDATE_MISSING_CHECKSUM, FAILURE(6)),
+ ERROR(NS_ERROR_UC_UPDATE_UNKNOWN, FAILURE(1)),
+ ERROR(NS_ERROR_UC_UPDATE_DUPLICATE_PREFIX, FAILURE(2)),
+ ERROR(NS_ERROR_UC_UPDATE_INFINITE_LOOP, FAILURE(3)),
+ ERROR(NS_ERROR_UC_UPDATE_WRONG_REMOVAL_INDICES, FAILURE(4)),
+ ERROR(NS_ERROR_UC_UPDATE_CHECKSUM_MISMATCH, FAILURE(5)),
+ ERROR(NS_ERROR_UC_UPDATE_MISSING_CHECKSUM, FAILURE(6)),
+ ERROR(NS_ERROR_UC_UPDATE_SHUTDOWNING, FAILURE(7)),
+ ERROR(NS_ERROR_UC_UPDATE_TABLE_NOT_FOUND, FAILURE(8)),
+ ERROR(NS_ERROR_UC_UPDATE_BUILD_PREFIX_FAILURE, FAILURE(9)),
+ ERROR(NS_ERROR_UC_UPDATE_FAIL_TO_WRITE_DISK, FAILURE(10)),
+ ERROR(NS_ERROR_UC_UPDATE_PROTOCOL_PARSER_ERROR, FAILURE(11)),
#undef MODULE
/* ======================================================================= */
/* 43: NS_ERROR_MODULE_ERRORRESULT */
/* ======================================================================= */
#define MODULE NS_ERROR_MODULE_ERRORRESULT
/* Represents a JS Value being thrown as an exception. */
ERROR(NS_ERROR_INTERNAL_ERRORRESULT_JS_EXCEPTION, FAILURE(1)),