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 IDB_TRACE("IDBObjectStore::setName"); |
| 77 if (!m_transaction->isVersionChange()) { |
| 78 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::notVers
ionChangeTransactionErrorMessage); |
| 79 return; |
| 80 } |
| 81 if (isDeleted()) { |
| 82 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS
toreDeletedErrorMessage); |
| 83 return; |
| 84 } |
| 85 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
| 86 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
| 87 return; |
| 88 } |
| 89 if (!m_transaction->isActive()) { |
| 90 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
| 91 return; |
| 92 } |
| 93 |
| 94 if (m_metadata.name == name) |
| 95 return; |
| 96 if (m_transaction->db()->containsObjectStore(name)) { |
| 97 exceptionState.throwDOMException(ConstraintError, IDBDatabase::objectSto
reNameTakenErrorMessage); |
| 98 return; |
| 99 } |
| 100 if (!backendDB()) { |
| 101 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
| 102 return; |
| 103 } |
| 104 |
| 105 backendDB()->renameObjectStore(m_transaction->id(), id(), name); |
| 106 m_transaction->objectStoreWillBeRenamed(m_metadata.name, name); |
| 107 m_metadata.name = name; |
| 108 |
| 109 // The name inside the database's version of the object store metadata is us
ed by IDBDatabase.objectStoreNames(). |
| 110 // If the transaction is aborted, this name will be reverted when the metada
ta is overwritten with the previousMetadata in IDBTransaction. |
| 111 m_transaction->db()->objectStoreRenamed(id(), name); |
| 112 } |
| 113 |
74 ScriptValue IDBObjectStore::keyPath(ScriptState* scriptState) const | 114 ScriptValue IDBObjectStore::keyPath(ScriptState* scriptState) const |
75 { | 115 { |
76 return ScriptValue::from(scriptState, m_metadata.keyPath); | 116 return ScriptValue::from(scriptState, m_metadata.keyPath); |
77 } | 117 } |
78 | 118 |
79 DOMStringList* IDBObjectStore::indexNames() const | 119 DOMStringList* IDBObjectStore::indexNames() const |
80 { | 120 { |
81 IDB_TRACE("IDBObjectStore::indexNames"); | 121 IDB_TRACE("IDBObjectStore::indexNames"); |
82 DOMStringList* indexNames = DOMStringList::create(DOMStringList::IndexedDB); | 122 DOMStringList* indexNames = DOMStringList::create(DOMStringList::IndexedDB); |
83 for (const auto& it : m_metadata.indexes) | 123 for (const auto& it : m_metadata.indexes) |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 } | 578 } |
539 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | 579 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
540 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 580 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
541 return nullptr; | 581 return nullptr; |
542 } | 582 } |
543 if (!m_transaction->isActive()) { | 583 if (!m_transaction->isActive()) { |
544 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 584 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
545 return nullptr; | 585 return nullptr; |
546 } | 586 } |
547 if (containsIndex(name)) { | 587 if (containsIndex(name)) { |
548 exceptionState.throwDOMException(ConstraintError, "An index with the spe
cified name already exists."); | 588 exceptionState.throwDOMException(ConstraintError, IDBDatabase::indexName
TakenErrorMessage); |
549 return nullptr; | 589 return nullptr; |
550 } | 590 } |
551 if (!keyPath.isValid()) { | 591 if (!keyPath.isValid()) { |
552 exceptionState.throwDOMException(SyntaxError, "The keyPath argument cont
ains an invalid key path."); | 592 exceptionState.throwDOMException(SyntaxError, "The keyPath argument cont
ains an invalid key path."); |
553 return nullptr; | 593 return nullptr; |
554 } | 594 } |
555 if (keyPath.getType() == IDBKeyPath::ArrayType && options.multiEntry()) { | 595 if (keyPath.getType() == IDBKeyPath::ArrayType && options.multiEntry()) { |
556 exceptionState.throwDOMException(InvalidAccessError, "The keyPath argume
nt was an array and the multiEntry option is true."); | 596 exceptionState.throwDOMException(InvalidAccessError, "The keyPath argume
nt was an array and the multiEntry option is true."); |
557 return nullptr; | 597 return nullptr; |
558 } | 598 } |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 void IDBObjectStore::transactionFinished() | 813 void IDBObjectStore::transactionFinished() |
774 { | 814 { |
775 ASSERT(m_transaction->isFinished()); | 815 ASSERT(m_transaction->isFinished()); |
776 | 816 |
777 // Break reference cycles. | 817 // Break reference cycles. |
778 // TODO(jsbell): This can be removed c/o Oilpan. | 818 // TODO(jsbell): This can be removed c/o Oilpan. |
779 m_indexMap.clear(); | 819 m_indexMap.clear(); |
780 m_createdIndexes.clear(); | 820 m_createdIndexes.clear(); |
781 } | 821 } |
782 | 822 |
| 823 void IDBObjectStore::indexWillBeRenamed(const String& oldName, const String& new
Name) |
| 824 { |
| 825 DCHECK(m_transaction->isVersionChange()); |
| 826 DCHECK(m_transaction->isActive()); |
| 827 |
| 828 DCHECK(m_indexMap.contains(oldName)); |
| 829 DCHECK(!m_indexMap.contains(newName)); |
| 830 IDBIndexMap::iterator it = m_indexMap.find(oldName); |
| 831 int64_t indexId = it->value->id(); |
| 832 m_indexMap.set(newName, it->value); |
| 833 m_indexMap.remove(oldName); |
| 834 |
| 835 IDBObjectStoreMetadata::IndexMap::iterator metadataIterator = m_metadata.ind
exes.find(indexId); |
| 836 DCHECK(metadataIterator != m_metadata.indexes.end()); |
| 837 DCHECK(metadataIterator->value.name == oldName); |
| 838 metadataIterator->value.name = newName; |
| 839 } |
| 840 |
783 int64_t IDBObjectStore::findIndexId(const String& name) const | 841 int64_t IDBObjectStore::findIndexId(const String& name) const |
784 { | 842 { |
785 for (const auto& it : m_metadata.indexes) { | 843 for (const auto& it : m_metadata.indexes) { |
786 if (it.value.name == name) { | 844 if (it.value.name == name) { |
787 ASSERT(it.key != IDBIndexMetadata::InvalidId); | 845 ASSERT(it.key != IDBIndexMetadata::InvalidId); |
788 return it.key; | 846 return it.key; |
789 } | 847 } |
790 } | 848 } |
791 return IDBIndexMetadata::InvalidId; | 849 return IDBIndexMetadata::InvalidId; |
792 } | 850 } |
793 | 851 |
794 WebIDBDatabase* IDBObjectStore::backendDB() const | 852 WebIDBDatabase* IDBObjectStore::backendDB() const |
795 { | 853 { |
796 return m_transaction->backendDB(); | 854 return m_transaction->backendDB(); |
797 } | 855 } |
798 | 856 |
799 } // namespace blink | 857 } // namespace blink |
OLD | NEW |