зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1339081 - Part 10: Unify GetDirectoryMetadata() in upgrade helpers; r=asuth
This commit is contained in:
Родитель
7cca6c51e2
Коммит
54f45ff479
|
@ -1418,13 +1418,17 @@ protected:
|
|||
|
||||
nsCOMPtr<nsIFile> mDirectory;
|
||||
|
||||
const bool mPersistent;
|
||||
|
||||
public:
|
||||
StorageDirectoryHelper(nsIFile* aDirectory)
|
||||
StorageDirectoryHelper(nsIFile* aDirectory,
|
||||
bool aPersistent)
|
||||
: mMutex("StorageDirectoryHelper::mMutex")
|
||||
, mCondVar(mMutex, "StorageDirectoryHelper::mCondVar")
|
||||
, mMainThreadResultCode(NS_OK)
|
||||
, mWaiting(true)
|
||||
, mDirectory(aDirectory)
|
||||
, mPersistent(aPersistent)
|
||||
{
|
||||
AssertIsOnIOThread();
|
||||
}
|
||||
|
@ -1433,6 +1437,13 @@ protected:
|
|||
~StorageDirectoryHelper()
|
||||
{ }
|
||||
|
||||
nsresult
|
||||
GetDirectoryMetadata(nsIFile* aDirectory,
|
||||
int64_t& aTimestamp,
|
||||
nsACString& aGroup,
|
||||
nsACString& aOrigin,
|
||||
Nullable<bool>& aIsApp);
|
||||
|
||||
nsresult
|
||||
ProcessOriginDirectories();
|
||||
|
||||
|
@ -1567,13 +1578,10 @@ private:
|
|||
class CreateOrUpgradeDirectoryMetadataHelper final
|
||||
: public StorageDirectoryHelper
|
||||
{
|
||||
const bool mPersistent;
|
||||
|
||||
public:
|
||||
CreateOrUpgradeDirectoryMetadataHelper(nsIFile* aDirectory,
|
||||
bool aPersistent)
|
||||
: StorageDirectoryHelper(aDirectory)
|
||||
, mPersistent(aPersistent)
|
||||
: StorageDirectoryHelper(aDirectory, aPersistent)
|
||||
{ }
|
||||
|
||||
nsresult
|
||||
|
@ -1583,13 +1591,6 @@ private:
|
|||
nsresult
|
||||
MaybeUpgradeOriginDirectory(nsIFile* aDirectory);
|
||||
|
||||
nsresult
|
||||
GetDirectoryMetadata(nsIFile* aDirectory,
|
||||
int64_t* aTimestamp,
|
||||
nsACString& aGroup,
|
||||
nsACString& aOrigin,
|
||||
bool* aHasIsApp);
|
||||
|
||||
virtual nsresult
|
||||
DoProcessOriginDirectories();
|
||||
};
|
||||
|
@ -1597,26 +1598,16 @@ private:
|
|||
class UpgradeStorageFrom0_0To1_0Helper final
|
||||
: public StorageDirectoryHelper
|
||||
{
|
||||
const bool mPersistent;
|
||||
|
||||
public:
|
||||
UpgradeStorageFrom0_0To1_0Helper(nsIFile* aDirectory,
|
||||
bool aPersistent)
|
||||
: StorageDirectoryHelper(aDirectory)
|
||||
, mPersistent(aPersistent)
|
||||
: StorageDirectoryHelper(aDirectory, aPersistent)
|
||||
{ }
|
||||
|
||||
nsresult
|
||||
DoUpgrade();
|
||||
|
||||
private:
|
||||
nsresult
|
||||
GetDirectoryMetadata(nsIFile* aDirectory,
|
||||
int64_t* aTimestamp,
|
||||
nsACString& aGroup,
|
||||
nsACString& aOrigin,
|
||||
bool* aIsApp);
|
||||
|
||||
virtual nsresult
|
||||
DoProcessOriginDirectories() override;
|
||||
};
|
||||
|
@ -1624,13 +1615,10 @@ private:
|
|||
class RestoreDirectoryMetadata2Helper final
|
||||
: public StorageDirectoryHelper
|
||||
{
|
||||
const bool mPersistent;
|
||||
|
||||
public:
|
||||
RestoreDirectoryMetadata2Helper(nsIFile* aDirectory,
|
||||
bool aPersistent)
|
||||
: StorageDirectoryHelper(aDirectory)
|
||||
, mPersistent(aPersistent)
|
||||
: StorageDirectoryHelper(aDirectory, aPersistent)
|
||||
{ }
|
||||
|
||||
nsresult
|
||||
|
@ -6783,6 +6771,55 @@ ClearDataOp::GetResponse(RequestResponse& aResponse)
|
|||
aResponse = ClearDataResponse();
|
||||
}
|
||||
|
||||
nsresult
|
||||
StorageDirectoryHelper::GetDirectoryMetadata(nsIFile* aDirectory,
|
||||
int64_t& aTimestamp,
|
||||
nsACString& aGroup,
|
||||
nsACString& aOrigin,
|
||||
Nullable<bool>& aIsApp)
|
||||
{
|
||||
AssertIsOnIOThread();
|
||||
MOZ_ASSERT(aDirectory);
|
||||
|
||||
nsCOMPtr<nsIBinaryInputStream> binaryStream;
|
||||
nsresult rv = GetBinaryInputStream(aDirectory,
|
||||
NS_LITERAL_STRING(METADATA_FILE_NAME),
|
||||
getter_AddRefs(binaryStream));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
uint64_t timestamp;
|
||||
rv = binaryStream->Read64(×tamp);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCString group;
|
||||
rv = binaryStream->ReadCString(group);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCString origin;
|
||||
rv = binaryStream->ReadCString(origin);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
Nullable<bool> isApp;
|
||||
bool value;
|
||||
if (NS_SUCCEEDED(binaryStream->ReadBoolean(&value))) {
|
||||
isApp.SetValue(value);
|
||||
}
|
||||
|
||||
aTimestamp = timestamp;
|
||||
aGroup = group;
|
||||
aOrigin = origin;
|
||||
aIsApp = Move(isApp);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
StorageDirectoryHelper::ProcessOriginDirectories()
|
||||
{
|
||||
|
@ -7395,12 +7432,12 @@ CreateOrUpgradeDirectoryMetadataHelper::CreateOrUpgradeMetadataFiles()
|
|||
int64_t timestamp;
|
||||
nsCString group;
|
||||
nsCString origin;
|
||||
bool hasIsApp;
|
||||
Nullable<bool> isApp;
|
||||
rv = GetDirectoryMetadata(originDir,
|
||||
×tamp,
|
||||
timestamp,
|
||||
group,
|
||||
origin,
|
||||
&hasIsApp);
|
||||
isApp);
|
||||
if (NS_FAILED(rv)) {
|
||||
timestamp = INT64_MIN;
|
||||
rv = GetLastModifiedTime(originDir, ×tamp);
|
||||
|
@ -7410,7 +7447,7 @@ CreateOrUpgradeDirectoryMetadataHelper::CreateOrUpgradeMetadataFiles()
|
|||
|
||||
originProps.mTimestamp = timestamp;
|
||||
originProps.mNeedsRestore = true;
|
||||
} else if (hasIsApp) {
|
||||
} else if (!isApp.IsNull()) {
|
||||
originProps.mIgnore = true;
|
||||
}
|
||||
}
|
||||
|
@ -7547,56 +7584,6 @@ CreateOrUpgradeDirectoryMetadataHelper::MaybeUpgradeOriginDirectory(
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
CreateOrUpgradeDirectoryMetadataHelper::GetDirectoryMetadata(
|
||||
nsIFile* aDirectory,
|
||||
int64_t* aTimestamp,
|
||||
nsACString& aGroup,
|
||||
nsACString& aOrigin,
|
||||
bool* aHasIsApp)
|
||||
{
|
||||
AssertIsOnIOThread();
|
||||
MOZ_ASSERT(aDirectory);
|
||||
MOZ_ASSERT(aTimestamp);
|
||||
MOZ_ASSERT(aHasIsApp);
|
||||
MOZ_ASSERT(!mPersistent);
|
||||
|
||||
nsCOMPtr<nsIBinaryInputStream> binaryStream;
|
||||
nsresult rv = GetBinaryInputStream(aDirectory,
|
||||
NS_LITERAL_STRING(METADATA_FILE_NAME),
|
||||
getter_AddRefs(binaryStream));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
uint64_t timestamp;
|
||||
rv = binaryStream->Read64(×tamp);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCString group;
|
||||
rv = binaryStream->ReadCString(group);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCString origin;
|
||||
rv = binaryStream->ReadCString(origin);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool dummyIsApp;
|
||||
bool hasIsApp = NS_SUCCEEDED(binaryStream->ReadBoolean(&dummyIsApp));
|
||||
|
||||
*aTimestamp = timestamp;
|
||||
aGroup = group;
|
||||
aOrigin = origin;
|
||||
*aHasIsApp = hasIsApp;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
CreateOrUpgradeDirectoryMetadataHelper::DoProcessOriginDirectories()
|
||||
{
|
||||
|
@ -7779,13 +7766,13 @@ UpgradeStorageFrom0_0To1_0Helper::DoUpgrade()
|
|||
int64_t timestamp;
|
||||
nsCString group;
|
||||
nsCString origin;
|
||||
bool isApp;
|
||||
Nullable<bool> isApp;
|
||||
nsresult rv = GetDirectoryMetadata(originDir,
|
||||
×tamp,
|
||||
timestamp,
|
||||
group,
|
||||
origin,
|
||||
&isApp);
|
||||
if (NS_FAILED(rv)) {
|
||||
isApp);
|
||||
if (NS_FAILED(rv) || isApp.IsNull()) {
|
||||
if (!mPersistent) {
|
||||
rv = GetLastModifiedTime(originDir, ×tamp);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
|
@ -7813,57 +7800,6 @@ UpgradeStorageFrom0_0To1_0Helper::DoUpgrade()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
UpgradeStorageFrom0_0To1_0Helper::GetDirectoryMetadata(nsIFile* aDirectory,
|
||||
int64_t* aTimestamp,
|
||||
nsACString& aGroup,
|
||||
nsACString& aOrigin,
|
||||
bool* aIsApp)
|
||||
{
|
||||
AssertIsOnIOThread();
|
||||
MOZ_ASSERT(aDirectory);
|
||||
MOZ_ASSERT(aTimestamp);
|
||||
MOZ_ASSERT(aIsApp);
|
||||
|
||||
nsCOMPtr<nsIBinaryInputStream> binaryStream;
|
||||
nsresult rv = GetBinaryInputStream(aDirectory,
|
||||
NS_LITERAL_STRING(METADATA_FILE_NAME),
|
||||
getter_AddRefs(binaryStream));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
uint64_t timestamp;
|
||||
rv = binaryStream->Read64(×tamp);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCString group;
|
||||
rv = binaryStream->ReadCString(group);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCString origin;
|
||||
rv = binaryStream->ReadCString(origin);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool isApp;
|
||||
rv = binaryStream->ReadBoolean(&isApp);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
*aTimestamp = timestamp;
|
||||
aGroup = group;
|
||||
aOrigin = origin;
|
||||
*aIsApp = isApp;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
UpgradeStorageFrom0_0To1_0Helper::DoProcessOriginDirectories()
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче