IDBCursorBackendOperations.cpp [plain text]
#include "config.h"
#include "IDBCursorBackendOperations.h"
#include "IDBServerConnection.h"
#if ENABLE(INDEXED_DATABASE)
#include "Logging.h"
namespace WebCore {
void CursorAdvanceOperation::perform(std::function<void()> completionCallback)
{
LOG(StorageAPI, "CursorAdvanceOperation");
RefPtr<CursorAdvanceOperation> operation(this);
auto callback = [this, operation, completionCallback](PassRefPtr<IDBKey> key, PassRefPtr<IDBKey> primaryKey, PassRefPtr<SharedBuffer> valueBuffer, PassRefPtr<IDBDatabaseError> error) {
if (error) {
m_cursor->clear();
m_callbacks->onError(error);
} else if (!key) {
m_cursor->clear();
m_callbacks->onSuccess(static_cast<SharedBuffer*>(nullptr));
} else {
m_cursor->updateCursorData(key.get(), primaryKey.get(), valueBuffer.get());
m_callbacks->onSuccess(key, primaryKey, valueBuffer);
}
completionCallback();
};
m_cursor->transaction().database().serverConnection().cursorAdvance(*m_cursor, *this, callback);
}
void CursorIterationOperation::perform(std::function<void()> completionCallback)
{
LOG(StorageAPI, "CursorIterationOperation");
RefPtr<CursorIterationOperation> operation(this);
auto callback = [this, operation, completionCallback](PassRefPtr<IDBKey> key, PassRefPtr<IDBKey> primaryKey, PassRefPtr<SharedBuffer> valueBuffer, PassRefPtr<IDBDatabaseError> error) {
if (error) {
m_cursor->clear();
m_callbacks->onError(error);
} else if (!key) {
m_cursor->clear();
m_callbacks->onSuccess(static_cast<SharedBuffer*>(nullptr));
} else {
m_cursor->updateCursorData(key.get(), primaryKey.get(), valueBuffer.get());
m_callbacks->onSuccess(key, primaryKey, valueBuffer);
}
completionCallback();
};
m_cursor->transaction().database().serverConnection().cursorIterate(*m_cursor, *this, callback);
}
}
#endif // ENABLED(INDEXED_DATABASE)