From 685aa0cc5e3616e81f390af4c3ee666ecd866575 Mon Sep 17 00:00:00 2001 From: Jan Varga Date: Fri, 24 Sep 2021 13:08:30 +0000 Subject: [PATCH] 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 --- dom/cache/Context.cpp | 5 +- dom/cache/DBAction.cpp | 22 +- dom/cache/DBSchema.cpp | 758 +++++++++++++++++++----------------- dom/cache/FileUtils.cpp | 60 +-- dom/cache/FileUtilsImpl.h | 2 +- dom/cache/Manager.cpp | 65 ++-- dom/cache/QuotaClient.cpp | 33 +- dom/cache/QuotaClientImpl.h | 10 +- 8 files changed, 505 insertions(+), 450 deletions(-) diff --git a/dom/cache/Context.cpp b/dom/cache/Context.cpp index b35e089034c3..9be0f329445a 100644 --- a/dom/cache/Context.cpp +++ b/dom/cache/Context.cpp @@ -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 diff --git a/dom/cache/DBAction.cpp b/dom/cache/DBAction.cpp index ec28f23c5451..4174f5d66fba 100644 --- a/dom/cache/DBAction.cpp +++ b/dom/cache/DBAction.cpp @@ -36,15 +36,15 @@ nsresult WipeDatabase(const QuotaInfo& aQuotaInfo, nsIFile& aDBFile) { QM_TRY_INSPECT(const auto& dbDir, MOZ_TO_RESULT_INVOKE_TYPED( nsCOMPtr, 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, 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, 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(); - QM_TRY(handler->Init()); + QM_TRY(MOZ_TO_RESULT(handler->Init())); QM_TRY_INSPECT(const auto& mutator, MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr, handler, @@ -159,9 +159,9 @@ Result, nsresult> OpenDBConnection( : EmptyCString(); nsCOMPtr 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, 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, storageService, @@ -200,14 +200,14 @@ Result, 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, storageService, OpenDatabaseWithFileURL, dbFileUrl, ""_ns)); } - QM_TRY(db::InitializeConnection(*conn)); + QM_TRY(MOZ_TO_RESULT(db::InitializeConnection(*conn))); return conn; } diff --git a/dom/cache/DBSchema.cpp b/dom/cache/DBSchema.cpp index 5203e3ffd525..5b9045e78f6c 100644 --- a/dom/cache/DBSchema.cpp +++ b/dom/cache/DBSchema.cpp @@ -479,7 +479,7 @@ nsresult CreateOrMigrateSchema(mozIStorageConnection& aConn) { if (schemaVersion == kLatestSchemaVersion) { // We already have the correct schema version. Validate it matches // our expected schema and then proceed. - QM_TRY(Validate(aConn)); + QM_TRY(MOZ_TO_RESULT(Validate(aConn))); return NS_OK; } @@ -490,32 +490,42 @@ nsresult CreateOrMigrateSchema(mozIStorageConnection& aConn) { mozStorageTransaction trans(&aConn, false, mozIStorageConnection::TRANSACTION_IMMEDIATE); - QM_TRY(trans.Start()); + QM_TRY(MOZ_TO_RESULT(trans.Start())); const bool migrating = schemaVersion != 0; if (migrating) { // A schema exists, but its not the current version. Attempt to // migrate it to our new schema. - QM_TRY(Migrate(aConn)); + QM_TRY(MOZ_TO_RESULT(Migrate(aConn))); } else { // There is no schema installed. Create the database from scratch. - QM_TRY(aConn.ExecuteSimpleSQL(nsLiteralCString(kTableCaches))); - QM_TRY(aConn.ExecuteSimpleSQL(nsLiteralCString(kTableSecurityInfo))); - QM_TRY(aConn.ExecuteSimpleSQL(nsLiteralCString(kIndexSecurityInfoHash))); - QM_TRY(aConn.ExecuteSimpleSQL(nsLiteralCString(kTableEntries))); - QM_TRY(aConn.ExecuteSimpleSQL(nsLiteralCString(kIndexEntriesRequest))); - QM_TRY(aConn.ExecuteSimpleSQL(nsLiteralCString(kTableRequestHeaders))); - QM_TRY(aConn.ExecuteSimpleSQL(nsLiteralCString(kTableResponseHeaders))); - QM_TRY(aConn.ExecuteSimpleSQL(nsLiteralCString(kIndexResponseHeadersName))); - QM_TRY(aConn.ExecuteSimpleSQL(nsLiteralCString(kTableResponseUrlList))); - QM_TRY(aConn.ExecuteSimpleSQL(nsLiteralCString(kTableStorage))); - QM_TRY(aConn.SetSchemaVersion(kLatestSchemaVersion)); + QM_TRY( + MOZ_TO_RESULT(aConn.ExecuteSimpleSQL(nsLiteralCString(kTableCaches)))); + QM_TRY(MOZ_TO_RESULT( + aConn.ExecuteSimpleSQL(nsLiteralCString(kTableSecurityInfo)))); + QM_TRY(MOZ_TO_RESULT( + aConn.ExecuteSimpleSQL(nsLiteralCString(kIndexSecurityInfoHash)))); + QM_TRY( + MOZ_TO_RESULT(aConn.ExecuteSimpleSQL(nsLiteralCString(kTableEntries)))); + QM_TRY(MOZ_TO_RESULT( + aConn.ExecuteSimpleSQL(nsLiteralCString(kIndexEntriesRequest)))); + QM_TRY(MOZ_TO_RESULT( + aConn.ExecuteSimpleSQL(nsLiteralCString(kTableRequestHeaders)))); + QM_TRY(MOZ_TO_RESULT( + aConn.ExecuteSimpleSQL(nsLiteralCString(kTableResponseHeaders)))); + QM_TRY(MOZ_TO_RESULT( + aConn.ExecuteSimpleSQL(nsLiteralCString(kIndexResponseHeadersName)))); + QM_TRY(MOZ_TO_RESULT( + aConn.ExecuteSimpleSQL(nsLiteralCString(kTableResponseUrlList)))); + QM_TRY( + MOZ_TO_RESULT(aConn.ExecuteSimpleSQL(nsLiteralCString(kTableStorage)))); + QM_TRY(MOZ_TO_RESULT(aConn.SetSchemaVersion(kLatestSchemaVersion))); QM_TRY_UNWRAP(schemaVersion, GetEffectiveSchemaVersion(aConn)); } - QM_TRY(Validate(aConn)); - QM_TRY(trans.Commit()); + QM_TRY(MOZ_TO_RESULT(Validate(aConn))); + QM_TRY(MOZ_TO_RESULT(trans.Commit())); if (migrating) { // Migrations happen infrequently and reflect a chance in DB structure. @@ -545,13 +555,13 @@ nsresult InitializeConnection(mozIStorageConnection& aConn) { // need ordering and the binary equality operations are correct. So, do // NOT set PRAGMA encoding to UTF-16. - QM_TRY(aConn.ExecuteSimpleSQL(nsPrintfCString( + QM_TRY(MOZ_TO_RESULT(aConn.ExecuteSimpleSQL(nsPrintfCString( // Use a smaller page size to improve perf/footprint; default is too large "PRAGMA page_size = %u; " // Enable auto_vacuum; this must happen after page_size and before WAL "PRAGMA auto_vacuum = INCREMENTAL; " "PRAGMA foreign_keys = ON; ", - kPageSize))); + kPageSize)))); // Limit fragmentation by growing the database by many pages at once. QM_TRY(QM_OR_ELSE_WARN_IF( @@ -564,14 +574,14 @@ nsresult InitializeConnection(mozIStorageConnection& aConn) { // Enable WAL journaling. This must be performed in a separate transaction // after changing the page_size and enabling auto_vacuum. - QM_TRY(aConn.ExecuteSimpleSQL(nsPrintfCString( + QM_TRY(MOZ_TO_RESULT(aConn.ExecuteSimpleSQL(nsPrintfCString( // WAL journal can grow to given number of *pages* "PRAGMA wal_autocheckpoint = %u; " // Always truncate the journal back to given number of *bytes* "PRAGMA journal_size_limit = %u; " // WAL must be enabled at the end to allow page size to be changed, etc. "PRAGMA journal_mode = WAL; ", - kWalAutoCheckpointPages, kWalAutoCheckpointSize))); + kWalAutoCheckpointPages, kWalAutoCheckpointSize)))); // Verify that we successfully set the vacuum mode to incremental. It // is very easy to put the database in a state where the auto_vacuum @@ -596,7 +606,8 @@ nsresult InitializeConnection(mozIStorageConnection& aConn) { Result CreateCacheId(mozIStorageConnection& aConn) { MOZ_ASSERT(!NS_IsMainThread()); - QM_TRY(aConn.ExecuteSimpleSQL("INSERT INTO caches DEFAULT VALUES;"_ns)); + QM_TRY(MOZ_TO_RESULT( + aConn.ExecuteSimpleSQL("INSERT INTO caches DEFAULT VALUES;"_ns))); QM_TRY_INSPECT(const auto& state, quota::CreateAndExecuteSingleStepStatement< @@ -624,7 +635,7 @@ Result DeleteCacheId(mozIStorageConnection& aConn, (auto [deletedBodyIdList, deletedSecurityIdList, deletedPaddingSize]), DeleteEntries(aConn, matches)); - QM_TRY(DeleteSecurityInfoList(aConn, deletedSecurityIdList)); + QM_TRY(MOZ_TO_RESULT(DeleteSecurityInfoList(aConn, deletedSecurityIdList))); // Delete the remainder of the cache using cascade semantics. QM_TRY_INSPECT(const auto& state, @@ -632,9 +643,9 @@ Result DeleteCacheId(mozIStorageConnection& aConn, nsCOMPtr, aConn, CreateStatement, "DELETE FROM caches WHERE id=:id;"_ns)); - QM_TRY(state->BindInt64ByName("id"_ns, aCacheId)); + QM_TRY(MOZ_TO_RESULT(state->BindInt64ByName("id"_ns, aCacheId))); - QM_TRY(state->Execute()); + QM_TRY(MOZ_TO_RESULT(state->Execute())); return DeletionInfo{std::move(deletedBodyIdList), deletedPaddingSize}; } @@ -773,12 +784,12 @@ Result CachePut(mozIStorageConnection& aConn, (auto [deletedBodyIdList, deletedSecurityIdList, deletedPaddingSize]), DeleteEntries(aConn, matches)); - QM_TRY(InsertEntry(aConn, aCacheId, aRequest, aRequestBodyId, aResponse, - aResponseBodyId)); + QM_TRY(MOZ_TO_RESULT(InsertEntry(aConn, aCacheId, aRequest, aRequestBodyId, + aResponse, aResponseBodyId))); // Delete the security values after doing the insert to avoid churning // the security table when its not necessary. - QM_TRY(DeleteSecurityInfoList(aConn, deletedSecurityIdList)); + QM_TRY(MOZ_TO_RESULT(DeleteSecurityInfoList(aConn, deletedSecurityIdList))); return DeletionInfo{std::move(deletedBodyIdList), deletedPaddingSize}; } @@ -800,7 +811,7 @@ Result, nsresult> CacheDelete( (auto [deletedBodyIdList, deletedSecurityIdList, deletedPaddingSize]), DeleteEntries(aConn, matches)); - QM_TRY(DeleteSecurityInfoList(aConn, deletedSecurityIdList)); + QM_TRY(MOZ_TO_RESULT(DeleteSecurityInfoList(aConn, deletedSecurityIdList))); return Some(DeletionInfo{std::move(deletedBodyIdList), deletedPaddingSize}); } @@ -857,7 +868,7 @@ Result, nsresult> StorageMatch( "SELECT cache_id FROM storage WHERE " "namespace=:namespace ORDER BY rowid;"_ns)); - QM_TRY(state->BindInt32ByName("namespace"_ns, aNamespace)); + QM_TRY(MOZ_TO_RESULT(state->BindInt32ByName("namespace"_ns, aNamespace))); QM_TRY_INSPECT( const auto& cacheIdList, @@ -895,7 +906,7 @@ Result, nsresult> StorageGetCacheId(mozIStorageConnection& aConn, QM_TRY_INSPECT(const auto& state, CreateAndBindKeyStatement(aConn, query, aKey)); - QM_TRY(state->BindInt32ByName("namespace"_ns, aNamespace)); + QM_TRY(MOZ_TO_RESULT(state->BindInt32ByName("namespace"_ns, aNamespace))); QM_TRY_INSPECT(const bool& hasMoreData, MOZ_TO_RESULT_INVOKE(*state, ExecuteStep)); @@ -917,10 +928,10 @@ nsresult StoragePutCache(mozIStorageConnection& aConn, Namespace aNamespace, "INSERT INTO storage (namespace, key, cache_id) " "VALUES (:namespace, :key, :cache_id);"_ns)); - QM_TRY(state->BindInt32ByName("namespace"_ns, aNamespace)); - QM_TRY(state->BindStringAsBlobByName("key"_ns, aKey)); - QM_TRY(state->BindInt64ByName("cache_id"_ns, aCacheId)); - QM_TRY(state->Execute()); + QM_TRY(MOZ_TO_RESULT(state->BindInt32ByName("namespace"_ns, aNamespace))); + QM_TRY(MOZ_TO_RESULT(state->BindStringAsBlobByName("key"_ns, aKey))); + QM_TRY(MOZ_TO_RESULT(state->BindInt64ByName("cache_id"_ns, aCacheId))); + QM_TRY(MOZ_TO_RESULT(state->Execute())); return NS_OK; } @@ -938,9 +949,9 @@ nsresult StorageForgetCache(mozIStorageConnection& aConn, Namespace aNamespace, QM_TRY_INSPECT(const auto& state, CreateAndBindKeyStatement(aConn, query, aKey)); - QM_TRY(state->BindInt32ByName("namespace"_ns, aNamespace)); + QM_TRY(MOZ_TO_RESULT(state->BindInt32ByName("namespace"_ns, aNamespace))); - QM_TRY(state->Execute()); + QM_TRY(MOZ_TO_RESULT(state->Execute())); return NS_OK; } @@ -955,7 +966,7 @@ Result, nsresult> StorageGetKeys( nsCOMPtr, aConn, CreateStatement, "SELECT key FROM storage WHERE namespace=:namespace ORDER BY rowid;"_ns)); - QM_TRY(state->BindInt32ByName("namespace"_ns, aNamespace)); + QM_TRY(MOZ_TO_RESULT(state->BindInt32ByName("namespace"_ns, aNamespace))); QM_TRY_RETURN(quota::CollectElementsWhileHasResult(*state, [](auto& stmt) { QM_TRY_RETURN( @@ -975,7 +986,7 @@ Result QueryAll(mozIStorageConnection& aConn, nsCOMPtr, aConn, CreateStatement, "SELECT id FROM entries WHERE cache_id=:cache_id ORDER BY id;"_ns)); - QM_TRY(state->BindInt64ByName("cache_id"_ns, aCacheId)); + QM_TRY(MOZ_TO_RESULT(state->BindInt64ByName("cache_id"_ns, aCacheId))); QM_TRY_RETURN((quota::CollectElementsWhileHasResultTyped( *state, [](auto& stmt) { @@ -1021,7 +1032,7 @@ Result QueryCache(mozIStorageConnection& aConn, MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr, aConn, CreateStatement, query)); - QM_TRY(state->BindInt64ByName("cache_id"_ns, aCacheId)); + QM_TRY(MOZ_TO_RESULT(state->BindInt64ByName("cache_id"_ns, aCacheId))); QM_TRY_INSPECT(const auto& crypto, ToResultGet>( MOZ_SELECT_OVERLOAD(do_CreateInstance), @@ -1030,22 +1041,23 @@ Result QueryCache(mozIStorageConnection& aConn, QM_TRY_INSPECT(const auto& urlWithoutQueryHash, HashCString(*crypto, aRequest.urlWithoutQuery())); - QM_TRY(state->BindUTF8StringAsBlobByName("url_no_query_hash"_ns, - urlWithoutQueryHash)); + QM_TRY(MOZ_TO_RESULT(state->BindUTF8StringAsBlobByName("url_no_query_hash"_ns, + urlWithoutQueryHash))); if (!aParams.ignoreSearch()) { QM_TRY_INSPECT(const auto& urlQueryHash, HashCString(*crypto, aRequest.urlQuery())); - QM_TRY( - state->BindUTF8StringAsBlobByName("url_query_hash"_ns, urlQueryHash)); + QM_TRY(MOZ_TO_RESULT( + state->BindUTF8StringAsBlobByName("url_query_hash"_ns, urlQueryHash))); } - QM_TRY(state->BindUTF8StringByName("url_no_query"_ns, - aRequest.urlWithoutQuery())); + QM_TRY(MOZ_TO_RESULT(state->BindUTF8StringByName( + "url_no_query"_ns, aRequest.urlWithoutQuery()))); if (!aParams.ignoreSearch()) { - QM_TRY(state->BindUTF8StringByName("url_query"_ns, aRequest.urlQuery())); + QM_TRY(MOZ_TO_RESULT( + state->BindUTF8StringByName("url_query"_ns, aRequest.urlQuery()))); } EntryIds entryIdList; @@ -1097,7 +1109,7 @@ Result MatchByVaryHeader(mozIStorageConnection& aConn, "WHERE name='vary' COLLATE NOCASE " "AND entry_id=:entry_id;"_ns)); - QM_TRY(state->BindInt32ByName("entry_id"_ns, entryId)); + QM_TRY(MOZ_TO_RESULT(state->BindInt32ByName("entry_id"_ns, entryId))); QM_TRY_RETURN(( quota::CollectElementsWhileHasResultTyped>( @@ -1116,7 +1128,7 @@ Result MatchByVaryHeader(mozIStorageConnection& aConn, "SELECT name, value FROM request_headers " "WHERE entry_id=:entry_id;"_ns)); - QM_TRY(state->BindInt32ByName("entry_id"_ns, entryId)); + QM_TRY(MOZ_TO_RESULT(state->BindInt32ByName("entry_id"_ns, entryId))); RefPtr cachedHeaders = new InternalHeaders(HeadersGuardEnum::None); @@ -1241,7 +1253,8 @@ static nsresult DeleteEntriesInternal( MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr, aConn, CreateStatement, query)); - QM_TRY(BindListParamsToQuery(*state, aEntryIdList, aPos, aLen)); + QM_TRY( + MOZ_TO_RESULT(BindListParamsToQuery(*state, aEntryIdList, aPos, aLen))); int64_t overallPaddingSize = 0; @@ -1320,9 +1333,10 @@ static nsresult DeleteEntriesInternal( MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr, aConn, CreateStatement, query)); - QM_TRY(BindListParamsToQuery(*state, aEntryIdList, aPos, aLen)); + QM_TRY( + MOZ_TO_RESULT(BindListParamsToQuery(*state, aEntryIdList, aPos, aLen))); - QM_TRY(state->Execute()); + QM_TRY(MOZ_TO_RESULT(state->Execute())); } return NS_OK; @@ -1333,9 +1347,9 @@ DeleteEntries(mozIStorageConnection& aConn, const nsTArray& aEntryIdList) { auto result = std::make_tuple(nsTArray{}, AutoTArray{}, int64_t{0}); - QM_TRY(DeleteEntriesInternal(aConn, aEntryIdList, std::get<0>(result), - std::get<1>(result), &std::get<2>(result), 0, - aEntryIdList.Length())); + QM_TRY(MOZ_TO_RESULT(DeleteEntriesInternal( + aConn, aEntryIdList, std::get<0>(result), std::get<1>(result), + &std::get<2>(result), 0, aEntryIdList.Length()))); return result; } @@ -1365,8 +1379,10 @@ Result InsertSecurityInfo(mozIStorageConnection& aConn, "SELECT id, refcount FROM security_info WHERE hash=:hash AND " "data=:data;"_ns, [&hash, &aData](auto& state) -> Result { - QM_TRY(state.BindUTF8StringAsBlobByName("hash"_ns, hash)); - QM_TRY(state.BindUTF8StringAsBlobByName("data"_ns, aData)); + QM_TRY(MOZ_TO_RESULT( + state.BindUTF8StringAsBlobByName("hash"_ns, hash))); + QM_TRY(MOZ_TO_RESULT( + state.BindUTF8StringAsBlobByName("data"_ns, aData))); return Ok{}; })); @@ -1386,9 +1402,9 @@ Result InsertSecurityInfo(mozIStorageConnection& aConn, nsCOMPtr, aConn, CreateStatement, "UPDATE security_info SET refcount=:refcount WHERE id=:id;"_ns)); - QM_TRY(state->BindInt32ByName("refcount"_ns, refcount + 1)); - QM_TRY(state->BindInt32ByName("id"_ns, id)); - QM_TRY(state->Execute()); + QM_TRY(MOZ_TO_RESULT(state->BindInt32ByName("refcount"_ns, refcount + 1))); + QM_TRY(MOZ_TO_RESULT(state->BindInt32ByName("id"_ns, id))); + QM_TRY(MOZ_TO_RESULT(state->Execute())); return id; } @@ -1401,9 +1417,9 @@ Result InsertSecurityInfo(mozIStorageConnection& aConn, "INSERT INTO security_info (hash, data, refcount) " "VALUES (:hash, :data, 1);"_ns)); - QM_TRY(state->BindUTF8StringAsBlobByName("hash"_ns, hash)); - QM_TRY(state->BindUTF8StringAsBlobByName("data"_ns, aData)); - QM_TRY(state->Execute()); + QM_TRY(MOZ_TO_RESULT(state->BindUTF8StringAsBlobByName("hash"_ns, hash))); + QM_TRY(MOZ_TO_RESULT(state->BindUTF8StringAsBlobByName("data"_ns, aData))); + QM_TRY(MOZ_TO_RESULT(state->Execute())); { QM_TRY_INSPECT(const auto& state, @@ -1424,7 +1440,7 @@ nsresult DeleteSecurityInfo(mozIStorageConnection& aConn, int32_t aId, quota::CreateAndExecuteSingleStepStatement( aConn, "SELECT refcount FROM security_info WHERE id=:id;"_ns, [aId](auto& state) -> Result { - QM_TRY(state.BindInt32ByName("id"_ns, aId)); + QM_TRY(MOZ_TO_RESULT(state.BindInt32ByName("id"_ns, aId))); return Ok{}; })); @@ -1444,8 +1460,8 @@ nsresult DeleteSecurityInfo(mozIStorageConnection& aConn, int32_t aId, nsCOMPtr, aConn, CreateStatement, "DELETE FROM security_info WHERE id=:id;"_ns)); - QM_TRY(state->BindInt32ByName("id"_ns, aId)); - QM_TRY(state->Execute()); + QM_TRY(MOZ_TO_RESULT(state->BindInt32ByName("id"_ns, aId))); + QM_TRY(MOZ_TO_RESULT(state->Execute())); return NS_OK; } @@ -1458,9 +1474,9 @@ nsresult DeleteSecurityInfo(mozIStorageConnection& aConn, int32_t aId, nsCOMPtr, aConn, CreateStatement, "UPDATE security_info SET refcount=:refcount WHERE id=:id;"_ns)); - QM_TRY(state->BindInt32ByName("refcount"_ns, newCount)); - QM_TRY(state->BindInt32ByName("id"_ns, aId)); - QM_TRY(state->Execute()); + QM_TRY(MOZ_TO_RESULT(state->BindInt32ByName("refcount"_ns, newCount))); + QM_TRY(MOZ_TO_RESULT(state->BindInt32ByName("id"_ns, aId))); + QM_TRY(MOZ_TO_RESULT(state->Execute())); return NS_OK; } @@ -1469,8 +1485,8 @@ nsresult DeleteSecurityInfoList( mozIStorageConnection& aConn, const nsTArray& aDeletedStorageIdList) { for (const auto& deletedStorageId : aDeletedStorageIdList) { - QM_TRY(DeleteSecurityInfo(aConn, deletedStorageId.mId, - deletedStorageId.mCount)); + QM_TRY(MOZ_TO_RESULT(DeleteSecurityInfo(aConn, deletedStorageId.mId, + deletedStorageId.mCount))); } return NS_OK; @@ -1551,81 +1567,86 @@ nsresult InsertEntry(mozIStorageConnection& aConn, CacheId aCacheId, ":cache_id " ");"_ns)); - QM_TRY(state->BindUTF8StringByName("request_method"_ns, aRequest.method())); + QM_TRY(MOZ_TO_RESULT( + state->BindUTF8StringByName("request_method"_ns, aRequest.method()))); - QM_TRY(state->BindUTF8StringByName("request_url_no_query"_ns, - aRequest.urlWithoutQuery())); + QM_TRY(MOZ_TO_RESULT(state->BindUTF8StringByName( + "request_url_no_query"_ns, aRequest.urlWithoutQuery()))); QM_TRY_INSPECT(const auto& urlWithoutQueryHash, HashCString(*crypto, aRequest.urlWithoutQuery())); - QM_TRY(state->BindUTF8StringAsBlobByName("request_url_no_query_hash"_ns, - urlWithoutQueryHash)); + QM_TRY(MOZ_TO_RESULT(state->BindUTF8StringAsBlobByName( + "request_url_no_query_hash"_ns, urlWithoutQueryHash))); - QM_TRY(state->BindUTF8StringByName("request_url_query"_ns, - aRequest.urlQuery())); + QM_TRY(MOZ_TO_RESULT(state->BindUTF8StringByName("request_url_query"_ns, + aRequest.urlQuery()))); QM_TRY_INSPECT(const auto& urlQueryHash, HashCString(*crypto, aRequest.urlQuery())); - QM_TRY(state->BindUTF8StringAsBlobByName("request_url_query_hash"_ns, - urlQueryHash)); + QM_TRY(MOZ_TO_RESULT(state->BindUTF8StringAsBlobByName( + "request_url_query_hash"_ns, urlQueryHash))); - QM_TRY(state->BindUTF8StringByName("request_url_fragment"_ns, - aRequest.urlFragment())); + QM_TRY(MOZ_TO_RESULT(state->BindUTF8StringByName("request_url_fragment"_ns, + aRequest.urlFragment()))); - QM_TRY(state->BindStringByName("request_referrer"_ns, aRequest.referrer())); + QM_TRY(MOZ_TO_RESULT( + state->BindStringByName("request_referrer"_ns, aRequest.referrer()))); - QM_TRY(state->BindInt32ByName( + QM_TRY(MOZ_TO_RESULT(state->BindInt32ByName( "request_referrer_policy"_ns, - static_cast(aRequest.referrerPolicy()))); + static_cast(aRequest.referrerPolicy())))); - QM_TRY( + QM_TRY(MOZ_TO_RESULT( state->BindInt32ByName("request_headers_guard"_ns, - static_cast(aRequest.headersGuard()))); + static_cast(aRequest.headersGuard())))); - QM_TRY(state->BindInt32ByName("request_mode"_ns, - static_cast(aRequest.mode()))); + QM_TRY(MOZ_TO_RESULT(state->BindInt32ByName( + "request_mode"_ns, static_cast(aRequest.mode())))); - QM_TRY( + QM_TRY(MOZ_TO_RESULT( state->BindInt32ByName("request_credentials"_ns, - static_cast(aRequest.credentials()))); + static_cast(aRequest.credentials())))); - QM_TRY(state->BindInt32ByName( + QM_TRY(MOZ_TO_RESULT(state->BindInt32ByName( "request_contentpolicytype"_ns, - static_cast(aRequest.contentPolicyType()))); + static_cast(aRequest.contentPolicyType())))); - QM_TRY(state->BindInt32ByName( - "request_cache"_ns, static_cast(aRequest.requestCache()))); + QM_TRY(MOZ_TO_RESULT(state->BindInt32ByName( + "request_cache"_ns, static_cast(aRequest.requestCache())))); - QM_TRY(state->BindInt32ByName( + QM_TRY(MOZ_TO_RESULT(state->BindInt32ByName( "request_redirect"_ns, - static_cast(aRequest.requestRedirect()))); + static_cast(aRequest.requestRedirect())))); + + QM_TRY(MOZ_TO_RESULT( + state->BindStringByName("request_integrity"_ns, aRequest.integrity()))); + + QM_TRY(MOZ_TO_RESULT(BindId(*state, "request_body_id"_ns, aRequestBodyId))); + + QM_TRY(MOZ_TO_RESULT(state->BindInt32ByName( + "response_type"_ns, static_cast(aResponse.type())))); + + QM_TRY(MOZ_TO_RESULT( + state->BindInt32ByName("response_status"_ns, aResponse.status()))); + + QM_TRY(MOZ_TO_RESULT(state->BindUTF8StringByName("response_status_text"_ns, + aResponse.statusText()))); + + QM_TRY(MOZ_TO_RESULT(state->BindInt32ByName( + "response_headers_guard"_ns, + static_cast(aResponse.headersGuard())))); QM_TRY( - state->BindStringByName("request_integrity"_ns, aRequest.integrity())); - - QM_TRY(BindId(*state, "request_body_id"_ns, aRequestBodyId)); - - QM_TRY(state->BindInt32ByName("response_type"_ns, - static_cast(aResponse.type()))); - - QM_TRY(state->BindInt32ByName("response_status"_ns, aResponse.status())); - - QM_TRY(state->BindUTF8StringByName("response_status_text"_ns, - aResponse.statusText())); - - QM_TRY( - state->BindInt32ByName("response_headers_guard"_ns, - static_cast(aResponse.headersGuard()))); - - QM_TRY(BindId(*state, "response_body_id"_ns, aResponseBodyId)); + MOZ_TO_RESULT(BindId(*state, "response_body_id"_ns, aResponseBodyId))); if (aResponse.channelInfo().securityInfo().IsEmpty()) { - QM_TRY(state->BindNullByName("response_security_info_id"_ns)); - } else { QM_TRY( - state->BindInt32ByName("response_security_info_id"_ns, securityId)); + MOZ_TO_RESULT(state->BindNullByName("response_security_info_id"_ns))); + } else { + QM_TRY(MOZ_TO_RESULT( + state->BindInt32ByName("response_security_info_id"_ns, securityId))); } nsAutoCString serializedInfo; @@ -1645,23 +1666,23 @@ nsresult InsertEntry(mozIStorageConnection& aConn, CacheId aCacheId, serializedInfo.Append(suffix); } - QM_TRY(state->BindUTF8StringByName("response_principal_info"_ns, - serializedInfo)); + QM_TRY(MOZ_TO_RESULT(state->BindUTF8StringByName( + "response_principal_info"_ns, serializedInfo))); if (aResponse.paddingSize() == InternalResponse::UNKNOWN_PADDING_SIZE) { MOZ_DIAGNOSTIC_ASSERT(aResponse.type() != ResponseType::Opaque); - QM_TRY(state->BindNullByName("response_padding_size"_ns)); + QM_TRY(MOZ_TO_RESULT(state->BindNullByName("response_padding_size"_ns))); } else { MOZ_DIAGNOSTIC_ASSERT(aResponse.paddingSize() >= 0); MOZ_DIAGNOSTIC_ASSERT(aResponse.type() == ResponseType::Opaque); - QM_TRY(state->BindInt64ByName("response_padding_size"_ns, - aResponse.paddingSize())); + QM_TRY(MOZ_TO_RESULT(state->BindInt64ByName("response_padding_size"_ns, + aResponse.paddingSize()))); } - QM_TRY(state->BindInt64ByName("cache_id"_ns, aCacheId)); + QM_TRY(MOZ_TO_RESULT(state->BindInt64ByName("cache_id"_ns, aCacheId))); - QM_TRY(state->Execute()); + QM_TRY(MOZ_TO_RESULT(state->Execute())); } QM_TRY_INSPECT(const int32_t& entryId, @@ -1684,13 +1705,15 @@ nsresult InsertEntry(mozIStorageConnection& aConn, CacheId aCacheId, ") VALUES (:name, :value, :entry_id)"_ns)); for (const auto& requestHeader : aRequest.headers()) { - QM_TRY(state->BindUTF8StringByName("name"_ns, requestHeader.name())); + QM_TRY(MOZ_TO_RESULT( + state->BindUTF8StringByName("name"_ns, requestHeader.name()))); - QM_TRY(state->BindUTF8StringByName("value"_ns, requestHeader.value())); + QM_TRY(MOZ_TO_RESULT( + state->BindUTF8StringByName("value"_ns, requestHeader.value()))); - QM_TRY(state->BindInt32ByName("entry_id"_ns, entryId)); + QM_TRY(MOZ_TO_RESULT(state->BindInt32ByName("entry_id"_ns, entryId))); - QM_TRY(state->Execute()); + QM_TRY(MOZ_TO_RESULT(state->Execute())); } } @@ -1705,10 +1728,12 @@ nsresult InsertEntry(mozIStorageConnection& aConn, CacheId aCacheId, ") VALUES (:name, :value, :entry_id)"_ns)); for (const auto& responseHeader : aResponse.headers()) { - QM_TRY(state->BindUTF8StringByName("name"_ns, responseHeader.name())); - QM_TRY(state->BindUTF8StringByName("value"_ns, responseHeader.value())); - QM_TRY(state->BindInt32ByName("entry_id"_ns, entryId)); - QM_TRY(state->Execute()); + QM_TRY(MOZ_TO_RESULT( + state->BindUTF8StringByName("name"_ns, responseHeader.name()))); + QM_TRY(MOZ_TO_RESULT( + state->BindUTF8StringByName("value"_ns, responseHeader.value()))); + QM_TRY(MOZ_TO_RESULT(state->BindInt32ByName("entry_id"_ns, entryId))); + QM_TRY(MOZ_TO_RESULT(state->Execute())); } } @@ -1722,9 +1747,9 @@ nsresult InsertEntry(mozIStorageConnection& aConn, CacheId aCacheId, ") VALUES (:url, :entry_id)"_ns)); for (const auto& responseUrl : aResponse.urlList()) { - QM_TRY(state->BindUTF8StringByName("url"_ns, responseUrl)); - QM_TRY(state->BindInt32ByName("entry_id"_ns, entryId)); - QM_TRY(state->Execute()); + QM_TRY(MOZ_TO_RESULT(state->BindUTF8StringByName("url"_ns, responseUrl))); + QM_TRY(MOZ_TO_RESULT(state->BindInt32ByName("entry_id"_ns, entryId))); + QM_TRY(MOZ_TO_RESULT(state->Execute())); } } @@ -1753,27 +1778,28 @@ Result ReadResponse(mozIStorageConnection& aConn, SavedResponse savedResponse; - QM_TRY_INSPECT(const auto& state, - quota::CreateAndExecuteSingleStepStatement( - aConn, - "SELECT " - "entries.response_type, " - "entries.response_status, " - "entries.response_status_text, " - "entries.response_headers_guard, " - "entries.response_body_id, " - "entries.response_principal_info, " - "entries.response_padding_size, " - "security_info.data " - "FROM entries " - "LEFT OUTER JOIN security_info " - "ON entries.response_security_info_id=security_info.id " - "WHERE entries.id=:id;"_ns, - [aEntryId](auto& state) -> Result { - QM_TRY(state.BindInt32ByName("id"_ns, aEntryId)); + QM_TRY_INSPECT( + const auto& state, + quota::CreateAndExecuteSingleStepStatement( + aConn, + "SELECT " + "entries.response_type, " + "entries.response_status, " + "entries.response_status_text, " + "entries.response_headers_guard, " + "entries.response_body_id, " + "entries.response_principal_info, " + "entries.response_padding_size, " + "security_info.data " + "FROM entries " + "LEFT OUTER JOIN security_info " + "ON entries.response_security_info_id=security_info.id " + "WHERE entries.id=:id;"_ns, + [aEntryId](auto& state) -> Result { + QM_TRY(MOZ_TO_RESULT(state.BindInt32ByName("id"_ns, aEntryId))); - return Ok{}; - })); + return Ok{}; + })); QM_TRY_INSPECT(const int32_t& type, MOZ_TO_RESULT_INVOKE(*state, GetInt32, 0)); @@ -1783,7 +1809,8 @@ Result ReadResponse(mozIStorageConnection& aConn, MOZ_TO_RESULT_INVOKE(*state, GetInt32, 1)); savedResponse.mValue.status() = static_cast(status); - QM_TRY(state->GetUTF8String(2, savedResponse.mValue.statusText())); + QM_TRY(MOZ_TO_RESULT( + state->GetUTF8String(2, savedResponse.mValue.statusText()))); QM_TRY_INSPECT(const int32_t& guard, MOZ_TO_RESULT_INVOKE(*state, GetInt32, 3)); @@ -1811,7 +1838,7 @@ Result ReadResponse(mozIStorageConnection& aConn, } RefPtr url; - QM_TRY(net::MozURL::Init(getter_AddRefs(url), specNoSuffix)); + QM_TRY(MOZ_TO_RESULT(net::MozURL::Init(getter_AddRefs(url), specNoSuffix))); #ifdef DEBUG nsDependentCSubstring scheme = url->Scheme(); @@ -1840,7 +1867,7 @@ Result ReadResponse(mozIStorageConnection& aConn, url->Origin(origin); nsCString baseDomain; - QM_TRY(url->BaseDomain(baseDomain)); + QM_TRY(MOZ_TO_RESULT(url->BaseDomain(baseDomain))); savedResponse.mValue.principalInfo() = Some(mozilla::ipc::ContentPrincipalInfo(attrs, origin, specNoSuffix, @@ -1862,8 +1889,8 @@ Result ReadResponse(mozIStorageConnection& aConn, savedResponse.mValue.paddingSize() = paddingSize; } - QM_TRY(state->GetBlobAsUTF8String( - 7, savedResponse.mValue.channelInfo().securityInfo())); + QM_TRY(MOZ_TO_RESULT(state->GetBlobAsUTF8String( + 7, savedResponse.mValue.channelInfo().securityInfo()))); { QM_TRY_INSPECT(const auto& state, @@ -1875,7 +1902,7 @@ Result ReadResponse(mozIStorageConnection& aConn, "FROM response_headers " "WHERE entry_id=:entry_id;"_ns)); - QM_TRY(state->BindInt32ByName("entry_id"_ns, aEntryId)); + QM_TRY(MOZ_TO_RESULT(state->BindInt32ByName("entry_id"_ns, aEntryId))); QM_TRY_UNWRAP(savedResponse.mValue.headers(), quota::CollectElementsWhileHasResult( @@ -1891,7 +1918,7 @@ Result ReadResponse(mozIStorageConnection& aConn, "FROM response_url_list " "WHERE entry_id=:entry_id;"_ns)); - QM_TRY(state->BindInt32ByName("entry_id"_ns, aEntryId)); + QM_TRY(MOZ_TO_RESULT(state->BindInt32ByName("entry_id"_ns, aEntryId))); QM_TRY_UNWRAP(savedResponse.mValue.urlList(), quota::CollectElementsWhileHasResult( @@ -1910,40 +1937,44 @@ Result ReadRequest(mozIStorageConnection& aConn, SavedRequest savedRequest; - QM_TRY_INSPECT(const auto& state, - quota::CreateAndExecuteSingleStepStatement< - quota::SingleStepResult::ReturnNullIfNoResult>( - aConn, - "SELECT " - "request_method, " - "request_url_no_query, " - "request_url_query, " - "request_url_fragment, " - "request_referrer, " - "request_referrer_policy, " - "request_headers_guard, " - "request_mode, " - "request_credentials, " - "request_contentpolicytype, " - "request_cache, " - "request_redirect, " - "request_integrity, " - "request_body_id " - "FROM entries " - "WHERE id=:id;"_ns, - [aEntryId](auto& state) -> Result { - QM_TRY(state.BindInt32ByName("id"_ns, aEntryId)); + QM_TRY_INSPECT( + const auto& state, + quota::CreateAndExecuteSingleStepStatement< + quota::SingleStepResult::ReturnNullIfNoResult>( + aConn, + "SELECT " + "request_method, " + "request_url_no_query, " + "request_url_query, " + "request_url_fragment, " + "request_referrer, " + "request_referrer_policy, " + "request_headers_guard, " + "request_mode, " + "request_credentials, " + "request_contentpolicytype, " + "request_cache, " + "request_redirect, " + "request_integrity, " + "request_body_id " + "FROM entries " + "WHERE id=:id;"_ns, + [aEntryId](auto& state) -> Result { + QM_TRY(MOZ_TO_RESULT(state.BindInt32ByName("id"_ns, aEntryId))); - return Ok{}; - })); + return Ok{}; + })); QM_TRY(OkIf(state), Err(NS_ERROR_UNEXPECTED)); - QM_TRY(state->GetUTF8String(0, savedRequest.mValue.method())); - QM_TRY(state->GetUTF8String(1, savedRequest.mValue.urlWithoutQuery())); - QM_TRY(state->GetUTF8String(2, savedRequest.mValue.urlQuery())); - QM_TRY(state->GetUTF8String(3, savedRequest.mValue.urlFragment())); - QM_TRY(state->GetString(4, savedRequest.mValue.referrer())); + QM_TRY(MOZ_TO_RESULT(state->GetUTF8String(0, savedRequest.mValue.method()))); + QM_TRY(MOZ_TO_RESULT( + state->GetUTF8String(1, savedRequest.mValue.urlWithoutQuery()))); + QM_TRY( + MOZ_TO_RESULT(state->GetUTF8String(2, savedRequest.mValue.urlQuery()))); + QM_TRY(MOZ_TO_RESULT( + state->GetUTF8String(3, savedRequest.mValue.urlFragment()))); + QM_TRY(MOZ_TO_RESULT(state->GetString(4, savedRequest.mValue.referrer()))); QM_TRY_INSPECT(const int32_t& referrerPolicy, MOZ_TO_RESULT_INVOKE(state, GetInt32, 5)); @@ -1976,7 +2007,7 @@ Result ReadRequest(mozIStorageConnection& aConn, savedRequest.mValue.requestRedirect() = static_cast(requestRedirect); - QM_TRY(state->GetString(12, savedRequest.mValue.integrity())); + QM_TRY(MOZ_TO_RESULT(state->GetString(12, savedRequest.mValue.integrity()))); QM_TRY_INSPECT(const bool& nullBody, MOZ_TO_RESULT_INVOKE(state, GetIsNull, 13)); @@ -1995,7 +2026,7 @@ Result ReadRequest(mozIStorageConnection& aConn, "FROM request_headers " "WHERE entry_id=:entry_id;"_ns)); - QM_TRY(state->BindInt32ByName("entry_id"_ns, aEntryId)); + QM_TRY(MOZ_TO_RESULT(state->BindInt32ByName("entry_id"_ns, aEntryId))); QM_TRY_UNWRAP(savedRequest.mValue.headers(), quota::CollectElementsWhileHasResult( @@ -2027,7 +2058,7 @@ nsresult BindListParamsToQuery(mozIStorageStatement& aState, MOZ_ASSERT(!NS_IsMainThread()); MOZ_DIAGNOSTIC_ASSERT((aPos + aLen) <= aEntryIdList.Length()); for (int32_t i = aPos; i < aLen; ++i) { - QM_TRY(aState.BindInt32ByIndex(i, aEntryIdList[i])); + QM_TRY(MOZ_TO_RESULT(aState.BindInt32ByIndex(i, aEntryIdList[i]))); } return NS_OK; } @@ -2037,13 +2068,14 @@ nsresult BindId(mozIStorageStatement& aState, const nsACString& aName, MOZ_ASSERT(!NS_IsMainThread()); if (!aId) { - QM_TRY(aState.BindNullByName(aName)); + QM_TRY(MOZ_TO_RESULT(aState.BindNullByName(aName))); return NS_OK; } char idBuf[NSID_LENGTH]; aId->ToProvidedString(idBuf); - QM_TRY(aState.BindUTF8StringByName(aName, nsDependentCString(idBuf))); + QM_TRY(MOZ_TO_RESULT( + aState.BindUTF8StringByName(aName, nsDependentCString(idBuf)))); return NS_OK; } @@ -2082,7 +2114,7 @@ CreateAndBindKeyStatement(mozIStorageConnection& aConn, aKey.IsEmpty() ? "key IS NULL" : "key=:key"))); if (!aKey.IsEmpty()) { - QM_TRY(state->BindStringAsBlobByName("key"_ns, aKey)); + QM_TRY(MOZ_TO_RESULT(state->BindStringAsBlobByName("key"_ns, aKey))); } return WrapNotNull(std::move(state)); @@ -2090,13 +2122,13 @@ CreateAndBindKeyStatement(mozIStorageConnection& aConn, Result HashCString(nsICryptoHash& aCrypto, const nsACString& aIn) { - QM_TRY(aCrypto.Init(nsICryptoHash::SHA1)); + QM_TRY(MOZ_TO_RESULT(aCrypto.Init(nsICryptoHash::SHA1))); - QM_TRY(aCrypto.Update(reinterpret_cast(aIn.BeginReading()), - aIn.Length())); + QM_TRY(MOZ_TO_RESULT(aCrypto.Update( + reinterpret_cast(aIn.BeginReading()), aIn.Length()))); nsAutoCString fullHash; - QM_TRY(aCrypto.Finish(false /* based64 result */, fullHash)); + QM_TRY(MOZ_TO_RESULT(aCrypto.Finish(false /* based64 result */, fullHash))); return Result{std::in_place, Substring(fullHash, 0, 8)}; @@ -2132,8 +2164,8 @@ nsresult IncrementalVacuum(mozIStorageConnection& aConn) { // chunks of multiple pages back to the OS. const int32_t pagesToRelease = freePages - kMaxFreePages; - QM_TRY(aConn.ExecuteSimpleSQL( - nsPrintfCString("PRAGMA incremental_vacuum(%d);", pagesToRelease))); + QM_TRY(MOZ_TO_RESULT(aConn.ExecuteSimpleSQL( + nsPrintfCString("PRAGMA incremental_vacuum(%d);", pagesToRelease)))); // Verify that our incremental vacuum actually did something #ifdef DEBUG @@ -2320,7 +2352,8 @@ constexpr Migration sMigrationList[] = { }; nsresult RewriteEntriesSchema(mozIStorageConnection& aConn) { - QM_TRY(aConn.ExecuteSimpleSQL("PRAGMA writable_schema = ON"_ns)); + QM_TRY( + MOZ_TO_RESULT(aConn.ExecuteSimpleSQL("PRAGMA writable_schema = ON"_ns))); QM_TRY_INSPECT( const auto& state, @@ -2328,11 +2361,12 @@ nsresult RewriteEntriesSchema(mozIStorageConnection& aConn) { nsCOMPtr, aConn, CreateStatement, "UPDATE sqlite_master SET sql=:sql WHERE name='entries'"_ns)); - QM_TRY( - state->BindUTF8StringByName("sql"_ns, nsDependentCString(kTableEntries))); - QM_TRY(state->Execute()); + QM_TRY(MOZ_TO_RESULT(state->BindUTF8StringByName( + "sql"_ns, nsDependentCString(kTableEntries)))); + QM_TRY(MOZ_TO_RESULT(state->Execute())); - QM_TRY(aConn.ExecuteSimpleSQL("PRAGMA writable_schema = OFF"_ns)); + QM_TRY( + MOZ_TO_RESULT(aConn.ExecuteSimpleSQL("PRAGMA writable_schema = OFF"_ns))); return NS_OK; } @@ -2353,7 +2387,7 @@ nsresult Migrate(mozIStorageConnection& aConn) { for (const auto& migration : sMigrationList) { if (migration.mFromVersion == currentVersion) { bool shouldRewrite = false; - QM_TRY(migration.mFunc(aConn, shouldRewrite)); + QM_TRY(MOZ_TO_RESULT(migration.mFunc(aConn, shouldRewrite))); if (shouldRewrite) { rewriteSchema = true; } @@ -2392,11 +2426,11 @@ nsresult MigrateFrom15To16(mozIStorageConnection& aConn, bool& aRewriteSchema) { // we need to apply the default "follow" to existing records in the table. // We don't actually want to keep the default in the schema for future // INSERTs. - QM_TRY(aConn.ExecuteSimpleSQL( + QM_TRY(MOZ_TO_RESULT(aConn.ExecuteSimpleSQL( "ALTER TABLE entries " - "ADD COLUMN request_redirect INTEGER NOT NULL DEFAULT 0"_ns)); + "ADD COLUMN request_redirect INTEGER NOT NULL DEFAULT 0"_ns))); - QM_TRY(aConn.SetSchemaVersion(16)); + QM_TRY(MOZ_TO_RESULT(aConn.SetSchemaVersion(16))); aRewriteSchema = true; @@ -2414,7 +2448,7 @@ nsresult MigrateFrom16To17(mozIStorageConnection& aConn, bool& aRewriteSchema) { // one. // Create a new_entries table with the new fields as of version 17. - QM_TRY(aConn.ExecuteSimpleSQL( + QM_TRY(MOZ_TO_RESULT(aConn.ExecuteSimpleSQL( "CREATE TABLE new_entries (" "id INTEGER NOT NULL PRIMARY KEY, " "request_method TEXT NOT NULL, " @@ -2439,69 +2473,70 @@ nsresult MigrateFrom16To17(mozIStorageConnection& aConn, bool& aRewriteSchema) { "response_principal_info TEXT NOT NULL, " "cache_id INTEGER NOT NULL REFERENCES caches(id) ON DELETE CASCADE, " "request_redirect INTEGER NOT NULL" - ")"_ns)); + ")"_ns))); // Copy all of the data to the newly created table. QM_TRY( - aConn.ExecuteSimpleSQL("INSERT INTO new_entries (" - "id, " - "request_method, " - "request_url_no_query, " - "request_url_no_query_hash, " - "request_url_query, " - "request_url_query_hash, " - "request_referrer, " - "request_headers_guard, " - "request_mode, " - "request_credentials, " - "request_contentpolicytype, " - "request_cache, " - "request_redirect, " - "request_body_id, " - "response_type, " - "response_url, " - "response_status, " - "response_status_text, " - "response_headers_guard, " - "response_body_id, " - "response_security_info_id, " - "response_principal_info, " - "cache_id " - ") SELECT " - "id, " - "request_method, " - "request_url_no_query, " - "request_url_no_query_hash, " - "request_url_query, " - "request_url_query_hash, " - "request_referrer, " - "request_headers_guard, " - "request_mode, " - "request_credentials, " - "request_contentpolicytype, " - "request_cache, " - "request_redirect, " - "request_body_id, " - "response_type, " - "response_url, " - "response_status, " - "response_status_text, " - "response_headers_guard, " - "response_body_id, " - "response_security_info_id, " - "response_principal_info, " - "cache_id " - "FROM entries;"_ns)); + MOZ_TO_RESULT(aConn.ExecuteSimpleSQL("INSERT INTO new_entries (" + "id, " + "request_method, " + "request_url_no_query, " + "request_url_no_query_hash, " + "request_url_query, " + "request_url_query_hash, " + "request_referrer, " + "request_headers_guard, " + "request_mode, " + "request_credentials, " + "request_contentpolicytype, " + "request_cache, " + "request_redirect, " + "request_body_id, " + "response_type, " + "response_url, " + "response_status, " + "response_status_text, " + "response_headers_guard, " + "response_body_id, " + "response_security_info_id, " + "response_principal_info, " + "cache_id " + ") SELECT " + "id, " + "request_method, " + "request_url_no_query, " + "request_url_no_query_hash, " + "request_url_query, " + "request_url_query_hash, " + "request_referrer, " + "request_headers_guard, " + "request_mode, " + "request_credentials, " + "request_contentpolicytype, " + "request_cache, " + "request_redirect, " + "request_body_id, " + "response_type, " + "response_url, " + "response_status, " + "response_status_text, " + "response_headers_guard, " + "response_body_id, " + "response_security_info_id, " + "response_principal_info, " + "cache_id " + "FROM entries;"_ns))); // Remove the old table. - QM_TRY(aConn.ExecuteSimpleSQL("DROP TABLE entries;"_ns)); + QM_TRY(MOZ_TO_RESULT(aConn.ExecuteSimpleSQL("DROP TABLE entries;"_ns))); // Rename new_entries to entries. - QM_TRY( - aConn.ExecuteSimpleSQL("ALTER TABLE new_entries RENAME to entries;"_ns)); + QM_TRY(MOZ_TO_RESULT( + aConn.ExecuteSimpleSQL("ALTER TABLE new_entries RENAME to entries;"_ns))); // Now, recreate our indices. - QM_TRY(aConn.ExecuteSimpleSQL(nsDependentCString(kIndexEntriesRequest))); + QM_TRY(MOZ_TO_RESULT( + aConn.ExecuteSimpleSQL(nsDependentCString(kIndexEntriesRequest)))); // Revalidate the foreign key constraints, and ensure that there are no // violations. @@ -2512,7 +2547,7 @@ nsresult MigrateFrom16To17(mozIStorageConnection& aConn, bool& aRewriteSchema) { QM_TRY(OkIf(!hasResult), NS_ERROR_FAILURE); - QM_TRY(aConn.SetSchemaVersion(17)); + QM_TRY(MOZ_TO_RESULT(aConn.SetSchemaVersion(17))); return NS_OK; } @@ -2529,11 +2564,11 @@ nsresult MigrateFrom17To18(mozIStorageConnection& aConn, bool& aRewriteSchema) { static_assert(int(RequestCache::Default) == 0, "This is where the 0 below comes from!"); - QM_TRY( + QM_TRY(MOZ_TO_RESULT( aConn.ExecuteSimpleSQL("UPDATE entries SET request_cache = 0 " - "WHERE request_cache = 5;"_ns)); + "WHERE request_cache = 5;"_ns))); - QM_TRY(aConn.SetSchemaVersion(18)); + QM_TRY(MOZ_TO_RESULT(aConn.SetSchemaVersion(18))); return NS_OK; } @@ -2553,11 +2588,11 @@ nsresult MigrateFrom18To19(mozIStorageConnection& aConn, bool& aRewriteSchema) { "This is where the numbers below come from!"); // 8 is former TYPE_REFRESH. - QM_TRY(aConn.ExecuteSimpleSQL( + QM_TRY(MOZ_TO_RESULT(aConn.ExecuteSimpleSQL( "UPDATE entries SET request_mode = 3 " - "WHERE request_contentpolicytype IN (6, 7, 28, 29, 8);"_ns)); + "WHERE request_contentpolicytype IN (6, 7, 28, 29, 8);"_ns))); - QM_TRY(aConn.SetSchemaVersion(19)); + QM_TRY(MOZ_TO_RESULT(aConn.SetSchemaVersion(19))); return NS_OK; } @@ -2570,11 +2605,11 @@ nsresult MigrateFrom19To20(mozIStorageConnection& aConn, bool& aRewriteSchema) { // because its required by ALTER TABLE and we need to apply the default // "no-referrer-when-downgrade" to existing records in the table. We don't // actually want to keep the default in the schema for future INSERTs. - QM_TRY(aConn.ExecuteSimpleSQL( + QM_TRY(MOZ_TO_RESULT(aConn.ExecuteSimpleSQL( "ALTER TABLE entries " - "ADD COLUMN request_referrer_policy INTEGER NOT NULL DEFAULT 2"_ns)); + "ADD COLUMN request_referrer_policy INTEGER NOT NULL DEFAULT 2"_ns))); - QM_TRY(aConn.SetSchemaVersion(20)); + QM_TRY(MOZ_TO_RESULT(aConn.SetSchemaVersion(20))); aRewriteSchema = true; @@ -2592,7 +2627,7 @@ nsresult MigrateFrom20To21(mozIStorageConnection& aConn, bool& aRewriteSchema) { // the old one. // Create a new_entries table with the new fields as of version 21. - QM_TRY(aConn.ExecuteSimpleSQL( + QM_TRY(MOZ_TO_RESULT(aConn.ExecuteSimpleSQL( "CREATE TABLE new_entries (" "id INTEGER NOT NULL PRIMARY KEY, " "request_method TEXT NOT NULL, " @@ -2617,86 +2652,87 @@ nsresult MigrateFrom20To21(mozIStorageConnection& aConn, bool& aRewriteSchema) { "cache_id INTEGER NOT NULL REFERENCES caches(id) ON DELETE CASCADE, " "request_redirect INTEGER NOT NULL, " "request_referrer_policy INTEGER NOT NULL" - ")"_ns)); + ")"_ns))); // Create a response_url_list table with the new fields as of version 21. - QM_TRY(aConn.ExecuteSimpleSQL( + QM_TRY(MOZ_TO_RESULT(aConn.ExecuteSimpleSQL( "CREATE TABLE response_url_list (" "url TEXT NOT NULL, " "entry_id INTEGER NOT NULL REFERENCES entries(id) ON DELETE CASCADE" - ")"_ns)); + ")"_ns))); // Copy all of the data to the newly created entries table. QM_TRY( - aConn.ExecuteSimpleSQL("INSERT INTO new_entries (" - "id, " - "request_method, " - "request_url_no_query, " - "request_url_no_query_hash, " - "request_url_query, " - "request_url_query_hash, " - "request_referrer, " - "request_headers_guard, " - "request_mode, " - "request_credentials, " - "request_contentpolicytype, " - "request_cache, " - "request_redirect, " - "request_referrer_policy, " - "request_body_id, " - "response_type, " - "response_status, " - "response_status_text, " - "response_headers_guard, " - "response_body_id, " - "response_security_info_id, " - "response_principal_info, " - "cache_id " - ") SELECT " - "id, " - "request_method, " - "request_url_no_query, " - "request_url_no_query_hash, " - "request_url_query, " - "request_url_query_hash, " - "request_referrer, " - "request_headers_guard, " - "request_mode, " - "request_credentials, " - "request_contentpolicytype, " - "request_cache, " - "request_redirect, " - "request_referrer_policy, " - "request_body_id, " - "response_type, " - "response_status, " - "response_status_text, " - "response_headers_guard, " - "response_body_id, " - "response_security_info_id, " - "response_principal_info, " - "cache_id " - "FROM entries;"_ns)); + MOZ_TO_RESULT(aConn.ExecuteSimpleSQL("INSERT INTO new_entries (" + "id, " + "request_method, " + "request_url_no_query, " + "request_url_no_query_hash, " + "request_url_query, " + "request_url_query_hash, " + "request_referrer, " + "request_headers_guard, " + "request_mode, " + "request_credentials, " + "request_contentpolicytype, " + "request_cache, " + "request_redirect, " + "request_referrer_policy, " + "request_body_id, " + "response_type, " + "response_status, " + "response_status_text, " + "response_headers_guard, " + "response_body_id, " + "response_security_info_id, " + "response_principal_info, " + "cache_id " + ") SELECT " + "id, " + "request_method, " + "request_url_no_query, " + "request_url_no_query_hash, " + "request_url_query, " + "request_url_query_hash, " + "request_referrer, " + "request_headers_guard, " + "request_mode, " + "request_credentials, " + "request_contentpolicytype, " + "request_cache, " + "request_redirect, " + "request_referrer_policy, " + "request_body_id, " + "response_type, " + "response_status, " + "response_status_text, " + "response_headers_guard, " + "response_body_id, " + "response_security_info_id, " + "response_principal_info, " + "cache_id " + "FROM entries;"_ns))); // Copy reponse_url to the newly created response_url_list table. QM_TRY( - aConn.ExecuteSimpleSQL("INSERT INTO response_url_list (" - "url, " - "entry_id " - ") SELECT " - "response_url, " - "id " - "FROM entries;"_ns)); + MOZ_TO_RESULT(aConn.ExecuteSimpleSQL("INSERT INTO response_url_list (" + "url, " + "entry_id " + ") SELECT " + "response_url, " + "id " + "FROM entries;"_ns))); // Remove the old table. - QM_TRY(aConn.ExecuteSimpleSQL("DROP TABLE entries;"_ns)); + QM_TRY(MOZ_TO_RESULT(aConn.ExecuteSimpleSQL("DROP TABLE entries;"_ns))); // Rename new_entries to entries. - QM_TRY( - aConn.ExecuteSimpleSQL("ALTER TABLE new_entries RENAME to entries;"_ns)); + QM_TRY(MOZ_TO_RESULT( + aConn.ExecuteSimpleSQL("ALTER TABLE new_entries RENAME to entries;"_ns))); // Now, recreate our indices. - QM_TRY(aConn.ExecuteSimpleSQL(nsLiteralCString(kIndexEntriesRequest))); + QM_TRY(MOZ_TO_RESULT( + aConn.ExecuteSimpleSQL(nsLiteralCString(kIndexEntriesRequest)))); // Revalidate the foreign key constraints, and ensure that there are no // violations. @@ -2707,7 +2743,7 @@ nsresult MigrateFrom20To21(mozIStorageConnection& aConn, bool& aRewriteSchema) { QM_TRY(OkIf(!hasResult), NS_ERROR_FAILURE); - QM_TRY(aConn.SetSchemaVersion(21)); + QM_TRY(MOZ_TO_RESULT(aConn.SetSchemaVersion(21))); aRewriteSchema = true; @@ -2718,14 +2754,14 @@ nsresult MigrateFrom21To22(mozIStorageConnection& aConn, bool& aRewriteSchema) { MOZ_ASSERT(!NS_IsMainThread()); // Add the request_integrity column. - QM_TRY(aConn.ExecuteSimpleSQL( + QM_TRY(MOZ_TO_RESULT(aConn.ExecuteSimpleSQL( "ALTER TABLE entries " - "ADD COLUMN request_integrity TEXT NOT NULL DEFAULT '';"_ns)); + "ADD COLUMN request_integrity TEXT NOT NULL DEFAULT '';"_ns))); - QM_TRY( - aConn.ExecuteSimpleSQL("UPDATE entries SET request_integrity = '';"_ns)); + QM_TRY(MOZ_TO_RESULT( + aConn.ExecuteSimpleSQL("UPDATE entries SET request_integrity = '';"_ns))); - QM_TRY(aConn.SetSchemaVersion(22)); + QM_TRY(MOZ_TO_RESULT(aConn.SetSchemaVersion(22))); aRewriteSchema = true; @@ -2737,7 +2773,7 @@ nsresult MigrateFrom22To23(mozIStorageConnection& aConn, bool& aRewriteSchema) { // The only change between 22 and 23 was a different snappy compression // format, but it's backwards-compatible. - QM_TRY(aConn.SetSchemaVersion(23)); + QM_TRY(MOZ_TO_RESULT(aConn.SetSchemaVersion(23))); return NS_OK; } @@ -2746,11 +2782,11 @@ nsresult MigrateFrom23To24(mozIStorageConnection& aConn, bool& aRewriteSchema) { MOZ_ASSERT(!NS_IsMainThread()); // Add the request_url_fragment column. - QM_TRY(aConn.ExecuteSimpleSQL( + QM_TRY(MOZ_TO_RESULT(aConn.ExecuteSimpleSQL( "ALTER TABLE entries " - "ADD COLUMN request_url_fragment TEXT NOT NULL DEFAULT ''"_ns)); + "ADD COLUMN request_url_fragment TEXT NOT NULL DEFAULT ''"_ns))); - QM_TRY(aConn.SetSchemaVersion(24)); + QM_TRY(MOZ_TO_RESULT(aConn.SetSchemaVersion(24))); aRewriteSchema = true; @@ -2761,7 +2797,7 @@ nsresult MigrateFrom24To25(mozIStorageConnection& aConn, bool& aRewriteSchema) { MOZ_ASSERT(!NS_IsMainThread()); // The only change between 24 and 25 was a new nsIContentPolicy type. - QM_TRY(aConn.SetSchemaVersion(25)); + QM_TRY(MOZ_TO_RESULT(aConn.SetSchemaVersion(25))); return NS_OK; } @@ -2771,16 +2807,16 @@ nsresult MigrateFrom25To26(mozIStorageConnection& aConn, bool& aRewriteSchema) { // Add the response_padding_size column. // Note: only opaque repsonse should be non-null interger. - QM_TRY(aConn.ExecuteSimpleSQL( + QM_TRY(MOZ_TO_RESULT(aConn.ExecuteSimpleSQL( "ALTER TABLE entries " - "ADD COLUMN response_padding_size INTEGER NULL "_ns)); + "ADD COLUMN response_padding_size INTEGER NULL "_ns))); - QM_TRY( + QM_TRY(MOZ_TO_RESULT( aConn.ExecuteSimpleSQL("UPDATE entries SET response_padding_size = 0 " "WHERE response_type = 4"_ns // opaque response - )); + ))); - QM_TRY(aConn.SetSchemaVersion(26)); + QM_TRY(MOZ_TO_RESULT(aConn.SetSchemaVersion(26))); aRewriteSchema = true; @@ -2790,7 +2826,7 @@ nsresult MigrateFrom25To26(mozIStorageConnection& aConn, bool& aRewriteSchema) { nsresult MigrateFrom26To27(mozIStorageConnection& aConn, bool& aRewriteSchema) { MOZ_ASSERT(!NS_IsMainThread()); - QM_TRY(aConn.SetSchemaVersion(kHackyDowngradeSchemaVersion)); + QM_TRY(MOZ_TO_RESULT(aConn.SetSchemaVersion(kHackyDowngradeSchemaVersion))); return NS_OK; } @@ -2802,11 +2838,11 @@ nsresult MigrateFrom27To28(mozIStorageConnection& aConn, bool& aRewriteSchema) { // However, at that time, the default value for the existing rows is NULL // which against the statement in kTableEntries. Thus, we need to have another // upgrade to update these values to an empty string. - QM_TRY( + QM_TRY(MOZ_TO_RESULT( aConn.ExecuteSimpleSQL("UPDATE entries SET request_integrity = '' " - "WHERE request_integrity is NULL;"_ns)); + "WHERE request_integrity is NULL;"_ns))); - QM_TRY(aConn.SetSchemaVersion(28)); + QM_TRY(MOZ_TO_RESULT(aConn.SetSchemaVersion(28))); return NS_OK; } diff --git a/dom/cache/FileUtils.cpp b/dom/cache/FileUtils.cpp index 365b4a61a29e..9165f406f34e 100644 --- a/dom/cache/FileUtils.cpp +++ b/dom/cache/FileUtils.cpp @@ -78,7 +78,7 @@ Result>, 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>, 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>, nsresult> BodyStartWriteStream( do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); nsCOMPtr 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>, 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 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, 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& file) -> Result { - 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 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 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 DirectoryPaddingRestore(nsIFile& aBaseDir, (aMustRestore ? Err(tryTempError) : Result{paddingSize})); - QM_TRY(DirectoryPaddingDeleteFile(aBaseDir, DirPaddingFile::TMP_FILE)); + QM_TRY(MOZ_TO_RESULT( + DirectoryPaddingDeleteFile(aBaseDir, DirPaddingFile::TMP_FILE))); return paddingSize; } diff --git a/dom/cache/FileUtilsImpl.h b/dom/cache/FileUtilsImpl.h index 1564cfc272d9..5f385ca4dbfb 100644 --- a/dom/cache/FileUtilsImpl.h +++ b/dom/cache/FileUtilsImpl.h @@ -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. diff --git a/dom/cache/Manager.cpp b/dom/cache/Manager.cpp index 478161344736..32af12ec0c46 100644 --- a/dom/cache/Manager.cpp +++ b/dom/cache/Manager.cpp @@ -61,8 +61,8 @@ nsresult MaybeUpdatePaddingFile(nsIFile* aBaseDir, mozIStorageConnection* aConn, RefPtr 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 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; diff --git a/dom/cache/QuotaClient.cpp b/dom/cache/QuotaClient.cpp index 7a25c037a3e1..38f50e83b7aa 100644 --- a/dom/cache/QuotaClient.cpp +++ b/dom/cache/QuotaClient.cpp @@ -145,7 +145,7 @@ Result 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 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 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{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::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::Get(); MOZ_DIAGNOSTIC_ASSERT(cacheQuotaClient); - QM_TRY(cacheQuotaClient->WipePaddingFileInternal(aQuotaInfo, aBaseDir)); + QM_TRY(MOZ_TO_RESULT( + cacheQuotaClient->WipePaddingFileInternal(aQuotaInfo, aBaseDir))); return NS_OK; } diff --git a/dom/cache/QuotaClientImpl.h b/dom/cache/QuotaClientImpl.h index 6c6d77d1fe81..b45c8e868a1e 100644 --- a/dom/cache/QuotaClientImpl.h +++ b/dom/cache/QuotaClientImpl.h @@ -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) {