Chromium Code Reviews| Index: third_party/WebKit/Source/modules/indexeddb/IDBObjectStore.cpp |
| diff --git a/third_party/WebKit/Source/modules/indexeddb/IDBObjectStore.cpp b/third_party/WebKit/Source/modules/indexeddb/IDBObjectStore.cpp |
| index 233de166d439ca55a86716d5adae8a0b1e49c79b..6da536f6cac46cff962471a41a460e685daf83cf 100644 |
| --- a/third_party/WebKit/Source/modules/indexeddb/IDBObjectStore.cpp |
| +++ b/third_party/WebKit/Source/modules/indexeddb/IDBObjectStore.cpp |
| @@ -71,6 +71,49 @@ DEFINE_TRACE(IDBObjectStore) |
| visitor->trace(m_createdIndexes); |
| } |
| +void IDBObjectStore::setName(const String& name, ExceptionState& exceptionState) |
| +{ |
| + if (!RuntimeEnabledFeatures::indexedDBExperimentalEnabled()) |
| + return; |
| + |
| + IDB_TRACE("IDBObjectStore::setName"); |
| + if (!m_transaction->isVersionChange()) { |
| + exceptionState.throwDOMException(InvalidStateError, IDBDatabase::notVersionChangeTransactionErrorMessage); |
| + return; |
| + } |
| + if (isDeleted()) { |
| + exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedErrorMessage); |
| + return; |
| + } |
| + if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
| + exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::transactionFinishedErrorMessage); |
| + return; |
| + } |
| + if (!m_transaction->isActive()) { |
| + exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::transactionInactiveErrorMessage); |
| + return; |
| + } |
| + |
| + if (m_metadata.name == name) |
| + return; |
| + if (m_transaction->db()->containsObjectStore(name)) { |
| + exceptionState.throwDOMException(ConstraintError, IDBDatabase::objectStoreNameTakenErrorMessage); |
| + return; |
| + } |
| + if (!backendDB()) { |
| + exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databaseClosedErrorMessage); |
| + return; |
| + } |
| + |
| + backendDB()->renameObjectStore(m_transaction->id(), id(), name); |
| + m_transaction->objectStoreWillBeRenamed(m_metadata.name, name); |
| + m_metadata.name = name; |
| + |
| + // The name inside the database's version of the object store metadata is used by IDBDatabase.objectStoreNames(). |
| + // If the transaction is aborted, this name will be reverted when the metadata is overwritten with the previousMetadata in IDBTransaction. |
| + m_transaction->db()->objectStoreRenamed(id(), name); |
| +} |
| + |
| ScriptValue IDBObjectStore::keyPath(ScriptState* scriptState) const |
| { |
| return ScriptValue::from(scriptState, m_metadata.keyPath); |
| @@ -545,7 +588,7 @@ IDBIndex* IDBObjectStore::createIndex(ScriptState* scriptState, const String& na |
| return nullptr; |
| } |
| if (containsIndex(name)) { |
| - exceptionState.throwDOMException(ConstraintError, "An index with the specified name already exists."); |
| + exceptionState.throwDOMException(ConstraintError, IDBDatabase::indexNameTakenErrorMessage); |
| return nullptr; |
| } |
| if (!keyPath.isValid()) { |
| @@ -780,6 +823,24 @@ void IDBObjectStore::transactionFinished() |
| m_createdIndexes.clear(); |
| } |
| +void IDBObjectStore::indexWillBeRenamed(const String& oldName, const String& newName) |
|
jsbell
2016/09/07 17:16:14
It seems like it would be simpler if this took the
pwnall
2016/09/07 22:43:52
Done.
|
| +{ |
| + DCHECK(m_transaction->isVersionChange()); |
| + DCHECK(m_transaction->isActive()); |
| + |
| + DCHECK(m_indexMap.contains(oldName)); |
| + DCHECK(!m_indexMap.contains(newName)); |
| + IDBIndexMap::iterator it = m_indexMap.find(oldName); |
| + int64_t indexId = it->value->id(); |
| + m_indexMap.set(newName, it->value); |
| + m_indexMap.remove(oldName); |
| + |
| + IDBObjectStoreMetadata::IndexMap::iterator metadataIterator = m_metadata.indexes.find(indexId); |
| + DCHECK(metadataIterator != m_metadata.indexes.end()); |
| + DCHECK(metadataIterator->value.name == oldName); |
| + metadataIterator->value.name = newName; |
| +} |
| + |
| int64_t IDBObjectStore::findIndexId(const String& name) const |
| { |
| for (const auto& it : m_metadata.indexes) { |