зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1623278 - Use SafeRefPtr for Database. r=dom-workers-and-storage-reviewers,asuth
Differential Revision: https://phabricator.services.mozilla.com/D65568 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
88b93c652a
Коммит
64d6929415
|
@ -5173,7 +5173,7 @@ class ConnectionPool final {
|
|||
NS_ASSERT_OWNINGTHREAD(ConnectionPool);
|
||||
}
|
||||
|
||||
nsresult GetOrCreateConnection(const Database* aDatabase,
|
||||
nsresult GetOrCreateConnection(const Database& aDatabase,
|
||||
RefPtr<DatabaseConnection>* aConnection);
|
||||
|
||||
uint64_t Start(const nsID& aBackgroundChildLoggingId,
|
||||
|
@ -6161,10 +6161,11 @@ class Database::StartTransactionOp final
|
|||
|
||||
class Database::UnmapBlobCallback final
|
||||
: public IPCBlobInputStreamParentCallback {
|
||||
RefPtr<Database> mDatabase;
|
||||
SafeRefPtr<Database> mDatabase;
|
||||
|
||||
public:
|
||||
explicit UnmapBlobCallback(Database* aDatabase) : mDatabase(aDatabase) {
|
||||
explicit UnmapBlobCallback(SafeRefPtr<Database> aDatabase)
|
||||
: mDatabase(std::move(aDatabase)) {
|
||||
AssertIsOnBackgroundThread();
|
||||
}
|
||||
|
||||
|
@ -6174,7 +6175,7 @@ class Database::UnmapBlobCallback final
|
|||
AssertIsOnBackgroundThread();
|
||||
MOZ_ASSERT(mDatabase);
|
||||
|
||||
const RefPtr<Database> database = std::move(mDatabase);
|
||||
const SafeRefPtr<Database> database = std::move(mDatabase);
|
||||
database->UnmapBlob(aID);
|
||||
}
|
||||
|
||||
|
@ -6314,7 +6315,7 @@ class TransactionBase {
|
|||
typedef IDBTransaction::Mode Mode;
|
||||
|
||||
private:
|
||||
const RefPtr<Database> mDatabase;
|
||||
const SafeRefPtr<Database> mDatabase;
|
||||
nsTArray<RefPtr<FullObjectStoreMetadata>>
|
||||
mModifiedAutoIncrementObjectStoreMetadataArray;
|
||||
InitializedOnceMustBeTrue<const uint64_t, LazyInit::Allow> mTransactionId;
|
||||
|
@ -6384,10 +6385,22 @@ class TransactionBase {
|
|||
|
||||
Mode GetMode() const { return mMode; }
|
||||
|
||||
Database* GetDatabase() const {
|
||||
const Database& GetDatabase() const {
|
||||
MOZ_ASSERT(mDatabase);
|
||||
|
||||
return mDatabase;
|
||||
return *mDatabase;
|
||||
}
|
||||
|
||||
Database& GetMutableDatabase() const {
|
||||
MOZ_ASSERT(mDatabase);
|
||||
|
||||
return *mDatabase;
|
||||
}
|
||||
|
||||
SafeRefPtr<Database> GetDatabasePtr() const {
|
||||
MOZ_ASSERT(mDatabase);
|
||||
|
||||
return mDatabase.clonePtr();
|
||||
}
|
||||
|
||||
DatabaseLoggingInfo* GetLoggingInfo() const {
|
||||
|
@ -6416,7 +6429,7 @@ class TransactionBase {
|
|||
AssertIsOnBackgroundThread();
|
||||
MOZ_ASSERT(!IsActorDestroyed());
|
||||
|
||||
return GetDatabase()->GetBackgroundParent();
|
||||
return GetDatabase().GetBackgroundParent();
|
||||
}
|
||||
|
||||
void NoteModifiedAutoIncrementObjectStore(FullObjectStoreMetadata* aMetadata);
|
||||
|
@ -6431,7 +6444,7 @@ class TransactionBase {
|
|||
void Invalidate();
|
||||
|
||||
protected:
|
||||
TransactionBase(Database* aDatabase, Mode aMode);
|
||||
TransactionBase(SafeRefPtr<Database> aDatabase, Mode aMode);
|
||||
|
||||
virtual ~TransactionBase();
|
||||
|
||||
|
@ -6554,7 +6567,7 @@ class NormalTransaction final : public TransactionBase,
|
|||
|
||||
private:
|
||||
// This constructor is only called by Database.
|
||||
NormalTransaction(Database* aDatabase, TransactionBase::Mode aMode,
|
||||
NormalTransaction(SafeRefPtr<Database> aDatabase, TransactionBase::Mode aMode,
|
||||
nsTArray<RefPtr<FullObjectStoreMetadata>>& aObjectStores);
|
||||
|
||||
// Reference counted.
|
||||
|
@ -6680,12 +6693,13 @@ class VersionChangeTransaction final
|
|||
};
|
||||
|
||||
class MutableFile : public BackgroundMutableFileParentBase {
|
||||
const RefPtr<Database> mDatabase;
|
||||
const SafeRefPtr<Database> mDatabase;
|
||||
const SafeRefPtr<FileInfo> mFileInfo;
|
||||
|
||||
public:
|
||||
static MOZ_MUST_USE RefPtr<MutableFile> Create(
|
||||
nsIFile* aFile, Database* aDatabase, SafeRefPtr<FileInfo> aFileInfo);
|
||||
nsIFile* aFile, SafeRefPtr<Database> aDatabase,
|
||||
SafeRefPtr<FileInfo> aFileInfo);
|
||||
|
||||
const Database& GetDatabase() const {
|
||||
AssertIsOnBackgroundThread();
|
||||
|
@ -6710,7 +6724,7 @@ class MutableFile : public BackgroundMutableFileParentBase {
|
|||
already_AddRefed<BlobImpl> CreateBlobImpl() override;
|
||||
|
||||
private:
|
||||
MutableFile(nsIFile* aFile, RefPtr<Database> aDatabase,
|
||||
MutableFile(nsIFile* aFile, SafeRefPtr<Database> aDatabase,
|
||||
SafeRefPtr<FileInfo> aFileInfo);
|
||||
|
||||
~MutableFile() override;
|
||||
|
@ -6731,12 +6745,15 @@ class FactoryOp
|
|||
public SupportsCheckedUnsafePtr<CheckIf<DiagnosticAssertEnabled>> {
|
||||
public:
|
||||
struct MaybeBlockedDatabaseInfo final {
|
||||
RefPtr<Database> mDatabase;
|
||||
SafeRefPtr<Database> mDatabase;
|
||||
bool mBlocked;
|
||||
|
||||
MOZ_IMPLICIT MaybeBlockedDatabaseInfo(Database* aDatabase)
|
||||
: mDatabase(aDatabase), mBlocked(false) {
|
||||
MOZ_ASSERT(aDatabase);
|
||||
MaybeBlockedDatabaseInfo(MaybeBlockedDatabaseInfo&&) = default;
|
||||
MaybeBlockedDatabaseInfo& operator=(MaybeBlockedDatabaseInfo&&) = default;
|
||||
|
||||
MOZ_IMPLICIT MaybeBlockedDatabaseInfo(SafeRefPtr<Database> aDatabase)
|
||||
: mDatabase(std::move(aDatabase)), mBlocked(false) {
|
||||
MOZ_ASSERT(mDatabase);
|
||||
|
||||
MOZ_COUNT_CTOR(FactoryOp::MaybeBlockedDatabaseInfo);
|
||||
}
|
||||
|
@ -6745,11 +6762,13 @@ class FactoryOp
|
|||
MOZ_COUNT_DTOR(FactoryOp::MaybeBlockedDatabaseInfo);
|
||||
}
|
||||
|
||||
bool operator==(const MaybeBlockedDatabaseInfo& aOther) const {
|
||||
return mDatabase == aOther.mDatabase;
|
||||
bool operator==(const Database* aOther) const {
|
||||
return mDatabase == aOther;
|
||||
}
|
||||
|
||||
Database* operator->() MOZ_NO_ADDREF_RELEASE_ON_RETURN { return mDatabase; }
|
||||
Database* operator->() const& MOZ_NO_ADDREF_RELEASE_ON_RETURN {
|
||||
return mDatabase.unsafeGetRawPtr();
|
||||
}
|
||||
};
|
||||
|
||||
protected:
|
||||
|
@ -6914,7 +6933,7 @@ class FactoryOp
|
|||
void FinishSendResults();
|
||||
|
||||
nsresult SendVersionChangeMessages(DatabaseActorInfo* aDatabaseActorInfo,
|
||||
Database* aOpeningDatabase,
|
||||
Maybe<Database&> aOpeningDatabase,
|
||||
uint64_t aOldVersion,
|
||||
const Maybe<uint64_t>& aNewVersion);
|
||||
|
||||
|
@ -6980,7 +6999,7 @@ class OpenDatabaseOp final : public FactoryOp {
|
|||
uint64_t mRequestedVersion;
|
||||
SafeRefPtr<FileManager> mFileManager;
|
||||
|
||||
RefPtr<Database> mDatabase;
|
||||
SafeRefPtr<Database> mDatabase;
|
||||
RefPtr<VersionChangeTransaction> mVersionChangeTransaction;
|
||||
|
||||
// This is only set while a VersionChangeOp is live. It holds a strong
|
||||
|
@ -7131,7 +7150,7 @@ class DeleteDatabaseOp::VersionChangeOp final : public DatabaseOperationBase {
|
|||
class DatabaseOp : public DatabaseOperationBase,
|
||||
public PBackgroundIDBDatabaseRequestParent {
|
||||
protected:
|
||||
RefPtr<Database> mDatabase;
|
||||
SafeRefPtr<Database> mDatabase;
|
||||
|
||||
enum class State {
|
||||
// Just created on the PBackground thread, dispatched to the main thread.
|
||||
|
@ -7160,7 +7179,7 @@ class DatabaseOp : public DatabaseOperationBase,
|
|||
}
|
||||
|
||||
protected:
|
||||
DatabaseOp(Database* aDatabase);
|
||||
DatabaseOp(SafeRefPtr<Database> aDatabase);
|
||||
|
||||
~DatabaseOp() override {
|
||||
MOZ_ASSERT_IF(OperationMayProceed(),
|
||||
|
@ -7188,7 +7207,8 @@ class CreateFileOp final : public DatabaseOp {
|
|||
InitializedOnce<const SafeRefPtr<FileInfo>, LazyInit::Allow> mFileInfo;
|
||||
|
||||
public:
|
||||
CreateFileOp(Database* aDatabase, const DatabaseRequestParams& aParams);
|
||||
CreateFileOp(SafeRefPtr<Database> aDatabase,
|
||||
const DatabaseRequestParams& aParams);
|
||||
|
||||
private:
|
||||
~CreateFileOp() override = default;
|
||||
|
@ -7745,7 +7765,7 @@ class ObjectStoreGetRequestOp final : public NormalTransactionOp {
|
|||
friend class TransactionBase;
|
||||
|
||||
const IndexOrObjectStoreId mObjectStoreId;
|
||||
RefPtr<Database> mDatabase;
|
||||
SafeRefPtr<Database> mDatabase;
|
||||
const Maybe<SerializedKeyRange> mOptionalKeyRange;
|
||||
AutoTArray<StructuredCloneReadInfoParent, 1> mResponse;
|
||||
PBackgroundParent* mBackgroundParent;
|
||||
|
@ -7876,7 +7896,7 @@ class IndexRequestOpBase : public NormalTransactionOp {
|
|||
class IndexGetRequestOp final : public IndexRequestOpBase {
|
||||
friend class TransactionBase;
|
||||
|
||||
RefPtr<Database> mDatabase;
|
||||
SafeRefPtr<Database> mDatabase;
|
||||
const Maybe<SerializedKeyRange> mOptionalKeyRange;
|
||||
AutoTArray<StructuredCloneReadInfoParent, 1> mResponse;
|
||||
PBackgroundParent* mBackgroundParent;
|
||||
|
@ -8107,7 +8127,7 @@ class ValueCursorBase {
|
|||
|
||||
protected:
|
||||
explicit ValueCursorBase(TransactionBase* const aTransaction)
|
||||
: mDatabase(aTransaction->GetDatabase()),
|
||||
: mDatabase(aTransaction->GetDatabasePtr()),
|
||||
mFileManager(mDatabase->GetFileManagerPtr()),
|
||||
mBackgroundParent(aTransaction->GetBackgroundParent()) {
|
||||
MOZ_ASSERT(mDatabase);
|
||||
|
@ -8118,7 +8138,7 @@ class ValueCursorBase {
|
|||
|
||||
~ValueCursorBase() { MOZ_ASSERT(!mBackgroundParent); }
|
||||
|
||||
const RefPtr<Database> mDatabase;
|
||||
const SafeRefPtr<Database> mDatabase;
|
||||
const SafeRefPtr<FileManager> mFileManager;
|
||||
|
||||
InitializedOnceMustBeTrue<PBackgroundParent* const> mBackgroundParent;
|
||||
|
@ -9258,7 +9278,7 @@ bool GetBaseFilename(const nsAString& aFilename, const nsAString& aSuffix,
|
|||
|
||||
mozilla::Result<nsTArray<SerializedStructuredCloneFile>, nsresult>
|
||||
SerializeStructuredCloneFiles(PBackgroundParent* aBackgroundActor,
|
||||
Database* aDatabase,
|
||||
const SafeRefPtr<Database>& aDatabase,
|
||||
const nsTArray<StructuredCloneFileParent>& aFiles,
|
||||
bool aForPreprocess) {
|
||||
AssertIsOnBackgroundThread();
|
||||
|
@ -9324,8 +9344,8 @@ SerializeStructuredCloneFiles(PBackgroundParent* aBackgroundActor,
|
|||
if (aDatabase->IsFileHandleDisabled()) {
|
||||
result.EmplaceBack(null_t(), StructuredCloneFileBase::eMutableFile);
|
||||
} else {
|
||||
RefPtr<MutableFile> actor =
|
||||
MutableFile::Create(nativeFile, aDatabase, file.FileInfoPtr());
|
||||
RefPtr<MutableFile> actor = MutableFile::Create(
|
||||
nativeFile, aDatabase.clonePtr(), file.FileInfoPtr());
|
||||
if (!actor) {
|
||||
IDB_REPORT_INTERNAL_ERR();
|
||||
return Err(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
||||
|
@ -11528,7 +11548,7 @@ nsresult DatabaseConnection::AutoSavepoint::Start(
|
|||
aTransaction.GetMode() == IDBTransaction::Mode::Cleanup ||
|
||||
aTransaction.GetMode() == IDBTransaction::Mode::VersionChange);
|
||||
|
||||
DatabaseConnection* connection = aTransaction.GetDatabase()->GetConnection();
|
||||
DatabaseConnection* connection = aTransaction.GetDatabase().GetConnection();
|
||||
MOZ_ASSERT(connection);
|
||||
connection->AssertIsOnConnectionThread();
|
||||
|
||||
|
@ -12089,10 +12109,9 @@ void ConnectionPool::IdleTimerCallback(nsITimer* aTimer, void* aClosure) {
|
|||
}
|
||||
|
||||
nsresult ConnectionPool::GetOrCreateConnection(
|
||||
const Database* aDatabase, RefPtr<DatabaseConnection>* aConnection) {
|
||||
const Database& aDatabase, RefPtr<DatabaseConnection>* aConnection) {
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
MOZ_ASSERT(!IsOnBackgroundThread());
|
||||
MOZ_ASSERT(aDatabase);
|
||||
MOZ_ASSERT(aConnection);
|
||||
|
||||
AUTO_PROFILER_LABEL("ConnectionPool::GetOrCreateConnection", DOM);
|
||||
|
@ -12101,7 +12120,7 @@ nsresult ConnectionPool::GetOrCreateConnection(
|
|||
{
|
||||
MutexAutoLock lock(mDatabasesMutex);
|
||||
|
||||
dbInfo = mDatabases.Get(aDatabase->Id());
|
||||
dbInfo = mDatabases.Get(aDatabase.Id());
|
||||
}
|
||||
|
||||
MOZ_ASSERT(dbInfo);
|
||||
|
@ -12111,15 +12130,15 @@ nsresult ConnectionPool::GetOrCreateConnection(
|
|||
MOZ_ASSERT(!dbInfo->mDEBUGConnectionThread);
|
||||
|
||||
nsCOMPtr<mozIStorageConnection> storageConnection;
|
||||
nsresult rv = GetStorageConnection(
|
||||
aDatabase->FilePath(), aDatabase->DirectoryLockId(),
|
||||
aDatabase->TelemetryId(), &storageConnection);
|
||||
nsresult rv =
|
||||
GetStorageConnection(aDatabase.FilePath(), aDatabase.DirectoryLockId(),
|
||||
aDatabase.TelemetryId(), &storageConnection);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
connection = new DatabaseConnection(storageConnection,
|
||||
aDatabase->GetFileManagerPtr());
|
||||
aDatabase.GetFileManagerPtr());
|
||||
|
||||
rv = connection->Init();
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
|
@ -12130,7 +12149,7 @@ nsresult ConnectionPool::GetOrCreateConnection(
|
|||
|
||||
IDB_DEBUG_LOG(("ConnectionPool created connection 0x%p for '%s'",
|
||||
dbInfo->mConnection.get(),
|
||||
NS_ConvertUTF16toUTF8(aDatabase->FilePath()).get()));
|
||||
NS_ConvertUTF16toUTF8(aDatabase.FilePath()).get()));
|
||||
|
||||
#ifdef DEBUG
|
||||
dbInfo->mDEBUGConnectionThread = PR_GetCurrentThread();
|
||||
|
@ -13821,7 +13840,7 @@ nsresult Database::EnsureConnection() {
|
|||
AUTO_PROFILER_LABEL("Database::EnsureConnection", DOM);
|
||||
|
||||
if (!mConnection || !mConnection->GetStorageConnection()) {
|
||||
nsresult rv = gConnectionPool->GetOrCreateConnection(this, &mConnection);
|
||||
nsresult rv = gConnectionPool->GetOrCreateConnection(*this, &mConnection);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
@ -13936,7 +13955,8 @@ void Database::MapBlob(const IPCBlob& aIPCBlob,
|
|||
MOZ_ASSERT(!mMappedBlobs.GetWeak(actor->ID()));
|
||||
mMappedBlobs.Put(actor->ID(), AsRefPtr(std::move(aFileInfo)));
|
||||
|
||||
RefPtr<UnmapBlobCallback> callback = new UnmapBlobCallback(this);
|
||||
RefPtr<UnmapBlobCallback> callback =
|
||||
new UnmapBlobCallback(SafeRefPtr{this, AcquireStrongRefFromRawPtr{}});
|
||||
actor->SetCallback(callback);
|
||||
}
|
||||
|
||||
|
@ -14205,7 +14225,8 @@ Database::AllocPBackgroundIDBDatabaseRequestParent(
|
|||
|
||||
switch (aParams.type()) {
|
||||
case DatabaseRequestParams::TCreateFileParams: {
|
||||
actor = new CreateFileOp(this, aParams);
|
||||
actor = new CreateFileOp(SafeRefPtr{this, AcquireStrongRefFromRawPtr{}},
|
||||
aParams);
|
||||
|
||||
NotePendingCreateFileOp();
|
||||
break;
|
||||
|
@ -14322,7 +14343,8 @@ PBackgroundIDBTransactionParent* Database::AllocPBackgroundIDBTransactionParent(
|
|||
infallibleObjectStores.SwapElements(fallibleObjectStores);
|
||||
|
||||
RefPtr<NormalTransaction> transaction =
|
||||
new NormalTransaction(this, aMode, infallibleObjectStores);
|
||||
new NormalTransaction(SafeRefPtr{this, AcquireStrongRefFromRawPtr{}},
|
||||
aMode, infallibleObjectStores);
|
||||
|
||||
MOZ_ASSERT(infallibleObjectStores.IsEmpty());
|
||||
|
||||
|
@ -14522,17 +14544,17 @@ void Database::StartTransactionOp::Cleanup() {
|
|||
* TransactionBase
|
||||
******************************************************************************/
|
||||
|
||||
TransactionBase::TransactionBase(Database* aDatabase, Mode aMode)
|
||||
: mDatabase(aDatabase),
|
||||
mDatabaseId(aDatabase->Id()),
|
||||
TransactionBase::TransactionBase(SafeRefPtr<Database> aDatabase, Mode aMode)
|
||||
: mDatabase(std::move(aDatabase)),
|
||||
mDatabaseId(mDatabase->Id()),
|
||||
mLoggingSerialNumber(
|
||||
aDatabase->GetLoggingInfo()->NextTransactionSN(aMode)),
|
||||
mDatabase->GetLoggingInfo()->NextTransactionSN(aMode)),
|
||||
mActiveRequestCount(0),
|
||||
mInvalidatedOnAnyThread(false),
|
||||
mMode(aMode),
|
||||
mResultCode(NS_OK) {
|
||||
AssertIsOnBackgroundThread();
|
||||
MOZ_ASSERT(aDatabase);
|
||||
MOZ_ASSERT(mDatabase);
|
||||
MOZ_ASSERT(mLoggingSerialNumber);
|
||||
}
|
||||
|
||||
|
@ -15369,9 +15391,9 @@ bool TransactionBase::DeallocCursor(PBackgroundIDBCursorParent* const aActor) {
|
|||
******************************************************************************/
|
||||
|
||||
NormalTransaction::NormalTransaction(
|
||||
Database* aDatabase, TransactionBase::Mode aMode,
|
||||
SafeRefPtr<Database> aDatabase, TransactionBase::Mode aMode,
|
||||
nsTArray<RefPtr<FullObjectStoreMetadata>>& aObjectStores)
|
||||
: TransactionBase(aDatabase, aMode) {
|
||||
: TransactionBase(std::move(aDatabase), aMode) {
|
||||
AssertIsOnBackgroundThread();
|
||||
MOZ_ASSERT(!aObjectStores.IsEmpty());
|
||||
|
||||
|
@ -15506,7 +15528,7 @@ bool NormalTransaction::DeallocPBackgroundIDBCursorParent(
|
|||
|
||||
VersionChangeTransaction::VersionChangeTransaction(
|
||||
OpenDatabaseOp* aOpenDatabaseOp)
|
||||
: TransactionBase(aOpenDatabaseOp->mDatabase,
|
||||
: TransactionBase(aOpenDatabaseOp->mDatabase.clonePtr(),
|
||||
IDBTransaction::Mode::VersionChange),
|
||||
mOpenDatabaseOp(aOpenDatabaseOp) {
|
||||
AssertIsOnBackgroundThread();
|
||||
|
@ -15545,7 +15567,7 @@ bool VersionChangeTransaction::CopyDatabaseMetadata() {
|
|||
AssertIsOnBackgroundThread();
|
||||
MOZ_ASSERT(!mOldMetadata);
|
||||
|
||||
const auto& origMetadata = GetDatabase()->Metadata();
|
||||
const auto& origMetadata = GetDatabase().Metadata();
|
||||
|
||||
SafeRefPtr<FullDatabaseMetadata> newMetadata = origMetadata.Duplicate();
|
||||
if (NS_WARN_IF(!newMetadata)) {
|
||||
|
@ -15571,7 +15593,6 @@ bool VersionChangeTransaction::CopyDatabaseMetadata() {
|
|||
|
||||
void VersionChangeTransaction::UpdateMetadata(nsresult aResult) {
|
||||
AssertIsOnBackgroundThread();
|
||||
MOZ_ASSERT(GetDatabase());
|
||||
MOZ_ASSERT(mOpenDatabaseOp);
|
||||
MOZ_ASSERT(!!mActorWasAlive == !!mOpenDatabaseOp->mDatabase);
|
||||
MOZ_ASSERT_IF(mActorWasAlive, !mOpenDatabaseOp->mDatabaseId.IsEmpty());
|
||||
|
@ -15711,7 +15732,7 @@ mozilla::ipc::IPCResult VersionChangeTransaction::RecvCreateObjectStore(
|
|||
}
|
||||
|
||||
const SafeRefPtr<FullDatabaseMetadata> dbMetadata =
|
||||
GetDatabase()->MetadataPtr();
|
||||
GetDatabase().MetadataPtr();
|
||||
|
||||
if (NS_WARN_IF(aMetadata.id() != dbMetadata->mNextObjectStoreId)) {
|
||||
ASSERT_UNLESS_FUZZING();
|
||||
|
@ -15764,7 +15785,7 @@ mozilla::ipc::IPCResult VersionChangeTransaction::RecvDeleteObjectStore(
|
|||
return IPC_FAIL_NO_REASON(this);
|
||||
}
|
||||
|
||||
const auto& dbMetadata = GetDatabase()->Metadata();
|
||||
const auto& dbMetadata = GetDatabase().Metadata();
|
||||
MOZ_ASSERT(dbMetadata.mNextObjectStoreId > 0);
|
||||
|
||||
if (NS_WARN_IF(aObjectStoreId >= dbMetadata.mNextObjectStoreId)) {
|
||||
|
@ -15823,7 +15844,7 @@ mozilla::ipc::IPCResult VersionChangeTransaction::RecvRenameObjectStore(
|
|||
}
|
||||
|
||||
{
|
||||
const auto& dbMetadata = GetDatabase()->Metadata();
|
||||
const auto& dbMetadata = GetDatabase().Metadata();
|
||||
MOZ_ASSERT(dbMetadata.mNextObjectStoreId > 0);
|
||||
|
||||
if (NS_WARN_IF(aObjectStoreId >= dbMetadata.mNextObjectStoreId)) {
|
||||
|
@ -15875,7 +15896,7 @@ mozilla::ipc::IPCResult VersionChangeTransaction::RecvCreateIndex(
|
|||
return IPC_FAIL_NO_REASON(this);
|
||||
}
|
||||
|
||||
const auto dbMetadata = GetDatabase()->MetadataPtr();
|
||||
const auto dbMetadata = GetDatabase().MetadataPtr();
|
||||
|
||||
if (NS_WARN_IF(aMetadata.id() != dbMetadata->mNextIndexId)) {
|
||||
ASSERT_UNLESS_FUZZING();
|
||||
|
@ -15941,7 +15962,7 @@ mozilla::ipc::IPCResult VersionChangeTransaction::RecvDeleteIndex(
|
|||
return IPC_FAIL_NO_REASON(this);
|
||||
}
|
||||
{
|
||||
const auto& dbMetadata = GetDatabase()->Metadata();
|
||||
const auto& dbMetadata = GetDatabase().Metadata();
|
||||
MOZ_ASSERT(dbMetadata.mNextObjectStoreId > 0);
|
||||
MOZ_ASSERT(dbMetadata.mNextIndexId > 0);
|
||||
|
||||
|
@ -16023,7 +16044,7 @@ mozilla::ipc::IPCResult VersionChangeTransaction::RecvRenameIndex(
|
|||
}
|
||||
|
||||
const SafeRefPtr<FullDatabaseMetadata> dbMetadata =
|
||||
GetDatabase()->MetadataPtr();
|
||||
GetDatabase().MetadataPtr();
|
||||
MOZ_ASSERT(dbMetadata);
|
||||
MOZ_ASSERT(dbMetadata->mNextObjectStoreId > 0);
|
||||
MOZ_ASSERT(dbMetadata->mNextIndexId > 0);
|
||||
|
@ -17496,12 +17517,13 @@ void QuotaClient::InvalidateLiveDatabasesMatching(const Condition& aCondition) {
|
|||
// we need to make a temporary list of the databases to invalidate to avoid
|
||||
// iterator invalidation.
|
||||
|
||||
nsTArray<RefPtr<Database>> databases;
|
||||
nsTArray<SafeRefPtr<Database>> databases;
|
||||
|
||||
for (const auto& liveDatabasesEntry : *gLiveDatabaseHashtable) {
|
||||
for (Database* database : liveDatabasesEntry.GetData()->mLiveDatabases) {
|
||||
if (aCondition(database)) {
|
||||
databases.AppendElement(database);
|
||||
databases.AppendElement(
|
||||
SafeRefPtr{database, AcquireStrongRefFromRawPtr{}});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20302,7 +20324,7 @@ void DatabaseOperationBase::AutoSetProgressHandler::Unregister() {
|
|||
mConnection = nullptr;
|
||||
}
|
||||
|
||||
MutableFile::MutableFile(nsIFile* aFile, RefPtr<Database> aDatabase,
|
||||
MutableFile::MutableFile(nsIFile* aFile, SafeRefPtr<Database> aDatabase,
|
||||
SafeRefPtr<FileInfo> aFileInfo)
|
||||
: BackgroundMutableFileParentBase(FILE_HANDLE_STORAGE_IDB, aDatabase->Id(),
|
||||
IntString(aFileInfo->Id()), aFile),
|
||||
|
@ -20315,12 +20337,13 @@ MutableFile::MutableFile(nsIFile* aFile, RefPtr<Database> aDatabase,
|
|||
|
||||
MutableFile::~MutableFile() { mDatabase->UnregisterMutableFile(this); }
|
||||
|
||||
RefPtr<MutableFile> MutableFile::Create(nsIFile* aFile, Database* aDatabase,
|
||||
RefPtr<MutableFile> MutableFile::Create(nsIFile* aFile,
|
||||
SafeRefPtr<Database> aDatabase,
|
||||
SafeRefPtr<FileInfo> aFileInfo) {
|
||||
AssertIsOnBackgroundThread();
|
||||
|
||||
RefPtr<MutableFile> newMutableFile =
|
||||
new MutableFile(aFile, aDatabase, std::move(aFileInfo));
|
||||
new MutableFile(aFile, aDatabase.clonePtr(), std::move(aFileInfo));
|
||||
|
||||
if (!aDatabase->RegisterMutableFile(newMutableFile)) {
|
||||
return nullptr;
|
||||
|
@ -20927,7 +20950,7 @@ nsresult FactoryOp::CheckPermission(
|
|||
}
|
||||
|
||||
nsresult FactoryOp::SendVersionChangeMessages(
|
||||
DatabaseActorInfo* aDatabaseActorInfo, Database* aOpeningDatabase,
|
||||
DatabaseActorInfo* aDatabaseActorInfo, Maybe<Database&> aOpeningDatabase,
|
||||
uint64_t aOldVersion, const Maybe<uint64_t>& aNewVersion) {
|
||||
AssertIsOnOwningThread();
|
||||
MOZ_ASSERT(aDatabaseActorInfo);
|
||||
|
@ -20940,10 +20963,12 @@ nsresult FactoryOp::SendVersionChangeMessages(
|
|||
if (liveCount > expectedCount) {
|
||||
FallibleTArray<MaybeBlockedDatabaseInfo> maybeBlockedDatabases;
|
||||
for (const auto& database : aDatabaseActorInfo->mLiveDatabases) {
|
||||
if ((!aOpeningDatabase || database != aOpeningDatabase) &&
|
||||
if ((!aOpeningDatabase || database.get() != &aOpeningDatabase.ref()) &&
|
||||
!database->IsClosed() &&
|
||||
NS_WARN_IF(
|
||||
!maybeBlockedDatabases.AppendElement(database, fallible))) {
|
||||
NS_WARN_IF(!maybeBlockedDatabases.AppendElement(
|
||||
SafeRefPtr{static_cast<Database*>(database),
|
||||
AcquireStrongRefFromRawPtr{}},
|
||||
fallible))) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
@ -21962,7 +21987,7 @@ nsresult OpenDatabaseOp::BeginVersionChange() {
|
|||
DatabaseActorInfo* info;
|
||||
MOZ_ALWAYS_TRUE(gLiveDatabaseHashtable->Get(mDatabaseId, &info));
|
||||
|
||||
MOZ_ASSERT(info->mLiveDatabases.Contains(mDatabase));
|
||||
MOZ_ASSERT(info->mLiveDatabases.Contains(mDatabase.unsafeGetRawPtr()));
|
||||
MOZ_ASSERT(!info->mWaitingFactoryOp);
|
||||
MOZ_ASSERT(info->mMetadata == mMetadata);
|
||||
|
||||
|
@ -21978,8 +22003,9 @@ nsresult OpenDatabaseOp::BeginVersionChange() {
|
|||
|
||||
Maybe<uint64_t> newVersion = Some(mRequestedVersion);
|
||||
|
||||
nsresult rv = SendVersionChangeMessages(
|
||||
info, mDatabase, mMetadata->mCommonMetadata.version(), newVersion);
|
||||
nsresult rv = SendVersionChangeMessages(info, mDatabase.maybeDeref(),
|
||||
mMetadata->mCommonMetadata.version(),
|
||||
newVersion);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
@ -22187,9 +22213,11 @@ void OpenDatabaseOp::SendResults() {
|
|||
if (NS_SUCCEEDED(rv)) {
|
||||
// We successfully opened a database so use its actor as the success
|
||||
// result for this request.
|
||||
OpenDatabaseRequestResponse openResponse;
|
||||
openResponse.databaseParent() = mDatabase;
|
||||
response = openResponse;
|
||||
|
||||
// XXX OpenDatabaseRequestResponse stores a raw pointer, can this be
|
||||
// avoided?
|
||||
response =
|
||||
OpenDatabaseRequestResponse{mDatabase.unsafeGetRawPtr(), nullptr};
|
||||
} else {
|
||||
response = ClampResultCode(rv);
|
||||
#ifdef DEBUG
|
||||
|
@ -22272,16 +22300,17 @@ void OpenDatabaseOp::EnsureDatabaseActor() {
|
|||
mMetadata = info->mMetadata.clonePtr();
|
||||
}
|
||||
|
||||
mDatabase = MakeRefPtr<Database>(
|
||||
mDatabase = MakeSafeRefPtr<Database>(
|
||||
static_cast<Factory*>(Manager()), mCommonParams.principalInfo(),
|
||||
mOptionalContentParentId, mGroup, mOrigin, mTelemetryId,
|
||||
mMetadata.clonePtr(), mFileManager.clonePtr(), std::move(mDirectoryLock),
|
||||
mFileHandleDisabled, mChromeWriteAccessAllowed);
|
||||
|
||||
if (info) {
|
||||
info->mLiveDatabases.AppendElement(mDatabase);
|
||||
info->mLiveDatabases.AppendElement(mDatabase.unsafeGetRawPtr());
|
||||
} else {
|
||||
info = new DatabaseActorInfo(mMetadata.clonePtr(), mDatabase);
|
||||
info = new DatabaseActorInfo(mMetadata.clonePtr(),
|
||||
mDatabase.unsafeGetRawPtr());
|
||||
gLiveDatabaseHashtable->Put(mDatabaseId, info);
|
||||
}
|
||||
|
||||
|
@ -22310,7 +22339,8 @@ nsresult OpenDatabaseOp::EnsureDatabaseActorIsAlive() {
|
|||
// Transfer ownership to IPDL.
|
||||
mDatabase->SetActorAlive();
|
||||
|
||||
if (!factory->SendPBackgroundIDBDatabaseConstructor(mDatabase, spec, this)) {
|
||||
if (!factory->SendPBackgroundIDBDatabaseConstructor(
|
||||
mDatabase.unsafeGetRawPtr(), spec, this)) {
|
||||
IDB_REPORT_INTERNAL_ERR();
|
||||
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
||||
}
|
||||
|
@ -22729,7 +22759,7 @@ nsresult DeleteDatabaseOp::BeginVersionChange() {
|
|||
MOZ_ASSERT(!info->mWaitingFactoryOp);
|
||||
|
||||
nsresult rv =
|
||||
SendVersionChangeMessages(info, nullptr, mPreviousVersion, Nothing());
|
||||
SendVersionChangeMessages(info, Nothing(), mPreviousVersion, Nothing());
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
@ -22921,20 +22951,25 @@ void DeleteDatabaseOp::VersionChangeOp::RunOnOwningThread() {
|
|||
if (info) {
|
||||
MOZ_ASSERT(!info->mLiveDatabases.IsEmpty());
|
||||
|
||||
FallibleTArray<Database*> liveDatabases;
|
||||
if (NS_WARN_IF(!liveDatabases.AppendElements(info->mLiveDatabases,
|
||||
fallible))) {
|
||||
nsTArray<SafeRefPtr<Database>> liveDatabases;
|
||||
if (NS_WARN_IF(!liveDatabases.SetCapacity(info->mLiveDatabases.Length(),
|
||||
fallible))) {
|
||||
deleteOp->SetFailureCode(NS_ERROR_OUT_OF_MEMORY);
|
||||
} else {
|
||||
std::transform(info->mLiveDatabases.cbegin(),
|
||||
info->mLiveDatabases.cend(),
|
||||
MakeBackInserter(liveDatabases),
|
||||
[](const auto& aDatabase) -> SafeRefPtr<Database> {
|
||||
return {aDatabase, AcquireStrongRefFromRawPtr{}};
|
||||
});
|
||||
|
||||
#ifdef DEBUG
|
||||
// The code below should result in the deletion of |info|. Set to null
|
||||
// here to make sure we find invalid uses later.
|
||||
info = nullptr;
|
||||
#endif
|
||||
// TODO: Why do we convert to RefPtr here? If this is really
|
||||
// necessary, this is very error-prone, and provide the type of
|
||||
// liveDatabases should be changed.
|
||||
for (RefPtr<Database> database : liveDatabases) {
|
||||
|
||||
for (const auto& database : liveDatabases) {
|
||||
database->Invalidate();
|
||||
}
|
||||
|
||||
|
@ -23051,15 +23086,14 @@ void TransactionDatabaseOperationBase::RunOnConnectionThread() {
|
|||
IDB_REPORT_INTERNAL_ERR();
|
||||
OverrideFailureCode(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
||||
} else {
|
||||
Database* database = (*mTransaction)->GetDatabase();
|
||||
MOZ_ASSERT(database);
|
||||
Database& database = (*mTransaction)->GetMutableDatabase();
|
||||
|
||||
// Here we're actually going to perform the database operation.
|
||||
nsresult rv = database->EnsureConnection();
|
||||
nsresult rv = database.EnsureConnection();
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
SetFailureCode(rv);
|
||||
} else {
|
||||
DatabaseConnection* connection = database->GetConnection();
|
||||
DatabaseConnection* connection = database.GetConnection();
|
||||
MOZ_ASSERT(connection);
|
||||
MOZ_ASSERT(connection->GetStorageConnection());
|
||||
|
||||
|
@ -23284,10 +23318,8 @@ nsresult TransactionBase::CommitOp::WriteAutoIncrementCounts() {
|
|||
mTransaction->mModifiedAutoIncrementObjectStoreMetadataArray;
|
||||
|
||||
if (!metadataArray.IsEmpty()) {
|
||||
Database* database = mTransaction->GetDatabase();
|
||||
MOZ_ASSERT(database);
|
||||
|
||||
DatabaseConnection* connection = database->GetConnection();
|
||||
DatabaseConnection* connection =
|
||||
mTransaction->GetDatabase().GetConnection();
|
||||
MOZ_ASSERT(connection);
|
||||
|
||||
DatabaseConnection::CachedStatement stmt;
|
||||
|
@ -23406,10 +23438,8 @@ TransactionBase::CommitOp::Run() {
|
|||
|
||||
if (mTransaction->GetMode() != IDBTransaction::Mode::ReadOnly &&
|
||||
mTransaction->mHasBeenActiveOnConnectionThread) {
|
||||
Database* database = mTransaction->GetDatabase();
|
||||
MOZ_ASSERT(database);
|
||||
|
||||
if (DatabaseConnection* connection = database->GetConnection()) {
|
||||
if (DatabaseConnection* connection =
|
||||
mTransaction->GetDatabase().GetConnection()) {
|
||||
// May be null if the VersionChangeOp was canceled.
|
||||
DatabaseConnection::UpdateRefcountFunction* fileRefcountFunction =
|
||||
connection->GetUpdateRefcountFunction();
|
||||
|
@ -23499,10 +23529,7 @@ void TransactionBase::CommitOp::TransactionFinishedAfterUnblock() {
|
|||
|
||||
mTransaction->SendCompleteNotification(ClampResultCode(mResultCode));
|
||||
|
||||
Database* database = mTransaction->GetDatabase();
|
||||
MOZ_ASSERT(database);
|
||||
|
||||
database->UnregisterTransaction(mTransaction);
|
||||
mTransaction->GetMutableDatabase().UnregisterTransaction(mTransaction);
|
||||
|
||||
mTransaction = nullptr;
|
||||
|
||||
|
@ -23513,13 +23540,13 @@ void TransactionBase::CommitOp::TransactionFinishedAfterUnblock() {
|
|||
#endif
|
||||
}
|
||||
|
||||
DatabaseOp::DatabaseOp(Database* aDatabase)
|
||||
DatabaseOp::DatabaseOp(SafeRefPtr<Database> aDatabase)
|
||||
: DatabaseOperationBase(aDatabase->GetLoggingInfo()->Id(),
|
||||
aDatabase->GetLoggingInfo()->NextRequestSN()),
|
||||
mDatabase(aDatabase),
|
||||
mDatabase(std::move(aDatabase)),
|
||||
mState(State::Initial) {
|
||||
AssertIsOnBackgroundThread();
|
||||
MOZ_ASSERT(aDatabase);
|
||||
MOZ_ASSERT(mDatabase);
|
||||
}
|
||||
|
||||
nsresult DatabaseOp::SendToIOThread() {
|
||||
|
@ -23589,9 +23616,10 @@ void DatabaseOp::ActorDestroy(ActorDestroyReason aWhy) {
|
|||
NoteActorDestroyed();
|
||||
}
|
||||
|
||||
CreateFileOp::CreateFileOp(Database* aDatabase,
|
||||
CreateFileOp::CreateFileOp(SafeRefPtr<Database> aDatabase,
|
||||
const DatabaseRequestParams& aParams)
|
||||
: DatabaseOp(aDatabase), mParams(aParams.get_CreateFileParams()) {
|
||||
: DatabaseOp(std::move(aDatabase)),
|
||||
mParams(aParams.get_CreateFileParams()) {
|
||||
MOZ_ASSERT(aParams.type() == DatabaseRequestParams::TCreateFileParams);
|
||||
}
|
||||
|
||||
|
@ -23603,7 +23631,7 @@ nsresult CreateFileOp::CreateMutableFile(RefPtr<MutableFile>* aMutableFile) {
|
|||
}
|
||||
|
||||
RefPtr<MutableFile> mutableFile =
|
||||
MutableFile::Create(file, mDatabase, mFileInfo->clonePtr());
|
||||
MutableFile::Create(file, mDatabase.clonePtr(), mFileInfo->clonePtr());
|
||||
if (NS_WARN_IF(!mutableFile)) {
|
||||
IDB_REPORT_INTERNAL_ERR();
|
||||
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
||||
|
@ -24109,7 +24137,7 @@ CreateIndexOp::CreateIndexOp(RefPtr<VersionChangeTransaction> aTransaction,
|
|||
const IndexMetadata& aMetadata)
|
||||
: VersionChangeTransactionOp(std::move(aTransaction)),
|
||||
mMetadata(aMetadata),
|
||||
mFileManager(Transaction().GetDatabase()->GetFileManagerPtr()),
|
||||
mFileManager(Transaction().GetDatabase().GetFileManagerPtr()),
|
||||
mDatabaseId(Transaction().DatabaseId()),
|
||||
mObjectStoreId(aObjectStoreId) {
|
||||
MOZ_ASSERT(aObjectStoreId);
|
||||
|
@ -25190,9 +25218,9 @@ ObjectStoreAddOrPutRequestOp::ObjectStoreAddOrPutRequestOp(
|
|||
std::move(aParams.type() == RequestParams::TObjectStoreAddParams
|
||||
? aParams.get_ObjectStoreAddParams().commonParams()
|
||||
: aParams.get_ObjectStorePutParams().commonParams())),
|
||||
mGroup(Transaction().GetDatabase()->Group()),
|
||||
mOrigin(Transaction().GetDatabase()->Origin()),
|
||||
mPersistenceType(Transaction().GetDatabase()->Type()),
|
||||
mGroup(Transaction().GetDatabase().Group()),
|
||||
mOrigin(Transaction().GetDatabase().Origin()),
|
||||
mPersistenceType(Transaction().GetDatabase().Type()),
|
||||
mOverwrite(aParams.type() == RequestParams::TObjectStorePutParams),
|
||||
mObjectStoreMayHaveIndexes(false) {
|
||||
MOZ_ASSERT(aParams.type() == RequestParams::TObjectStoreAddParams ||
|
||||
|
@ -25358,7 +25386,7 @@ bool ObjectStoreAddOrPutRequestOp::Init(TransactionBase* aTransaction) {
|
|||
|
||||
if (mDataOverThreshold) {
|
||||
mStoredFileInfos.EmplaceBack(StoredFileInfo::CreateForStructuredClone(
|
||||
aTransaction->GetDatabase()->GetFileManager().CreateFileInfo(),
|
||||
aTransaction->GetDatabase().GetFileManager().CreateFileInfo(),
|
||||
MakeRefPtr<SCInputStream>(mParams.cloneInfo().data().data)));
|
||||
}
|
||||
|
||||
|
@ -25559,7 +25587,7 @@ nsresult ObjectStoreAddOrPutRequestOp::DoDatabaseWork(
|
|||
|
||||
if (inputStream) {
|
||||
if (fileHelper.isNothing()) {
|
||||
fileHelper.emplace(Transaction().GetDatabase()->GetFileManagerPtr());
|
||||
fileHelper.emplace(Transaction().GetDatabase().GetFileManagerPtr());
|
||||
rv = fileHelper->Init();
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
IDB_REPORT_INTERNAL_ERR();
|
||||
|
@ -25593,7 +25621,7 @@ nsresult ObjectStoreAddOrPutRequestOp::DoDatabaseWork(
|
|||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
// Try to remove the file if the copy failed.
|
||||
nsresult rv2 =
|
||||
Transaction().GetDatabase()->GetFileManager().SyncDeleteFile(
|
||||
Transaction().GetDatabase().GetFileManager().SyncDeleteFile(
|
||||
*file, *journalFile);
|
||||
if (NS_WARN_IF(NS_FAILED(rv2))) {
|
||||
return rv;
|
||||
|
@ -25753,7 +25781,7 @@ ObjectStoreGetRequestOp::ObjectStoreGetRequestOp(
|
|||
mObjectStoreId(aGetAll
|
||||
? aParams.get_ObjectStoreGetAllParams().objectStoreId()
|
||||
: aParams.get_ObjectStoreGetParams().objectStoreId()),
|
||||
mDatabase(Transaction().GetDatabase()),
|
||||
mDatabase(Transaction().GetDatabasePtr()),
|
||||
mOptionalKeyRange(
|
||||
aGetAll ? aParams.get_ObjectStoreGetAllParams().optionalKeyRange()
|
||||
: Some(aParams.get_ObjectStoreGetParams().keyRange())),
|
||||
|
@ -26357,7 +26385,7 @@ RefPtr<FullIndexMetadata> IndexRequestOpBase::IndexMetadataForParams(
|
|||
IndexGetRequestOp::IndexGetRequestOp(RefPtr<TransactionBase> aTransaction,
|
||||
const RequestParams& aParams, bool aGetAll)
|
||||
: IndexRequestOpBase(std::move(aTransaction), aParams),
|
||||
mDatabase(Transaction().GetDatabase()),
|
||||
mDatabase(Transaction().GetDatabasePtr()),
|
||||
mOptionalKeyRange(aGetAll
|
||||
? aParams.get_IndexGetAllParams().optionalKeyRange()
|
||||
: Some(aParams.get_IndexGetParams().keyRange())),
|
||||
|
|
Загрузка…
Ссылка в новой задаче