Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 ASSERT(m_transaction); | 64 ASSERT(m_transaction); |
| 65 } | 65 } |
| 66 | 66 |
| 67 DEFINE_TRACE(IDBObjectStore) | 67 DEFINE_TRACE(IDBObjectStore) |
| 68 { | 68 { |
| 69 visitor->trace(m_transaction); | 69 visitor->trace(m_transaction); |
| 70 visitor->trace(m_indexMap); | 70 visitor->trace(m_indexMap); |
| 71 visitor->trace(m_createdIndexes); | 71 visitor->trace(m_createdIndexes); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void IDBObjectStore::setName(const String& name, ExceptionState& exceptionState) | |
| 75 { | |
| 76 if (!RuntimeEnabledFeatures::indexedDBExperimentalEnabled()) | |
| 77 return; | |
|
foolip
2016/09/09 08:12:17
Ditto.
| |
| 78 | |
| 79 IDB_TRACE("IDBObjectStore::setName"); | |
| 80 if (!m_transaction->isVersionChange()) { | |
| 81 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::notVers ionChangeTransactionErrorMessage); | |
| 82 return; | |
| 83 } | |
| 84 if (isDeleted()) { | |
| 85 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage); | |
| 86 return; | |
| 87 } | |
| 88 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | |
| 89 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage); | |
| 90 return; | |
| 91 } | |
| 92 if (!m_transaction->isActive()) { | |
| 93 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage); | |
| 94 return; | |
| 95 } | |
| 96 | |
| 97 if (m_metadata.name == name) | |
| 98 return; | |
| 99 if (m_transaction->db()->containsObjectStore(name)) { | |
| 100 exceptionState.throwDOMException(ConstraintError, IDBDatabase::objectSto reNameTakenErrorMessage); | |
| 101 return; | |
| 102 } | |
| 103 if (!backendDB()) { | |
| 104 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage); | |
| 105 return; | |
| 106 } | |
| 107 | |
| 108 backendDB()->renameObjectStore(m_transaction->id(), id(), name); | |
| 109 m_transaction->objectStoreRenamed(m_metadata.name, name); | |
| 110 m_metadata.name = name; | |
| 111 | |
| 112 // The name inside the database's version of the object store metadata is us ed by IDBDatabase.objectStoreNames(). | |
| 113 // If the transaction is aborted, this name will be reverted when the metada ta is overwritten with the previousMetadata in IDBTransaction. | |
| 114 m_transaction->db()->objectStoreRenamed(id(), name); | |
| 115 } | |
| 116 | |
| 74 ScriptValue IDBObjectStore::keyPath(ScriptState* scriptState) const | 117 ScriptValue IDBObjectStore::keyPath(ScriptState* scriptState) const |
| 75 { | 118 { |
| 76 return ScriptValue::from(scriptState, m_metadata.keyPath); | 119 return ScriptValue::from(scriptState, m_metadata.keyPath); |
| 77 } | 120 } |
| 78 | 121 |
| 79 DOMStringList* IDBObjectStore::indexNames() const | 122 DOMStringList* IDBObjectStore::indexNames() const |
| 80 { | 123 { |
| 81 IDB_TRACE("IDBObjectStore::indexNames"); | 124 IDB_TRACE("IDBObjectStore::indexNames"); |
| 82 DOMStringList* indexNames = DOMStringList::create(DOMStringList::IndexedDB); | 125 DOMStringList* indexNames = DOMStringList::create(DOMStringList::IndexedDB); |
| 83 for (const auto& it : m_metadata.indexes) | 126 for (const auto& it : m_metadata.indexes) |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 538 } | 581 } |
| 539 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | 582 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
| 540 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage); | 583 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage); |
| 541 return nullptr; | 584 return nullptr; |
| 542 } | 585 } |
| 543 if (!m_transaction->isActive()) { | 586 if (!m_transaction->isActive()) { |
| 544 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage); | 587 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage); |
| 545 return nullptr; | 588 return nullptr; |
| 546 } | 589 } |
| 547 if (containsIndex(name)) { | 590 if (containsIndex(name)) { |
| 548 exceptionState.throwDOMException(ConstraintError, "An index with the spe cified name already exists."); | 591 exceptionState.throwDOMException(ConstraintError, IDBDatabase::indexName TakenErrorMessage); |
| 549 return nullptr; | 592 return nullptr; |
| 550 } | 593 } |
| 551 if (!keyPath.isValid()) { | 594 if (!keyPath.isValid()) { |
| 552 exceptionState.throwDOMException(SyntaxError, "The keyPath argument cont ains an invalid key path."); | 595 exceptionState.throwDOMException(SyntaxError, "The keyPath argument cont ains an invalid key path."); |
| 553 return nullptr; | 596 return nullptr; |
| 554 } | 597 } |
| 555 if (keyPath.getType() == IDBKeyPath::ArrayType && options.multiEntry()) { | 598 if (keyPath.getType() == IDBKeyPath::ArrayType && options.multiEntry()) { |
| 556 exceptionState.throwDOMException(InvalidAccessError, "The keyPath argume nt was an array and the multiEntry option is true."); | 599 exceptionState.throwDOMException(InvalidAccessError, "The keyPath argume nt was an array and the multiEntry option is true."); |
| 557 return nullptr; | 600 return nullptr; |
| 558 } | 601 } |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 773 void IDBObjectStore::transactionFinished() | 816 void IDBObjectStore::transactionFinished() |
| 774 { | 817 { |
| 775 ASSERT(m_transaction->isFinished()); | 818 ASSERT(m_transaction->isFinished()); |
| 776 | 819 |
| 777 // Break reference cycles. | 820 // Break reference cycles. |
| 778 // TODO(jsbell): This can be removed c/o Oilpan. | 821 // TODO(jsbell): This can be removed c/o Oilpan. |
| 779 m_indexMap.clear(); | 822 m_indexMap.clear(); |
| 780 m_createdIndexes.clear(); | 823 m_createdIndexes.clear(); |
| 781 } | 824 } |
| 782 | 825 |
| 826 void IDBObjectStore::indexRenamed(int64_t indexId, const String& newName) | |
| 827 { | |
| 828 DCHECK(m_transaction->isVersionChange()); | |
| 829 DCHECK(m_transaction->isActive()); | |
| 830 | |
| 831 IDBObjectStoreMetadata::IndexMap::iterator metadataIterator = m_metadata.ind exes.find(indexId); | |
| 832 DCHECK(metadataIterator != m_metadata.indexes.end()) << "Invalid indexId"; | |
| 833 const String& oldName = metadataIterator->value.name; | |
| 834 | |
| 835 DCHECK(m_indexMap.contains(oldName)) << "The index had to be accessed in ord er to be renamed."; | |
| 836 DCHECK(!m_indexMap.contains(newName)); | |
| 837 IDBIndexMap::iterator it = m_indexMap.find(oldName); | |
| 838 m_indexMap.set(newName, it->value); | |
| 839 m_indexMap.remove(oldName); | |
| 840 | |
| 841 metadataIterator->value.name = newName; | |
| 842 } | |
| 843 | |
| 783 int64_t IDBObjectStore::findIndexId(const String& name) const | 844 int64_t IDBObjectStore::findIndexId(const String& name) const |
| 784 { | 845 { |
| 785 for (const auto& it : m_metadata.indexes) { | 846 for (const auto& it : m_metadata.indexes) { |
| 786 if (it.value.name == name) { | 847 if (it.value.name == name) { |
| 787 ASSERT(it.key != IDBIndexMetadata::InvalidId); | 848 ASSERT(it.key != IDBIndexMetadata::InvalidId); |
| 788 return it.key; | 849 return it.key; |
| 789 } | 850 } |
| 790 } | 851 } |
| 791 return IDBIndexMetadata::InvalidId; | 852 return IDBIndexMetadata::InvalidId; |
| 792 } | 853 } |
| 793 | 854 |
| 794 WebIDBDatabase* IDBObjectStore::backendDB() const | 855 WebIDBDatabase* IDBObjectStore::backendDB() const |
| 795 { | 856 { |
| 796 return m_transaction->backendDB(); | 857 return m_transaction->backendDB(); |
| 797 } | 858 } |
| 798 | 859 |
| 799 } // namespace blink | 860 } // namespace blink |
| OLD | NEW |