Bug 1672140 - Rename cache::QuotaInfo to cache::ClientMetadata and rename corresponding functions; r=dom-storage-reviewers,janv

Differential Revision: https://phabricator.services.mozilla.com/D125583
This commit is contained in:
hxu 2021-11-24 20:50:36 +00:00
Родитель 19eb68c48d
Коммит 2dbd17aeac
13 изменённых файлов: 235 добавлений и 214 удалений

2
dom/cache/Action.h поставляемый
Просмотреть файл

@ -56,7 +56,7 @@ class Action : public SafeRefCounted<Action> {
// 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<Resolver> aResolver,
const QuotaInfo& aQuotaInfo,
const ClientMetadata& aClientMetadata,
Data* aOptionalData) = 0;
// Called on initiating thread when the Action is canceled. The Action is

45
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<Resolver> 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<Action> mInitAction;
nsCOMPtr<nsIEventTarget> mInitiatingEventTarget;
nsresult mResult;
QuotaInfo mQuotaInfo;
ClientMetadata mClientMetadata;
RefPtr<DirectoryLock> mDirectoryLock;
State mState;
Atomic<bool> mCanceled;
@ -233,7 +233,7 @@ void Context::QuotaInitRunnable::OpenDirectory() {
RefPtr<DirectoryLock> 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<quota::OriginMetadata&>(mQuotaInfo) = {
static_cast<quota::OriginMetadata&>(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<Context> aContext, Data* aData,
nsISerialEventTarget* aTarget, SafeRefPtr<Action> 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<Data> mData;
nsCOMPtr<nsISerialEventTarget> mTarget;
SafeRefPtr<Action> mAction;
const QuotaInfo mQuotaInfo;
const ClientMetadata mClientMetadata;
nsCOMPtr<nsIEventTarget> 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<Action> aAction, bool aDoomData) {
NS_ASSERT_OWNINGTHREAD(Context);
auto runnable = MakeSafeRefPtr<ActionRunnable>(
SafeRefPtrFromThis(), mData, mTarget, std::move(aAction), mQuotaInfo);
auto runnable =
MakeSafeRefPtr<ActionRunnable>(SafeRefPtrFromThis(), mData, mTarget,
std::move(aAction), mClientMetadata);
if (aDoomData) {
mData = nullptr;
@ -993,14 +994,14 @@ void Context::DispatchAction(SafeRefPtr<Action> aAction, bool aDoomData) {
AddActivity(*runnable);
}
void Context::OnQuotaInit(nsresult aRv, const QuotaInfo& aQuotaInfo,
void Context::OnQuotaInit(nsresult aRv, const ClientMetadata& aClientMetadata,
already_AddRefed<DirectoryLock> 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.

6
dom/cache/Context.h поставляемый
Просмотреть файл

@ -152,7 +152,7 @@ class Context final : public SafeRefCounted<Context> {
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<Context> {
void Init(Maybe<Context&> aOldContext);
void Start();
void DispatchAction(SafeRefPtr<Action> aAction, bool aDoomData = false);
void OnQuotaInit(nsresult aRv, const QuotaInfo& aQuotaInfo,
void OnQuotaInit(nsresult aRv, const ClientMetadata& aClientMetadata,
already_AddRefed<DirectoryLock> aDirectoryLock);
SafeRefPtr<ThreadsafeHandle> CreateThreadsafeHandle();
@ -193,7 +193,7 @@ class Context final : public SafeRefCounted<Context> {
RefPtr<Data> mData;
State mState;
bool mOrphanedData;
QuotaInfo mQuotaInfo;
ClientMetadata mClientMetadata;
RefPtr<QuotaInitRunnable> mInitRunnable;
SafeRefPtr<Action> mInitAction;
nsTArray<PendingAction> mPendingActions;

46
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<nsIFile>, 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<Resolver> 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<Resolver> 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<mozIStorageConnection> conn;
@ -83,7 +84,7 @@ void DBAction::RunOnTarget(SafeRefPtr<Resolver> 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<Resolver> aResolver,
}
}
RunWithDBOnTarget(std::move(aResolver), aQuotaInfo, dbDir, conn);
RunWithDBOnTarget(std::move(aResolver), aClientMetadata, dbDir, conn);
}
Result<nsCOMPtr<mozIStorageConnection>, 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<nsCOMPtr<mozIStorageConnection>, 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<Resolver> aResolver,
const QuotaInfo& aQuotaInfo,
const ClientMetadata& aClientMetadata,
nsIFile* aDBDir,
mozIStorageConnection* aConn) {
MOZ_ASSERT(!NS_IsMainThread());
@ -133,14 +134,14 @@ void SyncDBAction::RunWithDBOnTarget(SafeRefPtr<Resolver> 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<nsCOMPtr<mozIStorageConnection>, 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<nsCOMPtr<mozIStorageConnection>, 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<nsIFileURL> dbFileUrl;
@ -179,14 +181,14 @@ Result<nsCOMPtr<mozIStorageConnection>, nsresult> OpenDBConnection(
// Predicate.
IsDatabaseCorruptionError,
// Fallback.
([&aQuotaInfo, &aDBFile, &storageService,
([&aClientMetadata, &aDBFile, &storageService,
&dbFileUrl](const nsresult rv)
-> Result<nsCOMPtr<mozIStorageConnection>, 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<mozIStorageConnection>, storageService,
@ -200,7 +202,7 @@ Result<nsCOMPtr<mozIStorageConnection>, 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<mozIStorageConnection>, storageService,

15
dom/cache/DBAction.h поставляемый
Просмотреть файл

@ -19,7 +19,7 @@ namespace dom {
namespace cache {
Result<nsCOMPtr<mozIStorageConnection>, 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<Resolver> aResolver,
const QuotaInfo& aQuotaInfo, nsIFile* aDBDir,
const ClientMetadata& aClientMetadata,
nsIFile* aDBDir,
mozIStorageConnection* aConn) = 0;
private:
void RunOnTarget(SafeRefPtr<Resolver> aResolver, const QuotaInfo& aQuotaInfo,
void RunOnTarget(SafeRefPtr<Resolver> aResolver,
const ClientMetadata& aClientMetadata,
Data* aOptionalData) override;
Result<nsCOMPtr<mozIStorageConnection>, 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<Resolver> aResolver,
const QuotaInfo& aQuotaInfo, nsIFile* aDBDir,
const ClientMetadata& aClientMetadata,
nsIFile* aDBDir,
mozIStorageConnection* aConn) override;
};

105
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<std::pair<nsID, nsCOMPtr<nsISupports>>, 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<std::pair<nsID, nsCOMPtr<nsISupports>>, 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<SnappyCompressOutputStream>(fileStream.get());
@ -199,11 +201,11 @@ nsresult BodyFinalizeWrite(nsIFile& aBaseDir, const nsID& aId) {
}
Result<NotNull<nsCOMPtr<nsIInputStream>>, 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<RefPtr<FileInputStream>>&& stream) {
return WrapNotNullUnchecked(
@ -211,7 +213,7 @@ Result<NotNull<nsCOMPtr<nsIInputStream>>, 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> 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<nsID>& aIdList) {
nsresult BodyDeleteFiles(const ClientMetadata& aClientMetadata,
nsIFile& aBaseDir, const nsTArray<nsID>& 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<bool, nsresult> {
nsID fileId;
QM_TRY(OkIf(fileId.Parse(leafName.BeginReading())), true,
([&aQuotaInfo, &bodyFile](const auto) {
DebugOnly<nsresult> result =
RemoveNsIFile(aQuotaInfo, bodyFile, /* aTrackQuota */ false);
([&aClientMetadata, &bodyFile](const auto) {
DebugOnly<nsresult> result = RemoveNsIFile(
aClientMetadata, bodyFile, /* aTrackQuota */ false);
MOZ_ASSERT(NS_SUCCEEDED(result));
}));
if (id.Equals(fileId)) {
DebugOnly<nsresult> result = RemoveNsIFile(aQuotaInfo, bodyFile);
DebugOnly<nsresult> 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<nsID>& 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<nsIFile>& subdir) -> Result<Ok, nsresult> {
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<bool, nsresult> {
// 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<nsresult> 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<nsresult> result =
RemoveNsIFile(aQuotaInfo, *subdir, /* aTrackQuota */ false);
DebugOnly<nsresult> 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<nsCOMPtr<nsIFile>, 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<nsCOMPtr<nsIFile>, 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<nsresult> 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<nsIFile>& file) -> Result<Ok, nsresult> {
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,

40
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<std::pair<nsID, nsCOMPtr<nsISupports>>, 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<NotNull<nsCOMPtr<nsIInputStream>>, 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<nsID>& aIdList);
nsresult BodyDeleteFiles(const ClientMetadata& aClientMetadata,
nsIFile& aBaseDir, const nsTArray<nsID>& aIdList);
nsresult BodyDeleteOrphanedFiles(const QuotaInfo& aQuotaInfo, nsIFile& aBaseDir,
nsresult BodyDeleteOrphanedFiles(const ClientMetadata& aClientMetadata,
nsIFile& aBaseDir,
const nsTArray<nsID>& 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 <typename Func>
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.

18
dom/cache/FileUtilsImpl.h поставляемый
Просмотреть файл

@ -15,8 +15,8 @@ namespace dom {
namespace cache {
template <typename Func>
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<true> isEmpty;
QM_TRY(quota::CollectEachFile(
aBodyDir,
[&isEmpty, &aQuotaInfo, aTrackQuota, &aHandleFileFunc,
[&isEmpty, &aClientMetadata, aTrackQuota, &aHandleFileFunc,
aCanRemoveFiles](const nsCOMPtr<nsIFile>& file) -> Result<Ok, nsresult> {
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<nsresult> 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<nsresult> 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<nsresult> result =
RemoveNsIFile(aQuotaInfo, *file, /* aTrackQuota */ false);
DebugOnly<nsresult> 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<nsresult> result =
RemoveNsIFileRecursively(aQuotaInfo, aBodyDir, /* aTrackQuota */ false);
DebugOnly<nsresult> result = RemoveNsIFileRecursively(
aClientMetadata, aBodyDir, /* aTrackQuota */ false);
MOZ_ASSERT(NS_SUCCEEDED(result));
}

123
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<const CacheId&>& element)
-> Result<CheckedInt64, nsresult> {
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<Resolver> aResolver, const QuotaInfo& aQuotaInfo,
Data*) override {
void RunOnTarget(SafeRefPtr<Resolver> 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<Manager> mManager;
const CacheId mCacheId;
DeletionInfo mDeletionInfo;
Maybe<QuotaInfo> mQuotaInfo;
Maybe<ClientMetadata> 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<nsIInputStream> 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<nsIInputStream> 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<Resolver> 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<nsCOMPtr<nsISupports>> mCopyContextList;
Maybe<QuotaInfo> mQuotaInfo;
Maybe<ClientMetadata> 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<QuotaInfo> mQuotaInfo;
Maybe<ClientMetadata> 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<nsIInputStream> 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<nsIInputStream> 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;
}

41
dom/cache/QuotaClient.cpp поставляемый
Просмотреть файл

@ -64,8 +64,8 @@ Result<UsageInfo, nsresult> GetBodyUsage(nsIFile& aMorgueDir,
if (dirEntryKind != nsIFileKind::ExistsAsDirectory) {
if (dirEntryKind == nsIFileKind::ExistsAsFile) {
const DebugOnly<nsresult> result =
RemoveNsIFile(QuotaInfo{}, *bodyDir, /* aTrackQuota */ false);
const DebugOnly<nsresult> 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<UsageInfo, nsresult> 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<UsageInfo, nsresult> GetBodyUsage(nsIFile& aMorgueDir,
Result<int64_t, nsresult> GetPaddingSizeFromDB(
nsIFile& aDir, nsIFile& aDBFile, const OriginMetadata& aOriginMetadata) {
QuotaInfo quotaInfo;
static_cast<OriginMetadata&>(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<OriginMetadata&>(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<int64_t, nsresult> 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<UsageInfo, nsresult> 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;
}

3
dom/cache/QuotaClient.h поставляемый
Просмотреть файл

@ -39,7 +39,8 @@ already_AddRefed<quota::Client> 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;

2
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:

3
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<nsIFile> mDir;
int64_t mDirectoryLockId = -1;
};