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 ASSERT(m_objectStore); | 53 DCHECK(m_objectStore); |
54 ASSERT(m_transaction); | 54 DCHECK(m_transaction); |
55 ASSERT(m_metadata.id != IDBIndexMetadata::InvalidId); | 55 DCHECK(m_metadata.get()); |
| 56 DCHECK(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); |
65 visitor->trace(m_transaction); | 66 visitor->trace(m_transaction); |
66 } | 67 } |
67 | 68 |
68 void IDBIndex::setName(const String& name, ExceptionState& exceptionState) | 69 void IDBIndex::setName(const String& newName, ExceptionState& exceptionState) |
69 { | 70 { |
70 if (!RuntimeEnabledFeatures::indexedDBExperimentalEnabled()) | 71 if (!RuntimeEnabledFeatures::indexedDBExperimentalEnabled()) |
71 return; | 72 return; |
72 | 73 |
73 IDB_TRACE("IDBIndex::setName"); | 74 IDB_TRACE("IDBIndex::setName"); |
74 if (!m_transaction->isVersionChange()) { | 75 if (!m_transaction->isVersionChange()) { |
75 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::notVers
ionChangeTransactionErrorMessage); | 76 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::notVers
ionChangeTransactionErrorMessage); |
76 return; | 77 return; |
77 } | 78 } |
78 if (isDeleted()) { | 79 if (isDeleted()) { |
79 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); | 80 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); |
80 return; | 81 return; |
81 } | 82 } |
82 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | 83 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
83 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 84 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
84 return; | 85 return; |
85 } | 86 } |
86 if (!m_transaction->isActive()) { | 87 if (!m_transaction->isActive()) { |
87 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 88 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
88 return; | 89 return; |
89 } | 90 } |
90 | 91 |
91 if (m_metadata.name == name) | 92 if (name() == newName) |
92 return; | 93 return; |
93 if (m_objectStore->containsIndex(name)) { | 94 if (m_objectStore->containsIndex(newName)) { |
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(), new
Name); |
103 m_metadata.name = name; | 104 m_objectStore->renameIndex(id(), newName); |
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, m_metadata.keyPath); | 109 return ScriptValue::from(scriptState, metadata().keyPath); |
| 110 } |
| 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; |
111 } | 119 } |
112 | 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()) { |
(...skipping 14 matching lines...) Expand all Loading... |
135 return nullptr; | 143 return nullptr; |
136 } | 144 } |
137 | 145 |
138 return openCursor(scriptState, keyRange, direction); | 146 return openCursor(scriptState, keyRange, direction); |
139 } | 147 } |
140 | 148 |
141 IDBRequest* IDBIndex::openCursor(ScriptState* scriptState, IDBKeyRange* keyRange
, WebIDBCursorDirection direction) | 149 IDBRequest* IDBIndex::openCursor(ScriptState* scriptState, IDBKeyRange* keyRange
, WebIDBCursorDirection direction) |
142 { | 150 { |
143 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); | 151 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); |
144 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); | 152 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); |
145 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata
.id, keyRange, direction, false, WebIDBTaskTypeNormal, WebIDBCallbacksImpl::crea
te(request).release()); | 153 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), id(), keyR
ange, direction, false, WebIDBTaskTypeNormal, WebIDBCallbacksImpl::create(reques
t).release()); |
146 return request; | 154 return request; |
147 } | 155 } |
148 | 156 |
149 IDBRequest* IDBIndex::count(ScriptState* scriptState, const ScriptValue& range,
ExceptionState& exceptionState) | 157 IDBRequest* IDBIndex::count(ScriptState* scriptState, const ScriptValue& range,
ExceptionState& exceptionState) |
150 { | 158 { |
151 IDB_TRACE("IDBIndex::count"); | 159 IDB_TRACE("IDBIndex::count"); |
152 if (isDeleted()) { | 160 if (isDeleted()) { |
153 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); | 161 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); |
154 return nullptr; | 162 return nullptr; |
155 } | 163 } |
156 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | 164 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
157 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 165 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
158 return nullptr; | 166 return nullptr; |
159 } | 167 } |
160 if (!m_transaction->isActive()) { | 168 if (!m_transaction->isActive()) { |
161 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 169 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
162 return nullptr; | 170 return nullptr; |
163 } | 171 } |
164 | 172 |
165 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti
onContext(), range, exceptionState); | 173 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti
onContext(), range, exceptionState); |
166 if (exceptionState.hadException()) | 174 if (exceptionState.hadException()) |
167 return nullptr; | 175 return nullptr; |
168 | 176 |
169 if (!backendDB()) { | 177 if (!backendDB()) { |
170 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 178 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
171 return nullptr; | 179 return nullptr; |
172 } | 180 } |
173 | 181 |
174 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); | 182 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); |
175 backendDB()->count(m_transaction->id(), m_objectStore->id(), m_metadata.id,
keyRange, WebIDBCallbacksImpl::create(request).release()); | 183 backendDB()->count(m_transaction->id(), m_objectStore->id(), id(), keyRange,
WebIDBCallbacksImpl::create(request).release()); |
176 return request; | 184 return request; |
177 } | 185 } |
178 | 186 |
179 IDBRequest* IDBIndex::openKeyCursor(ScriptState* scriptState, const ScriptValue&
range, const String& directionString, ExceptionState& exceptionState) | 187 IDBRequest* IDBIndex::openKeyCursor(ScriptState* scriptState, const ScriptValue&
range, const String& directionString, ExceptionState& exceptionState) |
180 { | 188 { |
181 IDB_TRACE("IDBIndex::openKeyCursor"); | 189 IDB_TRACE("IDBIndex::openKeyCursor"); |
182 if (isDeleted()) { | 190 if (isDeleted()) { |
183 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); | 191 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); |
184 return nullptr; | 192 return nullptr; |
185 } | 193 } |
186 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | 194 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
187 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 195 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
188 return nullptr; | 196 return nullptr; |
189 } | 197 } |
190 if (!m_transaction->isActive()) { | 198 if (!m_transaction->isActive()) { |
191 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 199 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
192 return nullptr; | 200 return nullptr; |
193 } | 201 } |
194 WebIDBCursorDirection direction = IDBCursor::stringToDirection(directionStri
ng); | 202 WebIDBCursorDirection direction = IDBCursor::stringToDirection(directionStri
ng); |
195 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti
onContext(), range, exceptionState); | 203 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti
onContext(), range, exceptionState); |
196 if (exceptionState.hadException()) | 204 if (exceptionState.hadException()) |
197 return nullptr; | 205 return nullptr; |
198 if (!backendDB()) { | 206 if (!backendDB()) { |
199 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 207 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
200 return nullptr; | 208 return nullptr; |
201 } | 209 } |
202 | 210 |
203 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); | 211 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); |
204 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); | 212 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); |
205 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata
.id, keyRange, direction, true, WebIDBTaskTypeNormal, WebIDBCallbacksImpl::creat
e(request).release()); | 213 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), id(), keyR
ange, direction, true, WebIDBTaskTypeNormal, WebIDBCallbacksImpl::create(request
).release()); |
206 return request; | 214 return request; |
207 } | 215 } |
208 | 216 |
209 IDBRequest* IDBIndex::get(ScriptState* scriptState, const ScriptValue& key, Exce
ptionState& exceptionState) | 217 IDBRequest* IDBIndex::get(ScriptState* scriptState, const ScriptValue& key, Exce
ptionState& exceptionState) |
210 { | 218 { |
211 IDB_TRACE("IDBIndex::get"); | 219 IDB_TRACE("IDBIndex::get"); |
212 return getInternal(scriptState, key, exceptionState, false); | 220 return getInternal(scriptState, key, exceptionState, false); |
213 } | 221 } |
214 | 222 |
215 IDBRequest* IDBIndex::getAll(ScriptState* scriptState, const ScriptValue& range,
ExceptionState& exceptionState) | 223 IDBRequest* IDBIndex::getAll(ScriptState* scriptState, const ScriptValue& range,
ExceptionState& exceptionState) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 if (!keyRange) { | 269 if (!keyRange) { |
262 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange
ErrorMessage); | 270 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange
ErrorMessage); |
263 return nullptr; | 271 return nullptr; |
264 } | 272 } |
265 if (!backendDB()) { | 273 if (!backendDB()) { |
266 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 274 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
267 return nullptr; | 275 return nullptr; |
268 } | 276 } |
269 | 277 |
270 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); | 278 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); |
271 backendDB()->get(m_transaction->id(), m_objectStore->id(), m_metadata.id, ke
yRange, keyOnly, WebIDBCallbacksImpl::create(request).release()); | 279 backendDB()->get(m_transaction->id(), m_objectStore->id(), id(), keyRange, k
eyOnly, WebIDBCallbacksImpl::create(request).release()); |
272 return request; | 280 return request; |
273 } | 281 } |
274 | 282 |
275 IDBRequest* IDBIndex::getAllInternal(ScriptState* scriptState, const ScriptValue
& range, unsigned long maxCount, ExceptionState& exceptionState, bool keyOnly) | 283 IDBRequest* IDBIndex::getAllInternal(ScriptState* scriptState, const ScriptValue
& range, unsigned long maxCount, ExceptionState& exceptionState, bool keyOnly) |
276 { | 284 { |
277 if (!maxCount) | 285 if (!maxCount) |
278 maxCount = std::numeric_limits<uint32_t>::max(); | 286 maxCount = std::numeric_limits<uint32_t>::max(); |
279 | 287 |
280 if (isDeleted()) { | 288 if (isDeleted()) { |
281 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); | 289 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); |
(...skipping 10 matching lines...) Expand all Loading... |
292 | 300 |
293 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti
onContext(), range, exceptionState); | 301 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti
onContext(), range, exceptionState); |
294 if (exceptionState.hadException()) | 302 if (exceptionState.hadException()) |
295 return nullptr; | 303 return nullptr; |
296 if (!backendDB()) { | 304 if (!backendDB()) { |
297 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 305 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
298 return nullptr; | 306 return nullptr; |
299 } | 307 } |
300 | 308 |
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(), m_metadata.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 |