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
This commit is contained in:
Jan Varga 2020-08-21 05:16:40 +00:00
Родитель fceae5b85b
Коммит a07b1845e7
1 изменённых файлов: 48 добавлений и 48 удалений

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

@ -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<nsIFile> persistentStorageDir = persistentStorageDirOrErr.unwrap();
QM_TRY(
persistentStorageDir->Append(nsLiteralString(PERSISTENT_DIRECTORY_NAME)));
bool exists;
QM_TRY(persistentStorageDir->Exists(&exists));
if (exists) {
QM_WARNING("Deleting old <profile>/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<nsIFile> persistentStorageDir = persistentStorageDirOrErr.unwrap();
QM_TRY(persistentStorageDir->Append(
nsLiteralString(PERSISTENT_DIRECTORY_NAME)));
bool exists;
QM_TRY(persistentStorageDir->Exists(&exists));
if (exists) {
QM_WARNING("Deleting old <profile>/indexedDB directory!");
nsresult rv = aIndexedDBDir->Remove(/* aRecursive */ true);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
nsCOMPtr<nsIFile> 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<nsIFile> 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));