+2012-05-16 Joshua Bell <jsbell@chromium.org>
+
+ IndexedDB: Use accessors for backing store / database id in store/index backends
+ https://bugs.webkit.org/show_bug.cgi?id=86652
+
+ Reviewed by Tony Chang.
+
+ Hide the private members m_backingStore and m_databaseId of IDBObjectStoreBackendImpl
+ and IDBIndexBackendImpl behind accessors. This is preparation for removing these
+ members and only holding references to the IDBDatabaseBackendImpl: webkit.org/b/83074
+
+ No new tests - no functional changes.
+
+ * Modules/indexeddb/IDBIndexBackendImpl.cpp:
+ (WebCore::IDBIndexBackendImpl::openCursorInternal):
+ (WebCore::IDBIndexBackendImpl::countInternal):
+ (WebCore::IDBIndexBackendImpl::getInternal):
+ (WebCore::IDBIndexBackendImpl::getByRangeInternal):
+ (WebCore::IDBIndexBackendImpl::getKeyInternal):
+ (WebCore::IDBIndexBackendImpl::getKeyByRangeInternal):
+ (WebCore::IDBIndexBackendImpl::addingKeyAllowed):
+ * Modules/indexeddb/IDBIndexBackendImpl.h:
+ (WebCore::IDBIndexBackendImpl::backingStore): Added.
+ (WebCore::IDBIndexBackendImpl::databaseId): Added.
+ (IDBIndexBackendImpl):
+ * Modules/indexeddb/IDBObjectStoreBackendImpl.cpp:
+ (WebCore::IDBObjectStoreBackendImpl::getByRangeInternal):
+ (WebCore::IDBObjectStoreBackendImpl::getInternal):
+ (WebCore::IDBObjectStoreBackendImpl::putInternal):
+ (WebCore::IDBObjectStoreBackendImpl::deleteInternal):
+ (WebCore::IDBObjectStoreBackendImpl::clearInternal):
+ (WebCore):
+ (WebCore::IDBObjectStoreBackendImpl::createIndex):
+ (WebCore::IDBObjectStoreBackendImpl::createIndexInternal):
+ (WebCore::IDBObjectStoreBackendImpl::deleteIndexInternal):
+ (WebCore::IDBObjectStoreBackendImpl::openCursorInternal):
+ (WebCore::IDBObjectStoreBackendImpl::countInternal):
+ (WebCore::IDBObjectStoreBackendImpl::loadIndexes):
+ (WebCore::IDBObjectStoreBackendImpl::genAutoIncrementKey):
+ * Modules/indexeddb/IDBObjectStoreBackendImpl.h:
+ (WebCore::IDBObjectStoreBackendImpl::backingStore): Added.
+ (WebCore::IDBObjectStoreBackendImpl::databaseId): Added.
+ (IDBObjectStoreBackendImpl):
+
2012-05-15 Peter Kasting <pkasting@google.com>
Malformed GIF can cause decoder to read off end of heap buffer
switch (cursorType) {
case IDBCursorBackendInterface::IndexKeyCursor:
- backingStoreCursor = index->m_backingStore->openIndexKeyCursor(index->m_databaseId, index->m_objectStoreBackend->id(), index->id(), range.get(), direction);
+ backingStoreCursor = index->backingStore()->openIndexKeyCursor(index->databaseId(), index->m_objectStoreBackend->id(), index->id(), range.get(), direction);
break;
case IDBCursorBackendInterface::IndexCursor:
- backingStoreCursor = index->m_backingStore->openIndexCursor(index->m_databaseId, index->m_objectStoreBackend->id(), index->id(), range.get(), direction);
+ backingStoreCursor = index->backingStore()->openIndexCursor(index->databaseId(), index->m_objectStoreBackend->id(), index->id(), range.get(), direction);
break;
case IDBCursorBackendInterface::ObjectStoreCursor:
case IDBCursorBackendInterface::InvalidCursorType:
IDB_TRACE("IDBIndexBackendImpl::countInternal");
uint32_t count = 0;
- RefPtr<IDBBackingStore::Cursor> backingStoreCursor = index->m_backingStore->openIndexKeyCursor(index->m_databaseId, index->m_objectStoreBackend->id(), index->id(), range.get(), IDBCursor::NEXT);
+ RefPtr<IDBBackingStore::Cursor> backingStoreCursor = index->backingStore()->openIndexKeyCursor(index->databaseId(), index->m_objectStoreBackend->id(), index->id(), range.get(), IDBCursor::NEXT);
if (!backingStoreCursor) {
callbacks->onSuccess(SerializedScriptValue::numberValue(count));
return;
void IDBIndexBackendImpl::getInternal(ScriptExecutionContext*, PassRefPtr<IDBIndexBackendImpl> index, PassRefPtr<IDBKey> key, PassRefPtr<IDBCallbacks> callbacks)
{
IDB_TRACE("IDBIndexBackendImpl::getInternal");
- String value = index->m_backingStore->getObjectViaIndex(index->m_databaseId, index->m_objectStoreBackend->id(), index->id(), *key);
+ String value = index->backingStore()->getObjectViaIndex(index->databaseId(), index->m_objectStoreBackend->id(), index->id(), *key);
if (value.isNull()) {
callbacks->onSuccess(SerializedScriptValue::undefinedValue());
return;
IDB_TRACE("IDBIndexBackendImpl::getByRangeInternal");
RefPtr<IDBBackingStore::Cursor> backingStoreCursor =
- index->m_backingStore->openIndexCursor(index->m_databaseId, index->m_objectStoreBackend->id(), index->id(), keyRange.get(), IDBCursor::NEXT);
+ index->backingStore()->openIndexCursor(index->databaseId(), index->m_objectStoreBackend->id(), index->id(), keyRange.get(), IDBCursor::NEXT);
if (!backingStoreCursor) {
callbacks->onSuccess(SerializedScriptValue::undefinedValue());
return;
}
- String value = index->m_backingStore->getObjectViaIndex(index->m_databaseId, index->m_objectStoreBackend->id(), index->id(), *backingStoreCursor->key());
+ String value = index->backingStore()->getObjectViaIndex(index->databaseId(), index->m_objectStoreBackend->id(), index->id(), *backingStoreCursor->key());
if (value.isNull()) {
callbacks->onSuccess(SerializedScriptValue::undefinedValue());
backingStoreCursor->close();
void IDBIndexBackendImpl::getKeyInternal(ScriptExecutionContext*, PassRefPtr<IDBIndexBackendImpl> index, PassRefPtr<IDBKey> key, PassRefPtr<IDBCallbacks> callbacks)
{
IDB_TRACE("IDBIndexBackendImpl::getKeyInternal");
- RefPtr<IDBKey> keyResult = index->m_backingStore->getPrimaryKeyViaIndex(index->m_databaseId, index->m_objectStoreBackend->id(), index->id(), *key);
+ RefPtr<IDBKey> keyResult = index->backingStore()->getPrimaryKeyViaIndex(index->databaseId(), index->m_objectStoreBackend->id(), index->id(), *key);
if (!keyResult) {
callbacks->onSuccess(static_cast<IDBKey*>(0));
return;
IDB_TRACE("IDBIndexBackendImpl::getByRangeInternal");
RefPtr<IDBBackingStore::Cursor> backingStoreCursor =
- index->m_backingStore->openIndexKeyCursor(index->m_databaseId, index->m_objectStoreBackend->id(), index->id(), keyRange.get(), IDBCursor::NEXT);
+ index->backingStore()->openIndexKeyCursor(index->databaseId(), index->m_objectStoreBackend->id(), index->id(), keyRange.get(), IDBCursor::NEXT);
if (!backingStoreCursor) {
callbacks->onSuccess(static_cast<IDBKey*>(0));
return;
}
- RefPtr<IDBKey> keyResult = index->m_backingStore->getPrimaryKeyViaIndex(index->m_databaseId, index->m_objectStoreBackend->id(), index->id(), *backingStoreCursor->key());
+ RefPtr<IDBKey> keyResult = index->backingStore()->getPrimaryKeyViaIndex(index->databaseId(), index->m_objectStoreBackend->id(), index->id(), *backingStoreCursor->key());
if (!keyResult) {
callbacks->onSuccess(static_cast<IDBKey*>(0));
backingStoreCursor->close();
return true;
RefPtr<IDBKey> foundPrimaryKey;
- bool found = m_backingStore->keyExistsInIndex(m_databaseId, m_objectStoreBackend->id(), m_id, *indexKey, foundPrimaryKey);
+ bool found = backingStore()->keyExistsInIndex(databaseId(), m_objectStoreBackend->id(), m_id, *indexKey, foundPrimaryKey);
if (!found)
return true;
if (primaryKey && foundPrimaryKey->isEqual(primaryKey))
void IDBObjectStoreBackendImpl::getByRangeInternal(ScriptExecutionContext*, PassRefPtr<IDBObjectStoreBackendImpl> objectStore, PassRefPtr<IDBKeyRange> keyRange, PassRefPtr<IDBCallbacks> callbacks)
{
IDB_TRACE("IDBObjectStoreBackendImpl::getByRangeInternal");
- RefPtr<IDBBackingStore::Cursor> backingStoreCursor = objectStore->m_backingStore->openObjectStoreCursor(objectStore->m_databaseId, objectStore->id(), keyRange.get(), IDBCursor::NEXT);
+ RefPtr<IDBBackingStore::Cursor> backingStoreCursor = objectStore->backingStore()->openObjectStoreCursor(objectStore->databaseId(), objectStore->id(), keyRange.get(), IDBCursor::NEXT);
if (!backingStoreCursor) {
callbacks->onSuccess(SerializedScriptValue::undefinedValue());
return;
}
- String wireData = objectStore->m_backingStore->getObjectStoreRecord(objectStore->m_databaseId, objectStore->id(), *backingStoreCursor->key());
+ String wireData = objectStore->backingStore()->getObjectStoreRecord(objectStore->databaseId(), objectStore->id(), *backingStoreCursor->key());
if (wireData.isNull()) {
callbacks->onSuccess(SerializedScriptValue::undefinedValue());
backingStoreCursor->close();
void IDBObjectStoreBackendImpl::getInternal(ScriptExecutionContext*, PassRefPtr<IDBObjectStoreBackendImpl> objectStore, PassRefPtr<IDBKey> key, PassRefPtr<IDBCallbacks> callbacks)
{
IDB_TRACE("IDBObjectStoreBackendImpl::getInternal");
- String wireData = objectStore->m_backingStore->getObjectStoreRecord(objectStore->m_databaseId, objectStore->id(), *key);
+ String wireData = objectStore->backingStore()->getObjectStoreRecord(objectStore->databaseId(), objectStore->id(), *key);
if (wireData.isNull()) {
callbacks->onSuccess(SerializedScriptValue::undefinedValue());
return;
ASSERT(key && key->valid());
- RefPtr<IDBBackingStore::ObjectStoreRecordIdentifier> recordIdentifier = objectStore->m_backingStore->createInvalidRecordIdentifier();
- if (putMode == AddOnly && objectStore->m_backingStore->keyExistsInObjectStore(objectStore->m_databaseId, objectStore->id(), *key, recordIdentifier.get())) {
+ RefPtr<IDBBackingStore::ObjectStoreRecordIdentifier> recordIdentifier = objectStore->backingStore()->createInvalidRecordIdentifier();
+ if (putMode == AddOnly && objectStore->backingStore()->keyExistsInObjectStore(objectStore->databaseId(), objectStore->id(), *key, recordIdentifier.get())) {
objectStore->resetAutoIncrementKeyCache();
callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::CONSTRAINT_ERR, "Key already exists in the object store."));
return;
// Before this point, don't do any mutation. After this point, rollback the transaction in case of error.
- if (!objectStore->m_backingStore->putObjectStoreRecord(objectStore->m_databaseId, objectStore->id(), *key, value->toWireString(), recordIdentifier.get())) {
+ if (!objectStore->backingStore()->putObjectStoreRecord(objectStore->databaseId(), objectStore->id(), *key, value->toWireString(), recordIdentifier.get())) {
// FIXME: The Indexed Database specification does not have an error code dedicated to I/O errors.
callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "Error writing data to stable storage."));
transaction->abort();
if (!index->hasValidId())
continue; // The index object has been created, but does not exist in the database yet.
- if (!objectStore->m_backingStore->deleteIndexDataForRecord(objectStore->m_databaseId, objectStore->id(), index->id(), recordIdentifier.get())) {
+ if (!objectStore->backingStore()->deleteIndexDataForRecord(objectStore->databaseId(), objectStore->id(), index->id(), recordIdentifier.get())) {
// FIXME: The Indexed Database specification does not have an error code dedicated to I/O errors.
callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "Error writing data to stable storage."));
transaction->abort();
RefPtr<IDBKey> indexKey = indexKeys[i];
if (!index->multiEntry() || indexKey->type() != IDBKey::ArrayType) {
- if (!objectStore->m_backingStore->putIndexDataForRecord(objectStore->m_databaseId, objectStore->id(), index->id(), *indexKey, recordIdentifier.get())) {
+ if (!objectStore->backingStore()->putIndexDataForRecord(objectStore->databaseId(), objectStore->id(), index->id(), *indexKey, recordIdentifier.get())) {
// FIXME: The Indexed Database specification does not have an error code dedicated to I/O errors.
callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "Error writing data to stable storage."));
transaction->abort();
ASSERT(index->multiEntry());
ASSERT(indexKey->type() == IDBKey::ArrayType);
for (size_t j = 0; j < indexKey->array().size(); ++j) {
- if (!objectStore->m_backingStore->putIndexDataForRecord(objectStore->m_databaseId, objectStore->id(), index->id(), *indexKey->array()[j], recordIdentifier.get())) {
+ if (!objectStore->backingStore()->putIndexDataForRecord(objectStore->databaseId(), objectStore->id(), index->id(), *indexKey->array()[j], recordIdentifier.get())) {
// FIXME: The Indexed Database specification does not have an error code dedicated to I/O errors.
callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "Error writing data to stable storage."));
transaction->abort();
IDB_TRACE("IDBObjectStoreBackendImpl::deleteInternal");
RefPtr<IDBBackingStore::ObjectStoreRecordIdentifier> recordIdentifier;
- RefPtr<IDBBackingStore::Cursor> backingStoreCursor = objectStore->m_backingStore->openObjectStoreCursor(objectStore->m_databaseId, objectStore->id(), keyRange.get(), IDBCursor::NEXT);
+ RefPtr<IDBBackingStore::Cursor> backingStoreCursor = objectStore->backingStore()->openObjectStoreCursor(objectStore->databaseId(), objectStore->id(), keyRange.get(), IDBCursor::NEXT);
if (backingStoreCursor) {
do {
if (!it->second->hasValidId())
continue; // The index object has been created, but does not exist in the database yet.
- bool success = objectStore->m_backingStore->deleteIndexDataForRecord(objectStore->m_databaseId, objectStore->id(), it->second->id(), recordIdentifier.get());
+ bool success = objectStore->backingStore()->deleteIndexDataForRecord(objectStore->databaseId(), objectStore->id(), it->second->id(), recordIdentifier.get());
ASSERT_UNUSED(success, success);
}
- objectStore->m_backingStore->deleteObjectStoreRecord(objectStore->m_databaseId, objectStore->id(), recordIdentifier.get());
+ objectStore->backingStore()->deleteObjectStoreRecord(objectStore->databaseId(), objectStore->id(), recordIdentifier.get());
} while (backingStoreCursor->continueFunction(0));
void IDBObjectStoreBackendImpl::clearInternal(ScriptExecutionContext*, PassRefPtr<IDBObjectStoreBackendImpl> objectStore, PassRefPtr<IDBCallbacks> callbacks)
{
- objectStore->m_backingStore->clearObjectStore(objectStore->m_databaseId, objectStore->id());
+ objectStore->backingStore()->clearObjectStore(objectStore->databaseId(), objectStore->id());
callbacks->onSuccess(SerializedScriptValue::undefinedValue());
}
return 0;
}
- RefPtr<IDBIndexBackendImpl> index = IDBIndexBackendImpl::create(m_backingStore.get(), m_databaseId, this, name, m_name, keyPath, unique, multiEntry);
+ RefPtr<IDBIndexBackendImpl> index = IDBIndexBackendImpl::create(backingStore().get(), databaseId(), this, name, m_name, keyPath, unique, multiEntry);
ASSERT(index->name() == name);
RefPtr<IDBObjectStoreBackendImpl> objectStore = this;
void IDBObjectStoreBackendImpl::createIndexInternal(ScriptExecutionContext*, PassRefPtr<IDBObjectStoreBackendImpl> objectStore, PassRefPtr<IDBIndexBackendImpl> index, PassRefPtr<IDBTransactionBackendInterface> transaction)
{
int64_t id;
- if (!objectStore->m_backingStore->createIndex(objectStore->m_databaseId, objectStore->id(), index->name(), index->keyPath(), index->unique(), index->multiEntry(), id)) {
+ if (!objectStore->backingStore()->createIndex(objectStore->databaseId(), objectStore->id(), index->name(), index->keyPath(), index->unique(), index->multiEntry(), id)) {
transaction->abort();
return;
}
index->setId(id);
- if (!populateIndex(*objectStore->m_backingStore, objectStore->m_databaseId, objectStore->m_id, index)) {
+ if (!populateIndex(*objectStore->backingStore(), objectStore->databaseId(), objectStore->m_id, index)) {
transaction->abort();
return;
}
void IDBObjectStoreBackendImpl::deleteIndexInternal(ScriptExecutionContext*, PassRefPtr<IDBObjectStoreBackendImpl> objectStore, PassRefPtr<IDBIndexBackendImpl> index, PassRefPtr<IDBTransactionBackendInterface> transaction)
{
- objectStore->m_backingStore->deleteIndex(objectStore->m_databaseId, objectStore->id(), index->id());
+ objectStore->backingStore()->deleteIndex(objectStore->databaseId(), objectStore->id(), index->id());
transaction->didCompleteTaskEvents();
}
IDB_TRACE("IDBObjectStoreBackendImpl::openCursorInternal");
IDBCursor::Direction direction = static_cast<IDBCursor::Direction>(tmpDirection);
- RefPtr<IDBBackingStore::Cursor> backingStoreCursor = objectStore->m_backingStore->openObjectStoreCursor(objectStore->m_databaseId, objectStore->id(), range.get(), direction);
+ RefPtr<IDBBackingStore::Cursor> backingStoreCursor = objectStore->backingStore()->openObjectStoreCursor(objectStore->databaseId(), objectStore->id(), range.get(), direction);
if (!backingStoreCursor) {
callbacks->onSuccess(SerializedScriptValue::nullValue());
return;
{
IDB_TRACE("IDBObjectStoreBackendImpl::countInternal");
uint32_t count = 0;
- RefPtr<IDBBackingStore::Cursor> backingStoreCursor = objectStore->m_backingStore->openObjectStoreCursor(objectStore->m_databaseId, objectStore->id(), range.get(), IDBCursor::NEXT);
+ RefPtr<IDBBackingStore::Cursor> backingStoreCursor = objectStore->backingStore()->openObjectStoreCursor(objectStore->databaseId(), objectStore->id(), range.get(), IDBCursor::NEXT);
if (!backingStoreCursor) {
callbacks->onSuccess(SerializedScriptValue::numberValue(count));
return;
Vector<String> keyPaths;
Vector<bool> uniqueFlags;
Vector<bool> multiEntryFlags;
- m_backingStore->getIndexes(m_databaseId, m_id, ids, names, keyPaths, uniqueFlags, multiEntryFlags);
+ backingStore()->getIndexes(databaseId(), m_id, ids, names, keyPaths, uniqueFlags, multiEntryFlags);
ASSERT(names.size() == ids.size());
ASSERT(keyPaths.size() == ids.size());
ASSERT(multiEntryFlags.size() == ids.size());
for (size_t i = 0; i < ids.size(); i++)
- m_indexes.set(names[i], IDBIndexBackendImpl::create(m_backingStore.get(), m_databaseId, this, ids[i], names[i], m_name, keyPaths[i], uniqueFlags[i], multiEntryFlags[i]));
+ m_indexes.set(names[i], IDBIndexBackendImpl::create(backingStore().get(), databaseId(), this, ids[i], names[i], m_name, keyPaths[i], uniqueFlags[i], multiEntryFlags[i]));
}
void IDBObjectStoreBackendImpl::removeIndexFromMap(ScriptExecutionContext*, PassRefPtr<IDBObjectStoreBackendImpl> objectStore, PassRefPtr<IDBIndexBackendImpl> index)
if (m_autoIncrementNumber > 0)
return IDBKey::createNumber(m_autoIncrementNumber++);
- m_autoIncrementNumber = m_backingStore->nextAutoIncrementNumber(m_databaseId, id());
+ m_autoIncrementNumber = backingStore()->nextAutoIncrementNumber(databaseId(), id());
if (m_autoIncrementNumber > kMaxGeneratorValue)
return IDBKey::createInvalid();
return IDBKey::createNumber(m_autoIncrementNumber++);