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