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

Unified Diff: third_party/WebKit/Source/modules/indexeddb/IDBIndex.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/IDBIndex.cpp
diff --git a/third_party/WebKit/Source/modules/indexeddb/IDBIndex.cpp b/third_party/WebKit/Source/modules/indexeddb/IDBIndex.cpp
index 1599c7f233ae0a68d8ac6491df5dfad7fab1cb39..eb99c85bd95706fd20121a6e73fa8cadf4ea5095 100644
--- a/third_party/WebKit/Source/modules/indexeddb/IDBIndex.cpp
+++ b/third_party/WebKit/Source/modules/indexeddb/IDBIndex.cpp
@@ -45,14 +45,15 @@ using blink::WebIDBDatabase;
namespace blink {
-IDBIndex::IDBIndex(const IDBIndexMetadata& metadata, IDBObjectStore* objectStore, IDBTransaction* transaction)
- : m_metadata(metadata)
+IDBIndex::IDBIndex(RefPtr<IDBIndexMetadata> metadata, IDBObjectStore* objectStore, IDBTransaction* transaction)
+ : m_metadata(std::move(metadata))
, m_objectStore(objectStore)
, m_transaction(transaction)
{
- ASSERT(m_objectStore);
- ASSERT(m_transaction);
- ASSERT(m_metadata.id != IDBIndexMetadata::InvalidId);
+ DCHECK(m_objectStore);
+ DCHECK(m_transaction);
+ DCHECK(m_metadata.get());
+ DCHECK(id() != IDBIndexMetadata::InvalidId);
}
IDBIndex::~IDBIndex()
@@ -65,7 +66,7 @@ DEFINE_TRACE(IDBIndex)
visitor->trace(m_transaction);
}
-void IDBIndex::setName(const String& name, ExceptionState& exceptionState)
+void IDBIndex::setName(const String& newName, ExceptionState& exceptionState)
{
if (!RuntimeEnabledFeatures::indexedDBExperimentalEnabled())
return;
@@ -88,9 +89,9 @@ void IDBIndex::setName(const String& name, ExceptionState& exceptionState)
return;
}
- if (m_metadata.name == name)
+ if (name() == newName)
return;
- if (m_objectStore->containsIndex(name)) {
+ if (m_objectStore->containsIndex(newName)) {
exceptionState.throwDOMException(ConstraintError, IDBDatabase::indexNameTakenErrorMessage);
return;
}
@@ -99,15 +100,22 @@ void IDBIndex::setName(const String& name, ExceptionState& exceptionState)
return;
}
- backendDB()->renameIndex(m_transaction->id(), m_objectStore->id(), id(), name);
- m_metadata.name = name;
- m_objectStore->indexRenamed(m_metadata.id, name);
- m_transaction->db()->indexRenamed(m_objectStore->id(), id(), name);
+ backendDB()->renameIndex(m_transaction->id(), m_objectStore->id(), id(), newName);
+ m_objectStore->renameIndex(id(), newName);
}
ScriptValue IDBIndex::keyPath(ScriptState* scriptState) const
{
- return ScriptValue::from(scriptState, m_metadata.keyPath);
+ return ScriptValue::from(scriptState, metadata().keyPath);
+}
+
+void IDBIndex::revertMetadata(RefPtr<IDBIndexMetadata> oldMetadata)
+{
+ m_metadata = std::move(oldMetadata);
+
+ // An index's metadata will only get reverted if the index was in the
+ // database when the versionchange transaction started.
+ m_deleted = false;
}
IDBRequest* IDBIndex::openCursor(ScriptState* scriptState, const ScriptValue& range, const String& directionString, ExceptionState& exceptionState)
@@ -142,7 +150,7 @@ IDBRequest* IDBIndex::openCursor(ScriptState* scriptState, IDBKeyRange* keyRange
{
IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get());
request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction);
- backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata.id, keyRange, direction, false, WebIDBTaskTypeNormal, WebIDBCallbacksImpl::create(request).release());
+ backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), id(), keyRange, direction, false, WebIDBTaskTypeNormal, WebIDBCallbacksImpl::create(request).release());
return request;
}
@@ -172,7 +180,7 @@ IDBRequest* IDBIndex::count(ScriptState* scriptState, const ScriptValue& range,
}
IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get());
- backendDB()->count(m_transaction->id(), m_objectStore->id(), m_metadata.id, keyRange, WebIDBCallbacksImpl::create(request).release());
+ backendDB()->count(m_transaction->id(), m_objectStore->id(), id(), keyRange, WebIDBCallbacksImpl::create(request).release());
return request;
}
@@ -202,7 +210,7 @@ IDBRequest* IDBIndex::openKeyCursor(ScriptState* scriptState, const ScriptValue&
IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get());
request->setCursorDetails(IndexedDB::CursorKeyOnly, direction);
- backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata.id, keyRange, direction, true, WebIDBTaskTypeNormal, WebIDBCallbacksImpl::create(request).release());
+ backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), id(), keyRange, direction, true, WebIDBTaskTypeNormal, WebIDBCallbacksImpl::create(request).release());
return request;
}
@@ -268,7 +276,7 @@ IDBRequest* IDBIndex::getInternal(ScriptState* scriptState, const ScriptValue& k
}
IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get());
- backendDB()->get(m_transaction->id(), m_objectStore->id(), m_metadata.id, keyRange, keyOnly, WebIDBCallbacksImpl::create(request).release());
+ backendDB()->get(m_transaction->id(), m_objectStore->id(), id(), keyRange, keyOnly, WebIDBCallbacksImpl::create(request).release());
return request;
}
@@ -299,7 +307,7 @@ IDBRequest* IDBIndex::getAllInternal(ScriptState* scriptState, const ScriptValue
}
IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get());
- backendDB()->getAll(m_transaction->id(), m_objectStore->id(), m_metadata.id, keyRange, maxCount, keyOnly, WebIDBCallbacksImpl::create(request).release());
+ backendDB()->getAll(m_transaction->id(), m_objectStore->id(), id(), keyRange, maxCount, keyOnly, WebIDBCallbacksImpl::create(request).release());
return request;
}
@@ -308,9 +316,4 @@ WebIDBDatabase* IDBIndex::backendDB() const
return m_transaction->backendDB();
}
-bool IDBIndex::isDeleted() const
-{
- return m_deleted || m_objectStore->isDeleted();
-}
-
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698