Skip to content
Permalink
Browse files

Bug 1110485 P6 Remove useless cache::FileUtils type

  • Loading branch information...
rmottola committed Jul 21, 2019
1 parent 159b902 commit 1bdf00fc301aa12619834159054323e1366c0327
Showing with 75 additions and 78 deletions.
  1. +1 −1 dom/cache/DBAction.cpp
  2. +33 −18 dom/cache/FileUtils.cpp
  3. +23 −38 dom/cache/FileUtils.h
  4. +18 −21 dom/cache/Manager.cpp
@@ -170,7 +170,7 @@ DBAction::WipeDatabase(nsIFile* aDBFile, nsIFile* aDBDir)
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }

// Delete the morgue as well.
rv = FileUtils::BodyDeleteDir(aDBDir);
rv = BodyDeleteDir(aDBDir);
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }

return rv;
@@ -23,11 +23,24 @@ namespace cache {
using mozilla::dom::quota::FileInputStream;
using mozilla::dom::quota::FileOutputStream;
using mozilla::dom::quota::PERSISTENCE_TYPE_DEFAULT;
using mozilla::unused;

namespace {

enum BodyFileType
{
BODY_FILE_FINAL,
BODY_FILE_TMP
};

nsresult
BodyIdToFile(nsIFile* aBaseDir, const nsID& aId, BodyFileType aType,
nsIFile** aBodyFileOut);

} // anonymous namespace

// static
nsresult
FileUtils::BodyCreateDir(nsIFile* aBaseDir)
BodyCreateDir(nsIFile* aBaseDir)
{
MOZ_ASSERT(aBaseDir);

@@ -49,7 +62,7 @@ FileUtils::BodyCreateDir(nsIFile* aBaseDir)

// static
nsresult
FileUtils::BodyDeleteDir(nsIFile* aBaseDir)
BodyDeleteDir(nsIFile* aBaseDir)
{
MOZ_ASSERT(aBaseDir);

@@ -72,8 +85,7 @@ FileUtils::BodyDeleteDir(nsIFile* aBaseDir)

// static
nsresult
FileUtils::BodyGetCacheDir(nsIFile* aBaseDir, const nsID& aId,
nsIFile** aCacheDirOut)
BodyGetCacheDir(nsIFile* aBaseDir, const nsID& aId, nsIFile** aCacheDirOut)
{
MOZ_ASSERT(aBaseDir);
MOZ_ASSERT(aCacheDirOut);
@@ -107,11 +119,11 @@ FileUtils::BodyGetCacheDir(nsIFile* aBaseDir, const nsID& aId,

// static
nsresult
FileUtils::BodyStartWriteStream(const QuotaInfo& aQuotaInfo,
nsIFile* aBaseDir, nsIInputStream* aSource,
void* aClosure,
nsAsyncCopyCallbackFun aCallback, nsID* aIdOut,
nsISupports** aCopyContextOut)
BodyStartWriteStream(const QuotaInfo& aQuotaInfo,
nsIFile* aBaseDir, nsIInputStream* aSource,
void* aClosure,
nsAsyncCopyCallbackFun aCallback, nsID* aIdOut,
nsISupports** aCopyContextOut)
{
MOZ_ASSERT(aBaseDir);
MOZ_ASSERT(aSource);
@@ -168,7 +180,7 @@ FileUtils::BodyStartWriteStream(const QuotaInfo& aQuotaInfo,

// static
void
FileUtils::BodyCancelWrite(nsIFile* aBaseDir, nsISupports* aCopyContext)
BodyCancelWrite(nsIFile* aBaseDir, nsISupports* aCopyContext)
{
MOZ_ASSERT(aBaseDir);
MOZ_ASSERT(aCopyContext);
@@ -182,7 +194,7 @@ FileUtils::BodyCancelWrite(nsIFile* aBaseDir, nsISupports* aCopyContext)

// static
nsresult
FileUtils::BodyFinalizeWrite(nsIFile* aBaseDir, const nsID& aId)
BodyFinalizeWrite(nsIFile* aBaseDir, const nsID& aId)
{
MOZ_ASSERT(aBaseDir);

@@ -206,8 +218,8 @@ FileUtils::BodyFinalizeWrite(nsIFile* aBaseDir, const nsID& aId)

// static
nsresult
FileUtils::BodyOpen(const QuotaInfo& aQuotaInfo, nsIFile* aBaseDir,
const nsID& aId, nsIInputStream** aStreamOut)
BodyOpen(const QuotaInfo& aQuotaInfo, nsIFile* aBaseDir, const nsID& aId,
nsIInputStream** aStreamOut)
{
MOZ_ASSERT(aBaseDir);
MOZ_ASSERT(aStreamOut);
@@ -234,7 +246,7 @@ FileUtils::BodyOpen(const QuotaInfo& aQuotaInfo, nsIFile* aBaseDir,

// static
nsresult
FileUtils::BodyDeleteFiles(nsIFile* aBaseDir, const nsTArray<nsID>& aIdList)
BodyDeleteFiles(nsIFile* aBaseDir, const nsTArray<nsID>& aIdList)
{
nsresult rv = NS_OK;

@@ -273,10 +285,11 @@ FileUtils::BodyDeleteFiles(nsIFile* aBaseDir, const nsTArray<nsID>& aIdList)
return NS_OK;
}

// static
namespace {

nsresult
FileUtils::BodyIdToFile(nsIFile* aBaseDir, const nsID& aId,
BodyFileType aType, nsIFile** aBodyFileOut)
BodyIdToFile(nsIFile* aBaseDir, const nsID& aId, BodyFileType aType,
nsIFile** aBodyFileOut)
{
MOZ_ASSERT(aBaseDir);
MOZ_ASSERT(aBodyFileOut);
@@ -304,6 +317,8 @@ FileUtils::BodyIdToFile(nsIFile* aBaseDir, const nsID& aId,
return rv;
}

} // anonymous namespace

} // namespace cache
} // namespace dom
} // namespace mozilla
@@ -19,51 +19,36 @@ namespace mozilla {
namespace dom {
namespace cache {

// TODO: remove static class and use functions in cache namespace (bug 1110485)
class FileUtils final
{
public:
enum BodyFileType
{
BODY_FILE_FINAL,
BODY_FILE_TMP
};
nsresult
BodyCreateDir(nsIFile* aBaseDir);

static 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.
static nsresult BodyDeleteDir(nsIFile* aBaseDir);
static nsresult BodyGetCacheDir(nsIFile* aBaseDir, const nsID& aId,
nsIFile** aCacheDirOut);
// 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(nsIFile* aBaseDir);

static nsresult
BodyStartWriteStream(const QuotaInfo& aQuotaInfo, nsIFile* aBaseDir,
nsIInputStream* aSource, void* aClosure,
nsAsyncCopyCallbackFun aCallback, nsID* aIdOut,
nsISupports** aCopyContextOut);
nsresult
BodyGetCacheDir(nsIFile* aBaseDir, const nsID& aId, nsIFile** aCacheDirOut);

static void
BodyCancelWrite(nsIFile* aBaseDir, nsISupports* aCopyContext);
nsresult
BodyStartWriteStream(const QuotaInfo& aQuotaInfo, nsIFile* aBaseDir,
nsIInputStream* aSource, void* aClosure,
nsAsyncCopyCallbackFun aCallback, nsID* aIdOut,
nsISupports** aCopyContextOut);

static nsresult
BodyFinalizeWrite(nsIFile* aBaseDir, const nsID& aId);
void
BodyCancelWrite(nsIFile* aBaseDir, nsISupports* aCopyContext);

static nsresult
BodyOpen(const QuotaInfo& aQuotaInfo, nsIFile* aBaseDir, const nsID& aId,
nsIInputStream** aStreamOut);
nsresult
BodyFinalizeWrite(nsIFile* aBaseDir, const nsID& aId);

static nsresult
BodyDeleteFiles(nsIFile* aBaseDir, const nsTArray<nsID>& aIdList);
nsresult
BodyOpen(const QuotaInfo& aQuotaInfo, nsIFile* aBaseDir, const nsID& aId,
nsIInputStream** aStreamOut);

private:
static nsresult
BodyIdToFile(nsIFile* aBaseDir, const nsID& aId, BodyFileType aType,
nsIFile** aBodyFileOut);

FileUtils() = delete;
~FileUtils() = delete;
};
nsresult
BodyDeleteFiles(nsIFile* aBaseDir, const nsTArray<nsID>& aIdList);

} // namespace cache
} // namespace dom
@@ -34,7 +34,8 @@ namespace {

using mozilla::unused;
using mozilla::dom::cache::Action;
using mozilla::dom::cache::FileUtils;
using mozilla::dom::cache::BodyCreateDir;
using mozilla::dom::cache::BodyDeleteFiles;
using mozilla::dom::cache::QuotaInfo;
using mozilla::dom::cache::SyncDBAction;
using mozilla::dom::cache::db::CreateSchema;
@@ -59,7 +60,7 @@ class SetupAction final : public SyncDBAction
// TODO: have Context create/delete marker files in constructor/destructor
// and only do expensive maintenance if that marker is present (bug 1110446)

nsresult rv = FileUtils::BodyCreateDir(aDBDir);
nsresult rv = BodyCreateDir(aDBDir);
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }

mozStorageTransaction trans(aConn, false,
@@ -116,7 +117,7 @@ class DeleteOrphanedBodyAction final : public Action
return;
}

rv = FileUtils::BodyDeleteFiles(dbDir, mDeletedBodyIdList);
rv = BodyDeleteFiles(dbDir, mDeletedBodyIdList);
unused << NS_WARN_IF(NS_FAILED(rv));

aResolver->Resolve(rv);
@@ -511,8 +512,7 @@ class Manager::CacheMatchAction final : public Manager::BaseAction
}

nsCOMPtr<nsIInputStream> stream;
rv = FileUtils::BodyOpen(aQuotaInfo, aDBDir, mResponse.mBodyId,
getter_AddRefs(stream));
rv = BodyOpen(aQuotaInfo, aDBDir, mResponse.mBodyId, getter_AddRefs(stream));
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
if (NS_WARN_IF(!stream)) { return NS_ERROR_FILE_NOT_FOUND; }

@@ -575,9 +575,8 @@ class Manager::CacheMatchAllAction final : public Manager::BaseAction
}

nsCOMPtr<nsIInputStream> stream;
rv = FileUtils::BodyOpen(aQuotaInfo, aDBDir,
mSavedResponses[i].mBodyId,
getter_AddRefs(stream));
rv = BodyOpen(aQuotaInfo, aDBDir, mSavedResponses[i].mBodyId,
getter_AddRefs(stream));
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
if (NS_WARN_IF(!stream)) { return NS_ERROR_FILE_NOT_FOUND; }

@@ -762,14 +761,14 @@ class Manager::CachePutAllAction final : public DBAction
for (uint32_t i = 0; i < mList.Length(); ++i) {
Entry& e = mList[i];
if (e.mRequestStream) {
rv = FileUtils::BodyFinalizeWrite(mDBDir, e.mRequestBodyId);
rv = BodyFinalizeWrite(mDBDir, e.mRequestBodyId);
if (NS_WARN_IF(NS_FAILED(rv))) {
DoResolve(rv);
return;
}
}
if (e.mResponseStream) {
rv = FileUtils::BodyFinalizeWrite(mDBDir, e.mResponseBodyId);
rv = BodyFinalizeWrite(mDBDir, e.mResponseBodyId);
if (NS_WARN_IF(NS_FAILED(rv))) {
DoResolve(rv);
return;
@@ -874,10 +873,9 @@ class Manager::CachePutAllAction final : public DBAction

nsCOMPtr<nsISupports> copyContext;

nsresult rv = FileUtils::BodyStartWriteStream(aQuotaInfo, mDBDir, source,
this, AsyncCopyCompleteFunc,
bodyId,
getter_AddRefs(copyContext));
nsresult rv = BodyStartWriteStream(aQuotaInfo, mDBDir, source, this,
AsyncCopyCompleteFunc, bodyId,
getter_AddRefs(copyContext));
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }

mBodyIdWrittenList.AppendElement(*bodyId);
@@ -898,7 +896,7 @@ class Manager::CachePutAllAction final : public DBAction
// May occur on either owning thread or target thread
MutexAutoLock lock(mMutex);
for (uint32_t i = 0; i < mCopyContextList.Length(); ++i) {
FileUtils::BodyCancelWrite(mDBDir, mCopyContextList[i]);
BodyCancelWrite(mDBDir, mCopyContextList[i]);
}
mCopyContextList.Clear();
}
@@ -937,7 +935,7 @@ class Manager::CachePutAllAction final : public DBAction

// Clean up any files we might have written before hitting the error.
if (NS_FAILED(aRv)) {
FileUtils::BodyDeleteFiles(mDBDir, mBodyIdWrittenList);
BodyDeleteFiles(mDBDir, mBodyIdWrittenList);
}

// Must be released on the target thread where it was opened.
@@ -1062,9 +1060,8 @@ class Manager::CacheKeysAction final : public Manager::BaseAction
}

nsCOMPtr<nsIInputStream> stream;
rv = FileUtils::BodyOpen(aQuotaInfo, aDBDir,
mSavedRequests[i].mBodyId,
getter_AddRefs(stream));
rv = BodyOpen(aQuotaInfo, aDBDir, mSavedRequests[i].mBodyId,
getter_AddRefs(stream));
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
if (NS_WARN_IF(!stream)) { return NS_ERROR_FILE_NOT_FOUND; }

@@ -1125,8 +1122,8 @@ class Manager::StorageMatchAction final : public Manager::BaseAction
}

nsCOMPtr<nsIInputStream> stream;
rv = FileUtils::BodyOpen(aQuotaInfo, aDBDir, mSavedResponse.mBodyId,
getter_AddRefs(stream));
rv = BodyOpen(aQuotaInfo, aDBDir, mSavedResponse.mBodyId,
getter_AddRefs(stream));
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
if (NS_WARN_IF(!stream)) { return NS_ERROR_FILE_NOT_FOUND; }

0 comments on commit 1bdf00f

Please sign in to comment.
You can’t perform that action at this time.