зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1434206 - Use a TableUpdateV2 param in ApplyUpdate(). r=gcp
HashStore::ApplyUpdate() is a V2-only function and so we can be explicit about that and remove unnecessary casts. Add a new update error code for when we fail to cast a TableUpdate object to the expected protocol version. MozReview-Commit-ID: 65BBwiZJw6J --HG-- extra : rebase_source : 3f4bb0f7594d4015e2614ef747526ec5e8168a08
This commit is contained in:
Родитель
2a98feb53f
Коммит
d16c2f1d5c
|
@ -1235,26 +1235,27 @@ Classifier::UpdateHashStore(nsTArray<TableUpdate*>* aUpdates,
|
|||
|
||||
for (uint32_t i = 0; i < aUpdates->Length(); i++) {
|
||||
TableUpdate *update = aUpdates->ElementAt(i);
|
||||
if (!update || !update->TableName().Equals(store.TableName()))
|
||||
if (!update || !update->TableName().Equals(store.TableName())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
rv = store.ApplyUpdate(*update);
|
||||
TableUpdateV2* updateV2 = TableUpdate::Cast<TableUpdateV2>(update);
|
||||
NS_ENSURE_TRUE(updateV2, NS_ERROR_UC_UPDATE_UNEXPECTED_VERSION);
|
||||
|
||||
rv = store.ApplyUpdate(updateV2);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
applied++;
|
||||
|
||||
auto updateV2 = TableUpdate::Cast<TableUpdateV2>(update);
|
||||
if (updateV2) {
|
||||
LOG(("Applied update to table %s:", store.TableName().get()));
|
||||
LOG((" %d add chunks", updateV2->AddChunks().Length()));
|
||||
LOG((" %zu add prefixes", updateV2->AddPrefixes().Length()));
|
||||
LOG((" %zu add completions", updateV2->AddCompletes().Length()));
|
||||
LOG((" %d sub chunks", updateV2->SubChunks().Length()));
|
||||
LOG((" %zu sub prefixes", updateV2->SubPrefixes().Length()));
|
||||
LOG((" %zu sub completions", updateV2->SubCompletes().Length()));
|
||||
LOG((" %d add expirations", updateV2->AddExpirations().Length()));
|
||||
LOG((" %d sub expirations", updateV2->SubExpirations().Length()));
|
||||
}
|
||||
LOG(("Applied update to table %s:", store.TableName().get()));
|
||||
LOG((" %d add chunks", updateV2->AddChunks().Length()));
|
||||
LOG((" %zu add prefixes", updateV2->AddPrefixes().Length()));
|
||||
LOG((" %zu add completions", updateV2->AddCompletes().Length()));
|
||||
LOG((" %d sub chunks", updateV2->SubChunks().Length()));
|
||||
LOG((" %zu sub prefixes", updateV2->SubPrefixes().Length()));
|
||||
LOG((" %zu sub completions", updateV2->SubCompletes().Length()));
|
||||
LOG((" %d add expirations", updateV2->AddExpirations().Length()));
|
||||
LOG((" %d sub expirations", updateV2->SubExpirations().Length()));
|
||||
|
||||
aUpdates->ElementAt(i) = nullptr;
|
||||
}
|
||||
|
@ -1329,7 +1330,7 @@ Classifier::UpdateTableV4(nsTArray<TableUpdate*>* aUpdates,
|
|||
}
|
||||
|
||||
auto updateV4 = TableUpdate::Cast<TableUpdateV4>(update);
|
||||
NS_ENSURE_TRUE(updateV4, NS_ERROR_UC_UPDATE_TABLE_NOT_FOUND);
|
||||
NS_ENSURE_TRUE(updateV4, NS_ERROR_UC_UPDATE_UNEXPECTED_VERSION);
|
||||
|
||||
if (updateV4->IsFullUpdate()) {
|
||||
input->Clear();
|
||||
|
|
|
@ -619,36 +619,33 @@ Merge(ChunkSet* aStoreChunks,
|
|||
}
|
||||
|
||||
nsresult
|
||||
HashStore::ApplyUpdate(TableUpdate &aUpdate)
|
||||
HashStore::ApplyUpdate(TableUpdateV2 *aUpdate)
|
||||
{
|
||||
auto updateV2 = TableUpdate::Cast<TableUpdateV2>(&aUpdate);
|
||||
NS_ENSURE_TRUE(updateV2, NS_ERROR_FAILURE);
|
||||
MOZ_ASSERT(mTableName.Equals(aUpdate->TableName()));
|
||||
|
||||
TableUpdateV2& update = *updateV2;
|
||||
|
||||
nsresult rv = mAddExpirations.Merge(update.AddExpirations());
|
||||
nsresult rv = mAddExpirations.Merge(aUpdate->AddExpirations());
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = mSubExpirations.Merge(update.SubExpirations());
|
||||
rv = mSubExpirations.Merge(aUpdate->SubExpirations());
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = Expire();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = Merge(&mAddChunks, &mAddPrefixes,
|
||||
update.AddChunks(), update.AddPrefixes());
|
||||
aUpdate->AddChunks(), aUpdate->AddPrefixes());
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = Merge(&mAddChunks, &mAddCompletes,
|
||||
update.AddChunks(), update.AddCompletes(), true);
|
||||
aUpdate->AddChunks(), aUpdate->AddCompletes(), true);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = Merge(&mSubChunks, &mSubPrefixes,
|
||||
update.SubChunks(), update.SubPrefixes());
|
||||
aUpdate->SubChunks(), aUpdate->SubPrefixes());
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = Merge(&mSubChunks, &mSubCompletes,
|
||||
update.SubChunks(), update.SubCompletes(), true);
|
||||
aUpdate->SubChunks(), aUpdate->SubCompletes(), true);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return NS_OK;
|
||||
|
|
|
@ -220,7 +220,7 @@ public:
|
|||
nsresult BeginUpdate();
|
||||
|
||||
// Imports the data from a TableUpdate.
|
||||
nsresult ApplyUpdate(TableUpdate &aUpdate);
|
||||
nsresult ApplyUpdate(TableUpdateV2 *aUpdate);
|
||||
|
||||
// Process expired chunks
|
||||
nsresult Expire();
|
||||
|
|
|
@ -1085,6 +1085,7 @@ with modules["URL_CLASSIFIER"]:
|
|||
errors["NS_ERROR_UC_UPDATE_TABLE_NOT_FOUND"] = FAILURE(8)
|
||||
errors["NS_ERROR_UC_UPDATE_BUILD_PREFIX_FAILURE"] = FAILURE(9)
|
||||
errors["NS_ERROR_UC_UPDATE_FAIL_TO_WRITE_DISK"] = FAILURE(10)
|
||||
errors["NS_ERROR_UC_UPDATE_UNEXPECTED_VERSION"] = FAILURE(11)
|
||||
|
||||
# Specific errors while parsing pver2/pver4 responses
|
||||
errors["NS_ERROR_UC_PARSER_MISSING_PARAM"] = FAILURE(12)
|
||||
|
|
Загрузка…
Ссылка в новой задаче