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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 backendDB()->renameIndex(m_transaction->id(), m_objectStore->id(), id(), |
107 name); | 108 name); |
108 m_metadata.name = name; | 109 m_objectStore->renameIndex(id(), name); |
109 m_objectStore->indexRenamed(m_metadata.id, name); | |
110 m_transaction->db()->indexRenamed(m_objectStore->id(), id(), name); | |
111 } | 110 } |
112 | 111 |
113 ScriptValue IDBIndex::keyPath(ScriptState* scriptState) const { | 112 ScriptValue IDBIndex::keyPath(ScriptState* scriptState) const { |
114 return ScriptValue::from(scriptState, metadata().keyPath); | 113 return ScriptValue::from(scriptState, metadata().keyPath); |
115 } | 114 } |
116 | 115 |
| 116 void IDBIndex::revertMetadata(RefPtr<IDBIndexMetadata> oldMetadata) { |
| 117 m_metadata = std::move(oldMetadata); |
| 118 |
| 119 // An index's metadata will only get reverted if the index was in the |
| 120 // database when the versionchange transaction started. |
| 121 m_deleted = false; |
| 122 } |
| 123 |
117 IDBRequest* IDBIndex::openCursor(ScriptState* scriptState, | 124 IDBRequest* IDBIndex::openCursor(ScriptState* scriptState, |
118 const ScriptValue& range, | 125 const ScriptValue& range, |
119 const String& directionString, | 126 const String& directionString, |
120 ExceptionState& exceptionState) { | 127 ExceptionState& exceptionState) { |
121 IDB_TRACE("IDBIndex::openCursor"); | 128 IDB_TRACE("IDBIndex::openCursor"); |
122 if (isDeleted()) { | 129 if (isDeleted()) { |
123 exceptionState.throwDOMException(InvalidStateError, | 130 exceptionState.throwDOMException(InvalidStateError, |
124 IDBDatabase::indexDeletedErrorMessage); | 131 IDBDatabase::indexDeletedErrorMessage); |
125 return nullptr; | 132 return nullptr; |
126 } | 133 } |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 backendDB()->getAll(m_transaction->id(), m_objectStore->id(), id(), keyRange, | 374 backendDB()->getAll(m_transaction->id(), m_objectStore->id(), id(), keyRange, |
368 maxCount, keyOnly, | 375 maxCount, keyOnly, |
369 WebIDBCallbacksImpl::create(request).release()); | 376 WebIDBCallbacksImpl::create(request).release()); |
370 return request; | 377 return request; |
371 } | 378 } |
372 | 379 |
373 WebIDBDatabase* IDBIndex::backendDB() const { | 380 WebIDBDatabase* IDBIndex::backendDB() const { |
374 return m_transaction->backendDB(); | 381 return m_transaction->backendDB(); |
375 } | 382 } |
376 | 383 |
377 bool IDBIndex::isDeleted() const { | |
378 return m_deleted || m_objectStore->isDeleted(); | |
379 } | |
380 | |
381 } // namespace blink | 384 } // namespace blink |
OLD | NEW |