diff --git a/dom/cache/Action.h b/dom/cache/Action.h index 35c37da4ee0d..721d89a3ba1d 100644 --- a/dom/cache/Action.h +++ b/dom/cache/Action.h @@ -56,7 +56,7 @@ class Action : public SafeRefCounted { // Note: The "target" thread is determined when the Action is scheduled on // Context. The Action should not assume any particular thread is used. virtual void RunOnTarget(SafeRefPtr aResolver, - const QuotaInfo& aQuotaInfo, + const ClientMetadata& aClientMetadata, Data* aOptionalData) = 0; // Called on initiating thread when the Action is canceled. The Action is diff --git a/dom/cache/Context.cpp b/dom/cache/Context.cpp index 9be0f329445a..6568dc09c99f 100644 --- a/dom/cache/Context.cpp +++ b/dom/cache/Context.cpp @@ -25,14 +25,14 @@ namespace { using mozilla::dom::cache::Action; -using mozilla::dom::cache::QuotaInfo; +using mozilla::dom::cache::ClientMetadata; class NullAction final : public Action { public: NullAction() = default; virtual void RunOnTarget(mozilla::SafeRefPtr aResolver, - const QuotaInfo&, Data*) override { + const ClientMetadata&, Data*) override { // Resolve success immediately. This Action does no actual work. MOZ_DIAGNOSTIC_ASSERT(aResolver); aResolver->Resolve(NS_OK); @@ -215,7 +215,7 @@ class Context::QuotaInitRunnable final : public nsIRunnable, SafeRefPtr mInitAction; nsCOMPtr mInitiatingEventTarget; nsresult mResult; - QuotaInfo mQuotaInfo; + ClientMetadata mClientMetadata; RefPtr mDirectoryLock; State mState; Atomic mCanceled; @@ -233,7 +233,7 @@ void Context::QuotaInitRunnable::OpenDirectory() { RefPtr directoryLock = QuotaManager::Get()->CreateDirectoryLock( - PERSISTENCE_TYPE_DEFAULT, mQuotaInfo, quota::Client::DOMCACHE, + PERSISTENCE_TYPE_DEFAULT, mClientMetadata, quota::Client::DOMCACHE, /* aExclusive */ false); // DirectoryLock::Acquire() will hold a reference to us as a listener. We will @@ -252,7 +252,7 @@ void Context::QuotaInitRunnable::DirectoryLockAcquired(DirectoryLock* aLock) { mDirectoryLock = aLock; MOZ_DIAGNOSTIC_ASSERT(mDirectoryLock->Id() >= 0); - mQuotaInfo.mDirectoryLockId = mDirectoryLock->Id(); + mClientMetadata.mDirectoryLockId = mDirectoryLock->Id(); if (mCanceled) { Complete(NS_ERROR_ABORT); @@ -352,7 +352,7 @@ Context::QuotaInitRunnable::Run() { QM_TRY_UNWRAP(auto principalMetadata, QuotaManager::GetInfoFromPrincipal(principal)); - static_cast(mQuotaInfo) = { + static_cast(mClientMetadata) = { std::move(principalMetadata), PERSISTENCE_TYPE_DEFAULT}; mState = STATE_CREATE_QUOTA_MANAGER; @@ -416,10 +416,10 @@ Context::QuotaInitRunnable::Run() { QM_TRY( MOZ_TO_RESULT(quotaManager->EnsureTemporaryStorageIsInitialized())); - QM_TRY_UNWRAP(mQuotaInfo.mDir, + QM_TRY_UNWRAP(mClientMetadata.mDir, quotaManager ->EnsureTemporaryOriginIsInitialized( - PERSISTENCE_TYPE_DEFAULT, mQuotaInfo) + PERSISTENCE_TYPE_DEFAULT, mClientMetadata) .map([](const auto& res) { return res.first; })); mState = STATE_RUN_ON_TARGET; @@ -444,7 +444,7 @@ Context::QuotaInitRunnable::Run() { // Execute the provided initialization Action. The Action must Resolve() // before returning. - mInitAction->RunOnTarget(resolver.clonePtr(), mQuotaInfo, mData); + mInitAction->RunOnTarget(resolver.clonePtr(), mClientMetadata, mData); MOZ_DIAGNOSTIC_ASSERT(resolver->Resolved()); mData = nullptr; @@ -453,7 +453,7 @@ Context::QuotaInitRunnable::Run() { // the marker file. If it wasn't opened successfully, then no need to // create a marker file anyway. if (NS_SUCCEEDED(resolver->Result())) { - MOZ_ALWAYS_SUCCEEDS(CreateMarkerFile(mQuotaInfo)); + MOZ_ALWAYS_SUCCEEDS(CreateMarkerFile(mClientMetadata)); } break; @@ -462,7 +462,7 @@ Context::QuotaInitRunnable::Run() { case STATE_COMPLETING: { NS_ASSERT_OWNINGTHREAD(QuotaInitRunnable); mInitAction->CompleteOnInitiatingThread(mResult); - mContext->OnQuotaInit(mResult, mQuotaInfo, mDirectoryLock.forget()); + mContext->OnQuotaInit(mResult, mClientMetadata, mDirectoryLock.forget()); mState = STATE_COMPLETE; // Explicitly cleanup here as the destructor could fire on any of @@ -493,12 +493,12 @@ class Context::ActionRunnable final : public nsIRunnable, public: ActionRunnable(SafeRefPtr aContext, Data* aData, nsISerialEventTarget* aTarget, SafeRefPtr aAction, - const QuotaInfo& aQuotaInfo) + const ClientMetadata& aClientMetadata) : mContext(std::move(aContext)), mData(aData), mTarget(aTarget), mAction(std::move(aAction)), - mQuotaInfo(aQuotaInfo), + mClientMetadata(aClientMetadata), mInitiatingThread(GetCurrentEventTarget()), mState(STATE_INIT), mResult(NS_OK), @@ -507,7 +507,7 @@ class Context::ActionRunnable final : public nsIRunnable, // mData may be nullptr MOZ_DIAGNOSTIC_ASSERT(mTarget); MOZ_DIAGNOSTIC_ASSERT(mAction); - // mQuotaInfo.mDir may be nullptr if QuotaInitRunnable failed + // mClientMetadata.mDir may be nullptr if QuotaInitRunnable failed MOZ_DIAGNOSTIC_ASSERT(mInitiatingThread); } @@ -587,7 +587,7 @@ class Context::ActionRunnable final : public nsIRunnable, RefPtr mData; nsCOMPtr mTarget; SafeRefPtr mAction; - const QuotaInfo mQuotaInfo; + const ClientMetadata mClientMetadata; nsCOMPtr mInitiatingThread; State mState; nsresult mResult; @@ -649,7 +649,7 @@ Context::ActionRunnable::Run() { mExecutingRunOnTarget = true; mState = STATE_RUNNING; - mAction->RunOnTarget(SafeRefPtrFromThis(), mQuotaInfo, mData); + mAction->RunOnTarget(SafeRefPtrFromThis(), mClientMetadata, mData); mData = nullptr; @@ -921,8 +921,8 @@ Context::~Context() { // Note, this may set the mOrphanedData flag. mManager->RemoveContext(*this); - if (mQuotaInfo.mDir && !mOrphanedData) { - MOZ_ALWAYS_SUCCEEDS(DeleteMarkerFile(mQuotaInfo)); + if (mClientMetadata.mDir && !mOrphanedData) { + MOZ_ALWAYS_SUCCEEDS(DeleteMarkerFile(mClientMetadata)); } if (mNextContext) { @@ -977,8 +977,9 @@ void Context::Start() { void Context::DispatchAction(SafeRefPtr aAction, bool aDoomData) { NS_ASSERT_OWNINGTHREAD(Context); - auto runnable = MakeSafeRefPtr( - SafeRefPtrFromThis(), mData, mTarget, std::move(aAction), mQuotaInfo); + auto runnable = + MakeSafeRefPtr(SafeRefPtrFromThis(), mData, mTarget, + std::move(aAction), mClientMetadata); if (aDoomData) { mData = nullptr; @@ -993,14 +994,14 @@ void Context::DispatchAction(SafeRefPtr aAction, bool aDoomData) { AddActivity(*runnable); } -void Context::OnQuotaInit(nsresult aRv, const QuotaInfo& aQuotaInfo, +void Context::OnQuotaInit(nsresult aRv, const ClientMetadata& aClientMetadata, already_AddRefed aDirectoryLock) { NS_ASSERT_OWNINGTHREAD(Context); MOZ_DIAGNOSTIC_ASSERT(mInitRunnable); mInitRunnable = nullptr; - mQuotaInfo = aQuotaInfo; + mClientMetadata = aClientMetadata; // Always save the directory lock to ensure QuotaManager does not shutdown // before the Context has gone away. diff --git a/dom/cache/Context.h b/dom/cache/Context.h index f4b83ff95e08..89c9a326f306 100644 --- a/dom/cache/Context.h +++ b/dom/cache/Context.h @@ -152,7 +152,7 @@ class Context final : public SafeRefCounted { void AddActivity(Activity& aActivity); void RemoveActivity(Activity& aActivity); - const QuotaInfo& GetQuotaInfo() const { return mQuotaInfo; } + const ClientMetadata& GetClientMetadata() const { return mClientMetadata; } // Tell the Context that some state information has been orphaned in the // data store and won't be cleaned up. The Context will leave the marker @@ -179,7 +179,7 @@ class Context final : public SafeRefCounted { void Init(Maybe aOldContext); void Start(); void DispatchAction(SafeRefPtr aAction, bool aDoomData = false); - void OnQuotaInit(nsresult aRv, const QuotaInfo& aQuotaInfo, + void OnQuotaInit(nsresult aRv, const ClientMetadata& aClientMetadata, already_AddRefed aDirectoryLock); SafeRefPtr CreateThreadsafeHandle(); @@ -193,7 +193,7 @@ class Context final : public SafeRefCounted { RefPtr mData; State mState; bool mOrphanedData; - QuotaInfo mQuotaInfo; + ClientMetadata mClientMetadata; RefPtr mInitRunnable; SafeRefPtr mInitAction; nsTArray mPendingActions; diff --git a/dom/cache/DBAction.cpp b/dom/cache/DBAction.cpp index 111e85c9629c..07ac9cf48714 100644 --- a/dom/cache/DBAction.cpp +++ b/dom/cache/DBAction.cpp @@ -32,19 +32,19 @@ using mozilla::dom::quota::PersistenceType; namespace { -nsresult WipeDatabase(const QuotaInfo& aQuotaInfo, nsIFile& aDBFile) { +nsresult WipeDatabase(const ClientMetadata& aClientMetadata, nsIFile& aDBFile) { QM_TRY_INSPECT(const auto& dbDir, MOZ_TO_RESULT_INVOKE_TYPED( nsCOMPtr, aDBFile, GetParent)); - QM_TRY(MOZ_TO_RESULT(RemoveNsIFile(aQuotaInfo, aDBFile))); + QM_TRY(MOZ_TO_RESULT(RemoveNsIFile(aClientMetadata, 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(MOZ_TO_RESULT(BodyDeleteDir(aQuotaInfo, *dbDir))); + QM_TRY(MOZ_TO_RESULT(BodyDeleteDir(aClientMetadata, *dbDir))); - QM_TRY(MOZ_TO_RESULT(WipePaddingFile(aQuotaInfo, dbDir))); + QM_TRY(MOZ_TO_RESULT(WipePaddingFile(aClientMetadata, dbDir))); return NS_OK; } @@ -56,10 +56,11 @@ DBAction::DBAction(Mode aMode) : mMode(aMode) {} DBAction::~DBAction() = default; void DBAction::RunOnTarget(SafeRefPtr aResolver, - const QuotaInfo& aQuotaInfo, Data* aOptionalData) { + const ClientMetadata& aClientMetadata, + Data* aOptionalData) { MOZ_ASSERT(!NS_IsMainThread()); MOZ_DIAGNOSTIC_ASSERT(aResolver); - MOZ_DIAGNOSTIC_ASSERT(aQuotaInfo.mDir); + MOZ_DIAGNOSTIC_ASSERT(aClientMetadata.mDir); if (IsCanceled()) { aResolver->Resolve(NS_ERROR_ABORT); @@ -71,8 +72,8 @@ void DBAction::RunOnTarget(SafeRefPtr aResolver, }; QM_TRY_INSPECT(const auto& dbDir, - CloneFileAndAppend(*aQuotaInfo.mDir, u"cache"_ns), QM_VOID, - resolveErr); + CloneFileAndAppend(*aClientMetadata.mDir, u"cache"_ns), + QM_VOID, resolveErr); nsCOMPtr conn; @@ -83,7 +84,7 @@ void DBAction::RunOnTarget(SafeRefPtr aResolver, // If there is no previous Action, then we must open one. if (!conn) { - QM_TRY_UNWRAP(conn, OpenConnection(aQuotaInfo, *dbDir), QM_VOID, + QM_TRY_UNWRAP(conn, OpenConnection(aClientMetadata, *dbDir), QM_VOID, resolveErr); MOZ_DIAGNOSTIC_ASSERT(conn); @@ -99,13 +100,13 @@ void DBAction::RunOnTarget(SafeRefPtr aResolver, } } - RunWithDBOnTarget(std::move(aResolver), aQuotaInfo, dbDir, conn); + RunWithDBOnTarget(std::move(aResolver), aClientMetadata, dbDir, conn); } Result, nsresult> DBAction::OpenConnection( - const QuotaInfo& aQuotaInfo, nsIFile& aDBDir) { + const ClientMetadata& aClientMetadata, nsIFile& aDBDir) { MOZ_ASSERT(!NS_IsMainThread()); - MOZ_DIAGNOSTIC_ASSERT(aQuotaInfo.mDirectoryLockId >= 0); + MOZ_DIAGNOSTIC_ASSERT(aClientMetadata.mDirectoryLockId >= 0); QM_TRY_INSPECT(const bool& exists, MOZ_TO_RESULT_INVOKE(aDBDir, Exists)); @@ -117,7 +118,7 @@ Result, nsresult> DBAction::OpenConnection( QM_TRY_INSPECT(const auto& dbFile, CloneFileAndAppend(aDBDir, kCachesSQLiteFilename)); - QM_TRY_RETURN(OpenDBConnection(aQuotaInfo, *dbFile)); + QM_TRY_RETURN(OpenDBConnection(aClientMetadata, *dbFile)); } SyncDBAction::SyncDBAction(Mode aMode) : DBAction(aMode) {} @@ -125,7 +126,7 @@ SyncDBAction::SyncDBAction(Mode aMode) : DBAction(aMode) {} SyncDBAction::~SyncDBAction() = default; void SyncDBAction::RunWithDBOnTarget(SafeRefPtr aResolver, - const QuotaInfo& aQuotaInfo, + const ClientMetadata& aClientMetadata, nsIFile* aDBDir, mozIStorageConnection* aConn) { MOZ_ASSERT(!NS_IsMainThread()); @@ -133,14 +134,14 @@ void SyncDBAction::RunWithDBOnTarget(SafeRefPtr aResolver, MOZ_DIAGNOSTIC_ASSERT(aDBDir); MOZ_DIAGNOSTIC_ASSERT(aConn); - nsresult rv = RunSyncWithDBOnTarget(aQuotaInfo, aDBDir, aConn); + nsresult rv = RunSyncWithDBOnTarget(aClientMetadata, aDBDir, aConn); aResolver->Resolve(rv); } Result, nsresult> OpenDBConnection( - const QuotaInfo& aQuotaInfo, nsIFile& aDBFile) { + const ClientMetadata& aClientMetadata, nsIFile& aDBFile) { MOZ_ASSERT(!NS_IsMainThread()); - MOZ_DIAGNOSTIC_ASSERT(aQuotaInfo.mDirectoryLockId >= -1); + MOZ_DIAGNOSTIC_ASSERT(aClientMetadata.mDirectoryLockId >= -1); // Use our default file:// protocol handler directly to construct the database // URL. This avoids any problems if a plugin registers a custom file:// @@ -154,8 +155,9 @@ Result, nsresult> OpenDBConnection( NewFileURIMutator, &aDBFile)); const nsCString directoryLockIdClause = - aQuotaInfo.mDirectoryLockId >= 0 - ? "&directoryLockId="_ns + IntToCString(aQuotaInfo.mDirectoryLockId) + aClientMetadata.mDirectoryLockId >= 0 + ? "&directoryLockId="_ns + + IntToCString(aClientMetadata.mDirectoryLockId) : EmptyCString(); nsCOMPtr dbFileUrl; @@ -179,14 +181,14 @@ Result, nsresult> OpenDBConnection( // Predicate. IsDatabaseCorruptionError, // Fallback. - ([&aQuotaInfo, &aDBFile, &storageService, + ([&aClientMetadata, &aDBFile, &storageService, &dbFileUrl](const nsresult rv) -> Result, nsresult> { NS_WARNING("Cache database corrupted. Recreating empty database."); // There is nothing else we can do to recover. Also, this data // can be deleted by QuotaManager at any time anyways. - QM_TRY(MOZ_TO_RESULT(WipeDatabase(aQuotaInfo, aDBFile))); + QM_TRY(MOZ_TO_RESULT(WipeDatabase(aClientMetadata, aDBFile))); QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_TYPED( nsCOMPtr, storageService, @@ -200,7 +202,7 @@ Result, nsresult> OpenDBConnection( // Close existing connection before wiping database. conn = nullptr; - QM_TRY(MOZ_TO_RESULT(WipeDatabase(aQuotaInfo, aDBFile))); + QM_TRY(MOZ_TO_RESULT(WipeDatabase(aClientMetadata, aDBFile))); QM_TRY_UNWRAP(conn, MOZ_TO_RESULT_INVOKE_TYPED( nsCOMPtr, storageService, diff --git a/dom/cache/DBAction.h b/dom/cache/DBAction.h index 7e3c2811e25c..e5c6886f0e79 100644 --- a/dom/cache/DBAction.h +++ b/dom/cache/DBAction.h @@ -19,7 +19,7 @@ namespace dom { namespace cache { Result, nsresult> OpenDBConnection( - const QuotaInfo& aQuotaInfo, nsIFile& aDBFile); + const ClientMetadata& aClientMetadata, nsIFile& aDBFile); class DBAction : public Action { protected: @@ -36,15 +36,17 @@ class DBAction : public Action { // ref the DB connection. The connection can only be referenced from the // target thread and must be released upon resolve. virtual void RunWithDBOnTarget(SafeRefPtr aResolver, - const QuotaInfo& aQuotaInfo, nsIFile* aDBDir, + const ClientMetadata& aClientMetadata, + nsIFile* aDBDir, mozIStorageConnection* aConn) = 0; private: - void RunOnTarget(SafeRefPtr aResolver, const QuotaInfo& aQuotaInfo, + void RunOnTarget(SafeRefPtr aResolver, + const ClientMetadata& aClientMetadata, Data* aOptionalData) override; Result, nsresult> OpenConnection( - const QuotaInfo& aQuotaInfo, nsIFile& aDBDir); + const ClientMetadata& aClientMetadata, nsIFile& aDBDir); const Mode mMode; }; @@ -56,13 +58,14 @@ class SyncDBAction : public DBAction { // Action objects are deleted through their base pointer virtual ~SyncDBAction(); - virtual nsresult RunSyncWithDBOnTarget(const QuotaInfo& aQuotaInfo, + virtual nsresult RunSyncWithDBOnTarget(const ClientMetadata& aClientMetadata, nsIFile* aDBDir, mozIStorageConnection* aConn) = 0; private: virtual void RunWithDBOnTarget(SafeRefPtr aResolver, - const QuotaInfo& aQuotaInfo, nsIFile* aDBDir, + const ClientMetadata& aClientMetadata, + nsIFile* aDBDir, mozIStorageConnection* aConn) override; }; diff --git a/dom/cache/FileUtils.cpp b/dom/cache/FileUtils.cpp index 9a4b6882a860..3948f8341cb7 100644 --- a/dom/cache/FileUtils.cpp +++ b/dom/cache/FileUtils.cpp @@ -116,18 +116,19 @@ nsresult BodyCreateDir(nsIFile& aBaseDir) { return NS_OK; } -nsresult BodyDeleteDir(const QuotaInfo& aQuotaInfo, nsIFile& aBaseDir) { +nsresult BodyDeleteDir(const ClientMetadata& aClientMetadata, + nsIFile& aBaseDir) { QM_TRY_INSPECT(const auto& bodyDir, CloneFileAndAppend(aBaseDir, kMorgueDirectory)); - QM_TRY(MOZ_TO_RESULT(RemoveNsIFileRecursively(aQuotaInfo, *bodyDir))); + QM_TRY(MOZ_TO_RESULT(RemoveNsIFileRecursively(aClientMetadata, *bodyDir))); return NS_OK; } Result>, nsresult> BodyStartWriteStream( - const QuotaInfo& aQuotaInfo, nsIFile& aBaseDir, nsIInputStream& aSource, - void* aClosure, nsAsyncCopyCallbackFun aCallback) { + const ClientMetadata& aClientMetadata, nsIFile& aBaseDir, + nsIInputStream& aSource, void* aClosure, nsAsyncCopyCallbackFun aCallback) { MOZ_DIAGNOSTIC_ASSERT(aClosure); MOZ_DIAGNOSTIC_ASSERT(aCallback); @@ -152,9 +153,10 @@ Result>, nsresult> BodyStartWriteStream( QM_TRY_INSPECT(const auto& tmpFile, BodyIdToFile(aBaseDir, id, BODY_FILE_TMP)); - QM_TRY_INSPECT(const auto& fileStream, - CreateFileOutputStream(PERSISTENCE_TYPE_DEFAULT, aQuotaInfo, - Client::DOMCACHE, tmpFile.get())); + QM_TRY_INSPECT( + const auto& fileStream, + CreateFileOutputStream(PERSISTENCE_TYPE_DEFAULT, aClientMetadata, + Client::DOMCACHE, tmpFile.get())); const auto compressed = MakeRefPtr(fileStream.get()); @@ -199,11 +201,11 @@ nsresult BodyFinalizeWrite(nsIFile& aBaseDir, const nsID& aId) { } Result>, nsresult> BodyOpen( - const QuotaInfo& aQuotaInfo, nsIFile& aBaseDir, const nsID& aId) { + const ClientMetadata& aClientMetadata, nsIFile& aBaseDir, const nsID& aId) { QM_TRY_INSPECT(const auto& finalFile, BodyIdToFile(aBaseDir, aId, BODY_FILE_FINAL)); - QM_TRY_RETURN(CreateFileInputStream(PERSISTENCE_TYPE_DEFAULT, aQuotaInfo, + QM_TRY_RETURN(CreateFileInputStream(PERSISTENCE_TYPE_DEFAULT, aClientMetadata, Client::DOMCACHE, finalFile.get()) .map([](NotNull>&& stream) { return WrapNotNullUnchecked( @@ -211,7 +213,7 @@ Result>, nsresult> BodyOpen( })); } -nsresult BodyMaybeUpdatePaddingSize(const QuotaInfo& aQuotaInfo, +nsresult BodyMaybeUpdatePaddingSize(const ClientMetadata& aClientMetadata, nsIFile& aBaseDir, const nsID& aId, const uint32_t aPaddingInfo, int64_t* aPaddingSizeInOut) { @@ -225,8 +227,8 @@ nsresult BodyMaybeUpdatePaddingSize(const QuotaInfo& aQuotaInfo, int64_t fileSize = 0; RefPtr quotaObject = quotaManager->GetQuotaObject( - PERSISTENCE_TYPE_DEFAULT, aQuotaInfo, Client::DOMCACHE, bodyFile.get(), - -1, &fileSize); + PERSISTENCE_TYPE_DEFAULT, aClientMetadata, Client::DOMCACHE, + bodyFile.get(), -1, &fileSize); MOZ_DIAGNOSTIC_ASSERT(quotaObject); MOZ_DIAGNOSTIC_ASSERT(fileSize >= 0); // XXXtt: bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1422815 @@ -247,35 +249,35 @@ nsresult BodyMaybeUpdatePaddingSize(const QuotaInfo& aQuotaInfo, return NS_OK; } -nsresult BodyDeleteFiles(const QuotaInfo& aQuotaInfo, nsIFile& aBaseDir, - const nsTArray& aIdList) { +nsresult BodyDeleteFiles(const ClientMetadata& aClientMetadata, + nsIFile& aBaseDir, const nsTArray& aIdList) { for (const auto id : aIdList) { QM_TRY_INSPECT(const auto& bodyDir, BodyGetCacheDir(aBaseDir, id)); const auto removeFileForId = - [&aQuotaInfo, &id]( + [&aClientMetadata, &id]( nsIFile& bodyFile, const nsACString& leafName) -> Result { nsID fileId; QM_TRY(OkIf(fileId.Parse(leafName.BeginReading())), true, - ([&aQuotaInfo, &bodyFile](const auto) { - DebugOnly result = - RemoveNsIFile(aQuotaInfo, bodyFile, /* aTrackQuota */ false); + ([&aClientMetadata, &bodyFile](const auto) { + DebugOnly result = RemoveNsIFile( + aClientMetadata, bodyFile, /* aTrackQuota */ false); MOZ_ASSERT(NS_SUCCEEDED(result)); })); if (id.Equals(fileId)) { - DebugOnly result = RemoveNsIFile(aQuotaInfo, bodyFile); + DebugOnly result = RemoveNsIFile(aClientMetadata, bodyFile); MOZ_ASSERT(NS_SUCCEEDED(result)); return true; } return false; }; - QM_TRY( - MOZ_TO_RESULT(BodyTraverseFiles(aQuotaInfo, *bodyDir, removeFileForId, - /* aCanRemoveFiles */ false, - /* aTrackQuota */ true))); + QM_TRY(MOZ_TO_RESULT(BodyTraverseFiles(aClientMetadata, *bodyDir, + removeFileForId, + /* aCanRemoveFiles */ false, + /* aTrackQuota */ true))); } return NS_OK; @@ -344,7 +346,8 @@ nsresult DirectoryPaddingWrite(nsIFile& aBaseDir, } // namespace -nsresult BodyDeleteOrphanedFiles(const QuotaInfo& aQuotaInfo, nsIFile& aBaseDir, +nsresult BodyDeleteOrphanedFiles(const ClientMetadata& aClientMetadata, + nsIFile& aBaseDir, const nsTArray& aKnownBodyIdList) { // body files are stored in a directory structure like: // @@ -357,21 +360,21 @@ nsresult BodyDeleteOrphanedFiles(const QuotaInfo& aQuotaInfo, nsIFile& aBaseDir, // Iterate over all the intermediate morgue subdirs QM_TRY(quota::CollectEachFile( *dir, - [&aQuotaInfo, &aKnownBodyIdList]( + [&aClientMetadata, &aKnownBodyIdList]( const nsCOMPtr& subdir) -> Result { QM_TRY_INSPECT(const auto& dirEntryKind, GetDirEntryKind(*subdir)); switch (dirEntryKind) { case nsIFileKind::ExistsAsDirectory: { const auto removeOrphanedFiles = - [&aQuotaInfo, &aKnownBodyIdList]( + [&aClientMetadata, &aKnownBodyIdList]( nsIFile& bodyFile, const nsACString& leafName) -> Result { // Finally, parse the uuid out of the name. If it fails to parse, // then ignore the file. - auto cleanup = MakeScopeExit([&aQuotaInfo, &bodyFile] { + auto cleanup = MakeScopeExit([&aClientMetadata, &bodyFile] { DebugOnly result = - RemoveNsIFile(aQuotaInfo, bodyFile); + RemoveNsIFile(aClientMetadata, bodyFile); MOZ_ASSERT(NS_SUCCEEDED(result)); }); @@ -392,7 +395,7 @@ nsresult BodyDeleteOrphanedFiles(const QuotaInfo& aQuotaInfo, nsIFile& aBaseDir, // a warning in the reports is not desired). QM_TRY(QM_OR_ELSE_LOG_VERBOSE_IF( // Expression. - MOZ_TO_RESULT(BodyTraverseFiles(aQuotaInfo, *subdir, + MOZ_TO_RESULT(BodyTraverseFiles(aClientMetadata, *subdir, removeOrphanedFiles, /* aCanRemoveFiles */ true, /* aTrackQuota */ true)), @@ -406,8 +409,8 @@ nsresult BodyDeleteOrphanedFiles(const QuotaInfo& aQuotaInfo, nsIFile& aBaseDir, case nsIFileKind::ExistsAsFile: { // If a file got in here somehow, try to remove it and move on - DebugOnly result = - RemoveNsIFile(aQuotaInfo, *subdir, /* aTrackQuota */ false); + DebugOnly result = RemoveNsIFile(aClientMetadata, *subdir, + /* aTrackQuota */ false); MOZ_ASSERT(NS_SUCCEEDED(result)); break; } @@ -426,8 +429,9 @@ nsresult BodyDeleteOrphanedFiles(const QuotaInfo& aQuotaInfo, nsIFile& aBaseDir, namespace { Result, nsresult> GetMarkerFileHandle( - const QuotaInfo& aQuotaInfo) { - QM_TRY_UNWRAP(auto marker, CloneFileAndAppend(*aQuotaInfo.mDir, u"cache"_ns)); + const ClientMetadata& aClientMetadata) { + QM_TRY_UNWRAP(auto marker, + CloneFileAndAppend(*aClientMetadata.mDir, u"cache"_ns)); QM_TRY(MOZ_TO_RESULT(marker->Append(u"context_open.marker"_ns))); @@ -436,8 +440,8 @@ Result, nsresult> GetMarkerFileHandle( } // namespace -nsresult CreateMarkerFile(const QuotaInfo& aQuotaInfo) { - QM_TRY_INSPECT(const auto& marker, GetMarkerFileHandle(aQuotaInfo)); +nsresult CreateMarkerFile(const ClientMetadata& aClientMetadata) { + QM_TRY_INSPECT(const auto& marker, GetMarkerFileHandle(aClientMetadata)); // Callers call this function without checking if the file already exists // (idempotent usage). QM_OR_ELSE_WARN_IF is not used here since we just want @@ -470,11 +474,11 @@ nsresult CreateMarkerFile(const QuotaInfo& aQuotaInfo) { return NS_OK; } -nsresult DeleteMarkerFile(const QuotaInfo& aQuotaInfo) { - QM_TRY_INSPECT(const auto& marker, GetMarkerFileHandle(aQuotaInfo)); +nsresult DeleteMarkerFile(const ClientMetadata& aClientMetadata) { + QM_TRY_INSPECT(const auto& marker, GetMarkerFileHandle(aClientMetadata)); DebugOnly result = - RemoveNsIFile(aQuotaInfo, *marker, /* aTrackQuota */ false); + RemoveNsIFile(aClientMetadata, *marker, /* aTrackQuota */ false); MOZ_ASSERT(NS_SUCCEEDED(result)); // Again, no fsync is necessary. If the OS crashes before the file @@ -485,14 +489,15 @@ nsresult DeleteMarkerFile(const QuotaInfo& aQuotaInfo) { return NS_OK; } -bool MarkerFileExists(const QuotaInfo& aQuotaInfo) { - QM_TRY_INSPECT(const auto& marker, GetMarkerFileHandle(aQuotaInfo), false); +bool MarkerFileExists(const ClientMetadata& aClientMetadata) { + QM_TRY_INSPECT(const auto& marker, GetMarkerFileHandle(aClientMetadata), + false); QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE(marker, Exists), false); } -nsresult RemoveNsIFileRecursively(const QuotaInfo& aQuotaInfo, nsIFile& aFile, - const bool aTrackQuota) { +nsresult RemoveNsIFileRecursively(const ClientMetadata& aClientMetadata, + nsIFile& aFile, const bool aTrackQuota) { QM_TRY_INSPECT(const auto& dirEntryKind, GetDirEntryKind(aFile)); switch (dirEntryKind) { @@ -502,10 +507,10 @@ nsresult RemoveNsIFileRecursively(const QuotaInfo& aQuotaInfo, nsIFile& aFile, // one to update their usages to the QuotaManager. QM_TRY(quota::CollectEachFile( aFile, - [&aQuotaInfo, &aTrackQuota]( + [&aClientMetadata, &aTrackQuota]( const nsCOMPtr& file) -> Result { QM_TRY(MOZ_TO_RESULT( - RemoveNsIFileRecursively(aQuotaInfo, *file, aTrackQuota))); + RemoveNsIFileRecursively(aClientMetadata, *file, aTrackQuota))); return Ok{}; })); @@ -516,7 +521,7 @@ nsresult RemoveNsIFileRecursively(const QuotaInfo& aQuotaInfo, nsIFile& aFile, break; case nsIFileKind::ExistsAsFile: - return RemoveNsIFile(aQuotaInfo, aFile, aTrackQuota); + return RemoveNsIFile(aClientMetadata, aFile, aTrackQuota); case nsIFileKind::DoesNotExist: // Ignore files that got removed externally while iterating. @@ -526,7 +531,7 @@ nsresult RemoveNsIFileRecursively(const QuotaInfo& aQuotaInfo, nsIFile& aFile, return NS_OK; } -nsresult RemoveNsIFile(const QuotaInfo& aQuotaInfo, nsIFile& aFile, +nsresult RemoveNsIFile(const ClientMetadata& aClientMetadata, nsIFile& aFile, const bool aTrackQuota) { int64_t fileSize = 0; if (aTrackQuota) { @@ -557,21 +562,21 @@ nsresult RemoveNsIFile(const QuotaInfo& aQuotaInfo, nsIFile& aFile, if (fileSize > 0) { MOZ_ASSERT(aTrackQuota); - DecreaseUsageForQuotaInfo(aQuotaInfo, fileSize); + DecreaseUsageForClientMetadata(aClientMetadata, fileSize); } return NS_OK; } -void DecreaseUsageForQuotaInfo(const QuotaInfo& aQuotaInfo, - const int64_t aUpdatingSize) { +void DecreaseUsageForClientMetadata(const ClientMetadata& aClientMetadata, + const int64_t aUpdatingSize) { MOZ_DIAGNOSTIC_ASSERT(aUpdatingSize > 0); QuotaManager* quotaManager = QuotaManager::Get(); MOZ_DIAGNOSTIC_ASSERT(quotaManager); quotaManager->DecreaseUsageForClient( - quota::ClientMetadata{aQuotaInfo, Client::DOMCACHE}, aUpdatingSize); + quota::ClientMetadata{aClientMetadata, Client::DOMCACHE}, aUpdatingSize); } bool DirectoryPaddingFileExists(nsIFile& aBaseDir, diff --git a/dom/cache/FileUtils.h b/dom/cache/FileUtils.h index 0b8c117def86..37274d207cc9 100644 --- a/dom/cache/FileUtils.h +++ b/dom/cache/FileUtils.h @@ -31,30 +31,32 @@ nsresult BodyCreateDir(nsIFile& aBaseDir); // Note that this function can only be used during the initialization of the // database. We're unlikely to be able to delete the DB successfully past // that point due to the file being in use. -nsresult BodyDeleteDir(const QuotaInfo& aQuotaInfo, nsIFile& aBaseDir); +nsresult BodyDeleteDir(const ClientMetadata& aClientMetadata, + nsIFile& aBaseDir); // Returns a Result with a success value with the body id and, optionally, the // copy context. Result>, nsresult> BodyStartWriteStream( - const QuotaInfo& aQuotaInfo, nsIFile& aBaseDir, nsIInputStream& aSource, - void* aClosure, nsAsyncCopyCallbackFun aCallback); + const ClientMetadata& aClientMetadata, nsIFile& aBaseDir, + nsIInputStream& aSource, void* aClosure, nsAsyncCopyCallbackFun aCallback); void BodyCancelWrite(nsISupports& aCopyContext); nsresult BodyFinalizeWrite(nsIFile& aBaseDir, const nsID& aId); Result>, nsresult> BodyOpen( - const QuotaInfo& aQuotaInfo, nsIFile& aBaseDir, const nsID& aId); + const ClientMetadata& aClientMetadata, nsIFile& aBaseDir, const nsID& aId); -nsresult BodyMaybeUpdatePaddingSize(const QuotaInfo& aQuotaInfo, +nsresult BodyMaybeUpdatePaddingSize(const ClientMetadata& aClientMetadata, nsIFile& aBaseDir, const nsID& aId, uint32_t aPaddingInfo, int64_t* aPaddingSizeInOut); -nsresult BodyDeleteFiles(const QuotaInfo& aQuotaInfo, nsIFile& aBaseDir, - const nsTArray& aIdList); +nsresult BodyDeleteFiles(const ClientMetadata& aClientMetadata, + nsIFile& aBaseDir, const nsTArray& aIdList); -nsresult BodyDeleteOrphanedFiles(const QuotaInfo& aQuotaInfo, nsIFile& aBaseDir, +nsresult BodyDeleteOrphanedFiles(const ClientMetadata& aClientMetadata, + nsIFile& aBaseDir, const nsTArray& aKnownBodyIdList); // If aCanRemoveFiles is true, that means we are safe to touch the files which @@ -63,28 +65,28 @@ nsresult BodyDeleteOrphanedFiles(const QuotaInfo& aQuotaInfo, nsIFile& aBaseDir, // created by other threads. Note that if the files are not expected, we should // be safe to remove them in any case. template -nsresult BodyTraverseFiles(const QuotaInfo& aQuotaInfo, nsIFile& aBodyDir, - const Func& aHandleFileFunc, bool aCanRemoveFiles, - bool aTrackQuota = true); +nsresult BodyTraverseFiles(const ClientMetadata& aClientMetadata, + nsIFile& aBodyDir, const Func& aHandleFileFunc, + bool aCanRemoveFiles, bool aTrackQuota = true); -nsresult CreateMarkerFile(const QuotaInfo& aQuotaInfo); +nsresult CreateMarkerFile(const ClientMetadata& aClientMetadata); -nsresult DeleteMarkerFile(const QuotaInfo& aQuotaInfo); +nsresult DeleteMarkerFile(const ClientMetadata& aClientMetadata); -bool MarkerFileExists(const QuotaInfo& aQuotaInfo); +bool MarkerFileExists(const ClientMetadata& aClientMetadata); -nsresult RemoveNsIFileRecursively(const QuotaInfo& aQuotaInfo, nsIFile& aFile, - bool aTrackQuota = true); +nsresult RemoveNsIFileRecursively(const ClientMetadata& aClientMetadata, + nsIFile& aFile, bool aTrackQuota = true); // Delete a file that you think exists. If the file doesn't exist, an error // will not be returned, but warning telemetry will be generated! So only call // this on files that you know exist (idempotent usage, but it's not // recommended). -nsresult RemoveNsIFile(const QuotaInfo& aQuotaInfo, nsIFile& aFile, +nsresult RemoveNsIFile(const ClientMetadata& aClientMetadata, nsIFile& aFile, bool aTrackQuota = true); -void DecreaseUsageForQuotaInfo(const QuotaInfo& aQuotaInfo, - int64_t aUpdatingSize); +void DecreaseUsageForClientMetadata(const ClientMetadata& aClientMetadata, + int64_t aUpdatingSize); /** * This function is used to check if the directory padding file is existed. diff --git a/dom/cache/FileUtilsImpl.h b/dom/cache/FileUtilsImpl.h index 5f385ca4dbfb..16b8295947bd 100644 --- a/dom/cache/FileUtilsImpl.h +++ b/dom/cache/FileUtilsImpl.h @@ -15,8 +15,8 @@ namespace dom { namespace cache { template -nsresult BodyTraverseFiles(const QuotaInfo& aQuotaInfo, nsIFile& aBodyDir, - const Func& aHandleFileFunc, +nsresult BodyTraverseFiles(const ClientMetadata& aClientMetadata, + nsIFile& aBodyDir, const Func& aHandleFileFunc, const bool aCanRemoveFiles, const bool aTrackQuota) { #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED { @@ -36,7 +36,7 @@ nsresult BodyTraverseFiles(const QuotaInfo& aQuotaInfo, nsIFile& aBodyDir, FlippedOnce isEmpty; QM_TRY(quota::CollectEachFile( aBodyDir, - [&isEmpty, &aQuotaInfo, aTrackQuota, &aHandleFileFunc, + [&isEmpty, &aClientMetadata, aTrackQuota, &aHandleFileFunc, aCanRemoveFiles](const nsCOMPtr& file) -> Result { QM_TRY_INSPECT(const auto& dirEntryKind, quota::GetDirEntryKind(*file)); @@ -44,7 +44,7 @@ nsresult BodyTraverseFiles(const QuotaInfo& aQuotaInfo, nsIFile& aBodyDir, case quota::nsIFileKind::ExistsAsDirectory: { // If it's a directory somehow, try to remove it and move on DebugOnly result = RemoveNsIFileRecursively( - aQuotaInfo, *file, /* aTrackQuota */ false); + aClientMetadata, *file, /* aTrackQuota */ false); MOZ_ASSERT(NS_SUCCEEDED(result)); break; } @@ -58,7 +58,7 @@ nsresult BodyTraverseFiles(const QuotaInfo& aQuotaInfo, nsIFile& aBodyDir, if (StringEndsWith(leafName, ".tmp"_ns)) { if (aCanRemoveFiles) { DebugOnly result = - RemoveNsIFile(aQuotaInfo, *file, aTrackQuota); + RemoveNsIFile(aClientMetadata, *file, aTrackQuota); MOZ_ASSERT(NS_SUCCEEDED(result)); return Ok{}; } @@ -70,8 +70,8 @@ nsresult BodyTraverseFiles(const QuotaInfo& aQuotaInfo, nsIFile& aBodyDir, // If its not, try to remove it and move on. if (!maybeEndingOk) { - DebugOnly result = - RemoveNsIFile(aQuotaInfo, *file, /* aTrackQuota */ false); + DebugOnly result = RemoveNsIFile( + aClientMetadata, *file, /* aTrackQuota */ false); MOZ_ASSERT(NS_SUCCEEDED(result)); return Ok{}; } @@ -96,8 +96,8 @@ nsresult BodyTraverseFiles(const QuotaInfo& aQuotaInfo, nsIFile& aBodyDir, })); if (isEmpty && aCanRemoveFiles) { - DebugOnly result = - RemoveNsIFileRecursively(aQuotaInfo, aBodyDir, /* aTrackQuota */ false); + DebugOnly result = RemoveNsIFileRecursively( + aClientMetadata, aBodyDir, /* aTrackQuota */ false); MOZ_ASSERT(NS_SUCCEEDED(result)); } diff --git a/dom/cache/Manager.cpp b/dom/cache/Manager.cpp index fec4e990bb17..5f17a050e1e4 100644 --- a/dom/cache/Manager.cpp +++ b/dom/cache/Manager.cpp @@ -75,7 +75,7 @@ class SetupAction final : public SyncDBAction { SetupAction() : SyncDBAction(DBAction::Create) {} virtual nsresult RunSyncWithDBOnTarget( - const QuotaInfo& aQuotaInfo, nsIFile* aDBDir, + const ClientMetadata& aClientMetadata, nsIFile* aDBDir, mozIStorageConnection* aConn) override { MOZ_DIAGNOSTIC_ASSERT(aDBDir); @@ -94,7 +94,7 @@ class SetupAction final : public SyncDBAction { // // Note, this must be done after any schema version updates to // ensure our DBSchema methods work correctly. - if (MarkerFileExists(aQuotaInfo)) { + if (MarkerFileExists(aClientMetadata)) { NS_WARNING("Cache not shutdown cleanly! Cleaning up stale data..."); mozStorageTransaction trans(aConn, false, mozIStorageConnection::TRANSACTION_IMMEDIATE); @@ -109,18 +109,19 @@ class SetupAction final : public SyncDBAction { const CheckedInt64& overallDeletedPaddingSize, Reduce( orphanedCacheIdList, CheckedInt64(0), - [aConn, &aQuotaInfo, &aDBDir]( + [aConn, &aClientMetadata, &aDBDir]( CheckedInt64 oldValue, const Maybe& element) -> Result { QM_TRY_INSPECT(const auto& deletionInfo, db::DeleteCacheId(*aConn, *element)); - QM_TRY(MOZ_TO_RESULT(BodyDeleteFiles( - aQuotaInfo, *aDBDir, deletionInfo.mDeletedBodyIdList))); + QM_TRY(MOZ_TO_RESULT( + BodyDeleteFiles(aClientMetadata, *aDBDir, + deletionInfo.mDeletedBodyIdList))); if (deletionInfo.mDeletedPaddingSize > 0) { - DecreaseUsageForQuotaInfo(aQuotaInfo, - deletionInfo.mDeletedPaddingSize); + DecreaseUsageForClientMetadata( + aClientMetadata, deletionInfo.mDeletedPaddingSize); } return oldValue + deletionInfo.mDeletedPaddingSize; @@ -130,7 +131,7 @@ class SetupAction final : public SyncDBAction { QM_TRY_INSPECT(const auto& knownBodyIdList, db::GetKnownBodyIds(*aConn)); QM_TRY(MOZ_TO_RESULT( - BodyDeleteOrphanedFiles(aQuotaInfo, *aDBDir, knownBodyIdList))); + BodyDeleteOrphanedFiles(aClientMetadata, *aDBDir, knownBodyIdList))); // Commit() explicitly here, because we want to ensure the padding file // has the correct content. @@ -170,10 +171,10 @@ class DeleteOrphanedBodyAction final : public Action { explicit DeleteOrphanedBodyAction(const nsID& aBodyId) : mDeletedBodyIdList{aBodyId} {} - void RunOnTarget(SafeRefPtr aResolver, const QuotaInfo& aQuotaInfo, - Data*) override { + void RunOnTarget(SafeRefPtr aResolver, + const ClientMetadata& aClientMetadata, Data*) override { MOZ_DIAGNOSTIC_ASSERT(aResolver); - MOZ_DIAGNOSTIC_ASSERT(aQuotaInfo.mDir); + MOZ_DIAGNOSTIC_ASSERT(aClientMetadata.mDir); // Note that since DeleteOrphanedBodyAction isn't used while the context is // being initialized, we don't need to check for cancellation here. @@ -183,12 +184,12 @@ class DeleteOrphanedBodyAction final : public Action { }; QM_TRY_INSPECT(const auto& dbDir, - CloneFileAndAppend(*aQuotaInfo.mDir, u"cache"_ns), QM_VOID, - resolve); + CloneFileAndAppend(*aClientMetadata.mDir, u"cache"_ns), + QM_VOID, resolve); - QM_TRY( - MOZ_TO_RESULT(BodyDeleteFiles(aQuotaInfo, *dbDir, mDeletedBodyIdList)), - QM_VOID, resolve); + QM_TRY(MOZ_TO_RESULT( + BodyDeleteFiles(aClientMetadata, *dbDir, mDeletedBodyIdList)), + QM_VOID, resolve); aResolver->Resolve(NS_OK); } @@ -524,9 +525,9 @@ class Manager::DeleteOrphanedCacheAction final : public SyncDBAction { mCacheId(aCacheId) {} virtual nsresult RunSyncWithDBOnTarget( - const QuotaInfo& aQuotaInfo, nsIFile* aDBDir, + const ClientMetadata& aClientMetadata, nsIFile* aDBDir, mozIStorageConnection* aConn) override { - mQuotaInfo.emplace(aQuotaInfo); + mClientMetadata.emplace(aClientMetadata); mozStorageTransaction trans(aConn, false, mozIStorageConnection::TRANSACTION_IMMEDIATE); @@ -553,8 +554,8 @@ class Manager::DeleteOrphanedCacheAction final : public SyncDBAction { mManager->NoteOrphanedBodyIdList(mDeletionInfo.mDeletedBodyIdList); if (mDeletionInfo.mDeletedPaddingSize > 0) { - DecreaseUsageForQuotaInfo(mQuotaInfo.ref(), - mDeletionInfo.mDeletedPaddingSize); + DecreaseUsageForClientMetadata(mClientMetadata.ref(), + mDeletionInfo.mDeletedPaddingSize); } // ensure we release the manager on the initiating thread @@ -565,7 +566,7 @@ class Manager::DeleteOrphanedCacheAction final : public SyncDBAction { SafeRefPtr mManager; const CacheId mCacheId; DeletionInfo mDeletionInfo; - Maybe mQuotaInfo; + Maybe mClientMetadata; }; // ---------------------------------------------------------------------------- @@ -582,7 +583,7 @@ class Manager::CacheMatchAction final : public Manager::BaseAction { mFoundResponse(false) {} virtual nsresult RunSyncWithDBOnTarget( - const QuotaInfo& aQuotaInfo, nsIFile* aDBDir, + const ClientMetadata& aClientMetadata, nsIFile* aDBDir, mozIStorageConnection* aConn) override { MOZ_DIAGNOSTIC_ASSERT(aDBDir); @@ -603,7 +604,8 @@ class Manager::CacheMatchAction final : public Manager::BaseAction { nsCOMPtr stream; if (mArgs.openMode() == OpenMode::Eager) { - QM_TRY_UNWRAP(stream, BodyOpen(aQuotaInfo, *aDBDir, mResponse.mBodyId)); + QM_TRY_UNWRAP(stream, + BodyOpen(aClientMetadata, *aDBDir, mResponse.mBodyId)); } mStreamList->Add(mResponse.mBodyId, std::move(stream)); @@ -647,7 +649,7 @@ class Manager::CacheMatchAllAction final : public Manager::BaseAction { mStreamList(std::move(aStreamList)) {} virtual nsresult RunSyncWithDBOnTarget( - const QuotaInfo& aQuotaInfo, nsIFile* aDBDir, + const ClientMetadata& aClientMetadata, nsIFile* aDBDir, mozIStorageConnection* aConn) override { MOZ_DIAGNOSTIC_ASSERT(aDBDir); @@ -664,8 +666,8 @@ class Manager::CacheMatchAllAction final : public Manager::BaseAction { nsCOMPtr stream; if (mArgs.openMode() == OpenMode::Eager) { - QM_TRY_UNWRAP( - stream, BodyOpen(aQuotaInfo, *aDBDir, mSavedResponses[i].mBodyId)); + QM_TRY_UNWRAP(stream, BodyOpen(aClientMetadata, *aDBDir, + mSavedResponses[i].mBodyId)); } mStreamList->Add(mSavedResponses[i].mBodyId, std::move(stream)); @@ -731,7 +733,8 @@ class Manager::CachePutAllAction final : public DBAction { ~CachePutAllAction() = default; virtual void RunWithDBOnTarget(SafeRefPtr aResolver, - const QuotaInfo& aQuotaInfo, nsIFile* aDBDir, + const ClientMetadata& aClientMetadata, + nsIFile* aDBDir, mozIStorageConnection* aConn) override { MOZ_DIAGNOSTIC_ASSERT(aResolver); MOZ_DIAGNOSTIC_ASSERT(aDBDir); @@ -752,21 +755,21 @@ class Manager::CachePutAllAction final : public DBAction { mResolver = std::move(aResolver); mDBDir = aDBDir; mConn = aConn; - mQuotaInfo.emplace(aQuotaInfo); + mClientMetadata.emplace(aClientMetadata); // File bodies are streamed to disk via asynchronous copying. Start // this copying now. Each copy will eventually result in a call // to OnAsyncCopyComplete(). - const nsresult rv = [this, &aQuotaInfo]() -> nsresult { + const nsresult rv = [this, &aClientMetadata]() -> nsresult { QM_TRY(CollectEachInRange( - mList, [this, &aQuotaInfo](auto& entry) -> nsresult { - QM_TRY( - MOZ_TO_RESULT(StartStreamCopy(aQuotaInfo, entry, RequestStream, - &mExpectedAsyncCopyCompletions))); + mList, [this, &aClientMetadata](auto& entry) -> nsresult { + QM_TRY(MOZ_TO_RESULT( + StartStreamCopy(aClientMetadata, entry, RequestStream, + &mExpectedAsyncCopyCompletions))); - QM_TRY( - MOZ_TO_RESULT(StartStreamCopy(aQuotaInfo, entry, ResponseStream, - &mExpectedAsyncCopyCompletions))); + QM_TRY(MOZ_TO_RESULT( + StartStreamCopy(aClientMetadata, entry, ResponseStream, + &mExpectedAsyncCopyCompletions))); return NS_OK; })); @@ -853,7 +856,7 @@ class Manager::CachePutAllAction final : public DBAction { if (e.mResponse.type() == ResponseType::Opaque) { // It'll generate padding if we've not set it yet. QM_TRY(MOZ_TO_RESULT(BodyMaybeUpdatePaddingSize( - mQuotaInfo.ref(), *mDBDir, e.mResponseBodyId, + mClientMetadata.ref(), *mDBDir, e.mResponseBodyId, e.mResponse.paddingInfo(), &e.mResponse.paddingSize()))); MOZ_DIAGNOSTIC_ASSERT(INT64_MAX - e.mResponse.paddingSize() >= @@ -910,7 +913,8 @@ class Manager::CachePutAllAction final : public DBAction { mManager->NoteOrphanedBodyIdList(mDeletedBodyIdList); if (mDeletedPaddingSize > 0) { - DecreaseUsageForQuotaInfo(mQuotaInfo.ref(), mDeletedPaddingSize); + DecreaseUsageForClientMetadata(mClientMetadata.ref(), + mDeletedPaddingSize); } Listener* listener = mManager->GetListener(mListenerId); @@ -945,7 +949,7 @@ class Manager::CachePutAllAction final : public DBAction { enum StreamId { RequestStream, ResponseStream }; - nsresult StartStreamCopy(const QuotaInfo& aQuotaInfo, Entry& aEntry, + nsresult StartStreamCopy(const ClientMetadata& aClientMetadata, Entry& aEntry, StreamId aStreamId, uint32_t* aCopyCountOut) { MOZ_ASSERT(mTarget->IsOnCurrentThread()); MOZ_DIAGNOSTIC_ASSERT(aCopyCountOut); @@ -965,7 +969,7 @@ class Manager::CachePutAllAction final : public DBAction { } QM_TRY_INSPECT((const auto& [bodyId, copyContext]), - BodyStartWriteStream(aQuotaInfo, *mDBDir, *source, this, + BodyStartWriteStream(aClientMetadata, *mDBDir, *source, this, AsyncCopyCompleteFunc)); if (aStreamId == RequestStream) { @@ -1029,9 +1033,10 @@ class Manager::CachePutAllAction final : public DBAction { // Clean up any files we might have written before hitting the error. if (NS_FAILED(aRv)) { - BodyDeleteFiles(mQuotaInfo.ref(), *mDBDir, mBodyIdWrittenList); + BodyDeleteFiles(mClientMetadata.ref(), *mDBDir, mBodyIdWrittenList); if (mUpdatedPaddingSize > 0) { - DecreaseUsageForQuotaInfo(mQuotaInfo.ref(), mUpdatedPaddingSize); + DecreaseUsageForClientMetadata(mClientMetadata.ref(), + mUpdatedPaddingSize); } } @@ -1074,7 +1079,7 @@ class Manager::CachePutAllAction final : public DBAction { Mutex mMutex; nsTArray> mCopyContextList; - Maybe mQuotaInfo; + Maybe mClientMetadata; // Track how much pad amount has been added for new entries so that it can be // removed if an error occurs. int64_t mUpdatedPaddingSize; @@ -1094,9 +1099,9 @@ class Manager::CacheDeleteAction final : public Manager::BaseAction { mSuccess(false) {} virtual nsresult RunSyncWithDBOnTarget( - const QuotaInfo& aQuotaInfo, nsIFile* aDBDir, + const ClientMetadata& aClientMetadata, nsIFile* aDBDir, mozIStorageConnection* aConn) override { - mQuotaInfo.emplace(aQuotaInfo); + mClientMetadata.emplace(aClientMetadata); mozStorageTransaction trans(aConn, false, mozIStorageConnection::TRANSACTION_IMMEDIATE); @@ -1132,8 +1137,8 @@ class Manager::CacheDeleteAction final : public Manager::BaseAction { mManager->NoteOrphanedBodyIdList(mDeletionInfo.mDeletedBodyIdList); if (mDeletionInfo.mDeletedPaddingSize > 0) { - DecreaseUsageForQuotaInfo(mQuotaInfo.ref(), - mDeletionInfo.mDeletedPaddingSize); + DecreaseUsageForClientMetadata(mClientMetadata.ref(), + mDeletionInfo.mDeletedPaddingSize); } aListener->OnOpComplete(std::move(aRv), CacheDeleteResult(mSuccess)); @@ -1148,7 +1153,7 @@ class Manager::CacheDeleteAction final : public Manager::BaseAction { const CacheDeleteArgs mArgs; bool mSuccess; DeletionInfo mDeletionInfo; - Maybe mQuotaInfo; + Maybe mClientMetadata; }; // ---------------------------------------------------------------------------- @@ -1164,7 +1169,7 @@ class Manager::CacheKeysAction final : public Manager::BaseAction { mStreamList(std::move(aStreamList)) {} virtual nsresult RunSyncWithDBOnTarget( - const QuotaInfo& aQuotaInfo, nsIFile* aDBDir, + const ClientMetadata& aClientMetadata, nsIFile* aDBDir, mozIStorageConnection* aConn) override { MOZ_DIAGNOSTIC_ASSERT(aDBDir); @@ -1181,8 +1186,8 @@ class Manager::CacheKeysAction final : public Manager::BaseAction { nsCOMPtr stream; if (mArgs.openMode() == OpenMode::Eager) { - QM_TRY_UNWRAP(stream, - BodyOpen(aQuotaInfo, *aDBDir, mSavedRequests[i].mBodyId)); + QM_TRY_UNWRAP(stream, BodyOpen(aClientMetadata, *aDBDir, + mSavedRequests[i].mBodyId)); } mStreamList->Add(mSavedRequests[i].mBodyId, std::move(stream)); @@ -1223,7 +1228,7 @@ class Manager::StorageMatchAction final : public Manager::BaseAction { mFoundResponse(false) {} virtual nsresult RunSyncWithDBOnTarget( - const QuotaInfo& aQuotaInfo, nsIFile* aDBDir, + const ClientMetadata& aClientMetadata, nsIFile* aDBDir, mozIStorageConnection* aConn) override { MOZ_DIAGNOSTIC_ASSERT(aDBDir); @@ -1247,7 +1252,7 @@ class Manager::StorageMatchAction final : public Manager::BaseAction { nsCOMPtr stream; if (mArgs.openMode() == OpenMode::Eager) { QM_TRY_UNWRAP(stream, - BodyOpen(aQuotaInfo, *aDBDir, mSavedResponse.mBodyId)); + BodyOpen(aClientMetadata, *aDBDir, mSavedResponse.mBodyId)); } mStreamList->Add(mSavedResponse.mBodyId, std::move(stream)); @@ -1286,7 +1291,7 @@ class Manager::StorageHasAction final : public Manager::BaseAction { mCacheFound(false) {} virtual nsresult RunSyncWithDBOnTarget( - const QuotaInfo& aQuotaInfo, nsIFile* aDBDir, + const ClientMetadata& aClientMetadata, nsIFile* aDBDir, mozIStorageConnection* aConn) override { QM_TRY_INSPECT(const auto& maybeCacheId, db::StorageGetCacheId(*aConn, mNamespace, mArgs.key())); @@ -1318,7 +1323,7 @@ class Manager::StorageOpenAction final : public Manager::BaseAction { mCacheId(INVALID_CACHE_ID) {} virtual nsresult RunSyncWithDBOnTarget( - const QuotaInfo& aQuotaInfo, nsIFile* aDBDir, + const ClientMetadata& aClientMetadata, nsIFile* aDBDir, mozIStorageConnection* aConn) override { // Cache does not exist, create it instead mozStorageTransaction trans(aConn, false, @@ -1373,7 +1378,7 @@ class Manager::StorageDeleteAction final : public Manager::BaseAction { mCacheId(INVALID_CACHE_ID) {} virtual nsresult RunSyncWithDBOnTarget( - const QuotaInfo& aQuotaInfo, nsIFile* aDBDir, + const ClientMetadata& aClientMetadata, nsIFile* aDBDir, mozIStorageConnection* aConn) override { mozStorageTransaction trans(aConn, false, mozIStorageConnection::TRANSACTION_IMMEDIATE); @@ -1438,7 +1443,7 @@ class Manager::StorageKeysAction final : public Manager::BaseAction { : BaseAction(std::move(aManager), aListenerId), mNamespace(aNamespace) {} virtual nsresult RunSyncWithDBOnTarget( - const QuotaInfo& aQuotaInfo, nsIFile* aDBDir, + const ClientMetadata& aClientMetadata, nsIFile* aDBDir, mozIStorageConnection* aConn) override { QM_TRY_UNWRAP(mKeys, db::StorageGetKeys(*aConn, mNamespace)); @@ -1468,11 +1473,11 @@ class Manager::OpenStreamAction final : public Manager::BaseAction { mBodyId(aBodyId) {} virtual nsresult RunSyncWithDBOnTarget( - const QuotaInfo& aQuotaInfo, nsIFile* aDBDir, + const ClientMetadata& aClientMetadata, nsIFile* aDBDir, mozIStorageConnection* aConn) override { MOZ_DIAGNOSTIC_ASSERT(aDBDir); - QM_TRY_UNWRAP(mBodyStream, BodyOpen(aQuotaInfo, *aDBDir, mBodyId)); + QM_TRY_UNWRAP(mBodyStream, BodyOpen(aClientMetadata, *aDBDir, mBodyId)); return NS_OK; } diff --git a/dom/cache/QuotaClient.cpp b/dom/cache/QuotaClient.cpp index 1334b9b2e174..830153764df2 100644 --- a/dom/cache/QuotaClient.cpp +++ b/dom/cache/QuotaClient.cpp @@ -64,8 +64,8 @@ Result GetBodyUsage(nsIFile& aMorgueDir, if (dirEntryKind != nsIFileKind::ExistsAsDirectory) { if (dirEntryKind == nsIFileKind::ExistsAsFile) { - const DebugOnly result = - RemoveNsIFile(QuotaInfo{}, *bodyDir, /* aTrackQuota */ false); + const DebugOnly result = RemoveNsIFile( + ClientMetadata{}, *bodyDir, /* aTrackQuota */ false); // Try to remove the unexpected files, and keep moving on even if it // fails because it might be created by virus or the operation // system @@ -108,7 +108,8 @@ Result GetBodyUsage(nsIFile& aMorgueDir, // warning in the reports is not desired). QM_TRY(QM_OR_ELSE_LOG_VERBOSE_IF( // Expression. - MOZ_TO_RESULT(BodyTraverseFiles(QuotaInfo{}, *bodyDir, getUsage, + MOZ_TO_RESULT(BodyTraverseFiles(ClientMetadata{}, *bodyDir, + getUsage, /* aCanRemoveFiles */ true, /* aTrackQuota */ false)), // Predicate. @@ -122,15 +123,16 @@ Result GetBodyUsage(nsIFile& aMorgueDir, Result GetPaddingSizeFromDB( nsIFile& aDir, nsIFile& aDBFile, const OriginMetadata& aOriginMetadata) { - QuotaInfo quotaInfo; - static_cast(quotaInfo) = aOriginMetadata; - // quotaInfo.mDirectoryLockId must be -1 (which is default for new QuotaInfo) - // because this method should only be called from QuotaClient::InitOrigin when - // the temporary storage hasn't been initialized yet. At that time, the - // in-memory objects (e.g. OriginInfo) are only being created so it doesn't - // make sense to tunnel quota information to TelemetryVFS to get corresponding - // QuotaObject instance for the SQLite file). - MOZ_DIAGNOSTIC_ASSERT(quotaInfo.mDirectoryLockId == -1); + ClientMetadata clientMetadata; + static_cast(clientMetadata) = aOriginMetadata; + // clientMetadata.mDirectoryLockId must be -1 (which is default for new + // ClientMetadata) because this method should only be called from + // QuotaClient::InitOrigin when the temporary storage hasn't been initialized + // yet. At that time, the in-memory objects (e.g. OriginInfo) are only being + // created so it doesn't make sense to tunnel quota information to + // TelemetryVFS to get corresponding QuotaObject instance for the SQLite + // file). + MOZ_DIAGNOSTIC_ASSERT(clientMetadata.mDirectoryLockId == -1); #ifdef DEBUG { @@ -139,7 +141,7 @@ Result GetPaddingSizeFromDB( } #endif - QM_TRY_INSPECT(const auto& conn, OpenDBConnection(quotaInfo, aDBFile)); + QM_TRY_INSPECT(const auto& conn, OpenDBConnection(clientMetadata, aDBFile)); // Make sure that the database has the latest schema before we try to read // from it. We have to do this because GetPaddingSizeFromDB is called @@ -215,7 +217,7 @@ Result CacheQuotaClient::InitOrigin( QM_TRY_INSPECT(const auto& morgueDir, CloneFileAndAppend(*dir, kMorgueDirectoryFilename)); - QuotaInfo dummy; + ClientMetadata dummy; QM_TRY(MOZ_TO_RESULT(mozilla::dom::cache::RemoveNsIFileRecursively( dummy, *morgueDir, /* aTrackQuota */ false))); @@ -434,8 +436,8 @@ nsresult CacheQuotaClient::RestorePaddingFileInternal( return NS_OK; } -nsresult CacheQuotaClient::WipePaddingFileInternal(const QuotaInfo& aQuotaInfo, - nsIFile* aBaseDir) { +nsresult CacheQuotaClient::WipePaddingFileInternal( + const ClientMetadata& aClientMetadata, nsIFile* aBaseDir) { MOZ_ASSERT(!NS_IsMainThread()); MOZ_DIAGNOSTIC_ASSERT(aBaseDir); @@ -468,7 +470,7 @@ nsresult CacheQuotaClient::WipePaddingFileInternal(const QuotaInfo& aQuotaInfo, }())); if (paddingSize > 0) { - DecreaseUsageForQuotaInfo(aQuotaInfo, paddingSize); + DecreaseUsageForClientMetadata(aClientMetadata, paddingSize); } QM_TRY(MOZ_TO_RESULT( @@ -517,7 +519,8 @@ nsresult RestorePaddingFile(nsIFile* aBaseDir, mozIStorageConnection* aConn) { } // static -nsresult WipePaddingFile(const QuotaInfo& aQuotaInfo, nsIFile* aBaseDir) { +nsresult WipePaddingFile(const ClientMetadata& aClientMetadata, + nsIFile* aBaseDir) { MOZ_ASSERT(!NS_IsMainThread()); MOZ_DIAGNOSTIC_ASSERT(aBaseDir); @@ -525,7 +528,7 @@ nsresult WipePaddingFile(const QuotaInfo& aQuotaInfo, nsIFile* aBaseDir) { MOZ_DIAGNOSTIC_ASSERT(cacheQuotaClient); QM_TRY(MOZ_TO_RESULT( - cacheQuotaClient->WipePaddingFileInternal(aQuotaInfo, aBaseDir))); + cacheQuotaClient->WipePaddingFileInternal(aClientMetadata, aBaseDir))); return NS_OK; } diff --git a/dom/cache/QuotaClient.h b/dom/cache/QuotaClient.h index 2f5917aa5045..fc394925d30e 100644 --- a/dom/cache/QuotaClient.h +++ b/dom/cache/QuotaClient.h @@ -39,7 +39,8 @@ already_AddRefed CreateQuotaClient(); nsresult RestorePaddingFile(nsIFile* aBaseDir, mozIStorageConnection* aConn); -nsresult WipePaddingFile(const QuotaInfo& aQuotaInfo, nsIFile* aBaseDir); +nsresult WipePaddingFile(const ClientMetadata& aClientMetadata, + nsIFile* aBaseDir); extern const nsLiteralString kCachesSQLiteFilename; diff --git a/dom/cache/QuotaClientImpl.h b/dom/cache/QuotaClientImpl.h index 7ffced87a646..7d151bb1e6c1 100644 --- a/dom/cache/QuotaClientImpl.h +++ b/dom/cache/QuotaClientImpl.h @@ -116,7 +116,7 @@ class CacheQuotaClient final : public quota::Client { nsresult RestorePaddingFileInternal(nsIFile* aBaseDir, mozIStorageConnection* aConn); - nsresult WipePaddingFileInternal(const QuotaInfo& aQuotaInfo, + nsresult WipePaddingFileInternal(const ClientMetadata& aClientMetadata, nsIFile* aBaseDir); private: diff --git a/dom/cache/Types.h b/dom/cache/Types.h index f6c0b2192e23..2ce77ddb8417 100644 --- a/dom/cache/Types.h +++ b/dom/cache/Types.h @@ -29,9 +29,8 @@ static const Namespace INVALID_NAMESPACE = NUMBER_OF_NAMESPACES; using CacheId = int64_t; static const CacheId INVALID_CACHE_ID = -1; -// XXX Rename to OriginMetadata. // XXX Consider inheritance from ClientMetadata. -struct QuotaInfo : quota::OriginMetadata { +struct ClientMetadata : quota::OriginMetadata { nsCOMPtr mDir; int64_t mDirectoryLockId = -1; };