From a07b1845e7c69a3d6a8838779a622cfd67b77b69 Mon Sep 17 00:00:00 2001 From: Jan Varga Date: Fri, 21 Aug 2020 05:16:40 +0000 Subject: [PATCH] Bug 1659683 - QM: Record first initialization attempt directly in UpgradeFromIndexedDBDirectoryToPersistentStorageDirectory; r=dom-workers-and-storage-reviewers,ttung Differential Revision: https://phabricator.services.mozilla.com/D87424 --- dom/quota/ActorsParent.cpp | 96 +++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/dom/quota/ActorsParent.cpp b/dom/quota/ActorsParent.cpp index 85db068a8153..4599249e5aa2 100644 --- a/dom/quota/ActorsParent.cpp +++ b/dom/quota/ActorsParent.cpp @@ -5386,51 +5386,58 @@ QuotaManager::UpgradeFromIndexedDBDirectoryToPersistentStorageDirectory( AssertIsOnIOThread(); MOZ_ASSERT(aIndexedDBDir); - bool isDirectory; - QM_TRY(aIndexedDBDir->IsDirectory(&isDirectory)); + auto rv = [this, &aIndexedDBDir]() -> nsresult { + bool isDirectory; + QM_TRY(aIndexedDBDir->IsDirectory(&isDirectory)); - if (!isDirectory) { - NS_WARNING("indexedDB entry is not a directory!"); - return NS_OK; - } - - auto persistentStorageDirOrErr = QM_NewLocalFile(mStoragePath); - if (NS_WARN_IF(persistentStorageDirOrErr.isErr())) { - return persistentStorageDirOrErr.unwrapErr(); - } - - nsCOMPtr persistentStorageDir = persistentStorageDirOrErr.unwrap(); - - QM_TRY( - persistentStorageDir->Append(nsLiteralString(PERSISTENT_DIRECTORY_NAME))); - - bool exists; - QM_TRY(persistentStorageDir->Exists(&exists)); - - if (exists) { - QM_WARNING("Deleting old /indexedDB directory!"); - - nsresult rv = aIndexedDBDir->Remove(/* aRecursive */ true); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; + if (!isDirectory) { + NS_WARNING("indexedDB entry is not a directory!"); + return NS_OK; } + auto persistentStorageDirOrErr = QM_NewLocalFile(mStoragePath); + if (NS_WARN_IF(persistentStorageDirOrErr.isErr())) { + return persistentStorageDirOrErr.unwrapErr(); + } + + nsCOMPtr persistentStorageDir = persistentStorageDirOrErr.unwrap(); + + QM_TRY(persistentStorageDir->Append( + nsLiteralString(PERSISTENT_DIRECTORY_NAME))); + + bool exists; + QM_TRY(persistentStorageDir->Exists(&exists)); + + if (exists) { + QM_WARNING("Deleting old /indexedDB directory!"); + + nsresult rv = aIndexedDBDir->Remove(/* aRecursive */ true); + if (NS_WARN_IF(NS_FAILED(rv))) { + return rv; + } + + return NS_OK; + } + + nsCOMPtr storageDir; + QM_TRY(persistentStorageDir->GetParent(getter_AddRefs(storageDir))); + + // MoveTo() is atomic if the move happens on the same volume which should + // be our case, so even if we crash in the middle of the operation nothing + // breaks next time we try to initialize. + // However there's a theoretical possibility that the indexedDB directory + // is on different volume, but it should be rare enough that we don't have + // to worry about it. + QM_TRY(aIndexedDBDir->MoveTo(storageDir, + nsLiteralString(PERSISTENT_DIRECTORY_NAME))); + return NS_OK; - } + }(); - nsCOMPtr storageDir; - QM_TRY(persistentStorageDir->GetParent(getter_AddRefs(storageDir))); + mInitializationInfo.RecordFirstInitializationAttempt( + Initialization::UpgradeFromIndexedDBDirectory, rv); - // MoveTo() is atomic if the move happens on the same volume which should - // be our case, so even if we crash in the middle of the operation nothing - // breaks next time we try to initialize. - // However there's a theoretical possibility that the indexedDB directory - // is on different volume, but it should be rare enough that we don't have - // to worry about it. - QM_TRY(aIndexedDBDir->MoveTo(storageDir, - nsLiteralString(PERSISTENT_DIRECTORY_NAME))); - - return NS_OK; + return rv; } nsresult @@ -6377,15 +6384,8 @@ nsresult QuotaManager::EnsureStorageIsInitialized() { ToResultInvoke(indexedDBDir, &nsIFile::Exists)); if (indexedDBDirExists) { - // TODO: Convert to QM_TRY once upgrade functions record first - // initialization attempts directly. - nsresult rv = UpgradeFromIndexedDBDirectoryToPersistentStorageDirectory( - indexedDBDir); - mInitializationInfo.RecordFirstInitializationAttempt( - Initialization::UpgradeFromIndexedDBDirectory, rv); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } + QM_TRY(UpgradeFromIndexedDBDirectoryToPersistentStorageDirectory( + indexedDBDir)); } QM_TRY_VAR(auto persistentStorageDir, QM_NewLocalFile(mStoragePath));