Backed out 2 changesets (bug 1645943) for build bustages on QuotaClient.cpp. CLOSED TREE

Backed out changeset 7a2022403814 (bug 1645943)
Backed out changeset 3ed2b9424225 (bug 1645943)
This commit is contained in:
Brindusan Cristian 2020-06-23 01:11:33 +03:00
Родитель 83d0df93cf
Коммит a338574f2d
5 изменённых файлов: 50 добавлений и 95 удалений

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

@ -33,18 +33,12 @@ using mozilla::dom::quota::PersistenceType;
namespace {
nsresult WipeDatabase(const QuotaInfo& aQuotaInfo, nsIFile* aDBFile) {
nsresult WipeDatabase(const QuotaInfo& aQuotaInfo, nsIFile* aDBFile,
nsIFile* aDBDir) {
MOZ_DIAGNOSTIC_ASSERT(aDBFile);
MOZ_DIAGNOSTIC_ASSERT(aDBDir);
nsCOMPtr<nsIFile> dbDir;
nsresult rv = aDBFile->GetParent(getter_AddRefs(dbDir));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
MOZ_ASSERT(dbDir);
rv = RemoveNsIFile(aQuotaInfo, aDBFile);
nsresult rv = RemoveNsIFile(aQuotaInfo, aDBFile);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -53,12 +47,12 @@ nsresult WipeDatabase(const QuotaInfo& aQuotaInfo, nsIFile* aDBFile) {
// the new database is created. No need to explicitly delete it here.
// Delete the morgue as well.
rv = BodyDeleteDir(aQuotaInfo, dbDir);
rv = BodyDeleteDir(aQuotaInfo, aDBDir);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = WipePaddingFile(aQuotaInfo, dbDir);
rv = WipePaddingFile(aQuotaInfo, aDBDir);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -150,18 +144,9 @@ nsresult DBAction::OpenConnection(const QuotaInfo& aQuotaInfo, nsIFile* aDBDir,
}
}
nsCOMPtr<nsIFile> dbFile;
rv = aDBDir->Clone(getter_AddRefs(dbFile));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = OpenDBConnection(aQuotaInfo, aDBDir, aConnOut);
rv = dbFile->Append(kCachesSQLiteFilename);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return OpenDBConnection(aQuotaInfo, dbFile, aConnOut);
return rv;
}
SyncDBAction::SyncDBAction(Mode aMode) : DBAction(aMode) {}
@ -182,25 +167,44 @@ void SyncDBAction::RunWithDBOnTarget(Resolver* aResolver,
}
// static
nsresult OpenDBConnection(const QuotaInfo& aQuotaInfo, nsIFile* aDBFile,
nsresult OpenDBConnection(const QuotaInfo& aQuotaInfo, nsIFile* aDBDir,
mozIStorageConnection** aConnOut) {
MOZ_ASSERT(!NS_IsMainThread());
MOZ_DIAGNOSTIC_ASSERT(aQuotaInfo.mDirectoryLockId >= -1);
MOZ_DIAGNOSTIC_ASSERT(aDBFile);
MOZ_DIAGNOSTIC_ASSERT(aDBDir);
MOZ_DIAGNOSTIC_ASSERT(aConnOut);
nsCOMPtr<mozIStorageConnection> conn;
nsCOMPtr<nsIFile> dbFile;
nsresult rv = aDBDir->Clone(getter_AddRefs(dbFile));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = dbFile->Append(NS_LITERAL_STRING("caches.sqlite"));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
bool exists = false;
rv = dbFile->Exists(&exists);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
// Use our default file:// protocol handler directly to construct the database
// URL. This avoids any problems if a plugin registers a custom file://
// handler. If such a custom handler used javascript, then we would have a
// bad time running off the main thread here.
RefPtr<nsFileProtocolHandler> handler = new nsFileProtocolHandler();
nsresult rv = handler->Init();
rv = handler->Init();
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
nsCOMPtr<nsIURIMutator> mutator;
rv = handler->NewFileURIMutator(aDBFile, getter_AddRefs(mutator));
rv = handler->NewFileURIMutator(dbFile, getter_AddRefs(mutator));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -227,7 +231,6 @@ nsresult OpenDBConnection(const QuotaInfo& aQuotaInfo, nsIFile* aDBFile,
return NS_ERROR_UNEXPECTED;
}
nsCOMPtr<mozIStorageConnection> conn;
rv = ss->OpenDatabaseWithFileURL(dbFileUrl, getter_AddRefs(conn));
if (rv == NS_ERROR_FILE_CORRUPTED) {
NS_WARNING("Cache database corrupted. Recreating empty database.");
@ -236,7 +239,7 @@ nsresult OpenDBConnection(const QuotaInfo& aQuotaInfo, nsIFile* aDBFile,
// There is nothing else we can do to recover. Also, this data can
// be deleted by QuotaManager at any time anyways.
rv = WipeDatabase(aQuotaInfo, aDBFile);
rv = WipeDatabase(aQuotaInfo, dbFile, aDBDir);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -255,7 +258,7 @@ nsresult OpenDBConnection(const QuotaInfo& aQuotaInfo, nsIFile* aDBFile,
}
if (schemaVersion > 0 && schemaVersion < db::kFirstShippedSchemaVersion) {
conn = nullptr;
rv = WipeDatabase(aQuotaInfo, aDBFile);
rv = WipeDatabase(aQuotaInfo, dbFile, aDBDir);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}

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

@ -18,7 +18,7 @@ namespace mozilla {
namespace dom {
namespace cache {
nsresult OpenDBConnection(const QuotaInfo& aQuotaInfo, nsIFile* aDBFile,
nsresult OpenDBConnection(const QuotaInfo& aQuotaInfo, nsIFile* aDBDir,
mozIStorageConnection** aConnOut);
class DBAction : public Action {

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

@ -27,7 +27,6 @@ using mozilla::Some;
using mozilla::Unused;
using mozilla::dom::ContentParentId;
using mozilla::dom::cache::DirPaddingFile;
using mozilla::dom::cache::kCachesSQLiteFilename;
using mozilla::dom::cache::Manager;
using mozilla::dom::cache::QuotaInfo;
using mozilla::dom::quota::AssertIsOnIOThread;
@ -125,35 +124,15 @@ static nsresult LockedGetPaddingSizeFromDB(nsIFile* aDir,
// for the SQLite file).
MOZ_DIAGNOSTIC_ASSERT(quotaInfo.mDirectoryLockId == -1);
nsCOMPtr<nsIFile> dbFile;
nsresult rv = aDir->Clone(getter_AddRefs(dbFile));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = dbFile->Append(kCachesSQLiteFilename);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
bool exists = false;
rv = dbFile->Exists(&exists);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
// Return NS_OK with size = 0 if caches.sqlite doesn't exist.
// This function is only called if the value of the padding size couldn't be
// determined from the padding file, possibly because it doesn't exist, or a
// leftover temporary padding file was found.
// There is no other way to get the overall padding size of an origin.
if (!exists) {
nsCOMPtr<mozIStorageConnection> conn;
nsresult rv = mozilla::dom::cache::OpenDBConnection(quotaInfo, aDir,
getter_AddRefs(conn));
if (rv == NS_ERROR_FILE_NOT_FOUND ||
rv == NS_ERROR_FILE_TARGET_DOES_NOT_EXIST) {
// Return NS_OK with size = 0 if both the db and padding file don't exist.
// There is no other way to get the overall padding size of an origin.
return NS_OK;
}
nsCOMPtr<mozIStorageConnection> conn;
rv = mozilla::dom::cache::OpenDBConnection(quotaInfo, dbFile,
getter_AddRefs(conn));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -186,8 +165,6 @@ namespace mozilla {
namespace dom {
namespace cache {
const auto kCachesSQLiteFilename = NS_LITERAL_STRING("caches.sqlite");
CacheQuotaClient::CacheQuotaClient()
: mDirPaddingFileMutex("DOMCacheQuotaClient.mDirPaddingFileMutex") {
AssertIsOnBackgroundThread();
@ -483,7 +460,7 @@ nsresult CacheQuotaClient::GetUsageForOriginInternal(
continue;
}
if (leafName.Equals(kCachesSQLiteFilename) ||
if (leafName.EqualsLiteral("caches.sqlite") ||
leafName.EqualsLiteral("caches.sqlite-wal")) {
int64_t fileSize;
rv = file->GetFileSize(&fileSize);

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

@ -41,8 +41,6 @@ nsresult RestorePaddingFile(nsIFile* aBaseDir, mozIStorageConnection* aConn);
nsresult WipePaddingFile(const QuotaInfo& aQuotaInfo, nsIFile* aBaseDir);
extern const nsLiteralString kCachesSQLiteFilename;
} // namespace cache
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -6,21 +6,12 @@
/**
* This test is mainly to verify initTemporaryStorage() does call
* QuotaManager::EnsureTemporaryStorageIsInitialized() which does various
* things, for example,
* - it restores the directory metadata if it's broken or missing.
* - it isn't blocked by a cache directory in an origin that ends with period.
* things, for example, it restores the directory metadata if it's broken or
* missing.
*/
async function testSteps() {
const defaultRepositoryPath = "storage/default";
const originDirPaths = [
`${defaultRepositoryPath}/https+++foo.example.com`,
// Bug 1647316: We should have a test that checks all possible combinations
// that we can get during cache origin initialization. Once we have a test
// for that, we can revert this change.
`${defaultRepositoryPath}/https+++example.com.`,
];
const originDirPath = "storage/default/https+++foo.example.com";
const metadataFileName = ".metadata-v2";
info("Initializing");
@ -34,20 +25,8 @@ async function testSteps() {
info("Creating an empty directory");
let originDirs = [];
for (let originDirPath of originDirPaths) {
let originDir = getRelativeFile(originDirPath);
originDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0o755);
originDirs.push(originDir);
}
info("Creating an empty cache directory for origin that ends with period");
let originDirPathEndsWithPeriod = originDirPaths.find(path =>
path.endsWith(".")
);
let cacheDir = getRelativeFile(`${originDirPathEndsWithPeriod}/cache`);
cacheDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0o755);
let originDir = getRelativeFile(originDirPath);
originDir.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt("0755", 8));
info("Initializing the temporary storage");
@ -59,12 +38,10 @@ async function testSteps() {
"initTemporaryStorage()"
);
for (let originDir of originDirs) {
let metadataFile = originDir.clone();
metadataFile.append(metadataFileName);
let metadataFile = originDir.clone();
metadataFile.append(metadataFileName);
ok(metadataFile.exists(), "Directory metadata file does exist");
}
ok(metadataFile.exists(), "Directory metadata file does exist");
info("Verifying initialization status");