Ejemplo n.º 1
0
void IDBTransaction::finished() {
#if DCHECK_IS_ON()
  DCHECK(!m_finishCalled);
  m_finishCalled = true;
#endif  // DCHECK_IS_ON()

  m_database->transactionFinished(this);

  // Remove references to the IDBObjectStore and IDBIndex instances held by
  // this transaction, so Oilpan can garbage-collect the instances that aren't
  // used by JavaScript.

  for (auto& it : m_objectStoreMap) {
    IDBObjectStore* objectStore = it.value;
    if (!isVersionChange() || objectStore->isNewlyCreated()) {
      DCHECK(!m_oldStoreMetadata.contains(objectStore));
      objectStore->clearIndexCache();
    } else {
      // We'll call clearIndexCache() on this store in the loop below.
      DCHECK(m_oldStoreMetadata.contains(objectStore));
    }
  }
  m_objectStoreMap.clear();

  for (auto& it : m_oldStoreMetadata) {
    IDBObjectStore* objectStore = it.key;
    objectStore->clearIndexCache();
  }
  m_oldStoreMetadata.clear();

  m_deletedIndexes.clear();
  m_deletedObjectStores.clear();
}
Ejemplo n.º 2
0
IDBObjectStore* IDBTransaction::objectStore(const String& name,
                                            ExceptionState& exceptionState) {
  if (isFinished()) {
    exceptionState.throwDOMException(
        InvalidStateError, IDBDatabase::transactionFinishedErrorMessage);
    return nullptr;
  }

  IDBObjectStoreMap::iterator it = m_objectStoreMap.find(name);
  if (it != m_objectStoreMap.end())
    return it->value;

  if (!isVersionChange() && !m_scope.contains(name)) {
    exceptionState.throwDOMException(
        NotFoundError, IDBDatabase::noSuchObjectStoreErrorMessage);
    return nullptr;
  }

  int64_t objectStoreId = m_database->findObjectStoreId(name);
  if (objectStoreId == IDBObjectStoreMetadata::InvalidId) {
    DCHECK(isVersionChange());
    exceptionState.throwDOMException(
        NotFoundError, IDBDatabase::noSuchObjectStoreErrorMessage);
    return nullptr;
  }

  DCHECK(m_database->metadata().objectStores.contains(objectStoreId));
  RefPtr<IDBObjectStoreMetadata> objectStoreMetadata =
      m_database->metadata().objectStores.get(objectStoreId);
  DCHECK(objectStoreMetadata.get());

  IDBObjectStore* objectStore =
      IDBObjectStore::create(std::move(objectStoreMetadata), this);
  DCHECK(!m_objectStoreMap.contains(name));
  m_objectStoreMap.set(name, objectStore);

  if (isVersionChange()) {
    DCHECK(!objectStore->isNewlyCreated())
        << "Object store IDs are not assigned sequentially";
    RefPtr<IDBObjectStoreMetadata> backupMetadata =
        objectStore->metadata().createCopy();
    m_oldStoreMetadata.set(objectStore, std::move(backupMetadata));
  }
  return objectStore;
}