Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(422)

Unified Diff: third_party/WebKit/Source/modules/indexeddb/IDBDatabase.cpp

Issue 2314933005: Align IndexedDB metadata rollback on transaction abort to spec. (Closed)
Patch Set: Rebased. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/indexeddb/IDBDatabase.cpp
diff --git a/third_party/WebKit/Source/modules/indexeddb/IDBDatabase.cpp b/third_party/WebKit/Source/modules/indexeddb/IDBDatabase.cpp
index 73d7737ac5c70ed671586856dc5345e71f0299e0..b94e560abb79690c727d807278d11ab0f8f14669 100644
--- a/third_party/WebKit/Source/modules/indexeddb/IDBDatabase.cpp
+++ b/third_party/WebKit/Source/modules/indexeddb/IDBDatabase.cpp
@@ -109,29 +109,17 @@ int64_t IDBDatabase::nextTransactionId()
return atomicIncrement(&currentTransactionId);
}
-void IDBDatabase::indexCreated(int64_t objectStoreId, const IDBIndexMetadata& metadata)
+void IDBDatabase::setMetadata(const IDBDatabaseMetadata& metadata)
{
- IDBDatabaseMetadata::ObjectStoreMap::iterator it = m_metadata.objectStores.find(objectStoreId);
- ASSERT_WITH_SECURITY_IMPLICATION(it != m_metadata.objectStores.end());
- it->value.indexes.set(metadata.id, metadata);
+ m_metadata = metadata;
}
-void IDBDatabase::indexDeleted(int64_t objectStoreId, int64_t indexId)
+void IDBDatabase::setDatabaseMetadata(const IDBDatabaseMetadata& metadata)
{
- IDBDatabaseMetadata::ObjectStoreMap::iterator it = m_metadata.objectStores.find(objectStoreId);
- ASSERT_WITH_SECURITY_IMPLICATION(it != m_metadata.objectStores.end());
- it->value.indexes.remove(indexId);
-}
-
-void IDBDatabase::indexRenamed(int64_t objectStoreId, int64_t indexId, const String& newName)
-{
- IDBDatabaseMetadata::ObjectStoreMap::iterator storeIterator = m_metadata.objectStores.find(objectStoreId);
- SECURITY_DCHECK(storeIterator != m_metadata.objectStores.end());
-
- IDBObjectStoreMetadata& storeMetadata = storeIterator->value;
- IDBObjectStoreMetadata::IndexMap::iterator indexIterator = storeMetadata.indexes.find(indexId);
- DCHECK_NE(indexIterator, storeMetadata.indexes.end());
- indexIterator->value.name = newName;
+ m_metadata.name = metadata.name;
+ m_metadata.id = metadata.id;
+ m_metadata.version = metadata.version;
+ m_metadata.maxObjectStoreId = metadata.maxObjectStoreId;
}
void IDBDatabase::transactionCreated(IDBTransaction* transaction)
@@ -178,7 +166,7 @@ DOMStringList* IDBDatabase::objectStoreNames() const
{
DOMStringList* objectStoreNames = DOMStringList::create(DOMStringList::IndexedDB);
for (const auto& it : m_metadata.objectStores)
- objectStoreNames->append(it.value.name);
+ objectStoreNames->append(it.value->name);
objectStoreNames->sort();
return objectStoreNames;
}
@@ -187,7 +175,7 @@ const String& IDBDatabase::getObjectStoreName(int64_t objectStoreId) const
{
const auto& it = m_metadata.objectStores.find(objectStoreId);
DCHECK(it != m_metadata.objectStores.end());
- return it->value.name;
+ return it->value->name;
}
IDBObjectStore* IDBDatabase::createObjectStore(const String& name, const IDBKeyPath& keyPath, bool autoIncrement, ExceptionState& exceptionState)
@@ -229,14 +217,16 @@ IDBObjectStore* IDBDatabase::createObjectStore(const String& name, const IDBKeyP
}
int64_t objectStoreId = m_metadata.maxObjectStoreId + 1;
+ DCHECK_NE(objectStoreId, IDBObjectStoreMetadata::InvalidId);
m_backend->createObjectStore(m_versionChangeTransaction->id(), objectStoreId, name, keyPath, autoIncrement);
- IDBObjectStoreMetadata metadata(name, objectStoreId, keyPath, autoIncrement, WebIDBDatabase::minimumIndexId);
- IDBObjectStore* objectStore = IDBObjectStore::create(metadata, m_versionChangeTransaction.get());
- m_metadata.objectStores.set(metadata.id, metadata);
+ RefPtr<IDBObjectStoreMetadata> storeMetadata = adoptRef(new IDBObjectStoreMetadata(
+ name, objectStoreId, keyPath, autoIncrement, WebIDBDatabase::minimumIndexId));
+ IDBObjectStore* objectStore = IDBObjectStore::create(storeMetadata, m_versionChangeTransaction.get());
+ m_versionChangeTransaction->objectStoreCreated(name, objectStore);
+ m_metadata.objectStores.set(objectStoreId, std::move(storeMetadata));
++m_metadata.maxObjectStoreId;
- m_versionChangeTransaction->objectStoreCreated(name, objectStore);
return objectStore;
}
@@ -269,7 +259,7 @@ void IDBDatabase::deleteObjectStore(const String& name, ExceptionState& exceptio
}
m_backend->deleteObjectStore(m_versionChangeTransaction->id(), objectStoreId);
- m_versionChangeTransaction->objectStoreDeleted(name);
+ m_versionChangeTransaction->objectStoreDeleted(objectStoreId, name);
m_metadata.objectStores.remove(objectStoreId);
}
@@ -426,7 +416,7 @@ DispatchEventResult IDBDatabase::dispatchEventInternal(Event* event)
int64_t IDBDatabase::findObjectStoreId(const String& name) const
{
for (const auto& it : m_metadata.objectStores) {
- if (it.value.name == name) {
+ if (it.value->name == name) {
DCHECK_NE(it.key, IDBObjectStoreMetadata::InvalidId);
return it.key;
}
@@ -434,14 +424,35 @@ int64_t IDBDatabase::findObjectStoreId(const String& name) const
return IDBObjectStoreMetadata::InvalidId;
}
-void IDBDatabase::objectStoreRenamed(int64_t objectStoreId, const String& newName)
+void IDBDatabase::renameObjectStore(int64_t objectStoreId, const String& newName)
{
DCHECK(m_versionChangeTransaction) << "Object store renamed on database without a versionchange transaction";
DCHECK(m_versionChangeTransaction->isActive()) << "Object store renamed when versionchange transaction is not active";
DCHECK(m_backend) << "Object store renamed after database connection closed";
DCHECK(m_metadata.objectStores.contains(objectStoreId));
+
+ m_backend->renameObjectStore(m_versionChangeTransaction->id(), objectStoreId, newName);
+
IDBDatabaseMetadata::ObjectStoreMap::iterator it = m_metadata.objectStores.find(objectStoreId);
- it->value.name = newName;
+ IDBObjectStoreMetadata* objectStoreMetadata = it->value.get();
+ m_versionChangeTransaction->objectStoreRenamed(objectStoreMetadata->name, newName);
+ objectStoreMetadata->name = newName;
+}
+
+void IDBDatabase::revertObjectStoreCreation(int64_t objectStoreId)
+{
+ DCHECK(m_versionChangeTransaction) << "Object store metadata reverted on database without a versionchange transaction";
+ DCHECK(!m_versionChangeTransaction->isActive()) << "Object store metadata reverted when versionchange transaction is still active";
+ DCHECK(m_metadata.objectStores.contains(objectStoreId));
+ m_metadata.objectStores.remove(objectStoreId);
+}
+
+void IDBDatabase::revertObjectStoreMetadata(RefPtr<IDBObjectStoreMetadata> oldMetadata)
+{
+ DCHECK(m_versionChangeTransaction) << "Object store metadata reverted on database without a versionchange transaction";
+ DCHECK(!m_versionChangeTransaction->isActive()) << "Object store metadata reverted when versionchange transaction is still active";
+ DCHECK(oldMetadata.get());
+ m_metadata.objectStores.set(oldMetadata->id, std::move(oldMetadata));
}
bool IDBDatabase::hasPendingActivity() const

Powered by Google App Engine
This is Rietveld 408576698