From a892bc01f676a916ca5d63e56e926ab0d760b085 Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Thu, 14 May 2020 09:14:04 +0000 Subject: [PATCH] Bug 1633719 - Use *InitializedOnce* with NotNull instead of *InitializedOnce*NotNull for pointers. r=dom-workers-and-storage-reviewers,janv Differential Revision: https://phabricator.services.mozilla.com/D73025 --- dom/indexedDB/ActorsChild.cpp | 4 +-- dom/indexedDB/ActorsChild.h | 4 +-- dom/indexedDB/ActorsParent.cpp | 55 +++++++++++++++++----------------- dom/indexedDB/IDBCursor.cpp | 2 +- dom/indexedDB/IDBCursor.h | 4 +-- 5 files changed, 34 insertions(+), 35 deletions(-) diff --git a/dom/indexedDB/ActorsChild.cpp b/dom/indexedDB/ActorsChild.cpp index 33711d2731b5..a55a30547808 100644 --- a/dom/indexedDB/ActorsChild.cpp +++ b/dom/indexedDB/ActorsChild.cpp @@ -3128,7 +3128,7 @@ BackgroundRequestChild::PreprocessHelper::OnFileMetadataReady( BackgroundCursorChildBase::BackgroundCursorChildBase(IDBRequest* const aRequest, const Direction aDirection) - : mRequest(aRequest), + : mRequest(WrapNotNull(aRequest)), mTransaction(aRequest->MaybeTransactionRef()), mStrongRequest(aRequest), mDirection(aDirection) { @@ -3140,7 +3140,7 @@ BackgroundCursorChild::BackgroundCursorChild(IDBRequest* aRequest, SourceType* aSource, Direction aDirection) : BackgroundCursorChildBase(aRequest, aDirection), - mSource(aSource), + mSource(WrapNotNull(aSource)), mCursor(nullptr), mInFlightResponseInvalidationNeeded(false) { aSource->AssertIsOnOwningThread(); diff --git a/dom/indexedDB/ActorsChild.h b/dom/indexedDB/ActorsChild.h index e252227bb469..a603aa1e8758 100644 --- a/dom/indexedDB/ActorsChild.h +++ b/dom/indexedDB/ActorsChild.h @@ -640,7 +640,7 @@ class BackgroundCursorChildBase : public PBackgroundIDBCursorChild { private: NS_DECL_OWNINGTHREAD protected: - InitializedOnceNotNull mRequest; + InitializedOnce> mRequest; Maybe mTransaction; // These are only set while a request is in progress. @@ -685,7 +685,7 @@ class BackgroundCursorChild final : public BackgroundCursorChildBase { friend class BackgroundTransactionChild; friend class BackgroundVersionChangeTransactionChild; - InitializedOnceNotNull mSource; + InitializedOnce> mSource; IDBCursorImpl* mCursor; std::deque> mCachedResponses, mDelayedResponses; diff --git a/dom/indexedDB/ActorsParent.cpp b/dom/indexedDB/ActorsParent.cpp index 372721a4fb4f..628a3acc78bc 100644 --- a/dom/indexedDB/ActorsParent.cpp +++ b/dom/indexedDB/ActorsParent.cpp @@ -4660,9 +4660,9 @@ class DatabaseConnection final { class UpdateRefcountFunction; private: - InitializedOnceNotNull> + InitializedOnce>> mStorageConnection; - InitializedOnceNotNull> mFileManager; + InitializedOnce>> mFileManager; nsInterfaceHashtable mCachedStatements; RefPtr mUpdateRefcountFunction; @@ -4967,7 +4967,7 @@ class ConnectionPool final { }; struct IdleDatabaseInfo final : public IdleResource { - InitializedOnceNotNull mDatabaseInfo; + InitializedOnce> mDatabaseInfo; public: explicit IdleDatabaseInfo(DatabaseInfo* aDatabaseInfo); @@ -5619,7 +5619,7 @@ class TransactionDatabaseOperationBase : public DatabaseOperationBase { Completed }; - InitializedOnceNotNull> mTransaction; + InitializedOnce>> mTransaction; InternalState mInternalState = InternalState::Initial; bool mWaitingForContinue = false; const bool mTransactionIsAborted; @@ -7390,7 +7390,7 @@ class ObjectStoreAddOrPutRequestOp final : public NormalTransactionOp { typedef mozilla::dom::quota::PersistenceType PersistenceType; class StoredFileInfo final { - InitializedOnceNotNull> mFileInfo; + InitializedOnce>> mFileInfo; // Either nothing, a file actor or a non-Blob-backed inputstream to write to // disk. using FileActorOrInputStream = @@ -7532,7 +7532,7 @@ void ObjectStoreAddOrPutRequestOp::StoredFileInfo::AssertInvariants() const { ObjectStoreAddOrPutRequestOp::StoredFileInfo::StoredFileInfo( SafeRefPtr aFileInfo) - : mFileInfo{std::move(aFileInfo)}, mFileActorOrInputStream { + : mFileInfo{WrapNotNull(std::move(aFileInfo))}, mFileActorOrInputStream { Nothing {} } #ifdef DEBUG @@ -7547,7 +7547,7 @@ ObjectStoreAddOrPutRequestOp::StoredFileInfo::StoredFileInfo( ObjectStoreAddOrPutRequestOp::StoredFileInfo::StoredFileInfo( SafeRefPtr aFileInfo, RefPtr aFileActor) - : mFileInfo{std::move(aFileInfo)}, mFileActorOrInputStream { + : mFileInfo{WrapNotNull(std::move(aFileInfo))}, mFileActorOrInputStream { std::move(aFileActor) } #ifdef DEBUG @@ -7562,7 +7562,7 @@ ObjectStoreAddOrPutRequestOp::StoredFileInfo::StoredFileInfo( ObjectStoreAddOrPutRequestOp::StoredFileInfo::StoredFileInfo( SafeRefPtr aFileInfo, nsCOMPtr aInputStream) - : mFileInfo{std::move(aFileInfo)}, mFileActorOrInputStream { + : mFileInfo{WrapNotNull(std::move(aFileInfo))}, mFileActorOrInputStream { std::move(aInputStream) } #ifdef DEBUG @@ -7947,7 +7947,7 @@ class CursorBase : public PBackgroundIDBCursorParent { // This should only be touched on the PBackground thread to check whether // the objectStore has been deleted. Holding these saves a hash lookup for // every call to continue()/advance(). - InitializedOnceNotNull> + InitializedOnce>> mObjectStoreMetadata; const IndexOrObjectStoreId mObjectStoreId; @@ -7995,7 +7995,7 @@ class IndexCursorBase : public CursorBase { ConstructFromTransactionBase aConstructionTag) : CursorBase{std::move(aTransaction), std::move(aObjectStoreMetadata), aDirection, aConstructionTag}, - mIndexMetadata(std::move(aIndexMetadata)), + mIndexMetadata(WrapNotNull(std::move(aIndexMetadata))), mIndexId((*mIndexMetadata)->mCommonMetadata.id()), mUniqueIndex((*mIndexMetadata)->mCommonMetadata.unique()), mLocale((*mIndexMetadata)->mCommonMetadata.locale()) {} @@ -8006,7 +8006,7 @@ class IndexCursorBase : public CursorBase { // This should only be touched on the PBackground thread to check whether // the index has been deleted. Holding these saves a hash lookup for every // call to continue()/advance(). - InitializedOnceNotNull> mIndexMetadata; + InitializedOnce>> mIndexMetadata; const IndexOrObjectStoreId mIndexId; const bool mUniqueIndex; const nsCString @@ -8068,7 +8068,7 @@ class ValueCursorBase { explicit ValueCursorBase(TransactionBase* const aTransaction) : mDatabase(aTransaction->GetDatabasePtr()), mFileManager(mDatabase->GetFileManagerPtr()), - mBackgroundParent(aTransaction->GetBackgroundParent()) { + mBackgroundParent(WrapNotNull(aTransaction->GetBackgroundParent())) { MOZ_ASSERT(mDatabase); MOZ_ASSERT(mFileManager); } @@ -8080,7 +8080,7 @@ class ValueCursorBase { const SafeRefPtr mDatabase; const SafeRefPtr mFileManager; - InitializedOnceNotNull mBackgroundParent; + InitializedOnce> mBackgroundParent; }; class KeyCursorBase { @@ -9075,11 +9075,11 @@ class DEBUGThreadSlower final : public nsIThreadObserver { class MOZ_STACK_CLASS FileHelper final { const SafeRefPtr mFileManager; - LazyInitializedOnceNotNull> mFileDirectory; - LazyInitializedOnceNotNull> mJournalDirectory; + LazyInitializedOnce>> mFileDirectory; + LazyInitializedOnce>> mJournalDirectory; class ReadCallback; - LazyInitializedOnceNotNull> mReadCallback; + LazyInitializedOnce>> mReadCallback; public: explicit FileHelper(SafeRefPtr&& aFileManager) @@ -10680,8 +10680,8 @@ nsresult FileManager::AsyncDeleteFile(int64_t aFileId) { DatabaseConnection::DatabaseConnection( nsCOMPtr aStorageConnection, SafeRefPtr aFileManager) - : mStorageConnection(std::move(aStorageConnection)), - mFileManager(std::move(aFileManager)), + : mStorageConnection(WrapNotNull(std::move(aStorageConnection))), + mFileManager(WrapNotNull(std::move(aFileManager))), mInReadTransaction(false), mInWriteTransaction(false) #ifdef DEBUG @@ -13180,7 +13180,7 @@ ConnectionPool::IdleDatabaseInfo::IdleDatabaseInfo(DatabaseInfo* aDatabaseInfo) (aDatabaseInfo->mIdle ? TimeDuration::FromMilliseconds(kConnectionIdleMaintenanceMS) : TimeDuration::FromMilliseconds(kConnectionIdleCloseMS))), - mDatabaseInfo(aDatabaseInfo) { + mDatabaseInfo(WrapNotNull(aDatabaseInfo)) { AssertIsOnBackgroundThread(); MOZ_ASSERT(aDatabaseInfo); @@ -16057,7 +16057,7 @@ CursorBase::CursorBase(SafeRefPtr aTransaction, const Direction aDirection, const ConstructFromTransactionBase /*aConstructionTag*/) : mTransaction(std::move(aTransaction)), - mObjectStoreMetadata(std::move(aObjectStoreMetadata)), + mObjectStoreMetadata(WrapNotNull(std::move(aObjectStoreMetadata))), mObjectStoreId((*mObjectStoreMetadata)->mCommonMetadata.id()), mDirection(aDirection), mMaxExtraCount(IndexedDatabaseManager::MaxPreloadExtraRecords()), @@ -16243,7 +16243,6 @@ void ValueCursorBase::ProcessFiles(CursorResponse& aResponse, aResponse.type() == CursorResponse::TArrayOfIndexCursorResponse); MOZ_ASSERT(this->mDatabase); - MOZ_ASSERT(*this->mBackgroundParent); auto res = SerializeStructuredCloneFiles((*this->mBackgroundParent), this->mDatabase, files, @@ -22884,7 +22883,7 @@ TransactionDatabaseOperationBase::TransactionDatabaseOperationBase( SafeRefPtr aTransaction) : DatabaseOperationBase(aTransaction->GetLoggingInfo()->Id(), aTransaction->GetLoggingInfo()->NextRequestSN()), - mTransaction(std::move(aTransaction)), + mTransaction(WrapNotNull(std::move(aTransaction))), mTransactionIsAborted((*mTransaction)->IsAborted()), mTransactionLoggingSerialNumber((*mTransaction)->LoggingSerialNumber()) { MOZ_ASSERT(LoggingSerialNumber()); @@ -22894,7 +22893,7 @@ TransactionDatabaseOperationBase::TransactionDatabaseOperationBase( SafeRefPtr aTransaction, uint64_t aLoggingSerialNumber) : DatabaseOperationBase(aTransaction->GetLoggingInfo()->Id(), aLoggingSerialNumber), - mTransaction(std::move(aTransaction)), + mTransaction(WrapNotNull(std::move(aTransaction))), mTransactionIsAborted((*mTransaction)->IsAborted()), mTransactionLoggingSerialNumber((*mTransaction)->LoggingSerialNumber()) {} @@ -27612,8 +27611,8 @@ nsresult FileHelper::Init() { MOZ_ASSERT(NS_SUCCEEDED(journalDirectory->IsDirectory(&isDirectory))); MOZ_ASSERT(isDirectory); - mFileDirectory.init(std::move(fileDirectory)); - mJournalDirectory.init(std::move(journalDirectory)); + mFileDirectory.init(WrapNotNullUnchecked(std::move(fileDirectory))); + mJournalDirectory.init(WrapNotNullUnchecked(std::move(journalDirectory))); return NS_OK; } @@ -27621,13 +27620,13 @@ nsresult FileHelper::Init() { nsCOMPtr FileHelper::GetFile(const FileInfo& aFileInfo) { MOZ_ASSERT(!IsOnBackgroundThread()); - return mFileManager->GetFileForId(*mFileDirectory, aFileInfo.Id()); + return mFileManager->GetFileForId(mFileDirectory->get(), aFileInfo.Id()); } nsCOMPtr FileHelper::GetJournalFile(const FileInfo& aFileInfo) { MOZ_ASSERT(!IsOnBackgroundThread()); - return mFileManager->GetFileForId(*mJournalDirectory, aFileInfo.Id()); + return mFileManager->GetFileForId(mJournalDirectory->get(), aFileInfo.Id()); } nsresult FileHelper::CreateFileFromStream(nsIFile& aFile, nsIFile& aJournalFile, @@ -27800,7 +27799,7 @@ nsresult FileHelper::SyncRead(nsIInputStream& aInputStream, char* const aBuffer, } if (!mReadCallback) { - mReadCallback.init(new ReadCallback()); + mReadCallback.init(MakeNotNull>()); } // We just need any thread with an event loop for receiving the diff --git a/dom/indexedDB/IDBCursor.cpp b/dom/indexedDB/IDBCursor.cpp index 3c7626c6ce62..ff5e954cfdda 100644 --- a/dom/indexedDB/IDBCursor.cpp +++ b/dom/indexedDB/IDBCursor.cpp @@ -28,7 +28,7 @@ namespace dom { using namespace indexedDB; IDBCursor::IDBCursor(BackgroundCursorChildBase* const aBackgroundActor) - : mBackgroundActor(aBackgroundActor), + : mBackgroundActor(WrapNotNull(aBackgroundActor)), mRequest(aBackgroundActor->GetRequest()), mTransaction(&mRequest->MutableTransactionRef()), mCachedKey(JS::UndefinedValue()), diff --git a/dom/indexedDB/IDBCursor.h b/dom/indexedDB/IDBCursor.h index 8e6e2698d29a..4c337972c6d2 100644 --- a/dom/indexedDB/IDBCursor.h +++ b/dom/indexedDB/IDBCursor.h @@ -52,7 +52,7 @@ class IDBCursor : public nsISupports, public nsWrapperCache { using Type = IDBCursorType; protected: - InitializedOnceNotNull + InitializedOnce> mBackgroundActor; // TODO: mRequest could be made const if Bug 1575173 is resolved. It is @@ -241,7 +241,7 @@ class IDBTypedCursor : public IDBCursor { // initialized that in the constructor from that type. We just want to avoid // having a second typed field. return *static_cast*>( - *mBackgroundActor); + mBackgroundActor->get()); } bool IsSourceDeleted() const;