示例#1
0
void IDBTransaction::revertDatabaseMetadata() {
  DCHECK_NE(m_state, Active);
  if (!isVersionChange())
    return;

  // Mark stores created by this transaction as deleted.
  for (auto& objectStore : m_objectStoreMap.values()) {
    const int64_t objectStoreId = objectStore->id();
    if (!objectStore->isNewlyCreated()) {
      DCHECK(m_oldStoreMetadata.contains(objectStore));
      continue;
    }

    DCHECK(!m_oldStoreMetadata.contains(objectStore));
    m_database->revertObjectStoreCreation(objectStoreId);
    objectStore->markDeleted();
  }

  for (auto& it : m_oldStoreMetadata) {
    IDBObjectStore* objectStore = it.key;
    RefPtr<IDBObjectStoreMetadata> oldMetadata = it.value;

    m_database->revertObjectStoreMetadata(oldMetadata);
    objectStore->revertMetadata(oldMetadata);
  }
  for (auto& index : m_deletedIndexes)
    index->objectStore()->revertDeletedIndexMetadata(*index);
  for (auto& oldMedata : m_deletedObjectStores)
    m_database->revertObjectStoreMetadata(std::move(oldMedata));

  // We only need to revert the database's own metadata because we have reverted
  // the metadata for the database's object stores above.
  m_database->setDatabaseMetadata(m_oldDatabaseMetadata);
}