diff options
author | Ben Murdoch <benm@google.com> | 2010-10-22 13:02:20 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2010-10-26 15:21:41 +0100 |
commit | a94275402997c11dd2e778633dacf4b7e630a35d (patch) | |
tree | e66f56c67e3b01f22c9c23cd932271ee9ac558ed /WebCore/storage/IDBIndexBackendImpl.cpp | |
parent | 09e26c78506587b3f5d930d7bc72a23287ffbec0 (diff) | |
download | external_webkit-a94275402997c11dd2e778633dacf4b7e630a35d.zip external_webkit-a94275402997c11dd2e778633dacf4b7e630a35d.tar.gz external_webkit-a94275402997c11dd2e778633dacf4b7e630a35d.tar.bz2 |
Merge WebKit at r70209: Initial merge by Git
Change-Id: Id23a68efa36e9d1126bcce0b137872db00892c8e
Diffstat (limited to 'WebCore/storage/IDBIndexBackendImpl.cpp')
-rw-r--r-- | WebCore/storage/IDBIndexBackendImpl.cpp | 56 |
1 files changed, 42 insertions, 14 deletions
diff --git a/WebCore/storage/IDBIndexBackendImpl.cpp b/WebCore/storage/IDBIndexBackendImpl.cpp index 6f698c6..2a991fa 100644 --- a/WebCore/storage/IDBIndexBackendImpl.cpp +++ b/WebCore/storage/IDBIndexBackendImpl.cpp @@ -28,6 +28,7 @@ #if ENABLE(INDEXED_DATABASE) +#include "CrossThreadTask.h" #include "IDBCallbacks.h" #include "IDBCursorBackendImpl.h" #include "IDBDatabaseBackendImpl.h" @@ -49,6 +50,15 @@ IDBIndexBackendImpl::IDBIndexBackendImpl(IDBObjectStoreBackendImpl* objectStore, { } +IDBIndexBackendImpl::IDBIndexBackendImpl(IDBObjectStoreBackendImpl* objectStore, const String& name, const String& keyPath, bool unique) + : m_objectStore(objectStore) + , m_id(InvalidId) + , m_name(name) + , m_keyPath(keyPath) + , m_unique(unique) +{ +} + IDBIndexBackendImpl::~IDBIndexBackendImpl() { } @@ -58,7 +68,7 @@ String IDBIndexBackendImpl::storeName() return m_objectStore->name(); } -static void openCursorInternal(SQLiteDatabase& database, IDBIndexBackendImpl* index, IDBKeyRange* range, unsigned short untypedDirection, bool objectCursor, IDBCallbacks* callbacks) +void IDBIndexBackendImpl::openCursorInternal(ScriptExecutionContext*, PassRefPtr<IDBIndexBackendImpl> index, PassRefPtr<IDBKeyRange> range, unsigned short untypedDirection, bool objectCursor, PassRefPtr<IDBCallbacks> callbacks, PassRefPtr<IDBTransactionBackendInterface> transaction) { // Several files depend on this order of selects. String sql = String("SELECT IndexData.id, IndexData.keyString, IndexData.keyDate, IndexData.keyNumber, ") @@ -80,7 +90,7 @@ static void openCursorInternal(SQLiteDatabase& database, IDBIndexBackendImpl* in else sql += "IndexData.keyString DESC, IndexData.keyDate DESC, IndexData.keyNumber DESC, IndexData.id DESC"; - OwnPtr<SQLiteStatement> query = adoptPtr(new SQLiteStatement(database, sql)); + OwnPtr<SQLiteStatement> query = adoptPtr(new SQLiteStatement(index->sqliteDatabase(), sql)); bool ok = query->prepare() == SQLResultOk; ASSERT_UNUSED(ok, ok); // FIXME: Better error handling? @@ -96,32 +106,42 @@ static void openCursorInternal(SQLiteDatabase& database, IDBIndexBackendImpl* in return; } - RefPtr<IDBCursorBackendInterface> cursor = IDBCursorBackendImpl::create(index, range, direction, query.release(), objectCursor); + RefPtr<IDBCursorBackendInterface> cursor = IDBCursorBackendImpl::create(index, range, direction, query.release(), objectCursor, transaction.get()); callbacks->onSuccess(cursor.release()); } -void IDBIndexBackendImpl::openObjectCursor(PassRefPtr<IDBKeyRange> keyRange, unsigned short direction, PassRefPtr<IDBCallbacks> callbacks) +void IDBIndexBackendImpl::openCursor(PassRefPtr<IDBKeyRange> prpKeyRange, unsigned short direction, PassRefPtr<IDBCallbacks> prpCallbacks, IDBTransactionBackendInterface* transactionPtr, ExceptionCode& ec) { - openCursorInternal(sqliteDatabase(), this, keyRange.get(), direction, true, callbacks.get()); + RefPtr<IDBIndexBackendImpl> index = this; + RefPtr<IDBKeyRange> keyRange = prpKeyRange; + RefPtr<IDBCallbacks> callbacks = prpCallbacks; + RefPtr<IDBTransactionBackendInterface> transaction = transactionPtr; + if (!transaction->scheduleTask(createCallbackTask(&openCursorInternal, index, keyRange, direction, true, callbacks, transaction))) + ec = IDBDatabaseException::NOT_ALLOWED_ERR; } -void IDBIndexBackendImpl::openCursor(PassRefPtr<IDBKeyRange> keyRange, unsigned short direction, PassRefPtr<IDBCallbacks> callbacks) +void IDBIndexBackendImpl::openKeyCursor(PassRefPtr<IDBKeyRange> prpKeyRange, unsigned short direction, PassRefPtr<IDBCallbacks> prpCallbacks, IDBTransactionBackendInterface* transactionPtr, ExceptionCode& ec) { - openCursorInternal(sqliteDatabase(), this, keyRange.get(), direction, false, callbacks.get()); + RefPtr<IDBIndexBackendImpl> index = this; + RefPtr<IDBKeyRange> keyRange = prpKeyRange; + RefPtr<IDBCallbacks> callbacks = prpCallbacks; + RefPtr<IDBTransactionBackendInterface> transaction = transactionPtr; + if (!transaction->scheduleTask(createCallbackTask(&openCursorInternal, index, keyRange, direction, false, callbacks, transaction))) + ec = IDBDatabaseException::NOT_ALLOWED_ERR; } -static void getInternal(SQLiteDatabase& database, int64 id, IDBKey* key, bool getObject, IDBCallbacks* callbacks) +void IDBIndexBackendImpl::getInternal(ScriptExecutionContext*, PassRefPtr<IDBIndexBackendImpl> index, PassRefPtr<IDBKey> key, bool getObject, PassRefPtr<IDBCallbacks> callbacks) { String sql = String("SELECT ") + (getObject ? "ObjectStoreData.value " : "ObjectStoreData.keyString, ObjectStoreData.keyDate, ObjectStoreData.keyNumber ") + "FROM IndexData INNER JOIN ObjectStoreData ON IndexData.objectStoreDataId = ObjectStoreData.id " + "WHERE IndexData.indexId = ? AND " + key->whereSyntax("IndexData.") + "ORDER BY IndexData.id LIMIT 1"; // Order by insertion order when all else fails. - SQLiteStatement query(database, sql); + SQLiteStatement query(index->sqliteDatabase(), sql); bool ok = query.prepare() == SQLResultOk; ASSERT_UNUSED(ok, ok); // FIXME: Better error handling? - query.bindInt64(1, id); + query.bindInt64(1, index->id()); key->bind(query, 2); if (query.step() != SQLResultRow) { callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::NOT_FOUND_ERR, "Key does not exist in the index.")); @@ -135,14 +155,22 @@ static void getInternal(SQLiteDatabase& database, int64 id, IDBKey* key, bool ge ASSERT(query.step() != SQLResultRow); } -void IDBIndexBackendImpl::getObject(PassRefPtr<IDBKey> key, PassRefPtr<IDBCallbacks> callbacks) +void IDBIndexBackendImpl::get(PassRefPtr<IDBKey> prpKey, PassRefPtr<IDBCallbacks> prpCallbacks, IDBTransactionBackendInterface* transaction, ExceptionCode& ec) { - getInternal(sqliteDatabase(), m_id, key.get(), true, callbacks.get()); + RefPtr<IDBIndexBackendImpl> index = this; + RefPtr<IDBKey> key = prpKey; + RefPtr<IDBCallbacks> callbacks = prpCallbacks; + if (!transaction->scheduleTask(createCallbackTask(&getInternal, index, key, true, callbacks))) + ec = IDBDatabaseException::NOT_ALLOWED_ERR; } -void IDBIndexBackendImpl::get(PassRefPtr<IDBKey> key, PassRefPtr<IDBCallbacks> callbacks) +void IDBIndexBackendImpl::getKey(PassRefPtr<IDBKey> prpKey, PassRefPtr<IDBCallbacks> prpCallbacks, IDBTransactionBackendInterface* transaction, ExceptionCode& ec) { - getInternal(sqliteDatabase(), m_id, key.get(), false, callbacks.get()); + RefPtr<IDBIndexBackendImpl> index = this; + RefPtr<IDBKey> key = prpKey; + RefPtr<IDBCallbacks> callbacks = prpCallbacks; + if (!transaction->scheduleTask(createCallbackTask(&getInternal, index, key, false, callbacks))) + ec = IDBDatabaseException::NOT_ALLOWED_ERR; } static String whereClause(IDBKey* key) |