Bug 1749504 - Rename EnsureStorageIsInitialized to EnsureStorageIsInitializedInternal; r=dom-storage-reviewers,jstutte

One of the goals of bug 1749504 is to call EnsureStorageIsInitialized only from
InitOp. Calling from other places including quota clients will be disallowed
by changing the method to a private method. The private nature of the method
should be emphasized by adding the Internal suffix.

Changes done in this patch:
- IsStorageInitialized renamed to IsStorageInitializedInternal
- AssertStorageIsInitialized renamed to AssertStorageIsInitializedInternal
- EnsureStorageIsInitialized renamed to EnsureStorageIsInitializedInternal

Differential Revision: https://phabricator.services.mozilla.com/D185547
This commit is contained in:
Jan Varga 2023-09-12 12:40:41 +00:00
Родитель 0f1b3b72f4
Коммит 13ff443644
11 изменённых файлов: 46 добавлений и 42 удалений

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

@ -395,7 +395,8 @@ Context::QuotaInitRunnable::Run() {
QuotaManager* quotaManager = QuotaManager::Get();
MOZ_DIAGNOSTIC_ASSERT(quotaManager);
QM_TRY(MOZ_TO_RESULT(quotaManager->EnsureStorageIsInitialized()));
QM_TRY(
MOZ_TO_RESULT(quotaManager->EnsureStorageIsInitializedInternal()));
QM_TRY(
MOZ_TO_RESULT(quotaManager->EnsureTemporaryStorageIsInitialized()));

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

@ -170,7 +170,7 @@ nsresult EnsureFileSystemDirectory(
quota::QuotaManager* quotaManager = quota::QuotaManager::Get();
MOZ_ASSERT(quotaManager);
QM_TRY(MOZ_TO_RESULT(quotaManager->EnsureStorageIsInitialized()));
QM_TRY(MOZ_TO_RESULT(quotaManager->EnsureStorageIsInitializedInternal()));
QM_TRY(MOZ_TO_RESULT(quotaManager->EnsureTemporaryStorageIsInitialized()));

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

@ -71,7 +71,7 @@ class TestFileSystemQuotaClient
quota::QuotaManager* qm = quota::QuotaManager::Get();
ASSERT_TRUE(qm);
ASSERT_NSEQ(NS_OK, qm->EnsureStorageIsInitialized());
ASSERT_NSEQ(NS_OK, qm->EnsureStorageIsInitializedInternal());
ASSERT_NSEQ(NS_OK, qm->EnsureTemporaryStorageIsInitialized());

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

@ -13001,7 +13001,7 @@ nsresult Maintenance::DirectoryWork() {
QuotaManager* const quotaManager = QuotaManager::Get();
MOZ_ASSERT(quotaManager);
QM_TRY(MOZ_TO_RESULT(quotaManager->EnsureStorageIsInitialized()));
QM_TRY(MOZ_TO_RESULT(quotaManager->EnsureStorageIsInitializedInternal()));
// Since idle maintenance may occur before temporary storage is initialized,
// make sure it's initialized here (all non-persistent origins need to be
@ -15136,7 +15136,7 @@ nsresult OpenDatabaseOp::DoDatabaseWork() {
QuotaManager* const quotaManager = QuotaManager::Get();
MOZ_ASSERT(quotaManager);
QM_TRY(MOZ_TO_RESULT(quotaManager->EnsureStorageIsInitialized()));
QM_TRY(MOZ_TO_RESULT(quotaManager->EnsureStorageIsInitializedInternal()));
QM_TRY_INSPECT(
const auto& dbDirectory,

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

@ -2847,7 +2847,7 @@ nsresult LoadArchivedOrigins() {
MOZ_ASSERT(quotaManager);
// Ensure that the webappsstore.sqlite is moved to new place.
QM_TRY(MOZ_TO_RESULT(quotaManager->EnsureStorageIsInitialized()));
QM_TRY(MOZ_TO_RESULT(quotaManager->EnsureStorageIsInitializedInternal()));
QM_TRY_INSPECT(const auto& connection, CreateArchiveStorageConnection(
quotaManager->GetStoragePath()));
@ -6921,7 +6921,7 @@ nsresult PrepareDatastoreOp::DatabaseWork() {
MOZ_ASSERT(quotaManager);
// This must be called before EnsureTemporaryStorageIsInitialized.
QM_TRY(MOZ_TO_RESULT(quotaManager->EnsureStorageIsInitialized()));
QM_TRY(MOZ_TO_RESULT(quotaManager->EnsureStorageIsInitializedInternal()));
// This ensures that usages for existings origin directories are cached in
// memory.

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

@ -4414,7 +4414,7 @@ Result<Ok, nsresult> QuotaManager::CopyLocalStorageArchiveFromWebAppsStore(
// If there's any corruption detected during
// MaybeCreateOrUpgradeLocalStorageArchive (including nested calls like
// CopyLocalStorageArchiveFromWebAppsStore and CreateWebAppsStoreConnection)
// EnsureStorageIsInitialized will fallback to
// EnsureStorageIsInitializedInternal will fallback to
// CreateEmptyLocalStorageArchive.
// Ensure the storage directory actually exists.
@ -4552,9 +4552,9 @@ nsresult QuotaManager::UpgradeLocalStorageArchiveFrom4To5(
#ifdef DEBUG
void QuotaManager::AssertStorageIsInitialized() const {
void QuotaManager::AssertStorageIsInitializedInternal() const {
AssertIsOnIOThread();
MOZ_ASSERT(IsStorageInitialized());
MOZ_ASSERT(IsStorageInitializedInternal());
}
#endif // DEBUG
@ -4847,7 +4847,7 @@ Result<Ok, nsresult> QuotaManager::CreateEmptyLocalStorageArchive(
return Ok{};
}
nsresult QuotaManager::EnsureStorageIsInitialized() {
nsresult QuotaManager::EnsureStorageIsInitializedInternal() {
DiagnosticAssertIsOnIOThread();
const auto innerFunc =

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

@ -702,7 +702,7 @@ nsresult ClearPrivateRepositoryOp::DoDirectoryWork(
AUTO_PROFILER_LABEL("ClearPrivateRepositoryOp::DoDirectoryWork", OTHER);
QM_TRY(MOZ_TO_RESULT(aQuotaManager.EnsureStorageIsInitialized()));
QM_TRY(MOZ_TO_RESULT(aQuotaManager.EnsureStorageIsInitializedInternal()));
QM_TRY_INSPECT(
const auto& directory,
@ -890,7 +890,7 @@ nsresult GetUsageOp::DoDirectoryWork(QuotaManager& aQuotaManager) {
AUTO_PROFILER_LABEL("GetUsageOp::DoDirectoryWork", OTHER);
QM_TRY(MOZ_TO_RESULT(aQuotaManager.EnsureStorageIsInitialized()));
QM_TRY(MOZ_TO_RESULT(aQuotaManager.EnsureStorageIsInitializedInternal()));
nsresult rv;
@ -970,7 +970,7 @@ nsresult GetOriginUsageOp::DoDirectoryWork(QuotaManager& aQuotaManager) {
AUTO_PROFILER_LABEL("GetOriginUsageOp::DoDirectoryWork", OTHER);
QM_TRY(MOZ_TO_RESULT(aQuotaManager.EnsureStorageIsInitialized()));
QM_TRY(MOZ_TO_RESULT(aQuotaManager.EnsureStorageIsInitializedInternal()));
if (mFromMemory) {
const PrincipalMetadata principalMetadata = {
@ -1065,7 +1065,7 @@ nsresult StorageInitializedOp::DoDirectoryWork(QuotaManager& aQuotaManager) {
AUTO_PROFILER_LABEL("StorageInitializedOp::DoDirectoryWork", OTHER);
mInitialized = aQuotaManager.IsStorageInitialized();
mInitialized = aQuotaManager.IsStorageInitializedInternal();
return NS_OK;
}
@ -1111,7 +1111,7 @@ nsresult InitOp::DoDirectoryWork(QuotaManager& aQuotaManager) {
AUTO_PROFILER_LABEL("InitOp::DoDirectoryWork", OTHER);
QM_TRY(MOZ_TO_RESULT(aQuotaManager.EnsureStorageIsInitialized()));
QM_TRY(MOZ_TO_RESULT(aQuotaManager.EnsureStorageIsInitializedInternal()));
return NS_OK;
}
@ -1133,7 +1133,8 @@ nsresult InitTemporaryStorageOp::DoDirectoryWork(QuotaManager& aQuotaManager) {
AUTO_PROFILER_LABEL("InitTemporaryStorageOp::DoDirectoryWork", OTHER);
QM_TRY(OkIf(aQuotaManager.IsStorageInitialized()), NS_ERROR_NOT_INITIALIZED);
QM_TRY(OkIf(aQuotaManager.IsStorageInitializedInternal()),
NS_ERROR_NOT_INITIALIZED);
QM_TRY(MOZ_TO_RESULT(aQuotaManager.EnsureTemporaryStorageIsInitialized()));
@ -1195,7 +1196,8 @@ nsresult InitializePersistentOriginOp::DoDirectoryWork(
AUTO_PROFILER_LABEL("InitializePersistentOriginOp::DoDirectoryWork", OTHER);
QM_TRY(OkIf(aQuotaManager.IsStorageInitialized()), NS_ERROR_NOT_INITIALIZED);
QM_TRY(OkIf(aQuotaManager.IsStorageInitializedInternal()),
NS_ERROR_NOT_INITIALIZED);
QM_TRY_UNWRAP(
mCreated,
@ -1231,7 +1233,8 @@ nsresult InitializeTemporaryOriginOp::DoDirectoryWork(
AUTO_PROFILER_LABEL("InitializeTemporaryOriginOp::DoDirectoryWork", OTHER);
QM_TRY(OkIf(aQuotaManager.IsStorageInitialized()), NS_ERROR_NOT_INITIALIZED);
QM_TRY(OkIf(aQuotaManager.IsStorageInitializedInternal()),
NS_ERROR_NOT_INITIALIZED);
QM_TRY(OkIf(aQuotaManager.IsTemporaryStorageInitialized()),
NS_ERROR_NOT_INITIALIZED);
@ -1286,7 +1289,7 @@ nsresult GetFullOriginMetadataOp::DoDirectoryWork(QuotaManager& aQuotaManager) {
AUTO_PROFILER_LABEL("GetFullOriginMetadataOp::DoDirectoryWork", OTHER);
QM_TRY(MOZ_TO_RESULT(aQuotaManager.EnsureStorageIsInitialized()));
QM_TRY(MOZ_TO_RESULT(aQuotaManager.EnsureStorageIsInitializedInternal()));
// Ensure temporary storage is initialized. If temporary storage hasn't
// been initialized yet, the method will initialize it by traversing the
@ -1604,7 +1607,7 @@ nsresult ClearRequestBase::DoDirectoryWork(QuotaManager& aQuotaManager) {
AUTO_PROFILER_LABEL("ClearRequestBase::DoDirectoryWork", OTHER);
QM_TRY(MOZ_TO_RESULT(aQuotaManager.EnsureStorageIsInitialized()));
QM_TRY(MOZ_TO_RESULT(aQuotaManager.EnsureStorageIsInitializedInternal()));
if (mPersistenceType.IsNull()) {
for (const PersistenceType type : kAllPersistenceTypes) {
@ -1745,7 +1748,7 @@ nsresult PersistedOp::DoDirectoryWork(QuotaManager& aQuotaManager) {
AUTO_PROFILER_LABEL("PersistedOp::DoDirectoryWork", OTHER);
QM_TRY(MOZ_TO_RESULT(aQuotaManager.EnsureStorageIsInitialized()));
QM_TRY(MOZ_TO_RESULT(aQuotaManager.EnsureStorageIsInitializedInternal()));
const OriginMetadata originMetadata = {
mSuffix, mGroup, nsCString{mOriginScope.GetOrigin()},
@ -1807,7 +1810,7 @@ nsresult PersistOp::DoDirectoryWork(QuotaManager& aQuotaManager) {
AUTO_PROFILER_LABEL("PersistOp::DoDirectoryWork", OTHER);
QM_TRY(MOZ_TO_RESULT(aQuotaManager.EnsureStorageIsInitialized()));
QM_TRY(MOZ_TO_RESULT(aQuotaManager.EnsureStorageIsInitializedInternal()));
// Update directory metadata on disk first. Then, create/update the originInfo
// if needed.
@ -1898,7 +1901,7 @@ nsresult EstimateOp::DoDirectoryWork(QuotaManager& aQuotaManager) {
AUTO_PROFILER_LABEL("EstimateOp::DoDirectoryWork", OTHER);
QM_TRY(MOZ_TO_RESULT(aQuotaManager.EnsureStorageIsInitialized()));
QM_TRY(MOZ_TO_RESULT(aQuotaManager.EnsureStorageIsInitializedInternal()));
// Ensure temporary storage is initialized. If temporary storage hasn't been
// initialized yet, the method will initialize it by traversing the
@ -1934,7 +1937,7 @@ nsresult ListOriginsOp::DoDirectoryWork(QuotaManager& aQuotaManager) {
AUTO_PROFILER_LABEL("ListOriginsOp::DoDirectoryWork", OTHER);
QM_TRY(MOZ_TO_RESULT(aQuotaManager.EnsureStorageIsInitialized()));
QM_TRY(MOZ_TO_RESULT(aQuotaManager.EnsureStorageIsInitializedInternal()));
for (const PersistenceType type : kAllPersistenceTypes) {
QM_TRY(MOZ_TO_RESULT(TraverseRepository(aQuotaManager, type)));

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

@ -301,12 +301,12 @@ class QuotaManager final : public BackgroundThreadObject {
template <typename P>
void CollectPendingOriginsForListing(P aPredicate);
bool IsStorageInitialized() const {
bool IsStorageInitializedInternal() const {
AssertIsOnIOThread();
return static_cast<bool>(mStorageConnection);
}
void AssertStorageIsInitialized() const
void AssertStorageIsInitializedInternal() const
#ifdef DEBUG
;
#else
@ -314,7 +314,7 @@ class QuotaManager final : public BackgroundThreadObject {
}
#endif
nsresult EnsureStorageIsInitialized();
nsresult EnsureStorageIsInitializedInternal();
// Returns a pair of an nsIFile object referring to the directory, and a bool
// indicating whether the directory was newly created.

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

@ -56,7 +56,7 @@ TEST_F(TestFileOutputStream, extendFileStreamWithSetEOF) {
auto originMetadata = GetOutputStreamTestOriginMetadata();
{
ASSERT_NS_SUCCEEDED(quotaManager->EnsureStorageIsInitialized());
ASSERT_NS_SUCCEEDED(quotaManager->EnsureStorageIsInitializedInternal());
ASSERT_NS_SUCCEEDED(quotaManager->EnsureTemporaryStorageIsInitialized());

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

@ -27,11 +27,11 @@ TEST_F(TestQuotaManager, ShutdownStorage_Simple) {
QuotaManager* quotaManager = QuotaManager::Get();
ASSERT_TRUE(quotaManager);
ASSERT_FALSE(quotaManager->IsStorageInitialized());
ASSERT_FALSE(quotaManager->IsStorageInitializedInternal());
ASSERT_NS_SUCCEEDED(quotaManager->EnsureStorageIsInitialized());
ASSERT_NS_SUCCEEDED(quotaManager->EnsureStorageIsInitializedInternal());
ASSERT_TRUE(quotaManager->IsStorageInitialized());
ASSERT_TRUE(quotaManager->IsStorageInitializedInternal());
});
ASSERT_NO_FATAL_FAILURE(ShutdownStorage());
@ -40,7 +40,7 @@ TEST_F(TestQuotaManager, ShutdownStorage_Simple) {
QuotaManager* quotaManager = QuotaManager::Get();
ASSERT_TRUE(quotaManager);
ASSERT_FALSE(quotaManager->IsStorageInitialized());
ASSERT_FALSE(quotaManager->IsStorageInitializedInternal());
});
ASSERT_NO_FATAL_FAILURE(ShutdownStorage());
@ -54,11 +54,11 @@ TEST_F(TestQuotaManager, ShutdownStorage_Ongoing) {
QuotaManager* quotaManager = QuotaManager::Get();
ASSERT_TRUE(quotaManager);
ASSERT_FALSE(quotaManager->IsStorageInitialized());
ASSERT_FALSE(quotaManager->IsStorageInitializedInternal());
ASSERT_NS_SUCCEEDED(quotaManager->EnsureStorageIsInitialized());
ASSERT_NS_SUCCEEDED(quotaManager->EnsureStorageIsInitializedInternal());
ASSERT_TRUE(quotaManager->IsStorageInitialized());
ASSERT_TRUE(quotaManager->IsStorageInitializedInternal());
});
PerformOnBackgroundThread([]() {
@ -91,7 +91,7 @@ TEST_F(TestQuotaManager, ShutdownStorage_Ongoing) {
QuotaManager* quotaManager = QuotaManager::Get();
ASSERT_TRUE(quotaManager);
ASSERT_FALSE(quotaManager->IsStorageInitialized());
ASSERT_FALSE(quotaManager->IsStorageInitializedInternal());
});
ASSERT_NO_FATAL_FAILURE(ShutdownStorage());
@ -106,11 +106,11 @@ TEST_F(TestQuotaManager, ShutdownStorage_OngoingWithScheduledInitialization) {
QuotaManager* quotaManager = QuotaManager::Get();
ASSERT_TRUE(quotaManager);
ASSERT_FALSE(quotaManager->IsStorageInitialized());
ASSERT_FALSE(quotaManager->IsStorageInitializedInternal());
ASSERT_NS_SUCCEEDED(quotaManager->EnsureStorageIsInitialized());
ASSERT_NS_SUCCEEDED(quotaManager->EnsureStorageIsInitializedInternal());
ASSERT_TRUE(quotaManager->IsStorageInitialized());
ASSERT_TRUE(quotaManager->IsStorageInitializedInternal());
});
PerformOnBackgroundThread([]() {
@ -148,7 +148,7 @@ TEST_F(TestQuotaManager, ShutdownStorage_OngoingWithScheduledInitialization) {
QuotaManager* quotaManager = QuotaManager::Get();
ASSERT_TRUE(quotaManager);
ASSERT_FALSE(quotaManager->IsStorageInitialized());
ASSERT_FALSE(quotaManager->IsStorageInitializedInternal());
});
ASSERT_NO_FATAL_FAILURE(ShutdownStorage());

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

@ -1182,7 +1182,7 @@ nsresult OpenOp::DatabaseWork() {
QuotaManager* quotaManager = QuotaManager::Get();
MOZ_ASSERT(quotaManager);
QM_TRY(MOZ_TO_RESULT(quotaManager->EnsureStorageIsInitialized()));
QM_TRY(MOZ_TO_RESULT(quotaManager->EnsureStorageIsInitializedInternal()));
QM_TRY_INSPECT(
const auto& dbDirectory,