Commit 59bc885b authored by Simon Giesecke's avatar Simon Giesecke
Browse files

Bug 1597954 - Switch indexedDB to use InitializedOnce from mfbt....

Bug 1597954 - Switch indexedDB to use InitializedOnce from mfbt. r=dom-workers-and-storage-reviewers,janv

Differential Revision: https://phabricator.services.mozilla.com/D65710

--HG--
extra : moz-landing-system : lando
parent a0175d81
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -3421,12 +3421,12 @@ void BackgroundCursorChild<CursorType>::SendDeleteMeInternal() {
  MOZ_ASSERT(!mStrongRequest);
  MOZ_ASSERT(!mStrongCursor);

  mRequest.reset();
  mRequest.destroy();
  mTransaction = nullptr;
  // TODO: The things until here could be pulled up to
  // BackgroundCursorChildBase.

  mSource.reset();
  mSource.destroy();

  if (mCursor) {
    mCursor->ClearBackgroundActor();
@@ -3677,9 +3677,9 @@ void BackgroundCursorChild<CursorType>::ActorDestroy(ActorDestroyReason aWhy) {
  }

#ifdef DEBUG
  mRequest.maybeReset();
  mRequest.maybeDestroy();
  mTransaction = nullptr;
  mSource.maybeReset();
  mSource.maybeDestroy();
#endif
}

+3 −2
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
#include "mozilla/dom/PBackgroundFileHandleChild.h"
#include "mozilla/dom/PBackgroundFileRequestChild.h"
#include "mozilla/dom/PBackgroundMutableFileChild.h"
#include "mozilla/InitializedOnce.h"
#include "mozilla/UniquePtr.h"
#include "nsCOMPtr.h"
#include "nsTArray.h"
@@ -636,7 +637,7 @@ class BackgroundCursorChildBase : public PBackgroundIDBCursorChild {
 private:
  NS_DECL_OWNINGTHREAD
 protected:
  InitializedOnceMustBeTrue<IDBRequest* const> mRequest;
  InitializedOnceNotNull<IDBRequest* const> mRequest;
  IDBTransaction* mTransaction;

  // These are only set while a request is in progress.
@@ -681,7 +682,7 @@ class BackgroundCursorChild final : public BackgroundCursorChildBase {
  friend class BackgroundTransactionChild;
  friend class BackgroundVersionChangeTransactionChild;

  InitializedOnceMustBeTrue<SourceType* const> mSource;
  InitializedOnceNotNull<SourceType* const> mSource;
  IDBCursorImpl<CursorType>* mCursor;

  std::deque<CursorData<CursorType>> mCachedResponses, mDelayedResponses;
+26 −32
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
#include "IndexedDatabase.h"
#include "IndexedDatabaseInlines.h"
#include "IndexedDatabaseManager.h"
#include "InitializedOnce.h"
#include "js/StructuredClone.h"
#include "js/Value.h"
#include "jsapi.h"
@@ -30,6 +29,7 @@
#include "mozilla/CycleCollectedJSRuntime.h"
#include "mozilla/EndianUtils.h"
#include "mozilla/ErrorNames.h"
#include "mozilla/InitializedOnce.h"
#include "mozilla/JSObjectHolder.h"
#include "mozilla/LazyIdleThread.h"
#include "mozilla/Maybe.h"
@@ -4719,9 +4719,9 @@ class DatabaseConnection final {
  class UpdateRefcountFunction;
 private:
  InitializedOnceMustBeTrue<const nsCOMPtr<mozIStorageConnection>>
  InitializedOnceNotNull<const nsCOMPtr<mozIStorageConnection>>
      mStorageConnection;
  InitializedOnceMustBeTrue<const SafeRefPtr<FileManager>> mFileManager;
  InitializedOnceNotNull<const SafeRefPtr<FileManager>> mFileManager;
  nsInterfaceHashtable<nsCStringHashKey, mozIStorageStatement>
      mCachedStatements;
  RefPtr<UpdateRefcountFunction> mUpdateRefcountFunction;
@@ -5308,7 +5308,7 @@ struct ConnectionPool::IdleResource {
};
struct ConnectionPool::IdleDatabaseInfo final : public IdleResource {
  InitializedOnceMustBeTrue<DatabaseInfo* const> mDatabaseInfo;
  InitializedOnceNotNull<DatabaseInfo* const> mDatabaseInfo;
 public:
  explicit IdleDatabaseInfo(DatabaseInfo* aDatabaseInfo);
@@ -5681,7 +5681,7 @@ class TransactionDatabaseOperationBase : public DatabaseOperationBase {
    Completed
  };
  InitializedOnce<const OwningNonNull<TransactionBase>> mTransaction;
  InitializedOnceNotNull<const RefPtr<TransactionBase>> mTransaction;
  InternalState mInternalState = InternalState::Initial;
  bool mWaitingForContinue = false;
  const bool mTransactionIsAborted;
@@ -6260,7 +6260,7 @@ class DatabaseFile final : public PBackgroundIDBDatabaseFileParent {
    MOZ_ASSERT(!IsOnBackgroundThread());
    MOZ_ASSERT(*mBlobImpl);
    mBlobImpl.reset();
    mBlobImpl.destroy();
  }
 public:
@@ -6322,7 +6322,7 @@ class TransactionBase {
  const SafeRefPtr<Database> mDatabase;
  nsTArray<RefPtr<FullObjectStoreMetadata>>
      mModifiedAutoIncrementObjectStoreMetadataArray;
  InitializedOnceMustBeTrue<const uint64_t, LazyInit::Allow> mTransactionId;
  LazyInitializedOnceNotNull<const uint64_t> mTransactionId;
  const nsCString mDatabaseId;
  const int64_t mLoggingSerialNumber;
  uint64_t mActiveRequestCount;
@@ -6338,8 +6338,7 @@ class TransactionBase {
  FlippedOnce<false> mCommitOrAbortReceived;
  FlippedOnce<false> mCommittedOrAborted;
  FlippedOnce<false> mForceAborted;
  InitializedOnce<const Maybe<int64_t>, LazyInit::Allow>
      mLastRequestBeforeCommit;
  LazyInitializedOnce<const Maybe<int64_t>> mLastRequestBeforeCommit;
  Maybe<int64_t> mLastFailedRequest;
 public:
@@ -7208,7 +7207,7 @@ class DatabaseOp : public DatabaseOperationBase,
class CreateFileOp final : public DatabaseOp {
  const CreateFileParams mParams;
  InitializedOnce<const SafeRefPtr<FileInfo>, LazyInit::Allow> mFileInfo;
  LazyInitializedOnce<const SafeRefPtr<FileInfo>> mFileInfo;
 public:
  CreateFileOp(SafeRefPtr<Database> aDatabase,
@@ -7494,7 +7493,7 @@ class ObjectStoreAddOrPutRequestOp final : public NormalTransactionOp {
};
class ObjectStoreAddOrPutRequestOp::StoredFileInfo final {
  InitializedOnceMustBeTrue<const SafeRefPtr<FileInfo>> mFileInfo;
  InitializedOnceNotNull<const SafeRefPtr<FileInfo>> mFileInfo;
  // Either nothing, a file actor or a non-Blob-backed inputstream to write to
  // disk.
  using FileActorOrInputStream =
@@ -7679,7 +7678,7 @@ class ObjectStoreAddOrPutRequestOp::StoredFileInfo final {
          auto res = inputStream;
          // reset() clears the inputStream parameter, so we needed to make a
          // copy before
          mFileActorOrInputStream.reset();
          mFileActorOrInputStream.destroy();
          AssertInvariants();
          return res;
        });
@@ -7981,12 +7980,12 @@ 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().
  InitializedOnceMustBeTrue<const RefPtr<FullObjectStoreMetadata>>
  InitializedOnceNotNull<const RefPtr<FullObjectStoreMetadata>>
      mObjectStoreMetadata;
  const IndexOrObjectStoreId mObjectStoreId;
  InitializedOnce<const Key, LazyInit::Allow>
  LazyInitializedOnce<const Key>
      mLocaleAwareRangeBound;  ///< If the cursor is based on a key range, the
                               ///< bound in the direction of iteration (e.g.
                               ///< the upper bound in case of mDirection ==
@@ -8040,7 +8039,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().
  InitializedOnceMustBeTrue<const RefPtr<FullIndexMetadata>> mIndexMetadata;
  InitializedOnceNotNull<const RefPtr<FullIndexMetadata>> mIndexMetadata;
  const IndexOrObjectStoreId mIndexId;
  const bool mUniqueIndex;
  const nsCString
@@ -8114,7 +8113,7 @@ class ValueCursorBase {
  const SafeRefPtr<Database> mDatabase;
  const SafeRefPtr<FileManager> mFileManager;
  InitializedOnceMustBeTrue<PBackgroundParent* const> mBackgroundParent;
  InitializedOnceNotNull<PBackgroundParent* const> mBackgroundParent;
};
class KeyCursorBase {
@@ -8171,8 +8170,7 @@ class Cursor final
  CursorOpBase* mCurrentlyRunningOp = nullptr;
  InitializedOnce<const typename Base::ContinueQueries, LazyInit::Allow>
      mContinueQueries;
  LazyInitializedOnce<const typename Base::ContinueQueries> mContinueQueries;
  // Only called by TransactionBase.
  bool Start(const OpenCursorParams& aParams) final;
@@ -9123,14 +9121,11 @@ class DEBUGThreadSlower final : public nsIThreadObserver {
class MOZ_STACK_CLASS FileHelper final {
  const SafeRefPtr<FileManager> mFileManager;
  InitializedOnceMustBeTrue<const nsCOMPtr<nsIFile>, LazyInit::Allow>
      mFileDirectory;
  InitializedOnceMustBeTrue<const nsCOMPtr<nsIFile>, LazyInit::Allow>
      mJournalDirectory;
  LazyInitializedOnceNotNull<const nsCOMPtr<nsIFile>> mFileDirectory;
  LazyInitializedOnceNotNull<const nsCOMPtr<nsIFile>> mJournalDirectory;
  class ReadCallback;
  InitializedOnceMustBeTrue<const RefPtr<ReadCallback>, LazyInit::Allow>
      mReadCallback;
  LazyInitializedOnceNotNull<const RefPtr<ReadCallback>> mReadCallback;
 public:
  explicit FileHelper(SafeRefPtr<FileManager>&& aFileManager)
@@ -10188,8 +10183,7 @@ struct ValuePopulateResponseHelper {
  }
 private:
  InitializedOnce<const StructuredCloneReadInfoParent,
                  LazyInit::AllowResettable>
  LazyInitializedOnceEarlyDestructible<const StructuredCloneReadInfoParent>
      mCloneInfo;
};
@@ -11331,9 +11325,9 @@ void DatabaseConnection::Close() {
  mCachedStatements.Clear();
  MOZ_ALWAYS_SUCCEEDS((*mStorageConnection)->Close());
  mStorageConnection.reset();
  mStorageConnection.destroy();
  mFileManager.reset();
  mFileManager.destroy();
}
nsresult DatabaseConnection::DisableQuotaChecks() {
@@ -16395,11 +16389,11 @@ void Cursor<CursorType>::ActorDestroy(ActorDestroyReason aWhy) {
  }
  if constexpr (IsValueCursor) {
    this->mBackgroundParent.reset();
    this->mBackgroundParent.destroy();
  }
  this->mObjectStoreMetadata.reset();
  this->mObjectStoreMetadata.destroy();
  if constexpr (IsIndexCursor) {
    this->mIndexMetadata.reset();
    this->mIndexMetadata.destroy();
  }
}
@@ -23298,7 +23292,7 @@ void TransactionDatabaseOperationBase::Cleanup() {
  AssertIsOnOwningThread();
  MOZ_ASSERT(mInternalState == InternalState::SendingResults);
  mTransaction.reset();
  mTransaction.destroy();
}
NS_IMETHODIMP
+3 −3
Original line number Diff line number Diff line
@@ -8,8 +8,8 @@
#define mozilla_dom_indexeddb_filemanager_h__

#include "mozilla/dom/quota/PersistenceType.h"
#include "mozilla/InitializedOnce.h"
#include "FileManagerBase.h"
#include "InitializedOnce.h"

class nsIFile;
class mozIStorageConnection;
@@ -28,8 +28,8 @@ class FileManager final : public FileManagerBase<FileManager> {
  const nsCString mOrigin;
  const nsString mDatabaseName;

  InitializedOnce<const nsString, LazyInit::Allow> mDirectoryPath;
  InitializedOnce<const nsString, LazyInit::Allow> mJournalDirectoryPath;
  LazyInitializedOnce<const nsString> mDirectoryPath;
  LazyInitializedOnce<const nsString> mJournalDirectoryPath;

  const bool mEnforcingQuota;

+3 −3
Original line number Diff line number Diff line
@@ -9,13 +9,13 @@

#include "IDBCursorType.h"
#include "IndexedDatabase.h"
#include "InitializedOnce.h"
#include "js/RootingAPI.h"
#include "mozilla/Attributes.h"
#include "mozilla/dom/IDBCursorBinding.h"
#include "mozilla/dom/IDBTransaction.h"
#include "mozilla/dom/indexedDB/Key.h"
#include "mozilla/dom/quota/CheckedUnsafePtr.h"
#include "mozilla/InitializedOnce.h"
#include "nsCycleCollectionParticipant.h"
#include "nsWrapperCache.h"

@@ -52,7 +52,7 @@ class IDBCursor : public nsISupports, public nsWrapperCache {
  using Type = IDBCursorType;

 protected:
  InitializedOnceMustBeTrue<indexedDB::BackgroundCursorChildBase* const>
  InitializedOnceNotNull<indexedDB::BackgroundCursorChildBase* const>
      mBackgroundActor;

  // TODO: mRequest could be made const if Bug 1575173 is resolved. It is
@@ -144,7 +144,7 @@ class IDBCursor : public nsISupports, public nsWrapperCache {
  void ClearBackgroundActor() {
    AssertIsOnOwningThread();

    mBackgroundActor.reset();
    mBackgroundActor.destroy();
  }

  virtual void InvalidateCachedResponses() = 0;
Loading