|
Lines 42-47
a/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp_sec1
|
| 42 |
#include "Logging.h" |
42 |
#include "Logging.h" |
| 43 |
#include "StorageQuotaManager.h" |
43 |
#include "StorageQuotaManager.h" |
| 44 |
#include "UniqueIDBDatabaseConnection.h" |
44 |
#include "UniqueIDBDatabaseConnection.h" |
|
|
45 |
#include "UniqueIDBDatabaseManager.h" |
| 45 |
#include <wtf/Scope.h> |
46 |
#include <wtf/Scope.h> |
| 46 |
|
47 |
|
| 47 |
namespace WebCore { |
48 |
namespace WebCore { |
|
Lines 134-141
static inline uint64_t estimateSize(const IDBObjectStoreInfo& info)
a/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp_sec2
|
| 134 |
return size; |
135 |
return size; |
| 135 |
} |
136 |
} |
| 136 |
|
137 |
|
| 137 |
UniqueIDBDatabase::UniqueIDBDatabase(IDBServer& server, const IDBDatabaseIdentifier& identifier) |
138 |
UniqueIDBDatabase::UniqueIDBDatabase(UniqueIDBDatabaseManager& manager, const IDBDatabaseIdentifier& identifier) |
| 138 |
: m_server(server) |
139 |
: m_manager(manager) |
| 139 |
, m_identifier(identifier) |
140 |
, m_identifier(identifier) |
| 140 |
{ |
141 |
{ |
| 141 |
ASSERT(!isMainThread()); |
142 |
ASSERT(!isMainThread()); |
|
Lines 163-168
const IDBDatabaseInfo& UniqueIDBDatabase::info() const
a/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp_sec3
|
| 163 |
return *m_databaseInfo; |
164 |
return *m_databaseInfo; |
| 164 |
} |
165 |
} |
| 165 |
|
166 |
|
|
|
167 |
UniqueIDBDatabaseManager* UniqueIDBDatabase::manager() |
| 168 |
{ |
| 169 |
return m_manager.get(); |
| 170 |
} |
| 171 |
|
| 166 |
void UniqueIDBDatabase::openDatabaseConnection(IDBConnectionToClient& connection, const IDBRequestData& requestData) |
172 |
void UniqueIDBDatabase::openDatabaseConnection(IDBConnectionToClient& connection, const IDBRequestData& requestData) |
| 167 |
{ |
173 |
{ |
| 168 |
LOG(IndexedDB, "UniqueIDBDatabase::openDatabaseConnection"); |
174 |
LOG(IndexedDB, "UniqueIDBDatabase::openDatabaseConnection"); |
|
Lines 185-201
void UniqueIDBDatabase::performCurrentOpenOperation()
a/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp_sec4
|
| 185 |
ASSERT(m_currentOpenDBRequest); |
191 |
ASSERT(m_currentOpenDBRequest); |
| 186 |
ASSERT(m_currentOpenDBRequest->isOpenRequest()); |
192 |
ASSERT(m_currentOpenDBRequest->isOpenRequest()); |
| 187 |
|
193 |
|
|
|
194 |
// We don't need to create the file so no need to do space check. |
| 195 |
if (m_backingStore) |
| 196 |
return performCurrentOpenOperationAfterSpaceCheck(true); |
| 197 |
|
| 198 |
if (!m_manager) |
| 199 |
return performCurrentOpenOperationAfterSpaceCheck(false); |
| 200 |
|
| 201 |
auto requestIdentifier = m_currentOpenDBRequest->requestData().requestIdentifier(); |
| 202 |
if (m_openDBRequestsForSpaceCheck.contains(requestIdentifier)) |
| 203 |
return; |
| 204 |
|
| 205 |
m_openDBRequestsForSpaceCheck.add(requestIdentifier); |
| 206 |
m_manager->requestSpace(m_identifier.origin(), defaultWriteOperationCost, [this, weakThis = WeakPtr { *this }, requestIdentifier](bool granted) mutable { |
| 207 |
if (!weakThis) |
| 208 |
return; |
| 209 |
|
| 210 |
m_openDBRequestsForSpaceCheck.remove(requestIdentifier); |
| 211 |
if (m_currentOpenDBRequest->requestData().requestIdentifier() != requestIdentifier) |
| 212 |
return; |
| 213 |
|
| 214 |
performCurrentOpenOperationAfterSpaceCheck(granted); |
| 215 |
}); |
| 216 |
} |
| 217 |
|
| 218 |
void UniqueIDBDatabase::performCurrentOpenOperationAfterSpaceCheck(bool isGranted) |
| 219 |
{ |
| 220 |
LOG(IndexedDB, "UniqueIDBDatabase::performCurrentOpenOperationAfterSpaceRequest (%p)", this); |
| 221 |
|
| 188 |
IDBError backingStoreOpenError; |
222 |
IDBError backingStoreOpenError; |
| 189 |
if (!m_backingStore) { |
223 |
if (!m_backingStore) { |
| 190 |
// Quota check. |
224 |
if (!m_manager) |
| 191 |
auto decision = m_server.requestSpace(m_identifier.origin(), defaultWriteOperationCost); |
225 |
backingStoreOpenError = IDBError { InvalidStateError }; |
| 192 |
if (decision == StorageQuotaManager::Decision::Deny) |
226 |
else if (!isGranted) |
| 193 |
backingStoreOpenError = IDBError { QuotaExceededError, quotaErrorMessageName("OpenBackingStore") }; |
227 |
backingStoreOpenError = IDBError { QuotaExceededError, quotaErrorMessageName("OpenBackingStore") }; |
| 194 |
else { |
228 |
else { |
| 195 |
m_backingStore = m_server.createBackingStore(m_identifier); |
229 |
m_backingStore = m_manager->createBackingStore(m_identifier); |
| 196 |
IDBDatabaseInfo databaseInfo; |
230 |
IDBDatabaseInfo databaseInfo; |
| 197 |
backingStoreOpenError = m_backingStore->getOrEstablishDatabaseInfo(databaseInfo); |
231 |
backingStoreOpenError = m_backingStore->getOrEstablishDatabaseInfo(databaseInfo); |
| 198 |
if (backingStoreOpenError.isNull()) |
232 |
if (!backingStoreOpenError) |
| 199 |
m_databaseInfo = makeUnique<IDBDatabaseInfo>(databaseInfo); |
233 |
m_databaseInfo = makeUnique<IDBDatabaseInfo>(databaseInfo); |
| 200 |
else { |
234 |
else { |
| 201 |
LOG_ERROR("Failed to get database info '%s'", backingStoreOpenError.message().utf8().data()); |
235 |
LOG_ERROR("Failed to get database info '%s'", backingStoreOpenError.message().utf8().data()); |
|
Lines 204-210
void UniqueIDBDatabase::performCurrentOpenOperation()
a/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp_sec5
|
| 204 |
} |
238 |
} |
| 205 |
} |
239 |
} |
| 206 |
|
240 |
|
| 207 |
if (!backingStoreOpenError.isNull()) { |
241 |
if (backingStoreOpenError) { |
| 208 |
auto result = IDBResultData::error(m_currentOpenDBRequest->requestData().requestIdentifier(), backingStoreOpenError); |
242 |
auto result = IDBResultData::error(m_currentOpenDBRequest->requestData().requestIdentifier(), backingStoreOpenError); |
| 209 |
m_currentOpenDBRequest->connection().didOpenDatabase(result); |
243 |
m_currentOpenDBRequest->connection().didOpenDatabase(result); |
| 210 |
m_currentOpenDBRequest = nullptr; |
244 |
m_currentOpenDBRequest = nullptr; |
|
Lines 294-300
void UniqueIDBDatabase::deleteBackingStore()
a/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp_sec6
|
| 294 |
ASSERT(!isMainThread()); |
328 |
ASSERT(!isMainThread()); |
| 295 |
LOG(IndexedDB, "UniqueIDBDatabase::deleteBackingStore"); |
329 |
LOG(IndexedDB, "UniqueIDBDatabase::deleteBackingStore"); |
| 296 |
|
330 |
|
| 297 |
auto backingStore = m_backingStore ? std::exchange(m_backingStore, nullptr) : m_server.createBackingStore(m_identifier); |
331 |
auto backingStore = m_backingStore ? std::exchange(m_backingStore, nullptr) : m_manager->createBackingStore(m_identifier); |
| 298 |
uint64_t deletedVersion = backingStore->databaseVersion(); |
332 |
uint64_t deletedVersion = backingStore->databaseVersion(); |
| 299 |
backingStore->deleteBackingStore(); |
333 |
backingStore->deleteBackingStore(); |
| 300 |
didDeleteBackingStore(deletedVersion); |
334 |
didDeleteBackingStore(deletedVersion); |
|
Lines 542-561
void UniqueIDBDatabase::addOpenDatabaseConnection(Ref<UniqueIDBDatabaseConnectio
a/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp_sec7
|
| 542 |
m_openDatabaseConnections.add(adoptRef(connection.leakRef())); |
576 |
m_openDatabaseConnections.add(adoptRef(connection.leakRef())); |
| 543 |
} |
577 |
} |
| 544 |
|
578 |
|
| 545 |
void UniqueIDBDatabase::createObjectStore(UniqueIDBDatabaseTransaction& transaction, const IDBObjectStoreInfo& info, ErrorCallback callback) |
579 |
void UniqueIDBDatabase::createObjectStore(UniqueIDBDatabaseTransaction& transaction, const IDBObjectStoreInfo& info, ErrorCallback callback, SpaceCheckResult spaceCheckResult) |
| 546 |
{ |
580 |
{ |
| 547 |
ASSERT(!isMainThread()); |
581 |
ASSERT(!isMainThread()); |
| 548 |
LOG(IndexedDB, "UniqueIDBDatabase::createObjectStore"); |
582 |
LOG(IndexedDB, "UniqueIDBDatabase::createObjectStore"); |
| 549 |
|
583 |
|
| 550 |
ASSERT(m_backingStore); |
584 |
if (!spaceCheckResult) { |
|
|
585 |
if (!m_manager) |
| 586 |
return callback(IDBError { InvalidStateError }); |
| 587 |
|
| 588 |
auto taskSize = defaultWriteOperationCost + estimateSize(info); |
| 589 |
m_manager->requestSpace(m_identifier.origin(), taskSize, [this, weakThis = WeakPtr { *this }, weakTransaction = WeakPtr { transaction }, info, callback = WTFMove(callback)](bool granted) mutable { |
| 590 |
if (!weakThis || !weakTransaction) |
| 591 |
return callback(IDBError { InvalidStateError, "Database or transaction is closed" }); |
| 592 |
createObjectStore(*weakTransaction, info, WTFMove(callback), granted); |
| 593 |
}); |
| 594 |
return; |
| 595 |
} |
| 551 |
|
596 |
|
| 552 |
// Quota check. |
597 |
if (!spaceCheckResult.value()) { |
| 553 |
auto taskSize = defaultWriteOperationCost + estimateSize(info); |
|
|
| 554 |
if (m_server.requestSpace(m_identifier.origin(), taskSize) == StorageQuotaManager::Decision::Deny) { |
| 555 |
callback(IDBError { QuotaExceededError, quotaErrorMessageName("CreateObjectStore") }); |
598 |
callback(IDBError { QuotaExceededError, quotaErrorMessageName("CreateObjectStore") }); |
| 556 |
return; |
599 |
return; |
| 557 |
} |
600 |
} |
| 558 |
|
601 |
|
|
|
602 |
if (!m_backingStore) |
| 603 |
return callback(IDBError { InvalidStateError, "Backing store has closed" }); |
| 604 |
|
| 559 |
auto error = m_backingStore->createObjectStore(transaction.info().identifier(), info); |
605 |
auto error = m_backingStore->createObjectStore(transaction.info().identifier(), info); |
| 560 |
if (error.isNull()) |
606 |
if (error.isNull()) |
| 561 |
m_databaseInfo->addExistingObjectStore(info); |
607 |
m_databaseInfo->addExistingObjectStore(info); |
|
Lines 563-580
void UniqueIDBDatabase::createObjectStore(UniqueIDBDatabaseTransaction& transact
a/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp_sec8
|
| 563 |
callback(error); |
609 |
callback(error); |
| 564 |
} |
610 |
} |
| 565 |
|
611 |
|
| 566 |
void UniqueIDBDatabase::deleteObjectStore(UniqueIDBDatabaseTransaction& transaction, const String& objectStoreName, ErrorCallback callback) |
612 |
void UniqueIDBDatabase::deleteObjectStore(UniqueIDBDatabaseTransaction& transaction, const String& objectStoreName, ErrorCallback callback, SpaceCheckResult spaceCheckResult) |
| 567 |
{ |
613 |
{ |
| 568 |
ASSERT(!isMainThread()); |
614 |
ASSERT(!isMainThread()); |
| 569 |
LOG(IndexedDB, "UniqueIDBDatabase::deleteObjectStore"); |
615 |
LOG(IndexedDB, "UniqueIDBDatabase::deleteObjectStore"); |
| 570 |
|
616 |
|
|
|
617 |
if (!spaceCheckResult) { |
| 618 |
if (!m_manager) |
| 619 |
return callback(IDBError { InvalidStateError }); |
| 620 |
|
| 621 |
m_manager->requestSpace(m_identifier.origin(), 0, [this, weakThis = WeakPtr { *this }, weakTransaction = WeakPtr { transaction }, objectStoreName, callback = WTFMove(callback)](bool granted) mutable { |
| 622 |
if (!weakThis || !weakTransaction) |
| 623 |
return callback(IDBError { InvalidStateError, "Database or transaction is closed" }); |
| 624 |
|
| 625 |
deleteObjectStore(*weakTransaction, objectStoreName, WTFMove(callback), granted); |
| 626 |
}); |
| 627 |
return; |
| 628 |
} |
| 629 |
|
| 630 |
ASSERT(spaceCheckResult.value()); |
| 571 |
auto* info = m_databaseInfo->infoForExistingObjectStore(objectStoreName); |
631 |
auto* info = m_databaseInfo->infoForExistingObjectStore(objectStoreName); |
| 572 |
if (!info) { |
632 |
if (!info) { |
| 573 |
callback(IDBError { UnknownError, "Attempt to delete non-existant object store"_s }); |
633 |
callback(IDBError { UnknownError, "Attempt to delete non-existant object store"_s }); |
| 574 |
return; |
634 |
return; |
| 575 |
} |
635 |
} |
| 576 |
|
636 |
|
| 577 |
ASSERT(m_backingStore); |
637 |
if (!m_backingStore) |
|
|
638 |
return callback(IDBError { InvalidStateError, "Backing store is closed" }); |
| 639 |
|
| 578 |
auto error = m_backingStore->deleteObjectStore(transaction.info().identifier(), info->identifier()); |
640 |
auto error = m_backingStore->deleteObjectStore(transaction.info().identifier(), info->identifier()); |
| 579 |
if (error.isNull()) |
641 |
if (error.isNull()) |
| 580 |
m_databaseInfo->deleteObjectStore(info->identifier()); |
642 |
m_databaseInfo->deleteObjectStore(info->identifier()); |
|
Lines 582-595
void UniqueIDBDatabase::deleteObjectStore(UniqueIDBDatabaseTransaction& transact
a/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp_sec9
|
| 582 |
callback(error); |
644 |
callback(error); |
| 583 |
} |
645 |
} |
| 584 |
|
646 |
|
| 585 |
void UniqueIDBDatabase::renameObjectStore(UniqueIDBDatabaseTransaction& transaction, uint64_t objectStoreIdentifier, const String& newName, ErrorCallback callback) |
647 |
void UniqueIDBDatabase::renameObjectStore(UniqueIDBDatabaseTransaction& transaction, uint64_t objectStoreIdentifier, const String& newName, ErrorCallback callback, SpaceCheckResult spaceCheckResult) |
| 586 |
{ |
648 |
{ |
| 587 |
ASSERT(!isMainThread()); |
649 |
ASSERT(!isMainThread()); |
| 588 |
LOG(IndexedDB, "UniqueIDBDatabase::renameObjectStore"); |
650 |
LOG(IndexedDB, "UniqueIDBDatabase::renameObjectStore"); |
| 589 |
|
651 |
|
| 590 |
// Quota check. |
652 |
if (!spaceCheckResult) { |
| 591 |
auto taskSize = defaultWriteOperationCost + newName.sizeInBytes(); |
653 |
if (!m_manager) |
| 592 |
if (m_server.requestSpace(m_identifier.origin(), taskSize) == StorageQuotaManager::Decision::Deny) { |
654 |
return callback(IDBError { InvalidStateError }); |
|
|
655 |
|
| 656 |
auto taskSize = defaultWriteOperationCost + newName.sizeInBytes(); |
| 657 |
m_manager->requestSpace(m_identifier.origin(), taskSize, [this, weakThis = WeakPtr { *this }, weakTransaction = WeakPtr { transaction }, objectStoreIdentifier, newName, callback = WTFMove(callback)](bool granted) mutable { |
| 658 |
if (!weakThis || !weakTransaction) |
| 659 |
return callback(IDBError { InvalidStateError, "Database or transaction is closed" }); |
| 660 |
|
| 661 |
renameObjectStore(*weakTransaction, objectStoreIdentifier, newName, WTFMove(callback), granted); |
| 662 |
}); |
| 663 |
return; |
| 664 |
} |
| 665 |
|
| 666 |
if (!spaceCheckResult.value()) { |
| 593 |
callback(IDBError(QuotaExceededError, quotaErrorMessageName("RenameObjectStore"))); |
667 |
callback(IDBError(QuotaExceededError, quotaErrorMessageName("RenameObjectStore"))); |
| 594 |
return; |
668 |
return; |
| 595 |
} |
669 |
} |
|
Lines 600-606
void UniqueIDBDatabase::renameObjectStore(UniqueIDBDatabaseTransaction& transact
a/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp_sec10
|
| 600 |
return; |
674 |
return; |
| 601 |
} |
675 |
} |
| 602 |
|
676 |
|
| 603 |
ASSERT(m_backingStore); |
677 |
if (!m_backingStore) |
|
|
678 |
return callback(IDBError { InvalidStateError, "Backing store is closed" }); |
| 679 |
|
| 604 |
auto error = m_backingStore->renameObjectStore(transaction.info().identifier(), objectStoreIdentifier, newName); |
680 |
auto error = m_backingStore->renameObjectStore(transaction.info().identifier(), objectStoreIdentifier, newName); |
| 605 |
if (error.isNull()) |
681 |
if (error.isNull()) |
| 606 |
m_databaseInfo->renameObjectStore(objectStoreIdentifier, newName); |
682 |
m_databaseInfo->renameObjectStore(objectStoreIdentifier, newName); |
|
Lines 608-637
void UniqueIDBDatabase::renameObjectStore(UniqueIDBDatabaseTransaction& transact
a/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp_sec11
|
| 608 |
callback(error); |
684 |
callback(error); |
| 609 |
} |
685 |
} |
| 610 |
|
686 |
|
| 611 |
void UniqueIDBDatabase::clearObjectStore(UniqueIDBDatabaseTransaction& transaction, uint64_t objectStoreIdentifier, ErrorCallback callback) |
687 |
void UniqueIDBDatabase::clearObjectStore(UniqueIDBDatabaseTransaction& transaction, uint64_t objectStoreIdentifier, ErrorCallback callback, SpaceCheckResult spaceCheckResult) |
| 612 |
{ |
688 |
{ |
| 613 |
ASSERT(!isMainThread()); |
689 |
ASSERT(!isMainThread()); |
| 614 |
LOG(IndexedDB, "UniqueIDBDatabase::clearObjectStore"); |
690 |
LOG(IndexedDB, "UniqueIDBDatabase::clearObjectStore"); |
| 615 |
|
691 |
|
| 616 |
ASSERT(m_backingStore); |
692 |
if (!spaceCheckResult) { |
| 617 |
auto error = m_backingStore->clearObjectStore(transaction.info().identifier(), objectStoreIdentifier); |
693 |
if (!m_manager) |
|
|
694 |
return callback(IDBError { InvalidStateError }); |
| 695 |
|
| 696 |
m_manager->requestSpace(m_identifier.origin(), 0, [this, weakThis = WeakPtr { *this }, weakTransaction = WeakPtr { transaction }, objectStoreIdentifier, callback = WTFMove(callback)](bool granted) mutable { |
| 697 |
if (!weakThis || !weakTransaction) |
| 698 |
return callback(IDBError { InvalidStateError, "Database or transaction is closed" }); |
| 699 |
|
| 700 |
clearObjectStore(*weakTransaction, objectStoreIdentifier, WTFMove(callback), granted); |
| 701 |
}); |
| 702 |
return; |
| 703 |
} |
| 704 |
|
| 705 |
ASSERT(spaceCheckResult.value()); |
| 706 |
if (!m_backingStore) |
| 707 |
return callback(IDBError { InvalidStateError, "Backing store is closed" }); |
| 618 |
|
708 |
|
|
|
709 |
auto error = m_backingStore->clearObjectStore(transaction.info().identifier(), objectStoreIdentifier); |
| 619 |
callback(error); |
710 |
callback(error); |
| 620 |
} |
711 |
} |
| 621 |
|
712 |
|
| 622 |
void UniqueIDBDatabase::createIndex(UniqueIDBDatabaseTransaction& transaction, const IDBIndexInfo& info, ErrorCallback callback) |
713 |
void UniqueIDBDatabase::createIndex(UniqueIDBDatabaseTransaction& transaction, const IDBIndexInfo& info, ErrorCallback callback, SpaceCheckResult spaceCheckResult) |
| 623 |
{ |
714 |
{ |
| 624 |
ASSERT(!isMainThread()); |
715 |
ASSERT(!isMainThread()); |
| 625 |
LOG(IndexedDB, "UniqueIDBDatabase::createIndex"); |
716 |
LOG(IndexedDB, "UniqueIDBDatabase::createIndex"); |
| 626 |
|
717 |
|
| 627 |
// Quota check. |
718 |
if (!spaceCheckResult) { |
| 628 |
auto taskSize = defaultWriteOperationCost + estimateSize(info); |
719 |
if (!m_manager) |
| 629 |
if (m_server.requestSpace(m_identifier.origin(), taskSize) == StorageQuotaManager::Decision::Deny) { |
720 |
return callback(IDBError { InvalidStateError }); |
|
|
721 |
|
| 722 |
auto taskSize = defaultWriteOperationCost + estimateSize(info); |
| 723 |
m_manager->requestSpace(m_identifier.origin(), taskSize, [this, weakThis = WeakPtr { *this }, weakTransaction = WeakPtr { transaction }, info, callback = WTFMove(callback)](bool granted) mutable { |
| 724 |
if (!weakThis || !weakTransaction) |
| 725 |
return callback(IDBError { InvalidStateError, "Database or transaction is closed" }); |
| 726 |
|
| 727 |
createIndex(*weakTransaction, info, WTFMove(callback), granted); |
| 728 |
}); |
| 729 |
return; |
| 730 |
} |
| 731 |
|
| 732 |
if (!spaceCheckResult.value()) { |
| 630 |
callback(IDBError { QuotaExceededError, quotaErrorMessageName("CreateIndex") }); |
733 |
callback(IDBError { QuotaExceededError, quotaErrorMessageName("CreateIndex") }); |
| 631 |
return; |
734 |
return; |
| 632 |
} |
735 |
} |
| 633 |
|
736 |
|
| 634 |
ASSERT(m_backingStore); |
737 |
if (!m_backingStore) |
|
|
738 |
return callback(IDBError { InvalidStateError, "Backing store is closed" }); |
| 739 |
|
| 635 |
auto error = m_backingStore->createIndex(transaction.info().identifier(), info); |
740 |
auto error = m_backingStore->createIndex(transaction.info().identifier(), info); |
| 636 |
if (error.isNull()) { |
741 |
if (error.isNull()) { |
| 637 |
ASSERT(m_databaseInfo); |
742 |
ASSERT(m_databaseInfo); |
|
Lines 644-654
void UniqueIDBDatabase::createIndex(UniqueIDBDatabaseTransaction& transaction, c
a/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp_sec12
|
| 644 |
callback(error); |
749 |
callback(error); |
| 645 |
} |
750 |
} |
| 646 |
|
751 |
|
| 647 |
void UniqueIDBDatabase::deleteIndex(UniqueIDBDatabaseTransaction& transaction, uint64_t objectStoreIdentifier, const String& indexName, ErrorCallback callback) |
752 |
void UniqueIDBDatabase::deleteIndex(UniqueIDBDatabaseTransaction& transaction, uint64_t objectStoreIdentifier, const String& indexName, ErrorCallback callback, SpaceCheckResult spaceCheckResult) |
| 648 |
{ |
753 |
{ |
| 649 |
ASSERT(!isMainThread()); |
754 |
ASSERT(!isMainThread()); |
| 650 |
LOG(IndexedDB, "UniqueIDBDatabase::deleteIndex"); |
755 |
LOG(IndexedDB, "UniqueIDBDatabase::deleteIndex"); |
| 651 |
|
756 |
|
|
|
757 |
if (!spaceCheckResult) { |
| 758 |
if (!m_manager) |
| 759 |
return callback(IDBError { InvalidStateError }); |
| 760 |
|
| 761 |
m_manager->requestSpace(m_identifier.origin(), 0, [this, weakThis = WeakPtr { *this }, weakTransaction = WeakPtr { transaction }, objectStoreIdentifier, indexName, callback = WTFMove(callback)](bool granted) mutable { |
| 762 |
if (!weakThis || !weakTransaction) |
| 763 |
return callback(IDBError { InvalidStateError, "Database or transaction is closed" }); |
| 764 |
|
| 765 |
deleteIndex(*weakTransaction, objectStoreIdentifier, indexName, WTFMove(callback), granted); |
| 766 |
}); |
| 767 |
return; |
| 768 |
} |
| 769 |
|
| 770 |
ASSERT(spaceCheckResult.value()); |
| 771 |
if (!m_backingStore) |
| 772 |
return callback(IDBError { InvalidStateError, "Backing store is closed" }); |
| 773 |
|
| 652 |
auto* objectStoreInfo = m_databaseInfo->infoForExistingObjectStore(objectStoreIdentifier); |
774 |
auto* objectStoreInfo = m_databaseInfo->infoForExistingObjectStore(objectStoreIdentifier); |
| 653 |
if (!objectStoreInfo) { |
775 |
if (!objectStoreInfo) { |
| 654 |
callback(IDBError { UnknownError, "Attempt to delete index from non-existant object store"_s }); |
776 |
callback(IDBError { UnknownError, "Attempt to delete index from non-existant object store"_s }); |
|
Lines 660-668
void UniqueIDBDatabase::deleteIndex(UniqueIDBDatabaseTransaction& transaction, u
a/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp_sec13
|
| 660 |
callback(IDBError { UnknownError, "Attempt to delete non-existant index"_s }); |
782 |
callback(IDBError { UnknownError, "Attempt to delete non-existant index"_s }); |
| 661 |
return; |
783 |
return; |
| 662 |
} |
784 |
} |
| 663 |
auto indexIdentifier = indexInfo->identifier(); |
|
|
| 664 |
|
785 |
|
| 665 |
ASSERT(m_backingStore); |
786 |
auto indexIdentifier = indexInfo->identifier(); |
| 666 |
auto error = m_backingStore->deleteIndex(transaction.info().identifier(), objectStoreIdentifier, indexIdentifier); |
787 |
auto error = m_backingStore->deleteIndex(transaction.info().identifier(), objectStoreIdentifier, indexIdentifier); |
| 667 |
if (error.isNull()) |
788 |
if (error.isNull()) |
| 668 |
objectStoreInfo->deleteIndex(indexIdentifier); |
789 |
objectStoreInfo->deleteIndex(indexIdentifier); |
|
Lines 670-687
void UniqueIDBDatabase::deleteIndex(UniqueIDBDatabaseTransaction& transaction, u
a/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp_sec14
|
| 670 |
callback(error); |
791 |
callback(error); |
| 671 |
} |
792 |
} |
| 672 |
|
793 |
|
| 673 |
void UniqueIDBDatabase::renameIndex(UniqueIDBDatabaseTransaction& transaction, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName, ErrorCallback callback) |
794 |
void UniqueIDBDatabase::renameIndex(UniqueIDBDatabaseTransaction& transaction, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName, ErrorCallback callback, SpaceCheckResult spaceCheckResult) |
| 674 |
{ |
795 |
{ |
| 675 |
ASSERT(!isMainThread()); |
796 |
ASSERT(!isMainThread()); |
| 676 |
LOG(IndexedDB, "UniqueIDBDatabase::renameIndex"); |
797 |
LOG(IndexedDB, "UniqueIDBDatabase::renameIndex"); |
| 677 |
|
798 |
|
| 678 |
// Quota check. |
799 |
if (!spaceCheckResult) { |
| 679 |
auto taskSize = defaultWriteOperationCost + newName.sizeInBytes(); |
800 |
if (!m_manager) |
| 680 |
if (m_server.requestSpace(m_identifier.origin(), taskSize) == StorageQuotaManager::Decision::Deny) { |
801 |
return callback(IDBError { InvalidStateError }); |
|
|
802 |
|
| 803 |
auto taskSize = defaultWriteOperationCost + newName.sizeInBytes(); |
| 804 |
m_manager->requestSpace(m_identifier.origin(), taskSize, [this, weakThis = WeakPtr { *this }, weakTransaction = WeakPtr { transaction }, objectStoreIdentifier, indexIdentifier, newName, callback = WTFMove(callback)](bool granted) mutable { |
| 805 |
if (!weakThis || !weakTransaction) |
| 806 |
return callback(IDBError { InvalidStateError, "Database or transaction is closed" }); |
| 807 |
|
| 808 |
renameIndex(*weakTransaction, objectStoreIdentifier, indexIdentifier, newName, WTFMove(callback), granted); |
| 809 |
}); |
| 810 |
return; |
| 811 |
} |
| 812 |
|
| 813 |
if (!spaceCheckResult.value()) { |
| 681 |
callback(IDBError { QuotaExceededError, quotaErrorMessageName("RenameIndex") }); |
814 |
callback(IDBError { QuotaExceededError, quotaErrorMessageName("RenameIndex") }); |
| 682 |
return; |
815 |
return; |
| 683 |
} |
816 |
} |
| 684 |
|
817 |
|
|
|
818 |
if (!m_backingStore) |
| 819 |
return callback(IDBError { InvalidStateError, "Backing store is closed" }); |
| 820 |
|
| 685 |
auto* objectStoreInfo = m_databaseInfo->infoForExistingObjectStore(objectStoreIdentifier); |
821 |
auto* objectStoreInfo = m_databaseInfo->infoForExistingObjectStore(objectStoreIdentifier); |
| 686 |
if (!objectStoreInfo) { |
822 |
if (!objectStoreInfo) { |
| 687 |
callback(IDBError { UnknownError, "Attempt to rename index in non-existant object store"_s }); |
823 |
callback(IDBError { UnknownError, "Attempt to rename index in non-existant object store"_s }); |
|
Lines 694-700
void UniqueIDBDatabase::renameIndex(UniqueIDBDatabaseTransaction& transaction, u
a/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp_sec15
|
| 694 |
return; |
830 |
return; |
| 695 |
} |
831 |
} |
| 696 |
|
832 |
|
| 697 |
ASSERT(m_backingStore); |
|
|
| 698 |
auto error = m_backingStore->renameIndex(transaction.info().identifier(), objectStoreIdentifier, indexIdentifier, newName); |
833 |
auto error = m_backingStore->renameIndex(transaction.info().identifier(), objectStoreIdentifier, indexIdentifier, newName); |
| 699 |
if (error.isNull()) |
834 |
if (error.isNull()) |
| 700 |
indexInfo->rename(newName); |
835 |
indexInfo->rename(newName); |
|
Lines 709-725
void UniqueIDBDatabase::putOrAdd(const IDBRequestData& requestData, const IDBKey
a/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp_sec16
|
| 709 |
|
844 |
|
| 710 |
ASSERT(m_databaseInfo); |
845 |
ASSERT(m_databaseInfo); |
| 711 |
|
846 |
|
| 712 |
IDBKeyData usedKey; |
847 |
if (!m_backingStore) |
| 713 |
IDBError error; |
848 |
return callback(IDBError { InvalidStateError, "Backing store is closed" }, keyData); |
| 714 |
|
849 |
|
| 715 |
ASSERT(m_backingStore); |
|
|
| 716 |
auto objectStoreIdentifier = requestData.objectStoreIdentifier(); |
850 |
auto objectStoreIdentifier = requestData.objectStoreIdentifier(); |
| 717 |
auto* objectStoreInfo = m_backingStore->infoForObjectStore(objectStoreIdentifier); |
851 |
auto* objectStoreInfo = m_backingStore->infoForObjectStore(objectStoreIdentifier); |
| 718 |
if (!objectStoreInfo) { |
852 |
if (!objectStoreInfo) |
| 719 |
callback(IDBError { InvalidStateError, "Object store cannot be found in the backing store"_s }, usedKey); |
853 |
return callback(IDBError { InvalidStateError, "Object store cannot be found in the backing store"_s }, keyData); |
| 720 |
return; |
854 |
|
| 721 |
} |
855 |
if (!m_manager) |
|
|
856 |
return callback(IDBError { InvalidStateError }, keyData); |
| 722 |
|
857 |
|
|
|
858 |
IDBKeyData usedKey; |
| 859 |
IDBError error; |
| 723 |
bool usedKeyIsGenerated = false; |
860 |
bool usedKeyIsGenerated = false; |
| 724 |
uint64_t keyNumber; |
861 |
uint64_t keyNumber; |
| 725 |
auto transactionIdentifier = requestData.transactionIdentifier(); |
862 |
auto transactionIdentifier = requestData.transactionIdentifier(); |
|
Lines 730-805
void UniqueIDBDatabase::putOrAdd(const IDBRequestData& requestData, const IDBKey
a/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp_sec17
|
| 730 |
|
867 |
|
| 731 |
if (objectStoreInfo->autoIncrement() && !keyData.isValid()) { |
868 |
if (objectStoreInfo->autoIncrement() && !keyData.isValid()) { |
| 732 |
error = m_backingStore->generateKeyNumber(transactionIdentifier, objectStoreIdentifier, keyNumber); |
869 |
error = m_backingStore->generateKeyNumber(transactionIdentifier, objectStoreIdentifier, keyNumber); |
| 733 |
if (!error.isNull()) { |
870 |
if (!error.isNull()) |
| 734 |
callback(error, usedKey); |
871 |
return callback(error, usedKey); |
| 735 |
return; |
872 |
|
| 736 |
} |
|
|
| 737 |
usedKey.setNumberValue(keyNumber); |
873 |
usedKey.setNumberValue(keyNumber); |
| 738 |
usedKeyIsGenerated = true; |
874 |
usedKeyIsGenerated = true; |
| 739 |
} else |
875 |
} else |
| 740 |
usedKey = keyData; |
876 |
usedKey = keyData; |
| 741 |
|
877 |
|
| 742 |
// Generate index keys up front for more accurate quota check. |
|
|
| 743 |
IndexIDToIndexKeyMap indexKeys; |
| 744 |
callOnIDBSerializationThreadAndWait([objectStoreInfo = objectStoreInfo->isolatedCopy(), key = usedKey.isolatedCopy(), value = value.isolatedCopy(), &indexKeys](auto& globalObject) { |
| 745 |
indexKeys = generateIndexKeyMapForValue(globalObject, objectStoreInfo, key, value); |
| 746 |
}); |
| 747 |
|
| 748 |
if (overwriteMode == IndexedDB::ObjectStoreOverwriteMode::NoOverwrite) { |
878 |
if (overwriteMode == IndexedDB::ObjectStoreOverwriteMode::NoOverwrite) { |
| 749 |
bool keyExists; |
879 |
bool keyExists; |
| 750 |
error = m_backingStore->keyExistsInObjectStore(transactionIdentifier, objectStoreIdentifier, usedKey, keyExists); |
880 |
error = m_backingStore->keyExistsInObjectStore(transactionIdentifier, objectStoreIdentifier, usedKey, keyExists); |
| 751 |
if (error.isNull() && keyExists) |
881 |
if (!error && keyExists) |
| 752 |
error = IDBError { ConstraintError, "Key already exists in the object store"_s }; |
882 |
error = IDBError { ConstraintError, "Key already exists in the object store"_s }; |
| 753 |
|
883 |
|
| 754 |
if (!error.isNull()) { |
884 |
if (!!error) |
| 755 |
callback(error, usedKey); |
885 |
return callback(error, usedKey); |
| 756 |
return; |
|
|
| 757 |
} |
| 758 |
} |
886 |
} |
| 759 |
|
887 |
|
| 760 |
// Quota check. |
888 |
// Generate index keys up front for more accurate quota check. |
|
|
889 |
IndexIDToIndexKeyMap indexKeys; |
| 890 |
callOnIDBSerializationThreadAndWait([objectStoreInfo = objectStoreInfo->isolatedCopy(), key = usedKey.isolatedCopy(), value = value.isolatedCopy(), &indexKeys](auto& globalObject) { |
| 891 |
indexKeys = generateIndexKeyMapForValue(globalObject, objectStoreInfo, key, value); |
| 892 |
}); |
| 893 |
|
| 894 |
generatedKeyResetter.release(); |
| 761 |
auto keySize = estimateSize(usedKey); |
895 |
auto keySize = estimateSize(usedKey); |
| 762 |
auto valueSize = estimateSize(value); |
896 |
auto valueSize = estimateSize(value); |
| 763 |
auto indexSize = estimateSize(*objectStoreInfo, indexKeys, keySize); |
897 |
auto indexSize = estimateSize(*objectStoreInfo, indexKeys, keySize); |
| 764 |
auto taskSize = defaultWriteOperationCost + keySize + valueSize + indexSize; |
898 |
auto taskSize = defaultWriteOperationCost + keySize + valueSize + indexSize; |
| 765 |
|
899 |
|
| 766 |
LOG(IndexedDB, "UniqueIDBDatabase::putOrAdd quota check with task size: %" PRIu64 " key size: %" PRIu64 " value size: %" PRIu64 " index size: %" PRIu64, taskSize, keySize, valueSize, indexSize); |
900 |
LOG(IndexedDB, "UniqueIDBDatabase::putOrAdd quota check with task size: %" PRIu64 " key size: %" PRIu64 " value size: %" PRIu64 " index size: %" PRIu64, taskSize, keySize, valueSize, indexSize); |
|
|
901 |
m_manager->requestSpace(m_identifier.origin(), taskSize, [this, weakThis = WeakPtr { *this }, requestData, usedKey, value, overwriteMode, callback = WTFMove(callback), usedKeyIsGenerated, indexKeys, objectStoreInfo = *objectStoreInfo](bool granted) mutable { |
| 902 |
if (!weakThis) |
| 903 |
return callback(IDBError { InvalidStateError, "Database is closed" }, usedKey); |
| 767 |
|
904 |
|
| 768 |
if (m_server.requestSpace(m_identifier.origin(), taskSize) == StorageQuotaManager::Decision::Deny) { |
905 |
putOrAddAfterSpaceCheck(requestData, usedKey, value, overwriteMode, WTFMove(callback), usedKeyIsGenerated, indexKeys, objectStoreInfo, granted); |
| 769 |
callback(IDBError { QuotaExceededError, quotaErrorMessageName("PutOrAdd") }, usedKey); |
906 |
}); |
| 770 |
return; |
907 |
} |
| 771 |
} |
908 |
|
|
|
909 |
void UniqueIDBDatabase::putOrAddAfterSpaceCheck(const IDBRequestData& requestData, const IDBKeyData& keyData, const IDBValue& value, IndexedDB::ObjectStoreOverwriteMode overwriteMode, KeyDataCallback callback, bool isKeyGenerated, const IndexIDToIndexKeyMap& indexKeys, const IDBObjectStoreInfo& objectStoreInfo, SpaceCheckResult spaceCheckResult) |
| 910 |
{ |
| 911 |
ASSERT(!isMainThread()); |
| 912 |
ASSERT(m_databaseInfo); |
| 913 |
|
| 914 |
if (!m_backingStore) |
| 915 |
return callback(IDBError { InvalidStateError, "Backing store is closed" }, keyData); |
| 916 |
|
| 917 |
uint64_t keyNumber = isKeyGenerated ? keyData.number() : 0; |
| 918 |
auto objectStoreIdentifier = objectStoreInfo.identifier(); |
| 919 |
auto transactionIdentifier = requestData.transactionIdentifier(); |
| 920 |
auto generatedKeyResetter = makeScopeExit([this, transactionIdentifier, objectStoreIdentifier, &keyNumber, &isKeyGenerated]() { |
| 921 |
if (isKeyGenerated) |
| 922 |
m_backingStore->revertGeneratedKeyNumber(transactionIdentifier, objectStoreIdentifier, keyNumber); |
| 923 |
}); |
| 772 |
|
924 |
|
|
|
925 |
if (!spaceCheckResult || !spaceCheckResult.value()) |
| 926 |
return callback(IDBError { QuotaExceededError, quotaErrorMessageName("PutOrAdd") }, keyData); |
| 773 |
// If a record already exists in store, then remove the record from store using the steps for deleting records from an object store. |
927 |
// If a record already exists in store, then remove the record from store using the steps for deleting records from an object store. |
| 774 |
// This is important because formally deleting it from from the object store also removes it from the appropriate indexes. |
928 |
// This is important because formally deleting it from the object store also removes it from the appropriate indexes. |
| 775 |
error = m_backingStore->deleteRange(transactionIdentifier, objectStoreIdentifier, usedKey); |
929 |
IDBError error = m_backingStore->deleteRange(transactionIdentifier, objectStoreIdentifier, keyData); |
| 776 |
if (!error.isNull()) { |
930 |
if (!error.isNull()) |
| 777 |
callback(error, usedKey); |
931 |
return callback(error, keyData); |
| 778 |
return; |
|
|
| 779 |
} |
| 780 |
|
932 |
|
| 781 |
error = m_backingStore->addRecord(transactionIdentifier, *objectStoreInfo, usedKey, indexKeys, value); |
933 |
error = m_backingStore->addRecord(transactionIdentifier, objectStoreInfo, keyData, indexKeys, value); |
| 782 |
if (!error.isNull()) { |
934 |
if (!error.isNull()) |
| 783 |
callback(error, usedKey); |
935 |
return callback(error, keyData); |
| 784 |
return; |
|
|
| 785 |
} |
| 786 |
|
936 |
|
| 787 |
if (overwriteMode != IndexedDB::ObjectStoreOverwriteMode::OverwriteForCursor && objectStoreInfo->autoIncrement() && keyData.type() == IndexedDB::KeyType::Number) |
937 |
if (overwriteMode != IndexedDB::ObjectStoreOverwriteMode::OverwriteForCursor && objectStoreInfo.autoIncrement() && keyData.type() == IndexedDB::KeyType::Number) |
| 788 |
error = m_backingStore->maybeUpdateKeyGeneratorNumber(transactionIdentifier, objectStoreIdentifier, keyData.number()); |
938 |
error = m_backingStore->maybeUpdateKeyGeneratorNumber(transactionIdentifier, objectStoreIdentifier, keyData.number()); |
| 789 |
|
939 |
|
| 790 |
generatedKeyResetter.release(); |
940 |
generatedKeyResetter.release(); |
| 791 |
callback(error, usedKey); |
941 |
callback(error, keyData); |
| 792 |
} |
942 |
} |
| 793 |
|
943 |
|
| 794 |
void UniqueIDBDatabase::getRecord(const IDBRequestData& requestData, const IDBGetRecordData& getRecordData, GetResultCallback callback) |
944 |
void UniqueIDBDatabase::getRecord(const IDBRequestData& requestData, const IDBGetRecordData& getRecordData, GetResultCallback callback, SpaceCheckResult spaceCheckResult) |
| 795 |
{ |
945 |
{ |
| 796 |
ASSERT(!isMainThread()); |
946 |
ASSERT(!isMainThread()); |
| 797 |
LOG(IndexedDB, "UniqueIDBDatabase::getRecord"); |
947 |
LOG(IndexedDB, "UniqueIDBDatabase::getRecord"); |
| 798 |
|
948 |
|
|
|
949 |
if (!spaceCheckResult) { |
| 950 |
if (!m_manager) |
| 951 |
return callback(IDBError { InvalidStateError }, IDBGetResult { }); |
| 952 |
|
| 953 |
m_manager->requestSpace(m_identifier.origin(), 0, [this, weakThis = WeakPtr { *this }, requestData, getRecordData, callback = WTFMove(callback)](bool granted) mutable { |
| 954 |
if (!weakThis) |
| 955 |
return callback(IDBError { InvalidStateError, "Database is closed" }, IDBGetResult { }); |
| 956 |
|
| 957 |
getRecord(requestData, getRecordData, WTFMove(callback), granted); |
| 958 |
}); |
| 959 |
return; |
| 960 |
} |
| 961 |
|
| 962 |
ASSERT(spaceCheckResult.value()); |
| 963 |
if (!m_backingStore) |
| 964 |
return callback(IDBError { InvalidStateError, "Backing store is closed" }, IDBGetResult { }); |
| 965 |
|
| 799 |
IDBGetResult result; |
966 |
IDBGetResult result; |
| 800 |
IDBError error; |
967 |
IDBError error; |
| 801 |
|
968 |
|
| 802 |
ASSERT(m_backingStore); |
|
|
| 803 |
if (uint64_t indexIdentifier = requestData.indexIdentifier()) |
969 |
if (uint64_t indexIdentifier = requestData.indexIdentifier()) |
| 804 |
error = m_backingStore->getIndexRecord(requestData.transactionIdentifier(), requestData.objectStoreIdentifier(), indexIdentifier, requestData.indexRecordType(), getRecordData.keyRangeData, result); |
970 |
error = m_backingStore->getIndexRecord(requestData.transactionIdentifier(), requestData.objectStoreIdentifier(), indexIdentifier, requestData.indexRecordType(), getRecordData.keyRangeData, result); |
| 805 |
else |
971 |
else |
|
Lines 808-854
void UniqueIDBDatabase::getRecord(const IDBRequestData& requestData, const IDBGe
a/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp_sec18
|
| 808 |
callback(error, result); |
974 |
callback(error, result); |
| 809 |
} |
975 |
} |
| 810 |
|
976 |
|
| 811 |
void UniqueIDBDatabase::getAllRecords(const IDBRequestData& requestData, const IDBGetAllRecordsData& getAllRecordsData, GetAllResultsCallback callback) |
977 |
void UniqueIDBDatabase::getAllRecords(const IDBRequestData& requestData, const IDBGetAllRecordsData& getAllRecordsData, GetAllResultsCallback callback, SpaceCheckResult spaceCheckResult) |
| 812 |
{ |
978 |
{ |
| 813 |
ASSERT(!isMainThread()); |
979 |
ASSERT(!isMainThread()); |
| 814 |
LOG(IndexedDB, "UniqueIDBDatabase::getAllRecords"); |
980 |
LOG(IndexedDB, "UniqueIDBDatabase::getAllRecords"); |
| 815 |
|
981 |
|
| 816 |
ASSERT(m_backingStore); |
982 |
if (!spaceCheckResult) { |
|
|
983 |
if (!m_manager) |
| 984 |
return callback(IDBError { InvalidStateError }, IDBGetAllResult { }); |
| 985 |
|
| 986 |
m_manager->requestSpace(m_identifier.origin(), 0, [this, weakThis = WeakPtr { *this }, requestData, getAllRecordsData, callback = WTFMove(callback)](bool granted) mutable { |
| 987 |
if (!weakThis) |
| 988 |
return callback(IDBError { InvalidStateError, "Database is closed" }, IDBGetAllResult { }); |
| 989 |
|
| 990 |
getAllRecords(requestData, getAllRecordsData, WTFMove(callback), granted); |
| 991 |
}); |
| 992 |
return; |
| 993 |
} |
| 994 |
|
| 995 |
ASSERT(spaceCheckResult.value()); |
| 996 |
if (!m_backingStore) |
| 997 |
return callback(IDBError { InvalidStateError, "Backing store is closed" }, IDBGetAllResult { }); |
| 998 |
|
| 817 |
IDBGetAllResult result; |
999 |
IDBGetAllResult result; |
| 818 |
auto error = m_backingStore->getAllRecords(requestData.transactionIdentifier(), getAllRecordsData, result); |
1000 |
auto error = m_backingStore->getAllRecords(requestData.transactionIdentifier(), getAllRecordsData, result); |
| 819 |
|
1001 |
|
| 820 |
callback(error, result); |
1002 |
callback(error, result); |
| 821 |
} |
1003 |
} |
| 822 |
|
1004 |
|
| 823 |
void UniqueIDBDatabase::getCount(const IDBRequestData& requestData, const IDBKeyRangeData& range, CountCallback callback) |
1005 |
void UniqueIDBDatabase::getCount(const IDBRequestData& requestData, const IDBKeyRangeData& range, CountCallback callback, SpaceCheckResult spaceCheckResult) |
| 824 |
{ |
1006 |
{ |
| 825 |
ASSERT(!isMainThread()); |
1007 |
ASSERT(!isMainThread()); |
| 826 |
LOG(IndexedDB, "UniqueIDBDatabase::getCount"); |
1008 |
LOG(IndexedDB, "UniqueIDBDatabase::getCount"); |
| 827 |
|
1009 |
|
| 828 |
ASSERT(m_backingStore); |
1010 |
if (!spaceCheckResult) { |
|
|
1011 |
if (!m_manager) |
| 1012 |
return callback(IDBError { InvalidStateError }, 0); |
| 1013 |
|
| 1014 |
m_manager->requestSpace(m_identifier.origin(), 0, [this, weakThis = WeakPtr { *this }, requestData, range, callback = WTFMove(callback)](bool granted) mutable { |
| 1015 |
if (!weakThis) |
| 1016 |
return callback(IDBError { InvalidStateError, "Database is closed" }, 0); |
| 1017 |
|
| 1018 |
getCount(requestData, range, WTFMove(callback), granted); |
| 1019 |
}); |
| 1020 |
return; |
| 1021 |
} |
| 1022 |
|
| 1023 |
ASSERT(spaceCheckResult.value()); |
| 1024 |
if (!m_backingStore) |
| 1025 |
return callback(IDBError { InvalidStateError, "Backing store is closed" }, 0); |
| 1026 |
|
| 829 |
uint64_t count = 0; |
1027 |
uint64_t count = 0; |
| 830 |
auto error = m_backingStore->getCount(requestData.transactionIdentifier(), requestData.objectStoreIdentifier(), requestData.indexIdentifier(), range, count); |
1028 |
auto error = m_backingStore->getCount(requestData.transactionIdentifier(), requestData.objectStoreIdentifier(), requestData.indexIdentifier(), range, count); |
| 831 |
|
1029 |
|
| 832 |
callback(error, count); |
1030 |
callback(error, count); |
| 833 |
} |
1031 |
} |
| 834 |
|
1032 |
|
| 835 |
void UniqueIDBDatabase::deleteRecord(const IDBRequestData& requestData, const IDBKeyRangeData& keyRangeData, ErrorCallback callback) |
1033 |
void UniqueIDBDatabase::deleteRecord(const IDBRequestData& requestData, const IDBKeyRangeData& keyRangeData, ErrorCallback callback, SpaceCheckResult spaceCheckResult) |
| 836 |
{ |
1034 |
{ |
| 837 |
ASSERT(!isMainThread()); |
1035 |
ASSERT(!isMainThread()); |
| 838 |
LOG(IndexedDB, "UniqueIDBDatabase::deleteRecord"); |
1036 |
LOG(IndexedDB, "UniqueIDBDatabase::deleteRecord"); |
| 839 |
|
1037 |
|
| 840 |
ASSERT(m_backingStore); |
1038 |
if (!spaceCheckResult) { |
|
|
1039 |
if (!m_manager) |
| 1040 |
return callback(IDBError { InvalidStateError }); |
| 1041 |
|
| 1042 |
m_manager->requestSpace(m_identifier.origin(), 0, [this, weakThis = WeakPtr { *this }, requestData, keyRangeData, callback = WTFMove(callback)](bool granted) mutable { |
| 1043 |
if (!weakThis) |
| 1044 |
return callback(IDBError { InvalidStateError, "Database is closed" }); |
| 1045 |
|
| 1046 |
deleteRecord(requestData, keyRangeData, WTFMove(callback), granted); |
| 1047 |
}); |
| 1048 |
return; |
| 1049 |
} |
| 1050 |
|
| 1051 |
ASSERT(spaceCheckResult.value()); |
| 1052 |
if (!m_backingStore) |
| 1053 |
return callback(IDBError { InvalidStateError, "Backing store is closed" }); |
| 1054 |
|
| 841 |
auto error = m_backingStore->deleteRange(requestData.transactionIdentifier(), requestData.objectStoreIdentifier(), keyRangeData); |
1055 |
auto error = m_backingStore->deleteRange(requestData.transactionIdentifier(), requestData.objectStoreIdentifier(), keyRangeData); |
| 842 |
|
1056 |
|
| 843 |
callback(error); |
1057 |
callback(error); |
| 844 |
} |
1058 |
} |
| 845 |
|
1059 |
|
| 846 |
void UniqueIDBDatabase::openCursor(const IDBRequestData& requestData, const IDBCursorInfo& info, GetResultCallback callback) |
1060 |
void UniqueIDBDatabase::openCursor(const IDBRequestData& requestData, const IDBCursorInfo& info, GetResultCallback callback, SpaceCheckResult spaceCheckResult) |
| 847 |
{ |
1061 |
{ |
| 848 |
ASSERT(!isMainThread()); |
1062 |
ASSERT(!isMainThread()); |
| 849 |
LOG(IndexedDB, "UniqueIDBDatabase::openCursor"); |
1063 |
LOG(IndexedDB, "UniqueIDBDatabase::openCursor"); |
| 850 |
|
1064 |
|
| 851 |
ASSERT(m_backingStore); |
1065 |
if (!spaceCheckResult) { |
|
|
1066 |
if (!m_manager) |
| 1067 |
return callback(IDBError { InvalidStateError }, IDBGetResult { }); |
| 1068 |
|
| 1069 |
m_manager->requestSpace(m_identifier.origin(), 0, [this, weakThis = WeakPtr { *this }, requestData, info, callback = WTFMove(callback)](bool granted) mutable { |
| 1070 |
if (!weakThis) |
| 1071 |
return callback(IDBError { InvalidStateError, "Database or transaction is closed" }, IDBGetResult { }); |
| 1072 |
|
| 1073 |
openCursor(requestData, info, WTFMove(callback), granted); |
| 1074 |
}); |
| 1075 |
return; |
| 1076 |
} |
| 1077 |
|
| 1078 |
ASSERT(spaceCheckResult.value()); |
| 1079 |
if (!m_backingStore) |
| 1080 |
return callback(IDBError { InvalidStateError, "Backing store is closed" }, IDBGetResult { }); |
| 852 |
|
1081 |
|
| 853 |
IDBGetResult result; |
1082 |
IDBGetResult result; |
| 854 |
auto error = m_backingStore->openCursor(requestData.transactionIdentifier(), info, result); |
1083 |
auto error = m_backingStore->openCursor(requestData.transactionIdentifier(), info, result); |
|
Lines 856-867
void UniqueIDBDatabase::openCursor(const IDBRequestData& requestData, const IDBC
a/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp_sec19
|
| 856 |
callback(error, result); |
1085 |
callback(error, result); |
| 857 |
} |
1086 |
} |
| 858 |
|
1087 |
|
| 859 |
void UniqueIDBDatabase::iterateCursor(const IDBRequestData& requestData, const IDBIterateCursorData& data, GetResultCallback callback) |
1088 |
void UniqueIDBDatabase::iterateCursor(const IDBRequestData& requestData, const IDBIterateCursorData& data, GetResultCallback callback, SpaceCheckResult spaceCheckResult) |
| 860 |
{ |
1089 |
{ |
| 861 |
ASSERT(!isMainThread()); |
1090 |
ASSERT(!isMainThread()); |
| 862 |
LOG(IndexedDB, "UniqueIDBDatabase::iterateCursor"); |
1091 |
LOG(IndexedDB, "UniqueIDBDatabase::iterateCursor"); |
| 863 |
|
1092 |
|
| 864 |
ASSERT(m_backingStore); |
1093 |
if (!spaceCheckResult) { |
|
|
1094 |
if (!m_manager) |
| 1095 |
return callback(IDBError { InvalidStateError }, IDBGetResult { }); |
| 1096 |
|
| 1097 |
m_manager->requestSpace(m_identifier.origin(), 0, [this, weakThis = WeakPtr { *this }, requestData, data, callback = WTFMove(callback)](bool granted) mutable { |
| 1098 |
if (!weakThis) |
| 1099 |
return callback(IDBError { InvalidStateError, "Database or transaction is closed" }, IDBGetResult { }); |
| 1100 |
|
| 1101 |
iterateCursor(requestData, data, WTFMove(callback), granted); |
| 1102 |
}); |
| 1103 |
return; |
| 1104 |
} |
| 1105 |
|
| 1106 |
ASSERT(spaceCheckResult.value()); |
| 1107 |
if (!m_backingStore) |
| 1108 |
return callback(IDBError { InvalidStateError, "Backing store is closed" }, IDBGetResult { }); |
| 865 |
|
1109 |
|
| 866 |
IDBGetResult result; |
1110 |
IDBGetResult result; |
| 867 |
auto transactionIdentifier = requestData.transactionIdentifier(); |
1111 |
auto transactionIdentifier = requestData.transactionIdentifier(); |
|
Lines 871-883
void UniqueIDBDatabase::iterateCursor(const IDBRequestData& requestData, const I
a/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp_sec20
|
| 871 |
callback(error, result); |
1115 |
callback(error, result); |
| 872 |
} |
1116 |
} |
| 873 |
|
1117 |
|
| 874 |
void UniqueIDBDatabase::commitTransaction(UniqueIDBDatabaseTransaction& transaction, ErrorCallback callback) |
1118 |
void UniqueIDBDatabase::commitTransaction(UniqueIDBDatabaseTransaction& transaction, ErrorCallback callback, SpaceCheckResult spaceCheckResult) |
| 875 |
{ |
1119 |
{ |
| 876 |
ASSERT(!isMainThread()); |
1120 |
ASSERT(!isMainThread()); |
| 877 |
LOG(IndexedDB, "UniqueIDBDatabase::commitTransaction - %s", transaction.info().identifier().loggingString().utf8().data()); |
1121 |
LOG(IndexedDB, "UniqueIDBDatabase::commitTransaction - %s", transaction.info().identifier().loggingString().utf8().data()); |
| 878 |
|
1122 |
|
|
|
1123 |
if (!spaceCheckResult) { |
| 1124 |
if (!m_manager) |
| 1125 |
return callback(IDBError { InvalidStateError }); |
| 1126 |
|
| 1127 |
m_manager->requestSpace(m_identifier.origin(), 0, [this, weakThis = WeakPtr { *this }, weakTransaction = WeakPtr { transaction }, callback = WTFMove(callback)](bool granted) mutable { |
| 1128 |
if (!weakThis || !weakTransaction) |
| 1129 |
return callback(IDBError { InvalidStateError, "Database or transaction is closed" }); |
| 1130 |
|
| 1131 |
commitTransaction(*weakTransaction, WTFMove(callback), granted); |
| 1132 |
}); |
| 1133 |
return; |
| 1134 |
} |
| 1135 |
|
| 1136 |
ASSERT(spaceCheckResult.value()); |
| 879 |
ASSERT(transaction.databaseConnection().database() == this); |
1137 |
ASSERT(transaction.databaseConnection().database() == this); |
| 880 |
ASSERT(m_backingStore); |
1138 |
|
|
|
1139 |
if (!m_backingStore) |
| 1140 |
return callback(IDBError { InvalidStateError, "Backing store is closed" }); |
| 1141 |
|
| 881 |
auto takenTransaction = m_inProgressTransactions.take(transaction.info().identifier()); |
1142 |
auto takenTransaction = m_inProgressTransactions.take(transaction.info().identifier()); |
| 882 |
if (!takenTransaction) { |
1143 |
if (!takenTransaction) { |
| 883 |
if (!m_openDatabaseConnections.contains(&transaction.databaseConnection())) |
1144 |
if (!m_openDatabaseConnections.contains(&transaction.databaseConnection())) |
|
Lines 893-903
void UniqueIDBDatabase::commitTransaction(UniqueIDBDatabaseTransaction& transact
a/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp_sec21
|
| 893 |
transactionCompleted(WTFMove(takenTransaction)); |
1154 |
transactionCompleted(WTFMove(takenTransaction)); |
| 894 |
} |
1155 |
} |
| 895 |
|
1156 |
|
| 896 |
void UniqueIDBDatabase::abortTransaction(UniqueIDBDatabaseTransaction& transaction, ErrorCallback callback) |
1157 |
void UniqueIDBDatabase::abortTransaction(UniqueIDBDatabaseTransaction& transaction, ErrorCallback callback, SpaceCheckResult spaceCheckResult) |
| 897 |
{ |
1158 |
{ |
| 898 |
ASSERT(!isMainThread()); |
1159 |
ASSERT(!isMainThread()); |
| 899 |
LOG(IndexedDB, "UniqueIDBDatabase::abortTransaction - %s", transaction.info().identifier().loggingString().utf8().data()); |
1160 |
LOG(IndexedDB, "UniqueIDBDatabase::abortTransaction - %s", transaction.info().identifier().loggingString().utf8().data()); |
| 900 |
|
1161 |
|
|
|
1162 |
if (!spaceCheckResult) { |
| 1163 |
if (!m_manager) |
| 1164 |
return callback(IDBError { InvalidStateError }); |
| 1165 |
|
| 1166 |
m_manager->requestSpace(m_identifier.origin(), 0, [this, weakThis = WeakPtr { *this }, weakTransaction = WeakPtr { transaction }, callback = WTFMove(callback)](bool granted) mutable { |
| 1167 |
if (!weakThis || !weakTransaction) |
| 1168 |
return callback(IDBError { InvalidStateError, "Database or transaction is closed" }); |
| 1169 |
|
| 1170 |
abortTransaction(*weakTransaction, WTFMove(callback), granted); |
| 1171 |
}); |
| 1172 |
return; |
| 1173 |
} |
| 1174 |
|
| 1175 |
ASSERT(spaceCheckResult.value()); |
| 901 |
ASSERT(transaction.databaseConnection().database() == this); |
1176 |
ASSERT(transaction.databaseConnection().database() == this); |
| 902 |
|
1177 |
|
| 903 |
auto takenTransaction = m_inProgressTransactions.take(transaction.info().identifier()); |
1178 |
auto takenTransaction = m_inProgressTransactions.take(transaction.info().identifier()); |
|
Lines 925-931
void UniqueIDBDatabase::abortTransaction(UniqueIDBDatabaseTransaction& transacti
a/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp_sec22
|
| 925 |
m_databaseInfo = makeUnique<IDBDatabaseInfo>(*m_versionChangeTransaction->originalDatabaseInfo()); |
1200 |
m_databaseInfo = makeUnique<IDBDatabaseInfo>(*m_versionChangeTransaction->originalDatabaseInfo()); |
| 926 |
} |
1201 |
} |
| 927 |
|
1202 |
|
| 928 |
auto error = m_backingStore->abortTransaction(transactionIdentifier); |
1203 |
IDBError error; |
|
|
1204 |
if (!m_backingStore) |
| 1205 |
error = IDBError { InvalidStateError, "Backing store is closed" }; |
| 1206 |
else |
| 1207 |
error = m_backingStore->abortTransaction(transactionIdentifier); |
| 929 |
|
1208 |
|
| 930 |
callback(error); |
1209 |
callback(error); |
| 931 |
transactionCompleted(WTFMove(takenTransaction)); |
1210 |
transactionCompleted(WTFMove(takenTransaction)); |
|
Lines 1204-1209
void UniqueIDBDatabase::abortActiveTransactions()
a/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp_sec23
|
| 1204 |
} |
1483 |
} |
| 1205 |
} |
1484 |
} |
| 1206 |
|
1485 |
|
|
|
1486 |
void UniqueIDBDatabase::abortInProgressTransactions() |
| 1487 |
{ |
| 1488 |
for (auto& identifier : copyToVector(m_inProgressTransactions.keys())) |
| 1489 |
m_inProgressTransactions.get(identifier)->abortWithoutCallback(); |
| 1490 |
} |
| 1491 |
|
| 1207 |
void UniqueIDBDatabase::close() |
1492 |
void UniqueIDBDatabase::close() |
| 1208 |
{ |
1493 |
{ |
| 1209 |
LOG(IndexedDB, "UniqueIDBDatabase::close"); |
1494 |
LOG(IndexedDB, "UniqueIDBDatabase::close"); |
|
Lines 1213-1219
void UniqueIDBDatabase::close()
a/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp_sec24
|
| 1213 |
m_backingStore = nullptr; |
1498 |
m_backingStore = nullptr; |
| 1214 |
} |
1499 |
} |
| 1215 |
} |
1500 |
} |
| 1216 |
|
1501 |
|
| 1217 |
bool UniqueIDBDatabase::tryClose() |
1502 |
bool UniqueIDBDatabase::tryClose() |
| 1218 |
{ |
1503 |
{ |
| 1219 |
if (m_backingStore && m_backingStore->isEphemeral()) |
1504 |
if (m_backingStore && m_backingStore->isEphemeral()) |
|
Lines 1225-1230
bool UniqueIDBDatabase::tryClose()
a/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp_sec25
|
| 1225 |
close(); |
1510 |
close(); |
| 1226 |
return true; |
1511 |
return true; |
| 1227 |
} |
1512 |
} |
|
|
1513 |
|
| 1514 |
bool UniqueIDBDatabase::hasDataInMemory() const |
| 1515 |
{ |
| 1516 |
return m_backingStore ? m_backingStore->isEphemeral() : false; |
| 1517 |
} |
| 1228 |
|
1518 |
|
| 1229 |
RefPtr<ServerOpenDBRequest> UniqueIDBDatabase::takeNextRunnableRequest(RequestType requestType) |
1519 |
RefPtr<ServerOpenDBRequest> UniqueIDBDatabase::takeNextRunnableRequest(RequestType requestType) |
| 1230 |
{ |
1520 |
{ |