зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1686031 - Fix storage upgrades and restoration of the metadata file to use proper persistence type internally; r=dom-storage-reviewers,sg
Differential Revision: https://phabricator.services.mozilla.com/D106907
This commit is contained in:
Родитель
2ff63d5811
Коммит
c6a31f1fb9
|
@ -1973,6 +1973,7 @@ class StorageOperationBase {
|
|||
struct OriginProps {
|
||||
enum Type { eChrome, eContent, eObsolete, eInvalid };
|
||||
|
||||
// XXX Change to NotNull<nsCOMPtr<nsIFile>> mDirectory;
|
||||
nsCOMPtr<nsIFile> mDirectory;
|
||||
nsString mLeafName;
|
||||
nsCString mSpec;
|
||||
|
@ -1981,6 +1982,8 @@ class StorageOperationBase {
|
|||
OriginMetadata mOriginMetadata;
|
||||
nsCString mOriginalSuffix;
|
||||
|
||||
LazyInitializedOnceEarlyDestructible<const PersistenceType>
|
||||
mPersistenceType;
|
||||
Type mType;
|
||||
bool mNeedsRestore;
|
||||
bool mNeedsRestore2;
|
||||
|
@ -1994,18 +1997,17 @@ class StorageOperationBase {
|
|||
mNeedsRestore2(false),
|
||||
mIgnore(false) {}
|
||||
|
||||
nsresult Init(nsIFile* aDirectory);
|
||||
template <typename PersistenceTypeFunc>
|
||||
nsresult Init(nsIFile* aDirectory,
|
||||
PersistenceTypeFunc&& aPersistenceTypeFunc);
|
||||
};
|
||||
|
||||
nsTArray<OriginProps> mOriginProps;
|
||||
|
||||
nsCOMPtr<nsIFile> mDirectory;
|
||||
|
||||
const bool mPersistent;
|
||||
|
||||
public:
|
||||
StorageOperationBase(nsIFile* aDirectory, bool aPersistent)
|
||||
: mDirectory(aDirectory), mPersistent(aPersistent) {
|
||||
explicit StorageOperationBase(nsIFile* aDirectory) : mDirectory(aDirectory) {
|
||||
AssertIsOnIOThread();
|
||||
}
|
||||
|
||||
|
@ -2028,6 +2030,8 @@ class StorageOperationBase {
|
|||
nsACString& aSuffix, nsACString& aGroup,
|
||||
nsACString& aOrigin, bool& aIsApp);
|
||||
|
||||
int64_t GetOriginLastModifiedTime(const OriginProps& aOriginProps);
|
||||
|
||||
nsresult RemoveObsoleteOrigin(const OriginProps& aOriginProps);
|
||||
|
||||
/**
|
||||
|
@ -2135,8 +2139,8 @@ class MOZ_STACK_CLASS OriginParser final {
|
|||
|
||||
class RepositoryOperationBase : public StorageOperationBase {
|
||||
public:
|
||||
RepositoryOperationBase(nsIFile* aDirectory, bool aPersistent)
|
||||
: StorageOperationBase(aDirectory, aPersistent) {}
|
||||
explicit RepositoryOperationBase(nsIFile* aDirectory)
|
||||
: StorageOperationBase(aDirectory) {}
|
||||
|
||||
nsresult ProcessRepository();
|
||||
|
||||
|
@ -2148,6 +2152,8 @@ class RepositoryOperationBase : public StorageOperationBase {
|
|||
UpgradeMethod aMethod);
|
||||
|
||||
private:
|
||||
virtual PersistenceType PersistenceTypeFromSpec(const nsCString& aSpec) = 0;
|
||||
|
||||
virtual nsresult PrepareOriginDirectory(OriginProps& aOriginProps,
|
||||
bool* aRemoved) = 0;
|
||||
|
||||
|
@ -2160,11 +2166,31 @@ class CreateOrUpgradeDirectoryMetadataHelper final
|
|||
: public RepositoryOperationBase {
|
||||
nsCOMPtr<nsIFile> mPermanentStorageDir;
|
||||
|
||||
// The legacy PersistenceType, before the default repository introduction.
|
||||
enum class LegacyPersistenceType {
|
||||
Persistent = 0,
|
||||
Temporary
|
||||
// The PersistenceType had also PERSISTENCE_TYPE_INVALID, but we don't need
|
||||
// it here.
|
||||
};
|
||||
|
||||
LazyInitializedOnce<const LegacyPersistenceType> mLegacyPersistenceType;
|
||||
|
||||
public:
|
||||
CreateOrUpgradeDirectoryMetadataHelper(nsIFile* aDirectory, bool aPersistent)
|
||||
: RepositoryOperationBase(aDirectory, aPersistent) {}
|
||||
explicit CreateOrUpgradeDirectoryMetadataHelper(nsIFile* aDirectory)
|
||||
: RepositoryOperationBase(aDirectory) {}
|
||||
|
||||
nsresult Init();
|
||||
|
||||
private:
|
||||
Maybe<LegacyPersistenceType> LegacyPersistenceTypeFromFile(nsIFile& aFile,
|
||||
const fallible_t&);
|
||||
|
||||
PersistenceType PersistenceTypeFromLegacyPersistentSpec(
|
||||
const nsCString& aSpec);
|
||||
|
||||
PersistenceType PersistenceTypeFromSpec(const nsCString& aSpec) override;
|
||||
|
||||
nsresult MaybeUpgradeOriginDirectory(nsIFile* aDirectory);
|
||||
|
||||
nsresult PrepareOriginDirectory(OriginProps& aOriginProps,
|
||||
|
@ -2173,10 +2199,23 @@ class CreateOrUpgradeDirectoryMetadataHelper final
|
|||
nsresult ProcessOriginDirectory(const OriginProps& aOriginProps) override;
|
||||
};
|
||||
|
||||
class UpgradeStorageFrom0_0To1_0Helper final : public RepositoryOperationBase {
|
||||
class UpgradeStorageHelperBase : public RepositoryOperationBase {
|
||||
LazyInitializedOnce<const PersistenceType> mPersistenceType;
|
||||
|
||||
public:
|
||||
UpgradeStorageFrom0_0To1_0Helper(nsIFile* aDirectory, bool aPersistent)
|
||||
: RepositoryOperationBase(aDirectory, aPersistent) {}
|
||||
explicit UpgradeStorageHelperBase(nsIFile* aDirectory)
|
||||
: RepositoryOperationBase(aDirectory) {}
|
||||
|
||||
nsresult Init();
|
||||
|
||||
private:
|
||||
PersistenceType PersistenceTypeFromSpec(const nsCString& aSpec) override;
|
||||
};
|
||||
|
||||
class UpgradeStorageFrom0_0To1_0Helper final : public UpgradeStorageHelperBase {
|
||||
public:
|
||||
explicit UpgradeStorageFrom0_0To1_0Helper(nsIFile* aDirectory)
|
||||
: UpgradeStorageHelperBase(aDirectory) {}
|
||||
|
||||
private:
|
||||
nsresult PrepareOriginDirectory(OriginProps& aOriginProps,
|
||||
|
@ -2185,10 +2224,10 @@ class UpgradeStorageFrom0_0To1_0Helper final : public RepositoryOperationBase {
|
|||
nsresult ProcessOriginDirectory(const OriginProps& aOriginProps) override;
|
||||
};
|
||||
|
||||
class UpgradeStorageFrom1_0To2_0Helper final : public RepositoryOperationBase {
|
||||
class UpgradeStorageFrom1_0To2_0Helper final : public UpgradeStorageHelperBase {
|
||||
public:
|
||||
UpgradeStorageFrom1_0To2_0Helper(nsIFile* aDirectory, bool aPersistent)
|
||||
: RepositoryOperationBase(aDirectory, aPersistent) {}
|
||||
explicit UpgradeStorageFrom1_0To2_0Helper(nsIFile* aDirectory)
|
||||
: UpgradeStorageHelperBase(aDirectory) {}
|
||||
|
||||
private:
|
||||
nsresult MaybeRemoveMorgueDirectory(const OriginProps& aOriginProps);
|
||||
|
@ -2208,10 +2247,10 @@ class UpgradeStorageFrom1_0To2_0Helper final : public RepositoryOperationBase {
|
|||
nsresult ProcessOriginDirectory(const OriginProps& aOriginProps) override;
|
||||
};
|
||||
|
||||
class UpgradeStorageFrom2_0To2_1Helper final : public RepositoryOperationBase {
|
||||
class UpgradeStorageFrom2_0To2_1Helper final : public UpgradeStorageHelperBase {
|
||||
public:
|
||||
UpgradeStorageFrom2_0To2_1Helper(nsIFile* aDirectory, bool aPersistent)
|
||||
: RepositoryOperationBase(aDirectory, aPersistent) {}
|
||||
explicit UpgradeStorageFrom2_0To2_1Helper(nsIFile* aDirectory)
|
||||
: UpgradeStorageHelperBase(aDirectory) {}
|
||||
|
||||
private:
|
||||
nsresult PrepareOriginDirectory(OriginProps& aOriginProps,
|
||||
|
@ -2220,10 +2259,10 @@ class UpgradeStorageFrom2_0To2_1Helper final : public RepositoryOperationBase {
|
|||
nsresult ProcessOriginDirectory(const OriginProps& aOriginProps) override;
|
||||
};
|
||||
|
||||
class UpgradeStorageFrom2_1To2_2Helper final : public RepositoryOperationBase {
|
||||
class UpgradeStorageFrom2_1To2_2Helper final : public UpgradeStorageHelperBase {
|
||||
public:
|
||||
UpgradeStorageFrom2_1To2_2Helper(nsIFile* aDirectory, bool aPersistent)
|
||||
: RepositoryOperationBase(aDirectory, aPersistent) {}
|
||||
explicit UpgradeStorageFrom2_1To2_2Helper(nsIFile* aDirectory)
|
||||
: UpgradeStorageHelperBase(aDirectory) {}
|
||||
|
||||
private:
|
||||
nsresult PrepareOriginDirectory(OriginProps& aOriginProps,
|
||||
|
@ -2236,9 +2275,13 @@ class UpgradeStorageFrom2_1To2_2Helper final : public RepositoryOperationBase {
|
|||
};
|
||||
|
||||
class RestoreDirectoryMetadata2Helper final : public StorageOperationBase {
|
||||
LazyInitializedOnce<const PersistenceType> mPersistenceType;
|
||||
|
||||
public:
|
||||
RestoreDirectoryMetadata2Helper(nsIFile* aDirectory, bool aPersistent)
|
||||
: StorageOperationBase(aDirectory, aPersistent) {}
|
||||
explicit RestoreDirectoryMetadata2Helper(nsIFile* aDirectory)
|
||||
: StorageOperationBase(aDirectory) {}
|
||||
|
||||
nsresult Init();
|
||||
|
||||
nsresult RestoreMetadata2File();
|
||||
|
||||
|
@ -2274,9 +2317,8 @@ Result<nsAutoString, nsresult> GetPathForStorage(
|
|||
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_TYPED(nsAutoString, storageDir, GetPath));
|
||||
}
|
||||
|
||||
int64_t GetLastModifiedTime(nsIFile* aFile, bool aPersistent) {
|
||||
int64_t GetLastModifiedTime(PersistenceType aPersistenceType, nsIFile& aFile) {
|
||||
AssertIsOnIOThread();
|
||||
MOZ_ASSERT(aFile);
|
||||
|
||||
class MOZ_STACK_CLASS Helper final {
|
||||
public:
|
||||
|
@ -2333,12 +2375,12 @@ int64_t GetLastModifiedTime(nsIFile* aFile, bool aPersistent) {
|
|||
}
|
||||
};
|
||||
|
||||
if (aPersistent) {
|
||||
if (aPersistenceType == PERSISTENCE_TYPE_PERSISTENT) {
|
||||
return PR_Now();
|
||||
}
|
||||
|
||||
int64_t timestamp = INT64_MIN;
|
||||
nsresult rv = Helper::GetLastModifiedTime(aFile, ×tamp);
|
||||
nsresult rv = Helper::GetLastModifiedTime(&aFile, ×tamp);
|
||||
if (NS_FAILED(rv)) {
|
||||
timestamp = PR_Now();
|
||||
}
|
||||
|
@ -4494,14 +4536,15 @@ Result<nsCOMPtr<nsIFile>, nsresult> QuotaManager::GetDirectoryForOrigin(
|
|||
return directory;
|
||||
}
|
||||
|
||||
nsresult QuotaManager::RestoreDirectoryMetadata2(nsIFile* aDirectory,
|
||||
bool aPersistent) {
|
||||
nsresult QuotaManager::RestoreDirectoryMetadata2(nsIFile* aDirectory) {
|
||||
AssertIsOnIOThread();
|
||||
MOZ_ASSERT(aDirectory);
|
||||
MOZ_ASSERT(mStorageConnection);
|
||||
|
||||
RefPtr<RestoreDirectoryMetadata2Helper> helper =
|
||||
new RestoreDirectoryMetadata2Helper(aDirectory, aPersistent);
|
||||
new RestoreDirectoryMetadata2Helper(aDirectory);
|
||||
|
||||
QM_TRY(helper->Init());
|
||||
|
||||
QM_TRY(helper->RestoreMetadata2File());
|
||||
|
||||
|
@ -4597,8 +4640,7 @@ QuotaManager::GetDirectoryMetadataWithOriginMetadata2WithRestore(
|
|||
}()));
|
||||
|
||||
if (!maybeFirstAttemptResult) {
|
||||
QM_TRY(RestoreDirectoryMetadata2(
|
||||
aDirectory, persistenceType == PERSISTENCE_TYPE_PERSISTENT));
|
||||
QM_TRY(RestoreDirectoryMetadata2(aDirectory));
|
||||
|
||||
QM_TRY_RETURN(
|
||||
GetDirectoryMetadataWithOriginMetadata2(aDirectory, persistenceType));
|
||||
|
@ -5044,8 +5086,9 @@ QuotaManager::UpgradeFromPersistentStorageDirectoryToDefaultStorageDirectory(
|
|||
// Create real metadata files for origin directories in persistent
|
||||
// storage.
|
||||
auto helper = MakeRefPtr<CreateOrUpgradeDirectoryMetadataHelper>(
|
||||
aPersistentStorageDir,
|
||||
/* aPersistent */ true);
|
||||
aPersistentStorageDir);
|
||||
|
||||
QM_TRY(helper->Init());
|
||||
|
||||
QM_TRY(helper->ProcessRepository());
|
||||
|
||||
|
@ -5066,8 +5109,9 @@ QuotaManager::UpgradeFromPersistentStorageDirectoryToDefaultStorageDirectory(
|
|||
}
|
||||
|
||||
helper = MakeRefPtr<CreateOrUpgradeDirectoryMetadataHelper>(
|
||||
temporaryStorageDir,
|
||||
/* aPersistent */ false);
|
||||
temporaryStorageDir);
|
||||
|
||||
QM_TRY(helper->Init());
|
||||
|
||||
QM_TRY(helper->ProcessRepository());
|
||||
}
|
||||
|
@ -5105,8 +5149,10 @@ nsresult QuotaManager::UpgradeStorage(const int32_t aOldVersion,
|
|||
continue;
|
||||
}
|
||||
|
||||
bool persistent = persistenceType == PERSISTENCE_TYPE_PERSISTENT;
|
||||
RefPtr<RepositoryOperationBase> helper = new Helper(directory, persistent);
|
||||
RefPtr<UpgradeStorageHelperBase> helper = new Helper(directory);
|
||||
|
||||
QM_TRY(helper->Init());
|
||||
|
||||
QM_TRY(helper->ProcessRepository());
|
||||
}
|
||||
|
||||
|
@ -9667,6 +9713,12 @@ nsresult StorageOperationBase::GetDirectoryMetadata2(
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
int64_t StorageOperationBase::GetOriginLastModifiedTime(
|
||||
const OriginProps& aOriginProps) {
|
||||
return GetLastModifiedTime(*aOriginProps.mPersistenceType,
|
||||
*aOriginProps.mDirectory);
|
||||
}
|
||||
|
||||
nsresult StorageOperationBase::RemoveObsoleteOrigin(
|
||||
const OriginProps& aOriginProps) {
|
||||
AssertIsOnIOThread();
|
||||
|
@ -9745,7 +9797,7 @@ nsresult StorageOperationBase::ProcessOriginDirectories() {
|
|||
switch (originProps.mType) {
|
||||
case OriginProps::eChrome: {
|
||||
originProps.mOriginMetadata = {QuotaManager::GetInfoForChrome(),
|
||||
PERSISTENCE_TYPE_INVALID};
|
||||
*originProps.mPersistenceType};
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -9786,7 +9838,7 @@ nsresult StorageOperationBase::ProcessOriginDirectories() {
|
|||
|
||||
originProps.mOriginMetadata = {
|
||||
QuotaManager::GetInfoFromValidatedPrincipalInfo(principalInfo),
|
||||
PERSISTENCE_TYPE_INVALID};
|
||||
*originProps.mPersistenceType};
|
||||
|
||||
#ifdef QM_PRINCIPALINFO_VERIFICATION_ENABLED
|
||||
principalInfos.AppendElement(principalInfo);
|
||||
|
@ -9832,7 +9884,12 @@ nsresult StorageOperationBase::ProcessOriginDirectories() {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult StorageOperationBase::OriginProps::Init(nsIFile* aDirectory) {
|
||||
// XXX Do the fallible initialization in a separate non-static member function
|
||||
// of StorageOperationBase and eventually get rid of this method and use a
|
||||
// normal constructor instead.
|
||||
template <typename PersistenceTypeFunc>
|
||||
nsresult StorageOperationBase::OriginProps::Init(
|
||||
nsIFile* aDirectory, PersistenceTypeFunc&& aPersistenceTypeFunc) {
|
||||
AssertIsOnIOThread();
|
||||
MOZ_ASSERT(aDirectory);
|
||||
|
||||
|
@ -9850,11 +9907,24 @@ nsresult StorageOperationBase::OriginProps::Init(nsIFile* aDirectory) {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
const auto persistenceType = [&]() -> PersistenceType {
|
||||
// XXX We shouldn't continue with initialization if OriginParser returned
|
||||
// anything else but ValidOrigin. Otherwise, we have to deal with empty
|
||||
// spec when the origin is obsolete, like here. The caller should handle
|
||||
// the errors. Until it's fixed, we have to treat obsolete origins as
|
||||
// origins with unknown/invalid persistence type.
|
||||
if (result != OriginParser::ValidOrigin) {
|
||||
return PERSISTENCE_TYPE_INVALID;
|
||||
}
|
||||
return std::forward<PersistenceTypeFunc>(aPersistenceTypeFunc)(spec);
|
||||
}();
|
||||
|
||||
mDirectory = aDirectory;
|
||||
mLeafName = leafName;
|
||||
mSpec = spec;
|
||||
mAttrs = attrs;
|
||||
mOriginalSuffix = originalSuffix;
|
||||
mPersistenceType.init(persistenceType);
|
||||
if (result == OriginParser::ObsoleteOrigin) {
|
||||
mType = eObsolete;
|
||||
} else if (mSpec.EqualsLiteral(kChromeOrigin)) {
|
||||
|
@ -10355,7 +10425,9 @@ nsresult RepositoryOperationBase::ProcessRepository() {
|
|||
},
|
||||
[&self = *this](const auto& originDir) -> Result<mozilla::Ok, nsresult> {
|
||||
OriginProps originProps;
|
||||
QM_TRY(originProps.Init(originDir));
|
||||
QM_TRY(originProps.Init(originDir, [&self](const auto& aSpec) {
|
||||
return self.PersistenceTypeFromSpec(aSpec);
|
||||
}));
|
||||
// Bypass invalid origins while upgrading
|
||||
QM_TRY(OkIf(originProps.mType != OriginProps::eInvalid), mozilla::Ok{});
|
||||
|
||||
|
@ -10444,6 +10516,57 @@ nsresult RepositoryOperationBase::PrepareClientDirectory(
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult CreateOrUpgradeDirectoryMetadataHelper::Init() {
|
||||
AssertIsOnIOThread();
|
||||
MOZ_ASSERT(mDirectory);
|
||||
|
||||
const auto maybeLegacyPersistenceType =
|
||||
LegacyPersistenceTypeFromFile(*mDirectory, fallible);
|
||||
QM_TRY(OkIf(maybeLegacyPersistenceType.isSome()), Err(NS_ERROR_FAILURE));
|
||||
|
||||
mLegacyPersistenceType.init(maybeLegacyPersistenceType.value());
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
Maybe<CreateOrUpgradeDirectoryMetadataHelper::LegacyPersistenceType>
|
||||
CreateOrUpgradeDirectoryMetadataHelper::LegacyPersistenceTypeFromFile(
|
||||
nsIFile& aFile, const fallible_t&) {
|
||||
nsAutoString leafName;
|
||||
MOZ_ALWAYS_SUCCEEDS(aFile.GetLeafName(leafName));
|
||||
|
||||
if (leafName.Equals(u"persistent"_ns)) {
|
||||
return Some(LegacyPersistenceType::Persistent);
|
||||
}
|
||||
|
||||
if (leafName.Equals(u"temporary"_ns)) {
|
||||
return Some(LegacyPersistenceType::Temporary);
|
||||
}
|
||||
|
||||
return Nothing();
|
||||
}
|
||||
|
||||
PersistenceType
|
||||
CreateOrUpgradeDirectoryMetadataHelper::PersistenceTypeFromLegacyPersistentSpec(
|
||||
const nsCString& aSpec) {
|
||||
if (QuotaManager::IsOriginInternal(aSpec)) {
|
||||
return PERSISTENCE_TYPE_PERSISTENT;
|
||||
}
|
||||
|
||||
return PERSISTENCE_TYPE_DEFAULT;
|
||||
}
|
||||
|
||||
PersistenceType CreateOrUpgradeDirectoryMetadataHelper::PersistenceTypeFromSpec(
|
||||
const nsCString& aSpec) {
|
||||
switch (*mLegacyPersistenceType) {
|
||||
case LegacyPersistenceType::Persistent:
|
||||
return PersistenceTypeFromLegacyPersistentSpec(aSpec);
|
||||
case LegacyPersistenceType::Temporary:
|
||||
return PERSISTENCE_TYPE_TEMPORARY;
|
||||
}
|
||||
MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE("Bad legacy persistence type value!");
|
||||
}
|
||||
|
||||
nsresult CreateOrUpgradeDirectoryMetadataHelper::MaybeUpgradeOriginDirectory(
|
||||
nsIFile* aDirectory) {
|
||||
AssertIsOnIOThread();
|
||||
|
@ -10511,12 +10634,10 @@ nsresult CreateOrUpgradeDirectoryMetadataHelper::PrepareOriginDirectory(
|
|||
MOZ_ASSERT(aOriginProps.mDirectory);
|
||||
MOZ_ASSERT(aRemoved);
|
||||
|
||||
if (mPersistent) {
|
||||
if (*mLegacyPersistenceType == LegacyPersistenceType::Persistent) {
|
||||
QM_TRY(MaybeUpgradeOriginDirectory(aOriginProps.mDirectory));
|
||||
|
||||
const bool persistent = QuotaManager::IsOriginInternal(aOriginProps.mSpec);
|
||||
aOriginProps.mTimestamp =
|
||||
GetLastModifiedTime(aOriginProps.mDirectory, persistent);
|
||||
aOriginProps.mTimestamp = GetOriginLastModifiedTime(aOriginProps);
|
||||
} else {
|
||||
int64_t timestamp;
|
||||
nsCString group;
|
||||
|
@ -10525,8 +10646,7 @@ nsresult CreateOrUpgradeDirectoryMetadataHelper::PrepareOriginDirectory(
|
|||
nsresult rv = GetDirectoryMetadata(aOriginProps.mDirectory, timestamp,
|
||||
group, origin, isApp);
|
||||
if (NS_FAILED(rv)) {
|
||||
aOriginProps.mTimestamp =
|
||||
GetLastModifiedTime(aOriginProps.mDirectory, mPersistent);
|
||||
aOriginProps.mTimestamp = GetOriginLastModifiedTime(aOriginProps);
|
||||
aOriginProps.mNeedsRestore = true;
|
||||
} else if (!isApp.IsNull()) {
|
||||
aOriginProps.mIgnore = true;
|
||||
|
@ -10541,13 +10661,14 @@ nsresult CreateOrUpgradeDirectoryMetadataHelper::ProcessOriginDirectory(
|
|||
const OriginProps& aOriginProps) {
|
||||
AssertIsOnIOThread();
|
||||
|
||||
if (mPersistent) {
|
||||
if (*mLegacyPersistenceType == LegacyPersistenceType::Persistent) {
|
||||
QM_TRY(CreateDirectoryMetadata(*aOriginProps.mDirectory,
|
||||
aOriginProps.mTimestamp,
|
||||
aOriginProps.mOriginMetadata));
|
||||
|
||||
// Move internal origins to new persistent storage.
|
||||
if (QuotaManager::IsOriginInternal(aOriginProps.mSpec)) {
|
||||
if (PersistenceTypeFromLegacyPersistentSpec(aOriginProps.mSpec) ==
|
||||
PERSISTENCE_TYPE_PERSISTENT) {
|
||||
if (!mPermanentStorageDir) {
|
||||
QuotaManager* quotaManager = QuotaManager::Get();
|
||||
MOZ_ASSERT(quotaManager);
|
||||
|
@ -10597,6 +10718,26 @@ nsresult CreateOrUpgradeDirectoryMetadataHelper::ProcessOriginDirectory(
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult UpgradeStorageHelperBase::Init() {
|
||||
AssertIsOnIOThread();
|
||||
MOZ_ASSERT(mDirectory);
|
||||
|
||||
const auto maybePersistenceType =
|
||||
PersistenceTypeFromFile(*mDirectory, fallible);
|
||||
QM_TRY(OkIf(maybePersistenceType.isSome()), Err(NS_ERROR_FAILURE));
|
||||
|
||||
mPersistenceType.init(maybePersistenceType.value());
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PersistenceType UpgradeStorageHelperBase::PersistenceTypeFromSpec(
|
||||
const nsCString& aSpec) {
|
||||
// There's no moving of origin directories between repositories like in the
|
||||
// CreateOrUpgradeDirectoryMetadataHelper
|
||||
return *mPersistenceType;
|
||||
}
|
||||
|
||||
nsresult UpgradeStorageFrom0_0To1_0Helper::PrepareOriginDirectory(
|
||||
OriginProps& aOriginProps, bool* aRemoved) {
|
||||
AssertIsOnIOThread();
|
||||
|
@ -10610,8 +10751,7 @@ nsresult UpgradeStorageFrom0_0To1_0Helper::PrepareOriginDirectory(
|
|||
nsresult rv = GetDirectoryMetadata(aOriginProps.mDirectory, timestamp, group,
|
||||
origin, isApp);
|
||||
if (NS_FAILED(rv) || isApp.IsNull()) {
|
||||
aOriginProps.mTimestamp =
|
||||
GetLastModifiedTime(aOriginProps.mDirectory, mPersistent);
|
||||
aOriginProps.mTimestamp = GetOriginLastModifiedTime(aOriginProps);
|
||||
aOriginProps.mNeedsRestore = true;
|
||||
} else {
|
||||
aOriginProps.mTimestamp = timestamp;
|
||||
|
@ -10737,8 +10877,7 @@ nsresult UpgradeStorageFrom1_0To2_0Helper::PrepareOriginDirectory(
|
|||
rv = GetDirectoryMetadata2(aOriginProps.mDirectory, timestamp, suffix, group,
|
||||
origin, isApp.SetValue());
|
||||
if (NS_FAILED(rv)) {
|
||||
aOriginProps.mTimestamp =
|
||||
GetLastModifiedTime(aOriginProps.mDirectory, mPersistent);
|
||||
aOriginProps.mTimestamp = GetOriginLastModifiedTime(aOriginProps);
|
||||
aOriginProps.mNeedsRestore2 = true;
|
||||
} else {
|
||||
aOriginProps.mTimestamp = timestamp;
|
||||
|
@ -10797,8 +10936,7 @@ nsresult UpgradeStorageFrom2_0To2_1Helper::PrepareOriginDirectory(
|
|||
rv = GetDirectoryMetadata2(aOriginProps.mDirectory, timestamp, suffix, group,
|
||||
origin, isApp.SetValue());
|
||||
if (NS_FAILED(rv)) {
|
||||
aOriginProps.mTimestamp =
|
||||
GetLastModifiedTime(aOriginProps.mDirectory, mPersistent);
|
||||
aOriginProps.mTimestamp = GetOriginLastModifiedTime(aOriginProps);
|
||||
aOriginProps.mNeedsRestore2 = true;
|
||||
} else {
|
||||
aOriginProps.mTimestamp = timestamp;
|
||||
|
@ -10850,8 +10988,7 @@ nsresult UpgradeStorageFrom2_1To2_2Helper::PrepareOriginDirectory(
|
|||
rv = GetDirectoryMetadata2(aOriginProps.mDirectory, timestamp, suffix, group,
|
||||
origin, isApp.SetValue());
|
||||
if (NS_FAILED(rv)) {
|
||||
aOriginProps.mTimestamp =
|
||||
GetLastModifiedTime(aOriginProps.mDirectory, mPersistent);
|
||||
aOriginProps.mTimestamp = GetOriginLastModifiedTime(aOriginProps);
|
||||
aOriginProps.mNeedsRestore2 = true;
|
||||
} else {
|
||||
aOriginProps.mTimestamp = timestamp;
|
||||
|
@ -10898,15 +11035,31 @@ nsresult UpgradeStorageFrom2_1To2_2Helper::PrepareClientDirectory(
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult RestoreDirectoryMetadata2Helper::RestoreMetadata2File() {
|
||||
nsresult RestoreDirectoryMetadata2Helper::Init() {
|
||||
AssertIsOnIOThread();
|
||||
MOZ_ASSERT(mDirectory);
|
||||
|
||||
nsCOMPtr<nsIFile> parentDir;
|
||||
QM_TRY(mDirectory->GetParent(getter_AddRefs(parentDir)));
|
||||
|
||||
const auto maybePersistenceType =
|
||||
PersistenceTypeFromFile(*parentDir, fallible);
|
||||
QM_TRY(OkIf(maybePersistenceType.isSome()), Err(NS_ERROR_FAILURE));
|
||||
|
||||
mPersistenceType.init(maybePersistenceType.value());
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult RestoreDirectoryMetadata2Helper::RestoreMetadata2File() {
|
||||
OriginProps originProps;
|
||||
QM_TRY(originProps.Init(mDirectory));
|
||||
QM_TRY(originProps.Init(mDirectory, [&self = *this](const auto& aSpec) {
|
||||
return *self.mPersistenceType;
|
||||
}));
|
||||
|
||||
QM_TRY(OkIf(originProps.mType != OriginProps::eInvalid), NS_ERROR_FAILURE);
|
||||
|
||||
originProps.mTimestamp = GetLastModifiedTime(mDirectory, mPersistent);
|
||||
originProps.mTimestamp = GetOriginLastModifiedTime(originProps);
|
||||
|
||||
mOriginProps.AppendElement(std::move(originProps));
|
||||
|
||||
|
|
|
@ -225,7 +225,7 @@ class QuotaManager final : public BackgroundThreadObject {
|
|||
Result<nsCOMPtr<nsIFile>, nsresult> GetDirectoryForOrigin(
|
||||
PersistenceType aPersistenceType, const nsACString& aASCIIOrigin) const;
|
||||
|
||||
nsresult RestoreDirectoryMetadata2(nsIFile* aDirectory, bool aPersistent);
|
||||
nsresult RestoreDirectoryMetadata2(nsIFile* aDirectory);
|
||||
|
||||
struct GetDirectoryResultWithOriginMetadata {
|
||||
int64_t mTimestamp;
|
||||
|
|
Загрузка…
Ссылка в новой задаче