Bug 1728267 - Remove implicit ToResult from QM_TRY when no extra argument is passed in dom/cache; r=dom-storage-reviewers,jstutte,jari

Differential Revision: https://phabricator.services.mozilla.com/D125319
This commit is contained in:
Jan Varga 2021-09-24 13:08:30 +00:00
parent 590fd74ae2
commit 685aa0cc5e
8 changed files with 505 additions and 450 deletions

View File

@ -411,9 +411,10 @@ Context::QuotaInitRunnable::Run() {
QuotaManager* quotaManager = QuotaManager::Get();
MOZ_DIAGNOSTIC_ASSERT(quotaManager);
QM_TRY(quotaManager->EnsureStorageIsInitialized());
QM_TRY(MOZ_TO_RESULT(quotaManager->EnsureStorageIsInitialized()));
QM_TRY(quotaManager->EnsureTemporaryStorageIsInitialized());
QM_TRY(
MOZ_TO_RESULT(quotaManager->EnsureTemporaryStorageIsInitialized()));
QM_TRY_UNWRAP(mQuotaInfo.mDir,
quotaManager

View File

@ -36,15 +36,15 @@ nsresult WipeDatabase(const QuotaInfo& aQuotaInfo, nsIFile& aDBFile) {
QM_TRY_INSPECT(const auto& dbDir, MOZ_TO_RESULT_INVOKE_TYPED(
nsCOMPtr<nsIFile>, aDBFile, GetParent));
QM_TRY(RemoveNsIFile(aQuotaInfo, aDBFile));
QM_TRY(MOZ_TO_RESULT(RemoveNsIFile(aQuotaInfo, aDBFile)));
// Note, the -wal journal file will be automatically deleted by sqlite when
// the new database is created. No need to explicitly delete it here.
// Delete the morgue as well.
QM_TRY(BodyDeleteDir(aQuotaInfo, *dbDir));
QM_TRY(MOZ_TO_RESULT(BodyDeleteDir(aQuotaInfo, *dbDir)));
QM_TRY(WipePaddingFile(aQuotaInfo, dbDir));
QM_TRY(MOZ_TO_RESULT(WipePaddingFile(aQuotaInfo, dbDir)));
return NS_OK;
}
@ -111,7 +111,7 @@ Result<nsCOMPtr<mozIStorageConnection>, nsresult> DBAction::OpenConnection(
if (!exists) {
QM_TRY(OkIf(mMode == Create), Err(NS_ERROR_FILE_NOT_FOUND));
QM_TRY(aDBDir.Create(nsIFile::DIRECTORY_TYPE, 0755));
QM_TRY(MOZ_TO_RESULT(aDBDir.Create(nsIFile::DIRECTORY_TYPE, 0755)));
}
QM_TRY_INSPECT(const auto& dbFile,
@ -147,7 +147,7 @@ Result<nsCOMPtr<mozIStorageConnection>, nsresult> OpenDBConnection(
// handler. If such a custom handler used javascript, then we would have a
// bad time running off the main thread here.
auto handler = MakeRefPtr<nsFileProtocolHandler>();
QM_TRY(handler->Init());
QM_TRY(MOZ_TO_RESULT(handler->Init()));
QM_TRY_INSPECT(const auto& mutator,
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<nsIURIMutator>, handler,
@ -159,9 +159,9 @@ Result<nsCOMPtr<mozIStorageConnection>, nsresult> OpenDBConnection(
: EmptyCString();
nsCOMPtr<nsIFileURL> dbFileUrl;
QM_TRY(NS_MutateURI(mutator)
.SetQuery("cache=private"_ns + directoryLockIdClause)
.Finalize(dbFileUrl));
QM_TRY(MOZ_TO_RESULT(NS_MutateURI(mutator)
.SetQuery("cache=private"_ns + directoryLockIdClause)
.Finalize(dbFileUrl)));
QM_TRY_INSPECT(
const auto& storageService,
@ -186,7 +186,7 @@ Result<nsCOMPtr<mozIStorageConnection>, nsresult> OpenDBConnection(
// There is nothing else we can do to recover. Also, this data
// can be deleted by QuotaManager at any time anyways.
QM_TRY(WipeDatabase(aQuotaInfo, aDBFile));
QM_TRY(MOZ_TO_RESULT(WipeDatabase(aQuotaInfo, aDBFile)));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_TYPED(
nsCOMPtr<mozIStorageConnection>, storageService,
@ -200,14 +200,14 @@ Result<nsCOMPtr<mozIStorageConnection>, nsresult> OpenDBConnection(
// Close existing connection before wiping database.
conn = nullptr;
QM_TRY(WipeDatabase(aQuotaInfo, aDBFile));
QM_TRY(MOZ_TO_RESULT(WipeDatabase(aQuotaInfo, aDBFile)));
QM_TRY_UNWRAP(conn, MOZ_TO_RESULT_INVOKE_TYPED(
nsCOMPtr<mozIStorageConnection>, storageService,
OpenDatabaseWithFileURL, dbFileUrl, ""_ns));
}
QM_TRY(db::InitializeConnection(*conn));
QM_TRY(MOZ_TO_RESULT(db::InitializeConnection(*conn)));
return conn;
}

758
dom/cache/DBSchema.cpp vendored

File diff suppressed because it is too large Load Diff

View File

@ -78,7 +78,7 @@ Result<NotNull<nsCOMPtr<nsIFile>>, nsresult> BodyGetCacheDir(nsIFile& aBaseDir,
// in a single directory. Mitigate this issue by spreading the body
// files out into sub-directories. We use the last byte of the ID for
// the name of the sub-directory.
QM_TRY(cacheDir->Append(IntToString(aId.m3[7])));
QM_TRY(MOZ_TO_RESULT(cacheDir->Append(IntToString(aId.m3[7]))));
// Callers call this function without checking if the directory already
// exists (idempotent usage). QM_OR_ELSE_WARN_IF is not used here since we
@ -120,7 +120,7 @@ nsresult BodyDeleteDir(const QuotaInfo& aQuotaInfo, nsIFile& aBaseDir) {
QM_TRY_INSPECT(const auto& bodyDir,
CloneFileAndAppend(aBaseDir, kMorgueDirectory));
QM_TRY(RemoveNsIFileRecursively(aQuotaInfo, *bodyDir));
QM_TRY(MOZ_TO_RESULT(RemoveNsIFileRecursively(aQuotaInfo, *bodyDir)));
return NS_OK;
}
@ -136,7 +136,7 @@ Result<std::pair<nsID, nsCOMPtr<nsISupports>>, nsresult> BodyStartWriteStream(
"@mozilla.org/uuid-generator;1"));
nsID id;
QM_TRY(idGen->GenerateUUIDInPlace(&id));
QM_TRY(MOZ_TO_RESULT(idGen->GenerateUUIDInPlace(&id)));
QM_TRY_INSPECT(const auto& finalFile,
BodyIdToFile(aBaseDir, id, BODY_FILE_FINAL));
@ -162,11 +162,11 @@ Result<std::pair<nsID, nsCOMPtr<nsISupports>>, nsresult> BodyStartWriteStream(
do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
nsCOMPtr<nsISupports> copyContext;
QM_TRY(NS_AsyncCopy(&aSource, compressed, target,
NS_ASYNCCOPY_VIA_WRITESEGMENTS, compressed->BlockSize(),
aCallback, aClosure, true,
true, // close streams
getter_AddRefs(copyContext)));
QM_TRY(MOZ_TO_RESULT(
NS_AsyncCopy(&aSource, compressed, target, NS_ASYNCCOPY_VIA_WRITESEGMENTS,
compressed->BlockSize(), aCallback, aClosure, true,
true, // close streams
getter_AddRefs(copyContext))));
return std::make_pair(id, std::move(copyContext));
}
@ -187,12 +187,12 @@ nsresult BodyFinalizeWrite(nsIFile& aBaseDir, const nsID& aId) {
BodyIdToFile(aBaseDir, aId, BODY_FILE_FINAL));
nsAutoString finalFileName;
QM_TRY(finalFile->GetLeafName(finalFileName));
QM_TRY(MOZ_TO_RESULT(finalFile->GetLeafName(finalFileName)));
// It's fine to not notify the QuotaManager that the path has been changed,
// because its path will be updated and its size will be recalculated when
// opening file next time.
QM_TRY(tmpFile->RenameTo(nullptr, finalFileName));
QM_TRY(MOZ_TO_RESULT(tmpFile->RenameTo(nullptr, finalFileName)));
return NS_OK;
}
@ -271,9 +271,10 @@ nsresult BodyDeleteFiles(const QuotaInfo& aQuotaInfo, nsIFile& aBaseDir,
return false;
};
QM_TRY(BodyTraverseFiles(aQuotaInfo, *bodyDir, removeFileForId,
/* aCanRemoveFiles */ false,
/* aTrackQuota */ true));
QM_TRY(
MOZ_TO_RESULT(BodyTraverseFiles(aQuotaInfo, *bodyDir, removeFileForId,
/* aCanRemoveFiles */ false,
/* aTrackQuota */ true)));
}
return NS_OK;
@ -296,7 +297,7 @@ Result<NotNull<nsCOMPtr<nsIFile>>, nsresult> BodyIdToFile(
fileName.AppendLiteral(".tmp");
}
QM_TRY(bodyFile->Append(fileName));
QM_TRY(MOZ_TO_RESULT(bodyFile->Append(fileName)));
return bodyFile;
}
@ -335,7 +336,7 @@ nsresult DirectoryPaddingWrite(nsIFile& aBaseDir,
nsCOMPtr<nsIObjectOutputStream> objectStream =
NS_NewObjectOutputStream(outputStream);
QM_TRY(objectStream->Write64(aPaddingSize));
QM_TRY(MOZ_TO_RESULT(objectStream->Write64(aPaddingSize)));
return NS_OK;
}
@ -427,7 +428,7 @@ Result<nsCOMPtr<nsIFile>, nsresult> GetMarkerFileHandle(
const QuotaInfo& aQuotaInfo) {
QM_TRY_UNWRAP(auto marker, CloneFileAndAppend(*aQuotaInfo.mDir, u"cache"_ns));
QM_TRY(marker->Append(u"context_open.marker"_ns));
QM_TRY(MOZ_TO_RESULT(marker->Append(u"context_open.marker"_ns)));
return marker;
}
@ -502,13 +503,14 @@ nsresult RemoveNsIFileRecursively(const QuotaInfo& aQuotaInfo, nsIFile& aFile,
aFile,
[&aQuotaInfo, &aTrackQuota](
const nsCOMPtr<nsIFile>& file) -> Result<Ok, nsresult> {
QM_TRY(RemoveNsIFileRecursively(aQuotaInfo, *file, aTrackQuota));
QM_TRY(MOZ_TO_RESULT(
RemoveNsIFileRecursively(aQuotaInfo, *file, aTrackQuota)));
return Ok{};
}));
// In the end, remove the folder
QM_TRY(aFile.Remove(/* recursive */ false));
QM_TRY(MOZ_TO_RESULT(aFile.Remove(/* recursive */ false)));
break;
@ -606,7 +608,8 @@ Result<int64_t, nsresult> DirectoryPaddingGet(nsIFile& aBaseDir) {
}
nsresult DirectoryPaddingInit(nsIFile& aBaseDir) {
QM_TRY(DirectoryPaddingWrite(aBaseDir, DirPaddingFile::FILE, 0));
QM_TRY(
MOZ_TO_RESULT(DirectoryPaddingWrite(aBaseDir, DirPaddingFile::FILE, 0)));
return NS_OK;
}
@ -641,7 +644,8 @@ nsresult UpdateDirectoryPaddingFile(nsIFile& aBaseDir,
// Not delete the temporary padding file here, because we're going
// to overwrite it below anyway.
QM_TRY(DirectoryPaddingDeleteFile(aBaseDir, DirPaddingFile::FILE));
QM_TRY(MOZ_TO_RESULT(
DirectoryPaddingDeleteFile(aBaseDir, DirPaddingFile::FILE)));
// We don't need to add the aIncreaseSize or aDecreaseSize here,
// because it's already encompassed within the database.
@ -672,7 +676,8 @@ nsresult UpdateDirectoryPaddingFile(nsIFile& aBaseDir,
// incorrect.
// Delete padding file to indicate the padding size is incorrect for
// avoiding error happening in the following lines.
QM_TRY(DirectoryPaddingDeleteFile(aBaseDir, DirPaddingFile::FILE));
QM_TRY(MOZ_TO_RESULT(
DirectoryPaddingDeleteFile(aBaseDir, DirPaddingFile::FILE)));
QM_TRY_UNWRAP(currentPaddingSize, db::FindOverallPaddingSize(aConn));
@ -696,8 +701,8 @@ nsresult UpdateDirectoryPaddingFile(nsIFile& aBaseDir,
MOZ_DIAGNOSTIC_ASSERT(currentPaddingSize >= 0);
QM_TRY(DirectoryPaddingWrite(aBaseDir, DirPaddingFile::TMP_FILE,
currentPaddingSize));
QM_TRY(MOZ_TO_RESULT(DirectoryPaddingWrite(aBaseDir, DirPaddingFile::TMP_FILE,
currentPaddingSize)));
return NS_OK;
}
@ -710,7 +715,8 @@ nsresult DirectoryPaddingFinalizeWrite(nsIFile& aBaseDir) {
const auto& file,
CloneFileAndAppend(aBaseDir, nsLiteralString(PADDING_TMP_FILE_NAME)));
QM_TRY(file->RenameTo(nullptr, nsLiteralString(PADDING_FILE_NAME)));
QM_TRY(MOZ_TO_RESULT(
file->RenameTo(nullptr, nsLiteralString(PADDING_FILE_NAME))));
return NS_OK;
}
@ -719,7 +725,8 @@ Result<int64_t, nsresult> DirectoryPaddingRestore(nsIFile& aBaseDir,
mozIStorageConnection& aConn,
const bool aMustRestore) {
// The content of padding file is untrusted, so remove it here.
QM_TRY(DirectoryPaddingDeleteFile(aBaseDir, DirPaddingFile::FILE));
QM_TRY(MOZ_TO_RESULT(
DirectoryPaddingDeleteFile(aBaseDir, DirPaddingFile::FILE)));
QM_TRY_INSPECT(const int64_t& paddingSize, db::FindOverallPaddingSize(aConn));
MOZ_DIAGNOSTIC_ASSERT(paddingSize >= 0);
@ -729,7 +736,8 @@ Result<int64_t, nsresult> DirectoryPaddingRestore(nsIFile& aBaseDir,
(aMustRestore ? Err(tryTempError)
: Result<int64_t, nsresult>{paddingSize}));
QM_TRY(DirectoryPaddingDeleteFile(aBaseDir, DirPaddingFile::TMP_FILE));
QM_TRY(MOZ_TO_RESULT(
DirectoryPaddingDeleteFile(aBaseDir, DirPaddingFile::TMP_FILE)));
return paddingSize;
}

View File

@ -51,7 +51,7 @@ nsresult BodyTraverseFiles(const QuotaInfo& aQuotaInfo, nsIFile& aBodyDir,
case quota::nsIFileKind::ExistsAsFile: {
nsAutoCString leafName;
QM_TRY(file->GetNativeLeafName(leafName));
QM_TRY(MOZ_TO_RESULT(file->GetNativeLeafName(leafName)));
// Delete all tmp files regardless of known bodies. These are all
// considered orphans.

65
dom/cache/Manager.cpp vendored
View File

@ -61,8 +61,8 @@ nsresult MaybeUpdatePaddingFile(nsIFile* aBaseDir, mozIStorageConnection* aConn,
RefPtr<CacheQuotaClient> cacheQuotaClient = CacheQuotaClient::Get();
MOZ_DIAGNOSTIC_ASSERT(cacheQuotaClient);
QM_TRY(cacheQuotaClient->MaybeUpdatePaddingFileInternal(
*aBaseDir, *aConn, aIncreaseSize, aDecreaseSize, aCommitHook));
QM_TRY(MOZ_TO_RESULT(cacheQuotaClient->MaybeUpdatePaddingFileInternal(
*aBaseDir, *aConn, aIncreaseSize, aDecreaseSize, aCommitHook)));
return NS_OK;
}
@ -79,10 +79,10 @@ class SetupAction final : public SyncDBAction {
mozIStorageConnection* aConn) override {
MOZ_DIAGNOSTIC_ASSERT(aDBDir);
QM_TRY(BodyCreateDir(*aDBDir));
QM_TRY(MOZ_TO_RESULT(BodyCreateDir(*aDBDir)));
// executes in its own transaction
QM_TRY(db::CreateOrMigrateSchema(*aConn));
QM_TRY(MOZ_TO_RESULT(db::CreateOrMigrateSchema(*aConn)));
// If the Context marker file exists, then the last session was
// not cleanly shutdown. In these cases sqlite will ensure that
@ -99,7 +99,7 @@ class SetupAction final : public SyncDBAction {
mozStorageTransaction trans(aConn, false,
mozIStorageConnection::TRANSACTION_IMMEDIATE);
QM_TRY(trans.Start());
QM_TRY(MOZ_TO_RESULT(trans.Start()));
// Clean up orphaned Cache objects
QM_TRY_INSPECT(const auto& orphanedCacheIdList,
@ -115,8 +115,8 @@ class SetupAction final : public SyncDBAction {
QM_TRY_INSPECT(const auto& deletionInfo,
db::DeleteCacheId(*aConn, *element));
QM_TRY(BodyDeleteFiles(aQuotaInfo, *aDBDir,
deletionInfo.mDeletedBodyIdList));
QM_TRY(MOZ_TO_RESULT(BodyDeleteFiles(
aQuotaInfo, *aDBDir, deletionInfo.mDeletedBodyIdList)));
if (deletionInfo.mDeletedPaddingSize > 0) {
DecreaseUsageForQuotaInfo(aQuotaInfo,
@ -129,7 +129,8 @@ class SetupAction final : public SyncDBAction {
// Clean up orphaned body objects
QM_TRY_INSPECT(const auto& knownBodyIdList, db::GetKnownBodyIds(*aConn));
QM_TRY(BodyDeleteOrphanedFiles(aQuotaInfo, *aDBDir, knownBodyIdList));
QM_TRY(MOZ_TO_RESULT(
BodyDeleteOrphanedFiles(aQuotaInfo, *aDBDir, knownBodyIdList)));
// Commit() explicitly here, because we want to ensure the padding file
// has the correct content.
@ -148,7 +149,7 @@ class SetupAction final : public SyncDBAction {
if (DirectoryPaddingFileExists(*aDBDir, DirPaddingFile::TMP_FILE) ||
!DirectoryPaddingFileExists(*aDBDir, DirPaddingFile::FILE)) {
QM_TRY(RestorePaddingFile(aDBDir, aConn));
QM_TRY(MOZ_TO_RESULT(RestorePaddingFile(aDBDir, aConn)));
}
return NS_OK;
@ -246,7 +247,7 @@ class Manager::Factory {
// Ensure there is a factory instance. This forces the Acquire() call
// below to use the same factory.
QM_TRY(MaybeCreateInstance());
QM_TRY(MOZ_TO_RESULT(MaybeCreateInstance()));
SafeRefPtr<Manager> ref = Acquire(*aManagerId);
if (!ref) {
@ -530,13 +531,13 @@ class Manager::DeleteOrphanedCacheAction final : public SyncDBAction {
mozStorageTransaction trans(aConn, false,
mozIStorageConnection::TRANSACTION_IMMEDIATE);
QM_TRY(trans.Start());
QM_TRY(MOZ_TO_RESULT(trans.Start()));
QM_TRY_UNWRAP(mDeletionInfo, db::DeleteCacheId(*aConn, mCacheId));
QM_TRY(MaybeUpdatePaddingFile(
QM_TRY(MOZ_TO_RESULT(MaybeUpdatePaddingFile(
aDBDir, aConn, /* aIncreaceSize */ 0, mDeletionInfo.mDeletedPaddingSize,
[&trans]() mutable { return trans.Commit(); }));
[&trans]() mutable { return trans.Commit(); })));
return NS_OK;
}
@ -759,11 +760,13 @@ class Manager::CachePutAllAction final : public DBAction {
const nsresult rv = [this, &aQuotaInfo]() -> nsresult {
QM_TRY(CollectEachInRange(
mList, [this, &aQuotaInfo](auto& entry) -> nsresult {
QM_TRY(StartStreamCopy(aQuotaInfo, entry, RequestStream,
&mExpectedAsyncCopyCompletions));
QM_TRY(
MOZ_TO_RESULT(StartStreamCopy(aQuotaInfo, entry, RequestStream,
&mExpectedAsyncCopyCompletions)));
QM_TRY(StartStreamCopy(aQuotaInfo, entry, ResponseStream,
&mExpectedAsyncCopyCompletions));
QM_TRY(
MOZ_TO_RESULT(StartStreamCopy(aQuotaInfo, entry, ResponseStream,
&mExpectedAsyncCopyCompletions)));
return NS_OK;
}));
@ -843,22 +846,22 @@ class Manager::CachePutAllAction final : public DBAction {
const nsresult rv = [this, &trans]() -> nsresult {
QM_TRY(CollectEachInRange(mList, [this](Entry& e) -> nsresult {
if (e.mRequestStream) {
QM_TRY(BodyFinalizeWrite(*mDBDir, e.mRequestBodyId));
QM_TRY(MOZ_TO_RESULT(BodyFinalizeWrite(*mDBDir, e.mRequestBodyId)));
}
if (e.mResponseStream) {
// Gerenate padding size for opaque response if needed.
if (e.mResponse.type() == ResponseType::Opaque) {
// It'll generate padding if we've not set it yet.
QM_TRY(BodyMaybeUpdatePaddingSize(
QM_TRY(MOZ_TO_RESULT(BodyMaybeUpdatePaddingSize(
mQuotaInfo.ref(), *mDBDir, e.mResponseBodyId,
e.mResponse.paddingInfo(), &e.mResponse.paddingSize()));
e.mResponse.paddingInfo(), &e.mResponse.paddingSize())));
MOZ_DIAGNOSTIC_ASSERT(INT64_MAX - e.mResponse.paddingSize() >=
mUpdatedPaddingSize);
mUpdatedPaddingSize += e.mResponse.paddingSize();
}
QM_TRY(BodyFinalizeWrite(*mDBDir, e.mResponseBodyId));
QM_TRY(MOZ_TO_RESULT(BodyFinalizeWrite(*mDBDir, e.mResponseBodyId)));
}
QM_TRY_UNWRAP(
@ -879,9 +882,9 @@ class Manager::CachePutAllAction final : public DBAction {
}));
// Update padding file when it's necessary
QM_TRY(MaybeUpdatePaddingFile(
QM_TRY(MOZ_TO_RESULT(MaybeUpdatePaddingFile(
mDBDir, mConn, mUpdatedPaddingSize, mDeletedPaddingSize,
[&trans]() mutable { return trans.Commit(); }));
[&trans]() mutable { return trans.Commit(); })));
return NS_OK;
}();
@ -1098,7 +1101,7 @@ class Manager::CacheDeleteAction final : public Manager::BaseAction {
mozStorageTransaction trans(aConn, false,
mozIStorageConnection::TRANSACTION_IMMEDIATE);
QM_TRY(trans.Start());
QM_TRY(MOZ_TO_RESULT(trans.Start()));
QM_TRY_UNWRAP(
auto maybeDeletionInfo,
@ -1321,7 +1324,7 @@ class Manager::StorageOpenAction final : public Manager::BaseAction {
mozStorageTransaction trans(aConn, false,
mozIStorageConnection::TRANSACTION_IMMEDIATE);
QM_TRY(trans.Start());
QM_TRY(MOZ_TO_RESULT(trans.Start()));
// Look for existing cache
QM_TRY_INSPECT(const auto& maybeCacheId,
@ -1335,9 +1338,10 @@ class Manager::StorageOpenAction final : public Manager::BaseAction {
QM_TRY_UNWRAP(mCacheId, db::CreateCacheId(*aConn));
QM_TRY(db::StoragePutCache(*aConn, mNamespace, mArgs.key(), mCacheId));
QM_TRY(MOZ_TO_RESULT(
db::StoragePutCache(*aConn, mNamespace, mArgs.key(), mCacheId)));
QM_TRY(trans.Commit());
QM_TRY(MOZ_TO_RESULT(trans.Commit()));
MOZ_DIAGNOSTIC_ASSERT(mCacheId != INVALID_CACHE_ID);
return NS_OK;
@ -1374,7 +1378,7 @@ class Manager::StorageDeleteAction final : public Manager::BaseAction {
mozStorageTransaction trans(aConn, false,
mozIStorageConnection::TRANSACTION_IMMEDIATE);
QM_TRY(trans.Start());
QM_TRY(MOZ_TO_RESULT(trans.Start()));
QM_TRY_INSPECT(const auto& maybeCacheId,
db::StorageGetCacheId(*aConn, mNamespace, mArgs.key()));
@ -1387,9 +1391,10 @@ class Manager::StorageDeleteAction final : public Manager::BaseAction {
// Don't delete the removing padding size here, we'll delete it on
// DeleteOrphanedCacheAction.
QM_TRY(db::StorageForgetCache(*aConn, mNamespace, mArgs.key()));
QM_TRY(
MOZ_TO_RESULT(db::StorageForgetCache(*aConn, mNamespace, mArgs.key())));
QM_TRY(trans.Commit());
QM_TRY(MOZ_TO_RESULT(trans.Commit()));
mCacheDeleted = true;
return NS_OK;

View File

@ -145,7 +145,7 @@ Result<int64_t, nsresult> GetPaddingSizeFromDB(
// from it. We have to do this because GetPaddingSizeFromDB is called
// by InitOrigin. And it means that SetupAction::RunSyncWithDBOnTarget hasn't
// checked the schema for the given origin yet).
QM_TRY(db::CreateOrMigrateSchema(*conn));
QM_TRY(MOZ_TO_RESULT(db::CreateOrMigrateSchema(*conn)));
QM_TRY_RETURN(DirectoryPaddingRestore(aDir, *conn,
/* aMustRestore */ false));
@ -182,7 +182,8 @@ Result<UsageInfo, nsresult> CacheQuotaClient::InitOrigin(
const auto& dir,
qm->GetDirectoryForOrigin(aPersistenceType, aOriginMetadata.mOrigin));
QM_TRY(dir->Append(NS_LITERAL_STRING_FROM_CSTRING(DOMCACHE_DIRECTORY_NAME)));
QM_TRY(MOZ_TO_RESULT(
dir->Append(NS_LITERAL_STRING_FROM_CSTRING(DOMCACHE_DIRECTORY_NAME))));
QM_TRY_INSPECT(
const auto& cachesSQLiteFile,
@ -205,19 +206,19 @@ Result<UsageInfo, nsresult> CacheQuotaClient::InitOrigin(
// XXX Long term, we might even think about removing entire origin
// directory because missing caches.sqlite while other files exist can
// be interpreted as database corruption.
QM_TRY(mozilla::dom::cache::DirectoryPaddingDeleteFile(
*dir, DirPaddingFile::TMP_FILE));
QM_TRY(MOZ_TO_RESULT(mozilla::dom::cache::DirectoryPaddingDeleteFile(
*dir, DirPaddingFile::TMP_FILE)));
QM_TRY(mozilla::dom::cache::DirectoryPaddingDeleteFile(
*dir, DirPaddingFile::FILE));
QM_TRY(MOZ_TO_RESULT(mozilla::dom::cache::DirectoryPaddingDeleteFile(
*dir, DirPaddingFile::FILE)));
QM_TRY_INSPECT(const auto& morgueDir,
CloneFileAndAppend(*dir, kMorgueDirectoryFilename));
QuotaInfo dummy;
QM_TRY(mozilla::dom::cache::RemoveNsIFileRecursively(
QM_TRY(MOZ_TO_RESULT(mozilla::dom::cache::RemoveNsIFileRecursively(
dummy, *morgueDir,
/* aTrackQuota */ false));
/* aTrackQuota */ false)));
return nsCOMPtr<nsIFile>{nullptr};
}
@ -414,7 +415,7 @@ nsresult CacheQuotaClient::UpgradeStorageFrom2_0To2_1(nsIFile* aDirectory) {
AssertIsOnIOThread();
MOZ_DIAGNOSTIC_ASSERT(aDirectory);
QM_TRY(DirectoryPaddingInit(*aDirectory));
QM_TRY(MOZ_TO_RESULT(DirectoryPaddingInit(*aDirectory)));
return NS_OK;
}
@ -470,12 +471,14 @@ nsresult CacheQuotaClient::WipePaddingFileInternal(const QuotaInfo& aQuotaInfo,
DecreaseUsageForQuotaInfo(aQuotaInfo, paddingSize);
}
QM_TRY(DirectoryPaddingDeleteFile(*aBaseDir, DirPaddingFile::FILE));
QM_TRY(MOZ_TO_RESULT(
DirectoryPaddingDeleteFile(*aBaseDir, DirPaddingFile::FILE)));
// Remove temporary file if we have one.
QM_TRY(DirectoryPaddingDeleteFile(*aBaseDir, DirPaddingFile::TMP_FILE));
QM_TRY(MOZ_TO_RESULT(
DirectoryPaddingDeleteFile(*aBaseDir, DirPaddingFile::TMP_FILE)));
QM_TRY(DirectoryPaddingInit(*aBaseDir));
QM_TRY(MOZ_TO_RESULT(DirectoryPaddingInit(*aBaseDir)));
return NS_OK;
}
@ -507,7 +510,8 @@ nsresult RestorePaddingFile(nsIFile* aBaseDir, mozIStorageConnection* aConn) {
RefPtr<CacheQuotaClient> cacheQuotaClient = CacheQuotaClient::Get();
MOZ_DIAGNOSTIC_ASSERT(cacheQuotaClient);
QM_TRY(cacheQuotaClient->RestorePaddingFileInternal(aBaseDir, aConn));
QM_TRY(MOZ_TO_RESULT(
cacheQuotaClient->RestorePaddingFileInternal(aBaseDir, aConn)));
return NS_OK;
}
@ -520,7 +524,8 @@ nsresult WipePaddingFile(const QuotaInfo& aQuotaInfo, nsIFile* aBaseDir) {
RefPtr<CacheQuotaClient> cacheQuotaClient = CacheQuotaClient::Get();
MOZ_DIAGNOSTIC_ASSERT(cacheQuotaClient);
QM_TRY(cacheQuotaClient->WipePaddingFileInternal(aQuotaInfo, aBaseDir));
QM_TRY(MOZ_TO_RESULT(
cacheQuotaClient->WipePaddingFileInternal(aQuotaInfo, aBaseDir)));
return NS_OK;
}

View File

@ -78,20 +78,20 @@ class CacheQuotaClient final : public quota::Client {
if (aIncreaseSize == aDecreaseSize && !temporaryPaddingFileExist) {
// Early return here, since most cache actions won't modify padding size.
QM_TRY(aCommitHook());
QM_TRY(MOZ_TO_RESULT(aCommitHook()));
return NS_OK;
}
// Don't delete the temporary padding file in case of an error to force the
// next action recalculate the padding size.
QM_TRY(UpdateDirectoryPaddingFile(aBaseDir, aConn, aIncreaseSize,
aDecreaseSize,
temporaryPaddingFileExist));
QM_TRY(MOZ_TO_RESULT(
UpdateDirectoryPaddingFile(aBaseDir, aConn, aIncreaseSize,
aDecreaseSize, temporaryPaddingFileExist)));
// Don't delete the temporary padding file in case of an error to force the
// next action recalculate the padding size.
QM_TRY(aCommitHook());
QM_TRY(MOZ_TO_RESULT(aCommitHook()));
QM_WARNONLY_TRY(ToResult(DirectoryPaddingFinalizeWrite(aBaseDir)),
([&aBaseDir](const nsresult) {