Bug 1467581 - Remove the use of default captures in closures. r=gcp
Explicitly specify the arguments to copy to avoid making a copy of a dangling `this` pointer. Convert nsUrlClassifierDBService::mClassifier to a RefPtr since the update closure might need to continue to access its members after it's been released by the main thread. MozReview-Commit-ID: CPio3n9MmsK
This commit is contained in:
@@ -255,17 +255,17 @@ Classifier::Reset()
|
||||
LOG(("Reset() is called so we interrupt the update."));
|
||||
mUpdateInterrupted = true;
|
||||
|
||||
auto resetFunc = [=] {
|
||||
DropStores();
|
||||
RefPtr<Classifier> self = this;
|
||||
auto resetFunc = [self] {
|
||||
self->DropStores();
|
||||
|
||||
mRootStoreDirectory->Remove(true);
|
||||
mBackupDirectory->Remove(true);
|
||||
mUpdatingDirectory->Remove(true);
|
||||
mToDeleteDirectory->Remove(true);
|
||||
self->mRootStoreDirectory->Remove(true);
|
||||
self->mBackupDirectory->Remove(true);
|
||||
self->mUpdatingDirectory->Remove(true);
|
||||
self->mToDeleteDirectory->Remove(true);
|
||||
|
||||
CreateStoreDirectory();
|
||||
|
||||
RegenActiveTables();
|
||||
self->CreateStoreDirectory();
|
||||
self->RegenActiveTables();
|
||||
};
|
||||
|
||||
if (!mUpdateThread) {
|
||||
@@ -708,36 +708,38 @@ Classifier::AsyncApplyUpdates(const TableUpdateArray& aUpdates,
|
||||
nsCOMPtr<nsIThread> callerThread = NS_GetCurrentThread();
|
||||
MOZ_ASSERT(callerThread != mUpdateThread);
|
||||
|
||||
RefPtr<Classifier> self = this;
|
||||
nsCOMPtr<nsIRunnable> bgRunnable =
|
||||
NS_NewRunnableFunction("safebrowsing::Classifier::AsyncApplyUpdates", [=] {
|
||||
MOZ_ASSERT(NS_GetCurrentThread() == mUpdateThread,
|
||||
NS_NewRunnableFunction("safebrowsing::Classifier::AsyncApplyUpdates",
|
||||
[self, aUpdates, aCallback, callerThread] {
|
||||
MOZ_ASSERT(NS_GetCurrentThread() == self->mUpdateThread,
|
||||
"MUST be on update thread");
|
||||
|
||||
nsresult bgRv;
|
||||
nsCString failedTableName;
|
||||
|
||||
TableUpdateArray updates;
|
||||
|
||||
// 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)) {
|
||||
LOG(("Step 1. ApplyUpdatesBackground on update thread."));
|
||||
bgRv = ApplyUpdatesBackground(updates, failedTableName);
|
||||
bgRv = self->ApplyUpdatesBackground(updates, failedTableName);
|
||||
} else {
|
||||
LOG(("Step 1. Not enough memory to run ApplyUpdatesBackground on update thread."));
|
||||
bgRv = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIRunnable> fgRunnable = NS_NewRunnableFunction(
|
||||
"safebrowsing::Classifier::AsyncApplyUpdates", [=] {
|
||||
"safebrowsing::Classifier::AsyncApplyUpdates",
|
||||
[self, aCallback, bgRv, failedTableName, callerThread] {
|
||||
MOZ_ASSERT(NS_GetCurrentThread() == callerThread,
|
||||
"MUST be on caller thread");
|
||||
|
||||
LOG(("Step 2. ApplyUpdatesForeground on caller thread"));
|
||||
nsresult rv = ApplyUpdatesForeground(bgRv, failedTableName);
|
||||
;
|
||||
nsresult rv = self->ApplyUpdatesForeground(bgRv, failedTableName);
|
||||
|
||||
LOG(("Step 3. Updates applied! Fire callback."));
|
||||
|
||||
aCallback(rv);
|
||||
});
|
||||
callerThread->Dispatch(fgRunnable, NS_DISPATCH_NORMAL);
|
||||
|
||||
Reference in New Issue
Block a user