Bug 1626570 - Improve handling of copying arrays in toolkit/components/url-classifier/. r=gcp

Differential Revision: https://phabricator.services.mozilla.com/D72328
This commit is contained in:
Simon Giesecke 2020-04-30 09:40:24 +00:00
Родитель e3a88d2d40
Коммит 4bef2b41e0
6 изменённых файлов: 13 добавлений и 10 удалений

Просмотреть файл

@ -747,7 +747,7 @@ nsresult Classifier::AsyncApplyUpdates(const TableUpdateArray& aUpdates,
RefPtr<Classifier> self = this;
nsCOMPtr<nsIRunnable> bgRunnable = NS_NewRunnableFunction(
"safebrowsing::Classifier::AsyncApplyUpdates",
[self, aUpdates, aCallback, callerThread]() mutable {
[self, aUpdates = aUpdates.Clone(), aCallback, callerThread]() mutable {
MOZ_ASSERT(self->OnUpdateThread(), "MUST be on update thread");
nsresult bgRv;
@ -757,7 +757,7 @@ nsresult Classifier::AsyncApplyUpdates(const TableUpdateArray& aUpdates,
// Make a copy of the array since we'll be removing entries as
// we process them on the background thread.
if (updates.AppendElements(aUpdates, fallible)) {
if (updates.AppendElements(std::move(aUpdates), fallible)) {
LOG(("Step 1. ApplyUpdatesBackground on update thread."));
bgRv = self->ApplyUpdatesBackground(updates, failedTableNames);
} else {
@ -774,7 +774,8 @@ nsresult Classifier::AsyncApplyUpdates(const TableUpdateArray& aUpdates,
// it in the udpate thread.
nsCOMPtr<nsIRunnable> fgRunnable = NS_NewRunnableFunction(
"safebrowsing::Classifier::AsyncApplyUpdates",
[self = std::move(self), aCallback, bgRv, failedTableNames,
[self = std::move(self), aCallback, bgRv,
failedTableNames = std::move(failedTableNames),
callerThread]() mutable {
RefPtr<Classifier> classifier = std::move(self);
@ -1044,7 +1045,7 @@ nsresult Classifier::ScanStoreDir(nsIFile* aDirectory,
}
nsresult Classifier::ActiveTables(nsTArray<nsCString>& aTables) const {
aTables = mActiveTablesCache;
aTables = mActiveTablesCache.Clone();
return NS_OK;
}

Просмотреть файл

@ -176,7 +176,7 @@ nsresult ProtocolParserV2::ProcessControl(bool* aDone) {
}
} else if (line.EqualsLiteral("r:pleasereset")) {
PARSER_LOG(("All tables will be reset."));
mTablesToReset = mRequestedTables;
mTablesToReset = mRequestedTables.Clone();
} else if (StringBeginsWith(line, NS_LITERAL_CSTRING("u:"))) {
rv = ProcessForward(line);
NS_ENSURE_SUCCESS(rv, rv);

Просмотреть файл

@ -34,7 +34,7 @@ class ProtocolParser {
virtual void SetCurrentTable(const nsACString& aTable) = 0;
void SetRequestedTables(const nsTArray<nsCString>& aRequestTables) {
mRequestedTables = aRequestTables;
mRequestedTables = aRequestTables.Clone();
}
nsresult Begin(const nsACString& aTable,

Просмотреть файл

@ -1023,7 +1023,7 @@ nsresult nsUrlClassifierDBServiceWorker::CacheCompletions(
rv = mClassifier->ApplyFullHashes(updates);
if (NS_SUCCEEDED(rv)) {
mLastResults = aResults;
mLastResults = aResults.Clone();
}
return rv;
}
@ -2558,7 +2558,9 @@ bool nsUrlClassifierDBService::AsyncClassifyLocalWithFeaturesUsingPreferences(
nsCOMPtr<nsIUrlClassifierFeatureCallback> callback(aCallback);
nsCOMPtr<nsIRunnable> cbRunnable = NS_NewRunnableFunction(
"nsUrlClassifierDBService::AsyncClassifyLocalWithFeatures",
[callback, results]() { callback->OnClassifyComplete(results); });
[callback, results = std::move(results)]() {
callback->OnClassifyComplete(results);
});
NS_DispatchToMainThread(cbRunnable);
return true;

Просмотреть файл

@ -123,7 +123,7 @@ class UrlClassifierDBServiceWorkerProxy final
: mozilla::Runnable(
"UrlClassifierDBServiceWorkerProxy::CacheCompletionsRunnable"),
mTarget(aTarget),
mEntries(aEntries) {}
mEntries(aEntries.Clone()) {}
NS_DECL_NSIRUNNABLE

Просмотреть файл

@ -153,7 +153,7 @@ class UrlClassifierPrefixSetTest : public ::testing::TestWithParam<uint32_t> {
}
void SetupPrefixesAndVerify(_PrefixArray& aArray) {
mArray = aArray;
mArray = aArray.Clone();
PrefixArrayToPrefixStringMap(mArray, mMap);
ASSERT_TRUE(NS_SUCCEEDED(mCache->Build(mMap)));