From 4286c739276bdefecb2d0c2a219d620643c0a668 Mon Sep 17 00:00:00 2001 From: Jan Varga Date: Tue, 2 Apr 2019 05:44:56 +0200 Subject: [PATCH] Bug 1540381 - LSNG: Result of SendRequestAllowToClose call is not checked; r=asuth Differential Revision: https://phabricator.services.mozilla.com/D25703 --- dom/localstorage/ActorsParent.cpp | 60 ++++++++++++++++++------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/dom/localstorage/ActorsParent.cpp b/dom/localstorage/ActorsParent.cpp index aa2f74d1e86f..48e96e334afb 100644 --- a/dom/localstorage/ActorsParent.cpp +++ b/dom/localstorage/ActorsParent.cpp @@ -2958,6 +2958,29 @@ void ClientValidationPrefChangedCallback(const char* aPrefName, gClientValidation = Preferences::GetBool(aPrefName, kDefaultClientValidation); } +template +void RequestAllowToCloseIf(P aPredicate) { + AssertIsOnBackgroundThread(); + + if (!gLiveDatabases) { + return; + } + + nsTArray> databases; + + for (Database* database : *gLiveDatabases) { + if (aPredicate(database)) { + databases.AppendElement(database); + } + } + + for (Database* database : databases) { + database->RequestAllowToClose(); + } + + databases.Clear(); +} + } // namespace /******************************************************************************* @@ -5127,8 +5150,9 @@ void Database::RequestAllowToClose() { // child actor. Except the case when the actor was already destroyed. if (mActorDestroyed) { MOZ_ASSERT(mAllowedToClose); - } else { - Unused << SendRequestAllowToClose(); + } else if (NS_WARN_IF(!SendRequestAllowToClose())) { + // Allow to close immediately if sending failed. + AllowToClose(); } } @@ -7997,29 +8021,21 @@ void QuotaClient::AbortOperations(const nsACString& aOrigin) { } } - if (gLiveDatabases) { - for (Database* database : *gLiveDatabases) { - if (aOrigin.IsVoid() || database->Origin() == aOrigin) { - // TODO: This just allows the database to close, but we can actually - // set a flag to abort any existing operations, so we can - // eventually close faster. - - database->RequestAllowToClose(); - } - } + if (aOrigin.IsVoid()) { + RequestAllowToCloseIf([](const Database* const) { return true; }); + } else { + RequestAllowToCloseIf([&aOrigin](const Database* const aDatabase) { + return aDatabase->Origin() == aOrigin; + }); } } void QuotaClient::AbortOperationsForProcess(ContentParentId aContentParentId) { AssertIsOnBackgroundThread(); - if (gLiveDatabases) { - for (Database* database : *gLiveDatabases) { - if (database->IsOwnedByProcess(aContentParentId)) { - database->RequestAllowToClose(); - } - } - } + RequestAllowToCloseIf([aContentParentId](const Database* const aDatabase) { + return aDatabase->IsOwnedByProcess(aContentParentId); + }); } void QuotaClient::StartIdleMaintenance() { AssertIsOnBackgroundThread(); } @@ -8045,11 +8061,7 @@ void QuotaClient::ShutdownWorkThreads() { gPreparedDatastores = nullptr; } - if (gLiveDatabases) { - for (Database* database : *gLiveDatabases) { - database->RequestAllowToClose(); - } - } + RequestAllowToCloseIf([](const Database* const) { return true; }); if (gPreparedObsevers) { gPreparedObsevers->Clear();