| 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 27 matching lines...) Expand all Loading... |
| 38 #include "modules/indexeddb/WebIDBCallbacksImpl.h" | 38 #include "modules/indexeddb/WebIDBCallbacksImpl.h" |
| 39 #include "public/platform/modules/indexeddb/WebIDBKeyRange.h" | 39 #include "public/platform/modules/indexeddb/WebIDBKeyRange.h" |
| 40 #include <memory> | 40 #include <memory> |
| 41 | 41 |
| 42 using blink::WebIDBCallbacks; | 42 using blink::WebIDBCallbacks; |
| 43 using blink::WebIDBCursor; | 43 using blink::WebIDBCursor; |
| 44 using blink::WebIDBDatabase; | 44 using blink::WebIDBDatabase; |
| 45 | 45 |
| 46 namespace blink { | 46 namespace blink { |
| 47 | 47 |
| 48 IDBIndex::IDBIndex(const IDBIndexMetadata& metadata, | 48 IDBIndex::IDBIndex(RefPtr<IDBIndexMetadata> metadata, |
| 49 IDBObjectStore* objectStore, | 49 IDBObjectStore* objectStore, |
| 50 IDBTransaction* transaction) | 50 IDBTransaction* transaction) |
| 51 : m_metadata(metadata), | 51 : m_metadata(std::move(metadata)), |
| 52 m_objectStore(objectStore), | 52 m_objectStore(objectStore), |
| 53 m_transaction(transaction) { | 53 m_transaction(transaction) { |
| 54 DCHECK(m_objectStore); | 54 DCHECK(m_objectStore); |
| 55 DCHECK(m_transaction); | 55 DCHECK(m_transaction); |
| 56 DCHECK(m_metadata.get()); |
| 56 DCHECK_NE(id(), IDBIndexMetadata::InvalidId); | 57 DCHECK_NE(id(), IDBIndexMetadata::InvalidId); |
| 57 } | 58 } |
| 58 | 59 |
| 59 IDBIndex::~IDBIndex() {} | 60 IDBIndex::~IDBIndex() {} |
| 60 | 61 |
| 61 DEFINE_TRACE(IDBIndex) { | 62 DEFINE_TRACE(IDBIndex) { |
| 62 visitor->trace(m_objectStore); | 63 visitor->trace(m_objectStore); |
| 63 visitor->trace(m_transaction); | 64 visitor->trace(m_transaction); |
| 64 } | 65 } |
| 65 | 66 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 96 exceptionState.throwDOMException(ConstraintError, | 97 exceptionState.throwDOMException(ConstraintError, |
| 97 IDBDatabase::indexNameTakenErrorMessage); | 98 IDBDatabase::indexNameTakenErrorMessage); |
| 98 return; | 99 return; |
| 99 } | 100 } |
| 100 if (!backendDB()) { | 101 if (!backendDB()) { |
| 101 exceptionState.throwDOMException(InvalidStateError, | 102 exceptionState.throwDOMException(InvalidStateError, |
| 102 IDBDatabase::databaseClosedErrorMessage); | 103 IDBDatabase::databaseClosedErrorMessage); |
| 103 return; | 104 return; |
| 104 } | 105 } |
| 105 | 106 |
| 106 backendDB()->renameIndex(m_transaction->id(), m_objectStore->id(), id(), | 107 m_objectStore->renameIndex(id(), name); |
| 107 name); | |
| 108 m_metadata.name = name; | |
| 109 m_objectStore->indexRenamed(m_metadata.id, name); | |
| 110 m_transaction->db()->indexRenamed(m_objectStore->id(), id(), name); | |
| 111 } | 108 } |
| 112 | 109 |
| 113 ScriptValue IDBIndex::keyPath(ScriptState* scriptState) const { | 110 ScriptValue IDBIndex::keyPath(ScriptState* scriptState) const { |
| 114 return ScriptValue::from(scriptState, metadata().keyPath); | 111 return ScriptValue::from(scriptState, metadata().keyPath); |
| 115 } | 112 } |
| 116 | 113 |
| 114 void IDBIndex::revertMetadata(RefPtr<IDBIndexMetadata> oldMetadata) { |
| 115 m_metadata = std::move(oldMetadata); |
| 116 |
| 117 // An index's metadata will only get reverted if the index was in the |
| 118 // database when the versionchange transaction started. |
| 119 m_deleted = false; |
| 120 } |
| 121 |
| 117 IDBRequest* IDBIndex::openCursor(ScriptState* scriptState, | 122 IDBRequest* IDBIndex::openCursor(ScriptState* scriptState, |
| 118 const ScriptValue& range, | 123 const ScriptValue& range, |
| 119 const String& directionString, | 124 const String& directionString, |
| 120 ExceptionState& exceptionState) { | 125 ExceptionState& exceptionState) { |
| 121 IDB_TRACE("IDBIndex::openCursor"); | 126 IDB_TRACE("IDBIndex::openCursor"); |
| 122 if (isDeleted()) { | 127 if (isDeleted()) { |
| 123 exceptionState.throwDOMException(InvalidStateError, | 128 exceptionState.throwDOMException(InvalidStateError, |
| 124 IDBDatabase::indexDeletedErrorMessage); | 129 IDBDatabase::indexDeletedErrorMessage); |
| 125 return nullptr; | 130 return nullptr; |
| 126 } | 131 } |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 backendDB()->getAll(m_transaction->id(), m_objectStore->id(), id(), keyRange, | 372 backendDB()->getAll(m_transaction->id(), m_objectStore->id(), id(), keyRange, |
| 368 maxCount, keyOnly, | 373 maxCount, keyOnly, |
| 369 WebIDBCallbacksImpl::create(request).release()); | 374 WebIDBCallbacksImpl::create(request).release()); |
| 370 return request; | 375 return request; |
| 371 } | 376 } |
| 372 | 377 |
| 373 WebIDBDatabase* IDBIndex::backendDB() const { | 378 WebIDBDatabase* IDBIndex::backendDB() const { |
| 374 return m_transaction->backendDB(); | 379 return m_transaction->backendDB(); |
| 375 } | 380 } |
| 376 | 381 |
| 377 bool IDBIndex::isDeleted() const { | |
| 378 return m_deleted || m_objectStore->isDeleted(); | |
| 379 } | |
| 380 | |
| 381 } // namespace blink | 382 } // namespace blink |
| OLD | NEW |