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, IDBObjectStore* objectStore
, IDBTransaction* transaction) | 48 IDBIndex::IDBIndex(RefPtr<IDBIndexMetadata> metadata, IDBObjectStore* objectStor
e, IDBTransaction* transaction) |
49 : m_metadata(metadata) | 49 : m_metadata(std::move(metadata)) |
50 , m_objectStore(objectStore) | 50 , m_objectStore(objectStore) |
51 , m_transaction(transaction) | 51 , m_transaction(transaction) |
52 { | 52 { |
53 DCHECK(m_objectStore); | 53 DCHECK(m_objectStore); |
54 DCHECK(m_transaction); | 54 DCHECK(m_transaction); |
| 55 DCHECK(m_metadata.get()); |
55 DCHECK_NE(id(), IDBIndexMetadata::InvalidId); | 56 DCHECK_NE(id(), IDBIndexMetadata::InvalidId); |
56 } | 57 } |
57 | 58 |
58 IDBIndex::~IDBIndex() | 59 IDBIndex::~IDBIndex() |
59 { | 60 { |
60 } | 61 } |
61 | 62 |
62 DEFINE_TRACE(IDBIndex) | 63 DEFINE_TRACE(IDBIndex) |
63 { | 64 { |
64 visitor->trace(m_objectStore); | 65 visitor->trace(m_objectStore); |
(...skipping 28 matching lines...) Expand all Loading... |
93 if (m_objectStore->containsIndex(name)) { | 94 if (m_objectStore->containsIndex(name)) { |
94 exceptionState.throwDOMException(ConstraintError, IDBDatabase::indexName
TakenErrorMessage); | 95 exceptionState.throwDOMException(ConstraintError, IDBDatabase::indexName
TakenErrorMessage); |
95 return; | 96 return; |
96 } | 97 } |
97 if (!backendDB()) { | 98 if (!backendDB()) { |
98 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 99 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
99 return; | 100 return; |
100 } | 101 } |
101 | 102 |
102 backendDB()->renameIndex(m_transaction->id(), m_objectStore->id(), id(), nam
e); | 103 backendDB()->renameIndex(m_transaction->id(), m_objectStore->id(), id(), nam
e); |
103 m_metadata.name = name; | 104 m_objectStore->renameIndex(id(), name); |
104 m_objectStore->indexRenamed(m_metadata.id, name); | |
105 m_transaction->db()->indexRenamed(m_objectStore->id(), id(), name); | |
106 } | 105 } |
107 | 106 |
108 ScriptValue IDBIndex::keyPath(ScriptState* scriptState) const | 107 ScriptValue IDBIndex::keyPath(ScriptState* scriptState) const |
109 { | 108 { |
110 return ScriptValue::from(scriptState, metadata().keyPath); | 109 return ScriptValue::from(scriptState, metadata().keyPath); |
111 } | 110 } |
112 | 111 |
| 112 void IDBIndex::revertMetadata(RefPtr<IDBIndexMetadata> oldMetadata) |
| 113 { |
| 114 m_metadata = std::move(oldMetadata); |
| 115 |
| 116 // An index's metadata will only get reverted if the index was in the |
| 117 // database when the versionchange transaction started. |
| 118 m_deleted = false; |
| 119 } |
| 120 |
113 IDBRequest* IDBIndex::openCursor(ScriptState* scriptState, const ScriptValue& ra
nge, const String& directionString, ExceptionState& exceptionState) | 121 IDBRequest* IDBIndex::openCursor(ScriptState* scriptState, const ScriptValue& ra
nge, const String& directionString, ExceptionState& exceptionState) |
114 { | 122 { |
115 IDB_TRACE("IDBIndex::openCursor"); | 123 IDB_TRACE("IDBIndex::openCursor"); |
116 if (isDeleted()) { | 124 if (isDeleted()) { |
117 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); | 125 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); |
118 return nullptr; | 126 return nullptr; |
119 } | 127 } |
120 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | 128 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
121 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 129 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
122 return nullptr; | 130 return nullptr; |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); | 309 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); |
302 backendDB()->getAll(m_transaction->id(), m_objectStore->id(), id(), keyRange
, maxCount, keyOnly, WebIDBCallbacksImpl::create(request).release()); | 310 backendDB()->getAll(m_transaction->id(), m_objectStore->id(), id(), keyRange
, maxCount, keyOnly, WebIDBCallbacksImpl::create(request).release()); |
303 return request; | 311 return request; |
304 } | 312 } |
305 | 313 |
306 WebIDBDatabase* IDBIndex::backendDB() const | 314 WebIDBDatabase* IDBIndex::backendDB() const |
307 { | 315 { |
308 return m_transaction->backendDB(); | 316 return m_transaction->backendDB(); |
309 } | 317 } |
310 | 318 |
311 bool IDBIndex::isDeleted() const | |
312 { | |
313 return m_deleted || m_objectStore->isDeleted(); | |
314 } | |
315 | |
316 } // namespace blink | 319 } // namespace blink |
OLD | NEW |