| 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 it->value.indexes.remove(indexId); | 123 it->value.indexes.remove(indexId); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void IDBDatabase::indexRenamed(int64_t objectStoreId, int64_t indexId, const Str
ing& newName) | 126 void IDBDatabase::indexRenamed(int64_t objectStoreId, int64_t indexId, const Str
ing& newName) |
| 127 { | 127 { |
| 128 IDBDatabaseMetadata::ObjectStoreMap::iterator storeIterator = m_metadata.obj
ectStores.find(objectStoreId); | 128 IDBDatabaseMetadata::ObjectStoreMap::iterator storeIterator = m_metadata.obj
ectStores.find(objectStoreId); |
| 129 SECURITY_DCHECK(storeIterator != m_metadata.objectStores.end()); | 129 SECURITY_DCHECK(storeIterator != m_metadata.objectStores.end()); |
| 130 | 130 |
| 131 IDBObjectStoreMetadata& storeMetadata = storeIterator->value; | 131 IDBObjectStoreMetadata& storeMetadata = storeIterator->value; |
| 132 IDBObjectStoreMetadata::IndexMap::iterator indexIterator = storeMetadata.ind
exes.find(indexId); | 132 IDBObjectStoreMetadata::IndexMap::iterator indexIterator = storeMetadata.ind
exes.find(indexId); |
| 133 DCHECK(indexIterator != storeMetadata.indexes.end()); | 133 DCHECK_NE(indexIterator, storeMetadata.indexes.end()); |
| 134 indexIterator->value.name = newName; | 134 indexIterator->value.name = newName; |
| 135 } | 135 } |
| 136 | 136 |
| 137 void IDBDatabase::transactionCreated(IDBTransaction* transaction) | 137 void IDBDatabase::transactionCreated(IDBTransaction* transaction) |
| 138 { | 138 { |
| 139 ASSERT(transaction); | 139 DCHECK(transaction); |
| 140 ASSERT(!m_transactions.contains(transaction->id())); | 140 DCHECK(!m_transactions.contains(transaction->id())); |
| 141 m_transactions.add(transaction->id(), transaction); | 141 m_transactions.add(transaction->id(), transaction); |
| 142 | 142 |
| 143 if (transaction->isVersionChange()) { | 143 if (transaction->isVersionChange()) { |
| 144 ASSERT(!m_versionChangeTransaction); | 144 DCHECK(!m_versionChangeTransaction); |
| 145 m_versionChangeTransaction = transaction; | 145 m_versionChangeTransaction = transaction; |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 | 148 |
| 149 void IDBDatabase::transactionFinished(const IDBTransaction* transaction) | 149 void IDBDatabase::transactionFinished(const IDBTransaction* transaction) |
| 150 { | 150 { |
| 151 ASSERT(transaction); | 151 DCHECK(transaction); |
| 152 ASSERT(m_transactions.contains(transaction->id())); | 152 DCHECK(m_transactions.contains(transaction->id())); |
| 153 ASSERT(m_transactions.get(transaction->id()) == transaction); | 153 DCHECK_EQ(m_transactions.get(transaction->id()), transaction); |
| 154 m_transactions.remove(transaction->id()); | 154 m_transactions.remove(transaction->id()); |
| 155 | 155 |
| 156 if (transaction->isVersionChange()) { | 156 if (transaction->isVersionChange()) { |
| 157 ASSERT(m_versionChangeTransaction == transaction); | 157 DCHECK_EQ(m_versionChangeTransaction, transaction); |
| 158 m_versionChangeTransaction = nullptr; | 158 m_versionChangeTransaction = nullptr; |
| 159 } | 159 } |
| 160 | 160 |
| 161 if (m_closePending && m_transactions.isEmpty()) | 161 if (m_closePending && m_transactions.isEmpty()) |
| 162 closeConnection(); | 162 closeConnection(); |
| 163 } | 163 } |
| 164 | 164 |
| 165 void IDBDatabase::onAbort(int64_t transactionId, DOMException* error) | 165 void IDBDatabase::onAbort(int64_t transactionId, DOMException* error) |
| 166 { | 166 { |
| 167 ASSERT(m_transactions.contains(transactionId)); | 167 DCHECK(m_transactions.contains(transactionId)); |
| 168 m_transactions.get(transactionId)->onAbort(error); | 168 m_transactions.get(transactionId)->onAbort(error); |
| 169 } | 169 } |
| 170 | 170 |
| 171 void IDBDatabase::onComplete(int64_t transactionId) | 171 void IDBDatabase::onComplete(int64_t transactionId) |
| 172 { | 172 { |
| 173 ASSERT(m_transactions.contains(transactionId)); | 173 DCHECK(m_transactions.contains(transactionId)); |
| 174 m_transactions.get(transactionId)->onComplete(); | 174 m_transactions.get(transactionId)->onComplete(); |
| 175 } | 175 } |
| 176 | 176 |
| 177 DOMStringList* IDBDatabase::objectStoreNames() const | 177 DOMStringList* IDBDatabase::objectStoreNames() const |
| 178 { | 178 { |
| 179 DOMStringList* objectStoreNames = DOMStringList::create(DOMStringList::Index
edDB); | 179 DOMStringList* objectStoreNames = DOMStringList::create(DOMStringList::Index
edDB); |
| 180 for (const auto& it : m_metadata.objectStores) | 180 for (const auto& it : m_metadata.objectStores) |
| 181 objectStoreNames->append(it.value.name); | 181 objectStoreNames->append(it.value.name); |
| 182 objectStoreNames->sort(); | 182 objectStoreNames->sort(); |
| 183 return objectStoreNames; | 183 return objectStoreNames; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 if (storeNames.isString()) { | 282 if (storeNames.isString()) { |
| 283 scope.add(storeNames.getAsString()); | 283 scope.add(storeNames.getAsString()); |
| 284 } else if (storeNames.isStringSequence()) { | 284 } else if (storeNames.isStringSequence()) { |
| 285 for (const String& name : storeNames.getAsStringSequence()) | 285 for (const String& name : storeNames.getAsStringSequence()) |
| 286 scope.add(name); | 286 scope.add(name); |
| 287 } else if (storeNames.isDOMStringList()) { | 287 } else if (storeNames.isDOMStringList()) { |
| 288 const Vector<String>& list = *storeNames.getAsDOMStringList(); | 288 const Vector<String>& list = *storeNames.getAsDOMStringList(); |
| 289 for (const String& name : list) | 289 for (const String& name : list) |
| 290 scope.add(name); | 290 scope.add(name); |
| 291 } else { | 291 } else { |
| 292 ASSERT_NOT_REACHED(); | 292 NOTREACHED(); |
| 293 } | 293 } |
| 294 | 294 |
| 295 if (m_versionChangeTransaction) { | 295 if (m_versionChangeTransaction) { |
| 296 exceptionState.throwDOMException(InvalidStateError, "A version change tr
ansaction is running."); | 296 exceptionState.throwDOMException(InvalidStateError, "A version change tr
ansaction is running."); |
| 297 return nullptr; | 297 return nullptr; |
| 298 } | 298 } |
| 299 | 299 |
| 300 if (m_closePending) { | 300 if (m_closePending) { |
| 301 exceptionState.throwDOMException(InvalidStateError, "The database connec
tion is closing."); | 301 exceptionState.throwDOMException(InvalidStateError, "The database connec
tion is closing."); |
| 302 return nullptr; | 302 return nullptr; |
| 303 } | 303 } |
| 304 | 304 |
| 305 if (!m_backend) { | 305 if (!m_backend) { |
| 306 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 306 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
| 307 return nullptr; | 307 return nullptr; |
| 308 } | 308 } |
| 309 | 309 |
| 310 | |
| 311 if (scope.isEmpty()) { | 310 if (scope.isEmpty()) { |
| 312 exceptionState.throwDOMException(InvalidAccessError, "The storeNames par
ameter was empty."); | 311 exceptionState.throwDOMException(InvalidAccessError, "The storeNames par
ameter was empty."); |
| 313 return nullptr; | 312 return nullptr; |
| 314 } | 313 } |
| 315 | 314 |
| 316 Vector<int64_t> objectStoreIds; | 315 Vector<int64_t> objectStoreIds; |
| 317 for (const String& name : scope) { | 316 for (const String& name : scope) { |
| 318 int64_t objectStoreId = findObjectStoreId(name); | 317 int64_t objectStoreId = findObjectStoreId(name); |
| 319 if (objectStoreId == IDBObjectStoreMetadata::InvalidId) { | 318 if (objectStoreId == IDBObjectStoreMetadata::InvalidId) { |
| 320 exceptionState.throwDOMException(NotFoundError, "One of the specifie
d object stores was not found."); | 319 exceptionState.throwDOMException(NotFoundError, "One of the specifie
d object stores was not found."); |
| 321 return nullptr; | 320 return nullptr; |
| 322 } | 321 } |
| 323 objectStoreIds.append(objectStoreId); | 322 objectStoreIds.append(objectStoreId); |
| 324 } | 323 } |
| 325 | 324 |
| 326 WebIDBTransactionMode mode = IDBTransaction::stringToMode(modeString); | 325 WebIDBTransactionMode mode = IDBTransaction::stringToMode(modeString); |
| 327 if (mode != WebIDBTransactionModeReadOnly && mode != WebIDBTransactionModeRe
adWrite) { | 326 if (mode != WebIDBTransactionModeReadOnly && mode != WebIDBTransactionModeRe
adWrite) { |
| 328 exceptionState.throwTypeError("The mode provided ('" + modeString + "')
is not one of 'readonly' or 'readwrite'."); | 327 exceptionState.throwTypeError("The mode provided ('" + modeString + "')
is not one of 'readonly' or 'readwrite'."); |
| 329 return nullptr; | 328 return nullptr; |
| 330 } | 329 } |
| 331 | 330 |
| 332 int64_t transactionId = nextTransactionId(); | 331 int64_t transactionId = nextTransactionId(); |
| 333 m_backend->createTransaction(transactionId, WebIDBDatabaseCallbacksImpl::cre
ate(m_databaseCallbacks).release(), objectStoreIds, mode); | 332 m_backend->createTransaction(transactionId, WebIDBDatabaseCallbacksImpl::cre
ate(m_databaseCallbacks).release(), objectStoreIds, mode); |
| 334 | 333 |
| 335 return IDBTransaction::create(scriptState, transactionId, scope, mode, this)
; | 334 return IDBTransaction::createNonVersionChange(scriptState, transactionId, sc
ope, mode, this); |
| 336 } | 335 } |
| 337 | 336 |
| 338 void IDBDatabase::forceClose() | 337 void IDBDatabase::forceClose() |
| 339 { | 338 { |
| 340 for (const auto& it : m_transactions) | 339 for (const auto& it : m_transactions) |
| 341 it.value->abort(IGNORE_EXCEPTION); | 340 it.value->abort(IGNORE_EXCEPTION); |
| 342 this->close(); | 341 this->close(); |
| 343 enqueueEvent(Event::create(EventTypeNames::close)); | 342 enqueueEvent(Event::create(EventTypeNames::close)); |
| 344 } | 343 } |
| 345 | 344 |
| 346 void IDBDatabase::close() | 345 void IDBDatabase::close() |
| 347 { | 346 { |
| 348 IDB_TRACE("IDBDatabase::close"); | 347 IDB_TRACE("IDBDatabase::close"); |
| 349 if (m_closePending) | 348 if (m_closePending) |
| 350 return; | 349 return; |
| 351 | 350 |
| 352 m_closePending = true; | 351 m_closePending = true; |
| 353 | 352 |
| 354 if (m_transactions.isEmpty()) | 353 if (m_transactions.isEmpty()) |
| 355 closeConnection(); | 354 closeConnection(); |
| 356 } | 355 } |
| 357 | 356 |
| 358 void IDBDatabase::closeConnection() | 357 void IDBDatabase::closeConnection() |
| 359 { | 358 { |
| 360 ASSERT(m_closePending); | 359 DCHECK(m_closePending); |
| 361 ASSERT(m_transactions.isEmpty()); | 360 DCHECK(m_transactions.isEmpty()); |
| 362 | 361 |
| 363 if (m_backend) { | 362 if (m_backend) { |
| 364 m_backend->close(); | 363 m_backend->close(); |
| 365 m_backend.reset(); | 364 m_backend.reset(); |
| 366 } | 365 } |
| 367 | 366 |
| 368 if (m_contextStopped || !getExecutionContext()) | 367 if (m_contextStopped || !getExecutionContext()) |
| 369 return; | 368 return; |
| 370 | 369 |
| 371 EventQueue* eventQueue = getExecutionContext()->getEventQueue(); | 370 EventQueue* eventQueue = getExecutionContext()->getEventQueue(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 392 m_backend->versionChangeIgnored(); | 391 m_backend->versionChangeIgnored(); |
| 393 return; | 392 return; |
| 394 } | 393 } |
| 395 | 394 |
| 396 Nullable<unsigned long long> newVersionNullable = (newVersion == IDBDatabase
Metadata::NoVersion) ? Nullable<unsigned long long>() : Nullable<unsigned long l
ong>(newVersion); | 395 Nullable<unsigned long long> newVersionNullable = (newVersion == IDBDatabase
Metadata::NoVersion) ? Nullable<unsigned long long>() : Nullable<unsigned long l
ong>(newVersion); |
| 397 enqueueEvent(IDBVersionChangeEvent::create(EventTypeNames::versionchange, ol
dVersion, newVersionNullable)); | 396 enqueueEvent(IDBVersionChangeEvent::create(EventTypeNames::versionchange, ol
dVersion, newVersionNullable)); |
| 398 } | 397 } |
| 399 | 398 |
| 400 void IDBDatabase::enqueueEvent(Event* event) | 399 void IDBDatabase::enqueueEvent(Event* event) |
| 401 { | 400 { |
| 402 ASSERT(!m_contextStopped); | 401 DCHECK(!m_contextStopped); |
| 403 ASSERT(getExecutionContext()); | 402 DCHECK(getExecutionContext()); |
| 404 EventQueue* eventQueue = getExecutionContext()->getEventQueue(); | 403 EventQueue* eventQueue = getExecutionContext()->getEventQueue(); |
| 405 event->setTarget(this); | 404 event->setTarget(this); |
| 406 eventQueue->enqueueEvent(event); | 405 eventQueue->enqueueEvent(event); |
| 407 m_enqueuedEvents.append(event); | 406 m_enqueuedEvents.append(event); |
| 408 } | 407 } |
| 409 | 408 |
| 410 DispatchEventResult IDBDatabase::dispatchEventInternal(Event* event) | 409 DispatchEventResult IDBDatabase::dispatchEventInternal(Event* event) |
| 411 { | 410 { |
| 412 IDB_TRACE("IDBDatabase::dispatchEvent"); | 411 IDB_TRACE("IDBDatabase::dispatchEvent"); |
| 413 if (m_contextStopped || !getExecutionContext()) | 412 if (m_contextStopped || !getExecutionContext()) |
| 414 return DispatchEventResult::CanceledBeforeDispatch; | 413 return DispatchEventResult::CanceledBeforeDispatch; |
| 415 ASSERT(event->type() == EventTypeNames::versionchange || event->type() == Ev
entTypeNames::close); | 414 DCHECK(event->type() == EventTypeNames::versionchange || event->type() == Ev
entTypeNames::close); |
| 416 for (size_t i = 0; i < m_enqueuedEvents.size(); ++i) { | 415 for (size_t i = 0; i < m_enqueuedEvents.size(); ++i) { |
| 417 if (m_enqueuedEvents[i].get() == event) | 416 if (m_enqueuedEvents[i].get() == event) |
| 418 m_enqueuedEvents.remove(i); | 417 m_enqueuedEvents.remove(i); |
| 419 } | 418 } |
| 420 | 419 |
| 421 DispatchEventResult dispatchResult = EventTarget::dispatchEventInternal(even
t); | 420 DispatchEventResult dispatchResult = EventTarget::dispatchEventInternal(even
t); |
| 422 if (event->type() == EventTypeNames::versionchange && !m_closePending && m_b
ackend) | 421 if (event->type() == EventTypeNames::versionchange && !m_closePending && m_b
ackend) |
| 423 m_backend->versionChangeIgnored(); | 422 m_backend->versionChangeIgnored(); |
| 424 return dispatchResult; | 423 return dispatchResult; |
| 425 } | 424 } |
| 426 | 425 |
| 427 int64_t IDBDatabase::findObjectStoreId(const String& name) const | 426 int64_t IDBDatabase::findObjectStoreId(const String& name) const |
| 428 { | 427 { |
| 429 for (const auto& it : m_metadata.objectStores) { | 428 for (const auto& it : m_metadata.objectStores) { |
| 430 if (it.value.name == name) { | 429 if (it.value.name == name) { |
| 431 ASSERT(it.key != IDBObjectStoreMetadata::InvalidId); | 430 DCHECK_NE(it.key, IDBObjectStoreMetadata::InvalidId); |
| 432 return it.key; | 431 return it.key; |
| 433 } | 432 } |
| 434 } | 433 } |
| 435 return IDBObjectStoreMetadata::InvalidId; | 434 return IDBObjectStoreMetadata::InvalidId; |
| 436 } | 435 } |
| 437 | 436 |
| 438 void IDBDatabase::objectStoreRenamed(int64_t storeId, const String& newName) | 437 void IDBDatabase::objectStoreRenamed(int64_t objectStoreId, const String& newNam
e) |
| 439 { | 438 { |
| 440 DCHECK(m_metadata.objectStores.contains(storeId)); | 439 DCHECK(m_versionChangeTransaction) << "Object store renamed on database with
out a versionchange transaction"; |
| 441 IDBDatabaseMetadata::ObjectStoreMap::iterator it = m_metadata.objectStores.f
ind(storeId); | 440 DCHECK(m_versionChangeTransaction->isActive()) << "Object store renamed when
versionchange transaction is not active"; |
| 441 DCHECK(m_backend) << "Object store renamed after database connection closed"
; |
| 442 DCHECK(m_metadata.objectStores.contains(objectStoreId)); |
| 443 IDBDatabaseMetadata::ObjectStoreMap::iterator it = m_metadata.objectStores.f
ind(objectStoreId); |
| 442 it->value.name = newName; | 444 it->value.name = newName; |
| 443 } | 445 } |
| 444 | 446 |
| 445 bool IDBDatabase::hasPendingActivity() const | 447 bool IDBDatabase::hasPendingActivity() const |
| 446 { | 448 { |
| 447 // The script wrapper must not be collected before the object is closed or | 449 // The script wrapper must not be collected before the object is closed or |
| 448 // we can't fire a "versionchange" event to let script manually close the co
nnection. | 450 // we can't fire a "versionchange" event to let script manually close the co
nnection. |
| 449 return !m_closePending && hasEventListeners() && !m_contextStopped; | 451 return !m_closePending && hasEventListeners() && !m_contextStopped; |
| 450 } | 452 } |
| 451 | 453 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 472 return ActiveDOMObject::getExecutionContext(); | 474 return ActiveDOMObject::getExecutionContext(); |
| 473 } | 475 } |
| 474 | 476 |
| 475 void IDBDatabase::recordApiCallsHistogram(IndexedDatabaseMethods method) | 477 void IDBDatabase::recordApiCallsHistogram(IndexedDatabaseMethods method) |
| 476 { | 478 { |
| 477 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, apiCallsHistogram, new
EnumerationHistogram("WebCore.IndexedDB.FrontEndAPICalls", IDBMethodsMax)); | 479 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, apiCallsHistogram, new
EnumerationHistogram("WebCore.IndexedDB.FrontEndAPICalls", IDBMethodsMax)); |
| 478 apiCallsHistogram.count(method); | 480 apiCallsHistogram.count(method); |
| 479 } | 481 } |
| 480 | 482 |
| 481 } // namespace blink | 483 } // namespace blink |
| OLD | NEW |