IndexedDB: simplify RecordIdentifier
[WebKit-https.git] / Source / WebCore / Modules / indexeddb / IDBBackingStore.cpp
index 6b5a62a..9905d5b 100644 (file)
@@ -27,7 +27,6 @@
 #include "IDBBackingStore.h"
 
 #if ENABLE(INDEXED_DATABASE)
-#if USE(LEVELDB)
 
 #include "FileSystem.h"
 #include "HistogramSupport.h"
@@ -35,7 +34,6 @@
 #include "IDBKey.h"
 #include "IDBKeyPath.h"
 #include "IDBKeyRange.h"
-#include "IDBLevelDBBackingStore.h"
 #include "IDBLevelDBCoding.h"
 #include "IDBMetadata.h"
 #include "IDBTracing.h"
@@ -74,7 +72,7 @@ static inline void recordInternalError(IDBLevelDBBackingStoreInternalErrorType t
     } while (0)
 
 template <typename DBOrTransaction>
-static bool getBool(DBOrTransaction* db, const Vector<char>& key, bool& foundBool)
+static bool getBool(DBOrTransaction* db, const LevelDBSlice& key, bool& foundBool)
 {
     Vector<char> result;
     if (!db->get(key, result))
@@ -84,14 +82,13 @@ static bool getBool(DBOrTransaction* db, const Vector<char>& key, bool& foundBoo
     return true;
 }
 
-template <typename DBOrTransaction>
-static bool putBool(DBOrTransaction* db, const Vector<char>& key, bool value)
+static void putBool(LevelDBTransaction* transaction, const LevelDBSlice& key, bool value)
 {
-    return db->put(key, encodeBool(value));
+    transaction->put(key, encodeBool(value));
 }
 
 template <typename DBOrTransaction>
-static bool getInt(DBOrTransaction* db, const Vector<char>& key, int64_t& foundInt)
+static bool getInt(DBOrTransaction* db, const LevelDBSlice& key, int64_t& foundInt)
 {
     Vector<char> result;
     if (!db->get(key, result))
@@ -101,17 +98,14 @@ static bool getInt(DBOrTransaction* db, const Vector<char>& key, int64_t& foundI
     return true;
 }
 
-template <typename DBOrTransaction>
-static bool putInt(DBOrTransaction* db, const Vector<char>& key, int64_t value)
+static void putInt(LevelDBTransaction* transaction, const LevelDBSlice& key, int64_t value)
 {
     ASSERT(value >= 0);
-    if (value < 0)
-        return false;
-    return db->put(key, encodeInt(value));
+    transaction->put(key, encodeInt(value));
 }
 
 template <typename DBOrTransaction>
-static bool getVarInt(DBOrTransaction* db, const Vector<char>& key, int64_t& foundInt)
+static bool getVarInt(DBOrTransaction* db, const LevelDBSlice& key, int64_t& foundInt)
 {
     Vector<char> result;
     if (!db->get(key, result))
@@ -120,14 +114,13 @@ static bool getVarInt(DBOrTransaction* db, const Vector<char>& key, int64_t& fou
     return decodeVarInt(result.begin(), result.end(), foundInt) == result.end();
 }
 
-template <typename DBOrTransaction>
-static bool putVarInt(DBOrTransaction* db, const Vector<char>& key, int64_t value)
+static void putVarInt(LevelDBTransaction* transaction, const LevelDBSlice& key, int64_t value)
 {
-    return db->put(key, encodeVarInt(value));
+    transaction->put(key, encodeVarInt(value));
 }
 
 template <typename DBOrTransaction>
-static bool getString(DBOrTransaction* db, const Vector<char>& key, String& foundString)
+static bool getString(DBOrTransaction* db, const LevelDBSlice& key, String& foundString)
 {
     Vector<char> result;
     if (!db->get(key, result))
@@ -137,20 +130,14 @@ static bool getString(DBOrTransaction* db, const Vector<char>& key, String& foun
     return true;
 }
 
-template <typename DBOrTransaction>
-static bool putString(DBOrTransaction* db, const Vector<char> key, const String& value)
+static void putString(LevelDBTransaction* transaction, const LevelDBSlice& key, const String& value)
 {
-    if (!db->put(key, encodeString(value)))
-        return false;
-    return true;
+    transaction->put(key, encodeString(value));
 }
 
-template <typename DBOrTransaction>
-static bool putIDBKeyPath(DBOrTransaction* db, const Vector<char> key, const IDBKeyPath& value)
+static void putIDBKeyPath(LevelDBTransaction* transaction, const LevelDBSlice& key, const IDBKeyPath& value)
 {
-    if (!db->put(key, encodeIDBKeyPath(value)))
-        return false;
-    return true;
+    transaction->put(key, encodeIDBKeyPath(value));
 }
 
 static int compareKeys(const LevelDBSlice& a, const LevelDBSlice& b)
@@ -182,50 +169,37 @@ static bool isSchemaKnown(LevelDBDatabase* db)
 static bool setUpMetadata(LevelDBDatabase* db, const String& origin)
 {
     const Vector<char> metaDataKey = SchemaVersionKey::encode();
+    RefPtr<LevelDBTransaction> transaction = LevelDBTransaction::create(db);
 
     int64_t schemaVersion = 0;
-    if (!getInt(db, metaDataKey, schemaVersion)) {
+    if (!getInt(transaction.get(), metaDataKey, schemaVersion)) {
         schemaVersion = latestSchemaVersion;
-        if (!putInt(db, metaDataKey, latestSchemaVersion)) {
-            InternalError(IDBLevelDBBackingStoreWriteError);
-            return false;
-        }
+        putInt(transaction.get(), metaDataKey, latestSchemaVersion);
     } else {
         ASSERT(schemaVersion <= latestSchemaVersion);
         if (!schemaVersion) {
             schemaVersion = latestSchemaVersion;
-            RefPtr<LevelDBTransaction> transaction = LevelDBTransaction::create(db);
-            transaction->put(metaDataKey, encodeInt(schemaVersion));
-
+            putInt(transaction.get(), metaDataKey, schemaVersion);
             const Vector<char> startKey = DatabaseNameKey::encodeMinKeyForOrigin(origin);
             const Vector<char> stopKey = DatabaseNameKey::encodeStopKeyForOrigin(origin);
             OwnPtr<LevelDBIterator> it = db->createIterator();
             for (it->seek(startKey); it->isValid() && compareKeys(it->key(), stopKey) < 0; it->next()) {
-                Vector<char> value;
-                bool ok = transaction->get(it->key(), value);
-                if (!ok) {
+                int64_t databaseId = 0;
+                if (!getInt(transaction.get(), it->key(), databaseId)) {
                     InternalError(IDBLevelDBBackingStoreReadError);
                     return false;
                 }
-                int databaseId = decodeInt(value.begin(), value.end());
                 Vector<char> intVersionKey = DatabaseMetaDataKey::encode(databaseId, DatabaseMetaDataKey::UserIntVersion);
-                transaction->put(intVersionKey, encodeVarInt(IDBDatabaseMetadata::DefaultIntVersion));
-                ok = transaction->get(it->key(), value);
-                if (!ok) {
-                    InternalError(IDBLevelDBBackingStoreReadError);
-                    return false;
-                }
-            }
-            bool ok = transaction->commit();
-            if (!ok) {
-                InternalError(IDBLevelDBBackingStoreWriteError);
-                return false;
+                putVarInt(transaction.get(), intVersionKey, IDBDatabaseMetadata::DefaultIntVersion);
             }
         }
     }
 
     ASSERT(schemaVersion == latestSchemaVersion);
-
+    if (!transaction->commit()) {
+        InternalError(IDBLevelDBBackingStoreWriteError);
+        return false;
+    }
     return true;
 }
 
@@ -247,7 +221,7 @@ static int64_t getMaxObjectStoreId(DBOrTransaction* db, const Vector<char>& maxO
     return maxObjectStoreId;
 }
 
-IDBLevelDBBackingStore::IDBLevelDBBackingStore(const String& identifier, IDBFactoryBackendImpl* factory, PassOwnPtr<LevelDBDatabase> db)
+IDBBackingStore::IDBBackingStore(const String& identifier, IDBFactoryBackendImpl* factory, PassOwnPtr<LevelDBDatabase> db)
     : m_identifier(identifier)
     , m_factory(factory)
     , m_db(db)
@@ -255,9 +229,15 @@ IDBLevelDBBackingStore::IDBLevelDBBackingStore(const String& identifier, IDBFact
     m_factory->addIDBBackingStore(identifier, this);
 }
 
-IDBLevelDBBackingStore::~IDBLevelDBBackingStore()
+IDBBackingStore::IDBBackingStore()
+{
+}
+
+IDBBackingStore::~IDBBackingStore()
 {
-    m_factory->removeIDBBackingStore(m_identifier);
+    // Only null in tests.
+    if (m_factory)
+        m_factory->removeIDBBackingStore(m_identifier);
 
     // m_db's destructor uses m_comparator. The order of destruction is important.
     m_db.clear();
@@ -275,9 +255,9 @@ enum IDBLevelDBBackingStoreOpenResult {
     IDBLevelDBBackingStoreOpenMax,
 };
 
-PassRefPtr<IDBBackingStore> IDBLevelDBBackingStore::open(SecurityOrigin* securityOrigin, const String& pathBaseArg, const String& fileIdentifier, IDBFactoryBackendImpl* factory)
+PassRefPtr<IDBBackingStore> IDBBackingStore::open(SecurityOrigin* securityOrigin, const String& pathBaseArg, const String& fileIdentifier, IDBFactoryBackendImpl* factory)
 {
-    IDB_TRACE("IDBLevelDBBackingStore::open");
+    IDB_TRACE("IDBBackingStore::open");
     String pathBase = pathBaseArg;
 
     OwnPtr<LevelDBComparator> comparator = adoptPtr(new Comparator());
@@ -299,7 +279,7 @@ PassRefPtr<IDBBackingStore> IDBLevelDBBackingStore::open(SecurityOrigin* securit
         if (db && !isSchemaKnown(db.get())) {
             LOG_ERROR("IndexedDB backing store had unknown schema, treating it as failure to open");
             HistogramSupport::histogramEnumeration("WebCore.IndexedDB.BackingStore.OpenStatus", IDBLevelDBBackingStoreOpenFailedUnknownSchema, IDBLevelDBBackingStoreOpenMax);
-            db.release();
+            db.clear();
         }
 
         if (db)
@@ -329,7 +309,7 @@ PassRefPtr<IDBBackingStore> IDBLevelDBBackingStore::open(SecurityOrigin* securit
 
     // FIXME: Handle comparator name changes.
 
-    RefPtr<IDBLevelDBBackingStore> backingStore(adoptRef(new IDBLevelDBBackingStore(fileIdentifier, factory, db.release())));
+    RefPtr<IDBBackingStore> backingStore(adoptRef(new IDBBackingStore(fileIdentifier, factory, db.release())));
     backingStore->m_comparator = comparator.release();
 
     if (!setUpMetadata(backingStore->m_db.get(), fileIdentifier))
@@ -338,7 +318,7 @@ PassRefPtr<IDBBackingStore> IDBLevelDBBackingStore::open(SecurityOrigin* securit
     return backingStore.release();
 }
 
-Vector<String> IDBLevelDBBackingStore::getDatabaseNames()
+Vector<String> IDBBackingStore::getDatabaseNames()
 {
     Vector<String> foundNames;
     const Vector<char> startKey = DatabaseNameKey::encodeMinKeyForOrigin(m_identifier);
@@ -360,7 +340,7 @@ Vector<String> IDBLevelDBBackingStore::getDatabaseNames()
     return foundNames;
 }
 
-bool IDBLevelDBBackingStore::getIDBDatabaseMetaData(const String& name, IDBDatabaseMetadata* metadata)
+bool IDBBackingStore::getIDBDatabaseMetaData(const String& name, IDBDatabaseMetadata* metadata)
 {
     const Vector<char> key = DatabaseNameKey::encode(m_identifier, name);
 
@@ -389,82 +369,69 @@ bool IDBLevelDBBackingStore::getIDBDatabaseMetaData(const String& name, IDBDatab
 
 static int64_t getNewDatabaseId(LevelDBDatabase* db)
 {
+    RefPtr<LevelDBTransaction> transaction = LevelDBTransaction::create(db);
+
     int64_t maxDatabaseId = -1;
-    if (!getInt(db, MaxDatabaseIdKey::encode(), maxDatabaseId))
+    if (!getInt(transaction.get(), MaxDatabaseIdKey::encode(), maxDatabaseId))
         maxDatabaseId = 0;
 
     ASSERT(maxDatabaseId >= 0);
 
     int64_t databaseId = maxDatabaseId + 1;
-    if (!putInt(db, MaxDatabaseIdKey::encode(), databaseId))
+    putInt(transaction.get(), MaxDatabaseIdKey::encode(), databaseId);
+    if (!transaction->commit()) {
+        InternalError(IDBLevelDBBackingStoreWriteError);
         return -1;
-
+    }
     return databaseId;
 }
 
-bool IDBLevelDBBackingStore::createIDBDatabaseMetaData(const String& name, const String& version, int64_t intVersion, int64_t& rowId)
+bool IDBBackingStore::createIDBDatabaseMetaData(const String& name, const String& version, int64_t intVersion, int64_t& rowId)
 {
     rowId = getNewDatabaseId(m_db.get());
     if (rowId < 0)
         return false;
 
-    const Vector<char> key = DatabaseNameKey::encode(m_identifier, name);
-    if (!putInt(m_db.get(), key, rowId)) {
-        InternalError(IDBLevelDBBackingStoreWriteError);
-        return false;
-    }
-    if (!putString(m_db.get(), DatabaseMetaDataKey::encode(rowId, DatabaseMetaDataKey::UserVersion), version)) {
-        InternalError(IDBLevelDBBackingStoreWriteError);
-        return false;
-    }
     if (intVersion == IDBDatabaseMetadata::NoIntVersion)
         intVersion = IDBDatabaseMetadata::DefaultIntVersion;
-    if (!putVarInt(m_db.get(), DatabaseMetaDataKey::encode(rowId, DatabaseMetaDataKey::UserIntVersion), intVersion)) {
+
+    RefPtr<LevelDBTransaction> transaction = LevelDBTransaction::create(m_db.get());
+    putInt(transaction.get(), DatabaseNameKey::encode(m_identifier, name), rowId);
+    putString(transaction.get(), DatabaseMetaDataKey::encode(rowId, DatabaseMetaDataKey::UserVersion), version);
+    putVarInt(transaction.get(), DatabaseMetaDataKey::encode(rowId, DatabaseMetaDataKey::UserIntVersion), intVersion);
+    if (!transaction->commit()) {
         InternalError(IDBLevelDBBackingStoreWriteError);
         return false;
     }
     return true;
 }
 
-bool IDBLevelDBBackingStore::updateIDBDatabaseIntVersion(IDBBackingStore::Transaction* transaction, int64_t rowId, int64_t intVersion)
+bool IDBBackingStore::updateIDBDatabaseIntVersion(IDBBackingStore::Transaction* transaction, int64_t rowId, int64_t intVersion)
 {
     if (intVersion == IDBDatabaseMetadata::NoIntVersion)
         intVersion = IDBDatabaseMetadata::DefaultIntVersion;
     ASSERT_WITH_MESSAGE(intVersion >= 0, "intVersion was %lld", static_cast<long long>(intVersion));
-    if (!putVarInt(Transaction::levelDBTransactionFrom(transaction), DatabaseMetaDataKey::encode(rowId, DatabaseMetaDataKey::UserIntVersion), intVersion)) {
-        InternalError(IDBLevelDBBackingStoreWriteError);
-        return false;
-    }
+    putVarInt(Transaction::levelDBTransactionFrom(transaction), DatabaseMetaDataKey::encode(rowId, DatabaseMetaDataKey::UserIntVersion), intVersion);
     return true;
 }
 
-bool IDBLevelDBBackingStore::updateIDBDatabaseMetaData(IDBBackingStore::Transaction* transaction, int64_t rowId, const String& version)
+bool IDBBackingStore::updateIDBDatabaseMetaData(IDBBackingStore::Transaction* transaction, int64_t rowId, const String& version)
 {
-    if (!putString(Transaction::levelDBTransactionFrom(transaction), DatabaseMetaDataKey::encode(rowId, DatabaseMetaDataKey::UserVersion), version)) {
-        InternalError(IDBLevelDBBackingStoreWriteError);
-        return false;
-    }
-
+    putString(Transaction::levelDBTransactionFrom(transaction), DatabaseMetaDataKey::encode(rowId, DatabaseMetaDataKey::UserVersion), version);
     return true;
 }
 
-static bool deleteRange(LevelDBTransaction* transaction, const Vector<char>& begin, const Vector<char>& end)
+static void deleteRange(LevelDBTransaction* transaction, const Vector<char>& begin, const Vector<char>& end)
 {
     OwnPtr<LevelDBIterator> it = transaction->createIterator();
-    for (it->seek(begin); it->isValid() && compareKeys(it->key(), end) < 0; it->next()) {
-        if (!transaction->remove(it->key())) {
-            InternalError(IDBLevelDBBackingStoreWriteError);
-            return false;
-        }
-    }
-
-    return true;
+    for (it->seek(begin); it->isValid() && compareKeys(it->key(), end) < 0; it->next())
+        transaction->remove(it->key());
 }
 
 
-bool IDBLevelDBBackingStore::deleteDatabase(const String& name)
+bool IDBBackingStore::deleteDatabase(const String& name)
 {
-    IDB_TRACE("IDBLevelDBBackingStore::deleteDatabase");
+    IDB_TRACE("IDBBackingStore::deleteDatabase");
     OwnPtr<LevelDBWriteOnlyTransaction> transaction = LevelDBWriteOnlyTransaction::create(m_db.get());
 
     IDBDatabaseMetadata metadata;
@@ -498,9 +465,9 @@ static bool checkObjectStoreAndMetaDataType(const LevelDBIterator* it, const Vec
     return true;
 }
 
-Vector<IDBObjectStoreMetadata> IDBLevelDBBackingStore::getObjectStores(int64_t databaseId)
+Vector<IDBObjectStoreMetadata> IDBBackingStore::getObjectStores(int64_t databaseId)
 {
-    IDB_TRACE("IDBLevelDBBackingStore::getObjectStores");
+    IDB_TRACE("IDBBackingStore::getObjectStores");
     Vector<IDBObjectStoreMetadata> objectStores;
     const Vector<char> startKey = ObjectStoreMetaDataKey::encode(databaseId, 1, 0);
     const Vector<char> stopKey = ObjectStoreMetaDataKey::encodeMaxKey(databaseId);
@@ -598,17 +565,14 @@ static bool setMaxObjectStoreId(LevelDBTransaction* transaction, int64_t databas
         InternalError(IDBLevelDBBackingStoreConsistencyError);
         return false;
     }
-    if (!putInt(transaction, maxObjectStoreIdKey, objectStoreId)) {
-        InternalError(IDBLevelDBBackingStoreWriteError);
-        return false;
-    }
+    putInt(transaction, maxObjectStoreIdKey, objectStoreId);
     return true;
 }
 
-bool IDBLevelDBBackingStore::createObjectStore(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, const String& name, const IDBKeyPath& keyPath, bool autoIncrement)
+bool IDBBackingStore::createObjectStore(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, const String& name, const IDBKeyPath& keyPath, bool autoIncrement)
 {
-    IDB_TRACE("IDBLevelDBBackingStore::createObjectStore");
-    LevelDBTransaction* levelDBTransaction = Transaction::levelDBTransactionFrom(transaction);
+    IDB_TRACE("IDBBackingStore::createObjectStore");
+    LevelDBTransaction* levelDBTransaction = IDBBackingStore::Transaction::levelDBTransactionFrom(transaction);
     if (!setMaxObjectStoreId(levelDBTransaction, databaseId, objectStoreId))
         return false;
 
@@ -622,94 +586,40 @@ bool IDBLevelDBBackingStore::createObjectStore(IDBBackingStore::Transaction* tra
     const Vector<char> keyGeneratorCurrentNumberKey = ObjectStoreMetaDataKey::encode(databaseId, objectStoreId, ObjectStoreMetaDataKey::KeyGeneratorCurrentNumber);
     const Vector<char> namesKey = ObjectStoreNamesKey::encode(databaseId, name);
 
-    bool ok = putString(levelDBTransaction, nameKey, name);
-    if (!ok) {
-        InternalError(IDBLevelDBBackingStoreWriteError);
-        return false;
-    }
-
-    ok = putIDBKeyPath(levelDBTransaction, keyPathKey, keyPath);
-    if (!ok) {
-        InternalError(IDBLevelDBBackingStoreWriteError);
-        return false;
-    }
-
-    ok = putInt(levelDBTransaction, autoIncrementKey, autoIncrement);
-    if (!ok) {
-        InternalError(IDBLevelDBBackingStoreWriteError);
-        return false;
-    }
-
-    ok = putInt(levelDBTransaction, evictableKey, false);
-    if (!ok) {
-        InternalError(IDBLevelDBBackingStoreWriteError);
-        return false;
-    }
-
-    ok = putInt(levelDBTransaction, lastVersionKey, 1);
-    if (!ok) {
-        InternalError(IDBLevelDBBackingStoreWriteError);
-        return false;
-    }
-
-    ok = putInt(levelDBTransaction, maxIndexIdKey, MinimumIndexId);
-    if (!ok) {
-        InternalError(IDBLevelDBBackingStoreWriteError);
-        return false;
-    }
-
-    ok = putBool(levelDBTransaction, hasKeyPathKey, !keyPath.isNull());
-    if (!ok) {
-        InternalError(IDBLevelDBBackingStoreWriteError);
-        return false;
-    }
-
-    ok = putInt(levelDBTransaction, keyGeneratorCurrentNumberKey, KeyGeneratorInitialNumber);
-    if (!ok) {
-        InternalError(IDBLevelDBBackingStoreWriteError);
-        return false;
-    }
-
-    ok = putInt(levelDBTransaction, namesKey, objectStoreId);
-    if (!ok) {
-        InternalError(IDBLevelDBBackingStoreWriteError);
-        return false;
-    }
-
+    putString(levelDBTransaction, nameKey, name);
+    putIDBKeyPath(levelDBTransaction, keyPathKey, keyPath);
+    putInt(levelDBTransaction, autoIncrementKey, autoIncrement);
+    putInt(levelDBTransaction, evictableKey, false);
+    putInt(levelDBTransaction, lastVersionKey, 1);
+    putInt(levelDBTransaction, maxIndexIdKey, MinimumIndexId);
+    putBool(levelDBTransaction, hasKeyPathKey, !keyPath.isNull());
+    putInt(levelDBTransaction, keyGeneratorCurrentNumberKey, KeyGeneratorInitialNumber);
+    putInt(levelDBTransaction, namesKey, objectStoreId);
     return true;
 }
 
-void IDBLevelDBBackingStore::deleteObjectStore(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId)
+void IDBBackingStore::deleteObjectStore(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId)
 {
-    IDB_TRACE("IDBLevelDBBackingStore::deleteObjectStore");
-    LevelDBTransaction* levelDBTransaction = Transaction::levelDBTransactionFrom(transaction);
+    IDB_TRACE("IDBBackingStore::deleteObjectStore");
+    LevelDBTransaction* levelDBTransaction = IDBBackingStore::Transaction::levelDBTransactionFrom(transaction);
 
     String objectStoreName;
     getString(levelDBTransaction, ObjectStoreMetaDataKey::encode(databaseId, objectStoreId, ObjectStoreMetaDataKey::Name), objectStoreName);
 
-    if (!deleteRange(levelDBTransaction, ObjectStoreMetaDataKey::encode(databaseId, objectStoreId, 0), ObjectStoreMetaDataKey::encodeMaxKey(databaseId, objectStoreId))) {
-        InternalError(IDBLevelDBBackingStoreWriteError);
-        return; // FIXME: Report error.
-    }
+    deleteRange(levelDBTransaction, ObjectStoreMetaDataKey::encode(databaseId, objectStoreId, 0), ObjectStoreMetaDataKey::encodeMaxKey(databaseId, objectStoreId));
 
     levelDBTransaction->remove(ObjectStoreNamesKey::encode(databaseId, objectStoreName));
 
-    if (!deleteRange(levelDBTransaction, IndexFreeListKey::encode(databaseId, objectStoreId, 0), IndexFreeListKey::encodeMaxKey(databaseId, objectStoreId))) {
-        InternalError(IDBLevelDBBackingStoreWriteError);
-        return; // FIXME: Report error.
-    }
-    if (!deleteRange(levelDBTransaction, IndexMetaDataKey::encode(databaseId, objectStoreId, 0, 0), IndexMetaDataKey::encodeMaxKey(databaseId, objectStoreId))) {
-        InternalError(IDBLevelDBBackingStoreWriteError);
-        return; // FIXME: Report error.
-    }
+    deleteRange(levelDBTransaction, IndexFreeListKey::encode(databaseId, objectStoreId, 0), IndexFreeListKey::encodeMaxKey(databaseId, objectStoreId));
+    deleteRange(levelDBTransaction, IndexMetaDataKey::encode(databaseId, objectStoreId, 0, 0), IndexMetaDataKey::encodeMaxKey(databaseId, objectStoreId));
 
     clearObjectStore(transaction, databaseId, objectStoreId);
 }
 
-String IDBLevelDBBackingStore::getRecord(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, const IDBKey& key)
+String IDBBackingStore::getRecord(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, const IDBKey& key)
 {
-    IDB_TRACE("IDBLevelDBBackingStore::getRecord");
-    LevelDBTransaction* levelDBTransaction = Transaction::levelDBTransactionFrom(transaction);
+    IDB_TRACE("IDBBackingStore::getRecord");
+    LevelDBTransaction* levelDBTransaction = IDBBackingStore::Transaction::levelDBTransactionFrom(transaction);
 
     const Vector<char> leveldbKey = ObjectStoreDataKey::encode(databaseId, objectStoreId, key);
     Vector<char> data;
@@ -728,27 +638,6 @@ String IDBLevelDBBackingStore::getRecord(IDBBackingStore::Transaction* transacti
     return decodeString(p, data.end());
 }
 
-namespace {
-class LevelDBRecordIdentifier : public IDBBackingStore::RecordIdentifier {
-public:
-    static PassRefPtr<LevelDBRecordIdentifier> create(const Vector<char>& primaryKey, int64_t version) { return adoptRef(new LevelDBRecordIdentifier(primaryKey, version)); }
-    static PassRefPtr<LevelDBRecordIdentifier> create() { return adoptRef(new LevelDBRecordIdentifier()); }
-
-    virtual bool isValid() const { return m_primaryKey.isEmpty(); }
-    Vector<char> primaryKey() const { return m_primaryKey; }
-    void setPrimaryKey(const Vector<char>& primaryKey) { m_primaryKey = primaryKey; }
-    int64_t version() const { return m_version; }
-    void setVersion(int64_t version) { m_version = version; }
-
-private:
-    LevelDBRecordIdentifier(const Vector<char>& primaryKey, int64_t version) : m_primaryKey(primaryKey), m_version(version) { ASSERT(!primaryKey.isEmpty()); }
-    LevelDBRecordIdentifier() : m_primaryKey(), m_version(-1) { }
-
-    Vector<char> m_primaryKey; // FIXME: Make it more clear that this is the *encoded* version of the key.
-    int64_t m_version;
-};
-}
-
 static int64_t getNewVersionNumber(LevelDBTransaction* transaction, int64_t databaseId, int64_t objectStoreId)
 {
     const Vector<char> lastVersionKey = ObjectStoreMetaDataKey::encode(databaseId, objectStoreId, ObjectStoreMetaDataKey::LastVersion);
@@ -760,19 +649,18 @@ static int64_t getNewVersionNumber(LevelDBTransaction* transaction, int64_t data
     ASSERT(lastVersion >= 0);
 
     int64_t version = lastVersion + 1;
-    bool ok = putInt(transaction, lastVersionKey, version);
-    ASSERT_UNUSED(ok, ok);
+    putInt(transaction, lastVersionKey, version);
 
     ASSERT(version > lastVersion); // FIXME: Think about how we want to handle the overflow scenario.
 
     return version;
 }
 
-bool IDBLevelDBBackingStore::putRecord(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, const IDBKey& key, const String& value, RecordIdentifier* recordIdentifier)
+void IDBBackingStore::putRecord(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, const IDBKey& key, const String& value, RecordIdentifier* recordIdentifier)
 {
-    IDB_TRACE("IDBLevelDBBackingStore::putRecord");
+    IDB_TRACE("IDBBackingStore::putRecord");
     ASSERT(key.isValid());
-    LevelDBTransaction* levelDBTransaction = Transaction::levelDBTransactionFrom(transaction);
+    LevelDBTransaction* levelDBTransaction = IDBBackingStore::Transaction::levelDBTransactionFrom(transaction);
     int64_t version = getNewVersionNumber(levelDBTransaction, databaseId, objectStoreId);
     const Vector<char> objectStoredataKey = ObjectStoreDataKey::encode(databaseId, objectStoreId, key);
 
@@ -780,55 +668,40 @@ bool IDBLevelDBBackingStore::putRecord(IDBBackingStore::Transaction* transaction
     v.append(encodeVarInt(version));
     v.append(encodeString(value));
 
-    if (!levelDBTransaction->put(objectStoredataKey, v)) {
-        InternalError(IDBLevelDBBackingStoreWriteError);
-        return false;
-    }
+    levelDBTransaction->put(objectStoredataKey, v);
 
     const Vector<char> existsEntryKey = ExistsEntryKey::encode(databaseId, objectStoreId, key);
-    if (!levelDBTransaction->put(existsEntryKey, encodeInt(version))) {
-        InternalError(IDBLevelDBBackingStoreWriteError);
-        return false;
-    }
+    levelDBTransaction->put(existsEntryKey, encodeInt(version));
 
-    LevelDBRecordIdentifier* levelDBRecordIdentifier = static_cast<LevelDBRecordIdentifier*>(recordIdentifier);
-    levelDBRecordIdentifier->setPrimaryKey(encodeIDBKey(key));
-    levelDBRecordIdentifier->setVersion(version);
-    return true;
+    recordIdentifier->reset(encodeIDBKey(key), version);
 }
 
-void IDBLevelDBBackingStore::clearObjectStore(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId)
+void IDBBackingStore::clearObjectStore(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId)
 {
-    IDB_TRACE("IDBLevelDBBackingStore::clearObjectStore");
-    LevelDBTransaction* levelDBTransaction = Transaction::levelDBTransactionFrom(transaction);
+    IDB_TRACE("IDBBackingStore::clearObjectStore");
+    LevelDBTransaction* levelDBTransaction = IDBBackingStore::Transaction::levelDBTransactionFrom(transaction);
     const Vector<char> startKey = KeyPrefix(databaseId, objectStoreId, 0).encode();
     const Vector<char> stopKey = KeyPrefix(databaseId, objectStoreId + 1, 0).encode();
 
     deleteRange(levelDBTransaction, startKey, stopKey);
 }
 
-PassRefPtr<IDBBackingStore::RecordIdentifier> IDBLevelDBBackingStore::createInvalidRecordIdentifier()
+void IDBBackingStore::deleteRecord(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, const RecordIdentifier& recordIdentifier)
 {
-    return LevelDBRecordIdentifier::create();
-}
-
-void IDBLevelDBBackingStore::deleteRecord(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, const RecordIdentifier* recordIdentifier)
-{
-    IDB_TRACE("IDBLevelDBBackingStore::deleteRecord");
-    LevelDBTransaction* levelDBTransaction = Transaction::levelDBTransactionFrom(transaction);
-    const LevelDBRecordIdentifier* levelDBRecordIdentifier = static_cast<const LevelDBRecordIdentifier*>(recordIdentifier);
+    IDB_TRACE("IDBBackingStore::deleteRecord");
+    LevelDBTransaction* levelDBTransaction = IDBBackingStore::Transaction::levelDBTransactionFrom(transaction);
 
-    const Vector<char> objectStoreDataKey = ObjectStoreDataKey::encode(databaseId, objectStoreId, levelDBRecordIdentifier->primaryKey());
+    const Vector<char> objectStoreDataKey = ObjectStoreDataKey::encode(databaseId, objectStoreId, recordIdentifier.primaryKey());
     levelDBTransaction->remove(objectStoreDataKey);
 
-    const Vector<char> existsEntryKey = ExistsEntryKey::encode(databaseId, objectStoreId, levelDBRecordIdentifier->primaryKey());
+    const Vector<char> existsEntryKey = ExistsEntryKey::encode(databaseId, objectStoreId, recordIdentifier.primaryKey());
     levelDBTransaction->remove(existsEntryKey);
 }
 
 
-int64_t IDBLevelDBBackingStore::getKeyGeneratorCurrentNumber(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId)
+int64_t IDBBackingStore::getKeyGeneratorCurrentNumber(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId)
 {
-    LevelDBTransaction* levelDBTransaction = Transaction::levelDBTransactionFrom(transaction);
+    LevelDBTransaction* levelDBTransaction = IDBBackingStore::Transaction::levelDBTransactionFrom(transaction);
 
     const Vector<char> keyGeneratorCurrentNumberKey = ObjectStoreMetaDataKey::encode(databaseId, objectStoreId, ObjectStoreMetaDataKey::KeyGeneratorCurrentNumber);
 
@@ -868,29 +741,24 @@ int64_t IDBLevelDBBackingStore::getKeyGeneratorCurrentNumber(IDBBackingStore::Tr
     return keyGeneratorCurrentNumber;
 }
 
-bool IDBLevelDBBackingStore::maybeUpdateKeyGeneratorCurrentNumber(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, int64_t newNumber, bool checkCurrent)
+void IDBBackingStore::maybeUpdateKeyGeneratorCurrentNumber(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, int64_t newNumber, bool checkCurrent)
 {
-    LevelDBTransaction* levelDBTransaction = Transaction::levelDBTransactionFrom(transaction);
+    LevelDBTransaction* levelDBTransaction = IDBBackingStore::Transaction::levelDBTransactionFrom(transaction);
 
     if (checkCurrent) {
         int64_t currentNumber = getKeyGeneratorCurrentNumber(transaction, databaseId, objectStoreId);
         if (newNumber <= currentNumber)
-            return true;
+            return;
     }
 
     const Vector<char> keyGeneratorCurrentNumberKey = ObjectStoreMetaDataKey::encode(databaseId, objectStoreId, ObjectStoreMetaDataKey::KeyGeneratorCurrentNumber);
-    bool ok = putInt(levelDBTransaction, keyGeneratorCurrentNumberKey, newNumber);
-    if (!ok) {
-        InternalError(IDBLevelDBBackingStoreWriteError);
-        return false;
-    }
-    return true;
+    putInt(levelDBTransaction, keyGeneratorCurrentNumberKey, newNumber);
 }
 
-bool IDBLevelDBBackingStore::keyExistsInObjectStore(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, const IDBKey& key, RecordIdentifier* foundRecordIdentifier)
+bool IDBBackingStore::keyExistsInObjectStore(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, const IDBKey& key, RecordIdentifier* foundRecordIdentifier)
 {
-    IDB_TRACE("IDBLevelDBBackingStore::keyExistsInObjectStore");
-    LevelDBTransaction* levelDBTransaction = Transaction::levelDBTransactionFrom(transaction);
+    IDB_TRACE("IDBBackingStore::keyExistsInObjectStore");
+    LevelDBTransaction* levelDBTransaction = IDBBackingStore::Transaction::levelDBTransactionFrom(transaction);
     const Vector<char> leveldbKey = ObjectStoreDataKey::encode(databaseId, objectStoreId, key);
     Vector<char> data;
 
@@ -901,9 +769,7 @@ bool IDBLevelDBBackingStore::keyExistsInObjectStore(IDBBackingStore::Transaction
     if (!decodeVarInt(data.begin(), data.end(), version))
         return false;
 
-    LevelDBRecordIdentifier* levelDBRecordIdentifier = static_cast<LevelDBRecordIdentifier*>(foundRecordIdentifier);
-    levelDBRecordIdentifier->setPrimaryKey(encodeIDBKey(key));
-    levelDBRecordIdentifier->setVersion(version);
+    foundRecordIdentifier->reset(encodeIDBKey(key), version);
     return true;
 }
 
@@ -923,9 +789,9 @@ static bool checkIndexAndMetaDataKey(const LevelDBIterator* it, const Vector<cha
 }
 
 
-Vector<IDBIndexMetadata> IDBLevelDBBackingStore::getIndexes(int64_t databaseId, int64_t objectStoreId)
+Vector<IDBIndexMetadata> IDBBackingStore::getIndexes(int64_t databaseId, int64_t objectStoreId)
 {
-    IDB_TRACE("IDBLevelDBBackingStore::getIndexes");
+    IDB_TRACE("IDBBackingStore::getIndexes");
     Vector<IDBIndexMetadata> indexes;
     const Vector<char> startKey = IndexMetaDataKey::encode(databaseId, objectStoreId, 0, 0);
     const Vector<char> stopKey = IndexMetaDataKey::encode(databaseId, objectStoreId + 1, 0, 0);
@@ -990,17 +856,14 @@ static bool setMaxIndexId(LevelDBTransaction* transaction, int64_t databaseId, i
         return false;
     }
 
-    if (!putInt(transaction, maxIndexIdKey, indexId)) {
-        InternalError(IDBLevelDBBackingStoreWriteError);
-        return false;
-    }
+    putInt(transaction, maxIndexIdKey, indexId);
     return true;
 }
 
-bool IDBLevelDBBackingStore::createIndex(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, int64_t indexId, const String& name, const IDBKeyPath& keyPath, bool isUnique, bool isMultiEntry)
+bool IDBBackingStore::createIndex(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, int64_t indexId, const String& name, const IDBKeyPath& keyPath, bool isUnique, bool isMultiEntry)
 {
-    IDB_TRACE("IDBLevelDBBackingStore::createIndex");
-    LevelDBTransaction* levelDBTransaction = Transaction::levelDBTransactionFrom(transaction);
+    IDB_TRACE("IDBBackingStore::createIndex");
+    LevelDBTransaction* levelDBTransaction = IDBBackingStore::Transaction::levelDBTransactionFrom(transaction);
     if (!setMaxIndexId(levelDBTransaction, databaseId, objectStoreId, indexId))
         return false;
 
@@ -1009,70 +872,41 @@ bool IDBLevelDBBackingStore::createIndex(IDBBackingStore::Transaction* transacti
     const Vector<char> keyPathKey = IndexMetaDataKey::encode(databaseId, objectStoreId, indexId, IndexMetaDataKey::KeyPath);
     const Vector<char> multiEntryKey = IndexMetaDataKey::encode(databaseId, objectStoreId, indexId, IndexMetaDataKey::MultiEntry);
 
-    bool ok = putString(levelDBTransaction, nameKey, name);
-    if (!ok) {
-        InternalError(IDBLevelDBBackingStoreWriteError);
-        return false;
-    }
-
-    ok = putBool(levelDBTransaction, uniqueKey, isUnique);
-    if (!ok) {
-        InternalError(IDBLevelDBBackingStoreWriteError);
-        return false;
-    }
-
-    ok = putIDBKeyPath(levelDBTransaction, keyPathKey, keyPath);
-    if (!ok) {
-        InternalError(IDBLevelDBBackingStoreWriteError);
-        return false;
-    }
-
-    ok = putBool(levelDBTransaction, multiEntryKey, isMultiEntry);
-    if (!ok) {
-        InternalError(IDBLevelDBBackingStoreWriteError);
-        return false;
-    }
-
+    putString(levelDBTransaction, nameKey, name);
+    putBool(levelDBTransaction, uniqueKey, isUnique);
+    putIDBKeyPath(levelDBTransaction, keyPathKey, keyPath);
+    putBool(levelDBTransaction, multiEntryKey, isMultiEntry);
     return true;
 }
 
-void IDBLevelDBBackingStore::deleteIndex(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, int64_t indexId)
+void IDBBackingStore::deleteIndex(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, int64_t indexId)
 {
-    IDB_TRACE("IDBLevelDBBackingStore::deleteIndex");
-    LevelDBTransaction* levelDBTransaction = Transaction::levelDBTransactionFrom(transaction);
+    IDB_TRACE("IDBBackingStore::deleteIndex");
+    LevelDBTransaction* levelDBTransaction = IDBBackingStore::Transaction::levelDBTransactionFrom(transaction);
 
     const Vector<char> indexMetaDataStart = IndexMetaDataKey::encode(databaseId, objectStoreId, indexId, 0);
     const Vector<char> indexMetaDataEnd = IndexMetaDataKey::encodeMaxKey(databaseId, objectStoreId, indexId);
-
-    if (!deleteRange(levelDBTransaction, indexMetaDataStart, indexMetaDataEnd)) {
-        InternalError(IDBLevelDBBackingStoreWriteError);
-        return;
-    }
+    deleteRange(levelDBTransaction, indexMetaDataStart, indexMetaDataEnd);
 
     const Vector<char> indexDataStart = IndexDataKey::encodeMinKey(databaseId, objectStoreId, indexId);
     const Vector<char> indexDataEnd = IndexDataKey::encodeMaxKey(databaseId, objectStoreId, indexId);
-
-    if (!deleteRange(levelDBTransaction, indexDataStart, indexDataEnd)) {
-        InternalError(IDBLevelDBBackingStoreWriteError);
-        return;
-    }
+    deleteRange(levelDBTransaction, indexDataStart, indexDataEnd);
 }
 
-bool IDBLevelDBBackingStore::putIndexDataForRecord(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKey& key, const RecordIdentifier* recordIdentifier)
+void IDBBackingStore::putIndexDataForRecord(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKey& key, const RecordIdentifier& recordIdentifier)
 {
-    IDB_TRACE("IDBLevelDBBackingStore::putIndexDataForRecord");
+    IDB_TRACE("IDBBackingStore::putIndexDataForRecord");
     ASSERT(key.isValid());
     ASSERT(indexId >= MinimumIndexId);
-    const LevelDBRecordIdentifier* levelDBRecordIdentifier = static_cast<const LevelDBRecordIdentifier*>(recordIdentifier);
 
-    LevelDBTransaction* levelDBTransaction = Transaction::levelDBTransactionFrom(transaction);
-    const Vector<char> indexDataKey = IndexDataKey::encode(databaseId, objectStoreId, indexId, encodeIDBKey(key), levelDBRecordIdentifier->primaryKey());
+    LevelDBTransaction* levelDBTransaction = IDBBackingStore::Transaction::levelDBTransactionFrom(transaction);
+    const Vector<char> indexDataKey = IndexDataKey::encode(databaseId, objectStoreId, indexId, encodeIDBKey(key), recordIdentifier.primaryKey());
 
     Vector<char> data;
-    data.append(encodeVarInt(levelDBRecordIdentifier->version()));
-    data.append(levelDBRecordIdentifier->primaryKey());
+    data.append(encodeVarInt(recordIdentifier.version()));
+    data.append(recordIdentifier.primaryKey());
 
-    return levelDBTransaction->put(indexDataKey, data);
+    levelDBTransaction->put(indexDataKey, data);
 }
 
 static bool findGreatestKeyLessThanOrEqual(LevelDBTransaction* transaction, const Vector<char>& target, Vector<char>& foundKey)
@@ -1103,12 +937,6 @@ static bool findGreatestKeyLessThanOrEqual(LevelDBTransaction* transaction, cons
     return true;
 }
 
-bool IDBLevelDBBackingStore::deleteIndexDataForRecord(IDBBackingStore::Transaction*, int64_t, int64_t, int64_t, const RecordIdentifier*)
-{
-    // FIXME: This isn't needed since we invalidate index data via the version number mechanism.
-    return true;
-}
-
 static bool versionExists(LevelDBTransaction* transaction, int64_t databaseId, int64_t objectStoreId, int64_t version, const Vector<char>& encodedPrimaryKey)
 {
     const Vector<char> key = ExistsEntryKey::encode(databaseId, objectStoreId, encodedPrimaryKey);
@@ -1120,12 +948,12 @@ static bool versionExists(LevelDBTransaction* transaction, int64_t databaseId, i
     return decodeInt(data.begin(), data.end()) == version;
 }
 
-bool IDBLevelDBBackingStore::findKeyInIndex(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKey& key, Vector<char>& foundEncodedPrimaryKey)
+bool IDBBackingStore::findKeyInIndex(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKey& key, Vector<char>& foundEncodedPrimaryKey)
 {
-    IDB_TRACE("IDBLevelDBBackingStore::findKeyInIndex");
+    IDB_TRACE("IDBBackingStore::findKeyInIndex");
     ASSERT(foundEncodedPrimaryKey.isEmpty());
 
-    LevelDBTransaction* levelDBTransaction = Transaction::levelDBTransactionFrom(transaction);
+    LevelDBTransaction* levelDBTransaction = IDBBackingStore::Transaction::levelDBTransactionFrom(transaction);
     const Vector<char> leveldbKey = IndexDataKey::encode(databaseId, objectStoreId, indexId, key);
     OwnPtr<LevelDBIterator> it = levelDBTransaction->createIterator();
     it->seek(leveldbKey);
@@ -1155,9 +983,9 @@ bool IDBLevelDBBackingStore::findKeyInIndex(IDBBackingStore::Transaction* transa
     }
 }
 
-PassRefPtr<IDBKey> IDBLevelDBBackingStore::getPrimaryKeyViaIndex(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKey& key)
+PassRefPtr<IDBKey> IDBBackingStore::getPrimaryKeyViaIndex(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKey& key)
 {
-    IDB_TRACE("IDBLevelDBBackingStore::getPrimaryKeyViaIndex");
+    IDB_TRACE("IDBBackingStore::getPrimaryKeyViaIndex");
 
     Vector<char> foundEncodedPrimaryKey;
     if (findKeyInIndex(transaction, databaseId, objectStoreId, indexId, key, foundEncodedPrimaryKey)) {
@@ -1169,9 +997,9 @@ PassRefPtr<IDBKey> IDBLevelDBBackingStore::getPrimaryKeyViaIndex(IDBBackingStore
     return 0;
 }
 
-bool IDBLevelDBBackingStore::keyExistsInIndex(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKey& indexKey, RefPtr<IDBKey>& foundPrimaryKey)
+bool IDBBackingStore::keyExistsInIndex(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKey& indexKey, RefPtr<IDBKey>& foundPrimaryKey)
 {
-    IDB_TRACE("IDBLevelDBBackingStore::keyExistsInIndex");
+    IDB_TRACE("IDBBackingStore::keyExistsInIndex");
 
     Vector<char> foundEncodedPrimaryKey;
     if (!findKeyInIndex(transaction, databaseId, objectStoreId, indexId, indexKey, foundEncodedPrimaryKey))
@@ -1181,64 +1009,22 @@ bool IDBLevelDBBackingStore::keyExistsInIndex(IDBBackingStore::Transaction* tran
     return true;
 }
 
-namespace {
-
-struct CursorOptions {
-    Vector<char> lowKey;
-    bool lowOpen;
-    Vector<char> highKey;
-    bool highOpen;
-    bool forward;
-    bool unique;
-};
-
-class CursorImplCommon : public IDBBackingStore::Cursor {
-public:
-    // IDBBackingStore::Cursor
-    virtual bool advance(unsigned long);
-    virtual bool continueFunction(const IDBKey* = 0, IteratorState = Seek);
-    virtual PassRefPtr<IDBKey> key() { return m_currentKey; }
-    virtual PassRefPtr<IDBKey> primaryKey() { return m_currentKey; }
-    virtual String value() = 0;
-    virtual PassRefPtr<IDBBackingStore::RecordIdentifier> objectStoreRecordIdentifier() = 0;
-
-    virtual bool loadCurrentRow() = 0;
-    bool firstSeek();
-
-protected:
-    CursorImplCommon(LevelDBTransaction* transaction, const CursorOptions& cursorOptions)
-        : m_transaction(transaction)
-        , m_cursorOptions(cursorOptions)
-    {
-    }
-
-    CursorImplCommon(const CursorImplCommon* other)
-        : m_transaction(other->m_transaction)
-        , m_cursorOptions(other->m_cursorOptions)
-        , m_currentKey(other->m_currentKey)
-    {
-        if (other->m_iterator) {
-            m_iterator = m_transaction->createIterator();
+IDBBackingStore::Cursor::Cursor(const IDBBackingStore::Cursor* other)
+    : m_transaction(other->m_transaction)
+    , m_cursorOptions(other->m_cursorOptions)
+    , m_currentKey(other->m_currentKey)
+{
+    if (other->m_iterator) {
+        m_iterator = m_transaction->createIterator();
 
-            if (other->m_iterator->isValid()) {
-                m_iterator->seek(other->m_iterator->key());
-                ASSERT(m_iterator->isValid());
-            }
+        if (other->m_iterator->isValid()) {
+            m_iterator->seek(other->m_iterator->key());
+            ASSERT(m_iterator->isValid());
         }
     }
+}
 
-    virtual ~CursorImplCommon() { }
-
-    bool isPastBounds() const;
-    bool haveEnteredRange() const;
-
-    LevelDBTransaction* m_transaction;
-    CursorOptions m_cursorOptions;
-    OwnPtr<LevelDBIterator> m_iterator;
-    RefPtr<IDBKey> m_currentKey;
-};
-
-bool CursorImplCommon::firstSeek()
+bool IDBBackingStore::Cursor::firstSeek()
 {
     m_iterator = m_transaction->createIterator();
     if (m_cursorOptions.forward)
@@ -1249,7 +1035,7 @@ bool CursorImplCommon::firstSeek()
     return continueFunction(0, Ready);
 }
 
-bool CursorImplCommon::advance(unsigned long count)
+bool IDBBackingStore::Cursor::advance(unsigned long count)
 {
     while (count--) {
         if (!continueFunction())
@@ -1258,7 +1044,7 @@ bool CursorImplCommon::advance(unsigned long count)
     return true;
 }
 
-bool CursorImplCommon::continueFunction(const IDBKey* key, IteratorState nextState)
+bool IDBBackingStore::Cursor::continueFunction(const IDBKey* key, IteratorState nextState)
 {
     RefPtr<IDBKey> previousKey = m_currentKey;
 
@@ -1350,7 +1136,7 @@ bool CursorImplCommon::continueFunction(const IDBKey* key, IteratorState nextSta
     return true;
 }
 
-bool CursorImplCommon::haveEnteredRange() const
+bool IDBBackingStore::Cursor::haveEnteredRange() const
 {
     if (m_cursorOptions.forward) {
         if (m_cursorOptions.lowOpen)
@@ -1364,7 +1150,7 @@ bool CursorImplCommon::haveEnteredRange() const
     return compareIndexKeys(m_iterator->key(), m_cursorOptions.highKey) <= 0;
 }
 
-bool CursorImplCommon::isPastBounds() const
+bool IDBBackingStore::Cursor::isPastBounds() const
 {
     if (m_cursorOptions.forward) {
         if (m_cursorOptions.highOpen)
@@ -1377,9 +1163,9 @@ bool CursorImplCommon::isPastBounds() const
     return compareIndexKeys(m_iterator->key(), m_cursorOptions.lowKey) < 0;
 }
 
-class ObjectStoreKeyCursorImpl : public CursorImplCommon {
+class ObjectStoreKeyCursorImpl : public IDBBackingStore::Cursor {
 public:
-    static PassRefPtr<ObjectStoreKeyCursorImpl> create(LevelDBTransaction* transaction, const CursorOptions& cursorOptions)
+    static PassRefPtr<ObjectStoreKeyCursorImpl> create(LevelDBTransaction* transaction, const IDBBackingStore::Cursor::CursorOptions& cursorOptions)
     {
         return adoptRef(new ObjectStoreKeyCursorImpl(transaction, cursorOptions));
     }
@@ -1389,26 +1175,21 @@ public:
         return adoptRef(new ObjectStoreKeyCursorImpl(this));
     }
 
-    // CursorImplCommon
-    virtual String value() { ASSERT_NOT_REACHED(); return String(); }
-    virtual PassRefPtr<IDBBackingStore::RecordIdentifier> objectStoreRecordIdentifier() OVERRIDE
-    {
-        return m_identifier;
-    }
+    // IDBBackingStore::Cursor
+    virtual String value() const { ASSERT_NOT_REACHED(); return String(); }
     virtual bool loadCurrentRow();
 
 private:
-    ObjectStoreKeyCursorImpl(LevelDBTransaction* transaction, const CursorOptions& cursorOptions)
-        : CursorImplCommon(transaction, cursorOptions)
+    ObjectStoreKeyCursorImpl(LevelDBTransaction* transaction, const IDBBackingStore::Cursor::CursorOptions& cursorOptions)
+        : IDBBackingStore::Cursor(transaction, cursorOptions)
     {
     }
 
     ObjectStoreKeyCursorImpl(const ObjectStoreKeyCursorImpl* other)
-        : CursorImplCommon(other)
+        : IDBBackingStore::Cursor(other)
     {
     }
 
-    RefPtr<LevelDBRecordIdentifier> m_identifier;
 };
 
 bool ObjectStoreKeyCursorImpl::loadCurrentRow()
@@ -1433,14 +1214,14 @@ bool ObjectStoreKeyCursorImpl::loadCurrentRow()
     }
 
     // FIXME: This re-encodes what was just decoded; try and optimize.
-    m_identifier = LevelDBRecordIdentifier::create(encodeIDBKey(*m_currentKey), version);
+    m_recordIdentifier.reset(encodeIDBKey(*m_currentKey), version);
 
     return true;
 }
 
-class ObjectStoreCursorImpl : public CursorImplCommon {
+class ObjectStoreCursorImpl : public IDBBackingStore::Cursor {
 public:
-    static PassRefPtr<ObjectStoreCursorImpl> create(LevelDBTransaction* transaction, const CursorOptions& cursorOptions)
+    static PassRefPtr<ObjectStoreCursorImpl> create(LevelDBTransaction* transaction, const IDBBackingStore::Cursor::CursorOptions& cursorOptions)
     {
         return adoptRef(new ObjectStoreCursorImpl(transaction, cursorOptions));
     }
@@ -1450,28 +1231,23 @@ public:
         return adoptRef(new ObjectStoreCursorImpl(this));
     }
 
-    // CursorImplCommon
-    virtual String value() { return m_currentValue; }
-    virtual PassRefPtr<IDBBackingStore::RecordIdentifier> objectStoreRecordIdentifier() OVERRIDE
-    {
-        return m_identifier;
-    }
+    // IDBBackingStore::Cursor
+    virtual String value() const { return m_currentValue; }
     virtual bool loadCurrentRow();
 
 private:
-    ObjectStoreCursorImpl(LevelDBTransaction* transaction, const CursorOptions& cursorOptions)
-        : CursorImplCommon(transaction, cursorOptions)
+    ObjectStoreCursorImpl(LevelDBTransaction* transaction, const IDBBackingStore::Cursor::CursorOptions& cursorOptions)
+        : IDBBackingStore::Cursor(transaction, cursorOptions)
     {
     }
 
     ObjectStoreCursorImpl(const ObjectStoreCursorImpl* other)
-        : CursorImplCommon(other)
+        : IDBBackingStore::Cursor(other)
         , m_currentValue(other->m_currentValue)
     {
     }
 
     String m_currentValue;
-    RefPtr<LevelDBRecordIdentifier> m_identifier;
 };
 
 bool ObjectStoreCursorImpl::loadCurrentRow()
@@ -1496,16 +1272,16 @@ bool ObjectStoreCursorImpl::loadCurrentRow()
     }
 
     // FIXME: This re-encodes what was just decoded; try and optimize.
-    m_identifier = LevelDBRecordIdentifier::create(encodeIDBKey(*m_currentKey), version);
+    m_recordIdentifier.reset(encodeIDBKey(*m_currentKey), version);
 
     m_currentValue = decodeString(valuePosition, m_iterator->value().end());
 
     return true;
 }
 
-class IndexKeyCursorImpl : public CursorImplCommon {
+class IndexKeyCursorImpl : public IDBBackingStore::Cursor {
 public:
-    static PassRefPtr<IndexKeyCursorImpl> create(LevelDBTransaction* transaction, const CursorOptions& cursorOptions)
+    static PassRefPtr<IndexKeyCursorImpl> create(LevelDBTransaction* transaction, const IDBBackingStore::Cursor::CursorOptions& cursorOptions)
     {
         return adoptRef(new IndexKeyCursorImpl(transaction, cursorOptions));
     }
@@ -1515,20 +1291,20 @@ public:
         return adoptRef(new IndexKeyCursorImpl(this));
     }
 
-    // CursorImplCommon
-    virtual String value() { ASSERT_NOT_REACHED(); return String(); }
-    virtual PassRefPtr<IDBKey> primaryKey() { return m_primaryKey; }
-    virtual PassRefPtr<IDBBackingStore::RecordIdentifier> objectStoreRecordIdentifier() { ASSERT_NOT_REACHED(); return 0; }
+    // IDBBackingStore::Cursor
+    virtual String value() const { ASSERT_NOT_REACHED(); return String(); }
+    virtual PassRefPtr<IDBKey> primaryKey() const { return m_primaryKey; }
+    virtual const IDBBackingStore::RecordIdentifier& recordIdentifier() const { ASSERT_NOT_REACHED(); return m_recordIdentifier; }
     virtual bool loadCurrentRow();
 
 private:
-    IndexKeyCursorImpl(LevelDBTransaction* transaction, const CursorOptions& cursorOptions)
-        : CursorImplCommon(transaction, cursorOptions)
+    IndexKeyCursorImpl(LevelDBTransaction* transaction, const IDBBackingStore::Cursor::CursorOptions& cursorOptions)
+        : IDBBackingStore::Cursor(transaction, cursorOptions)
     {
     }
 
     IndexKeyCursorImpl(const IndexKeyCursorImpl* other)
-        : CursorImplCommon(other)
+        : IDBBackingStore::Cursor(other)
         , m_primaryKey(other->m_primaryKey)
     {
     }
@@ -1582,9 +1358,9 @@ bool IndexKeyCursorImpl::loadCurrentRow()
     return true;
 }
 
-class IndexCursorImpl : public CursorImplCommon {
+class IndexCursorImpl : public IDBBackingStore::Cursor {
 public:
-    static PassRefPtr<IndexCursorImpl> create(LevelDBTransaction* transaction, const CursorOptions& cursorOptions)
+    static PassRefPtr<IndexCursorImpl> create(LevelDBTransaction* transaction, const IDBBackingStore::Cursor::CursorOptions& cursorOptions)
     {
         return adoptRef(new IndexCursorImpl(transaction, cursorOptions));
     }
@@ -1594,20 +1370,20 @@ public:
         return adoptRef(new IndexCursorImpl(this));
     }
 
-    // CursorImplCommon
-    virtual String value() { return m_value; }
-    virtual PassRefPtr<IDBKey> primaryKey() { return m_primaryKey; }
-    virtual PassRefPtr<IDBBackingStore::RecordIdentifier> objectStoreRecordIdentifier() { ASSERT_NOT_REACHED(); return 0; }
+    // IDBBackingStore::Cursor
+    virtual String value() const { return m_value; }
+    virtual PassRefPtr<IDBKey> primaryKey() const { return m_primaryKey; }
+    virtual const IDBBackingStore::RecordIdentifier& recordIdentifier() const { ASSERT_NOT_REACHED(); return m_recordIdentifier; }
     bool loadCurrentRow();
 
 private:
-    IndexCursorImpl(LevelDBTransaction* transaction, const CursorOptions& cursorOptions)
-        : CursorImplCommon(transaction, cursorOptions)
+    IndexCursorImpl(LevelDBTransaction* transaction, const IDBBackingStore::Cursor::CursorOptions& cursorOptions)
+        : IDBBackingStore::Cursor(transaction, cursorOptions)
     {
     }
 
     IndexCursorImpl(const IndexCursorImpl* other)
-        : CursorImplCommon(other)
+        : IDBBackingStore::Cursor(other)
         , m_primaryKey(other->m_primaryKey)
         , m_value(other->m_value)
         , m_primaryLevelDBKey(other->m_primaryLevelDBKey)
@@ -1668,7 +1444,7 @@ bool IndexCursorImpl::loadCurrentRow()
     return true;
 }
 
-bool objectStoreCursorOptions(LevelDBTransaction* transaction, int64_t databaseId, int64_t objectStoreId, const IDBKeyRange* range, IDBCursor::Direction direction, CursorOptions& cursorOptions)
+bool objectStoreCursorOptions(LevelDBTransaction* transaction, int64_t databaseId, int64_t objectStoreId, const IDBKeyRange* range, IDBCursor::Direction direction, IDBBackingStore::Cursor::CursorOptions& cursorOptions)
 {
     bool lowerBound = range && range->lower();
     bool upperBound = range && range->upper();
@@ -1715,7 +1491,7 @@ bool objectStoreCursorOptions(LevelDBTransaction* transaction, int64_t databaseI
     return true;
 }
 
-bool indexCursorOptions(LevelDBTransaction* transaction, int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKeyRange* range, IDBCursor::Direction direction, CursorOptions& cursorOptions)
+bool indexCursorOptions(LevelDBTransaction* transaction, int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKeyRange* range, IDBCursor::Direction direction, IDBBackingStore::Cursor::CursorOptions& cursorOptions)
 {
     ASSERT(transaction);
     bool lowerBound = range && range->lower();
@@ -1758,13 +1534,11 @@ bool indexCursorOptions(LevelDBTransaction* transaction, int64_t databaseId, int
     return true;
 }
 
-}
-
-PassRefPtr<IDBBackingStore::Cursor> IDBLevelDBBackingStore::openObjectStoreCursor(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, const IDBKeyRange* range, IDBCursor::Direction direction)
+PassRefPtr<IDBBackingStore::Cursor> IDBBackingStore::openObjectStoreCursor(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, const IDBKeyRange* range, IDBCursor::Direction direction)
 {
-    IDB_TRACE("IDBLevelDBBackingStore::openObjectStoreCursor");
-    LevelDBTransaction* levelDBTransaction = Transaction::levelDBTransactionFrom(transaction);
-    CursorOptions cursorOptions;
+    IDB_TRACE("IDBBackingStore::openObjectStoreCursor");
+    LevelDBTransaction* levelDBTransaction = IDBBackingStore::Transaction::levelDBTransactionFrom(transaction);
+    IDBBackingStore::Cursor::CursorOptions cursorOptions;
     if (!objectStoreCursorOptions(levelDBTransaction, databaseId, objectStoreId, range, direction, cursorOptions))
         return 0;
     RefPtr<ObjectStoreCursorImpl> cursor = ObjectStoreCursorImpl::create(levelDBTransaction, cursorOptions);
@@ -1774,11 +1548,11 @@ PassRefPtr<IDBBackingStore::Cursor> IDBLevelDBBackingStore::openObjectStoreCurso
     return cursor.release();
 }
 
-PassRefPtr<IDBBackingStore::Cursor> IDBLevelDBBackingStore::openObjectStoreKeyCursor(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, const IDBKeyRange* range, IDBCursor::Direction direction)
+PassRefPtr<IDBBackingStore::Cursor> IDBBackingStore::openObjectStoreKeyCursor(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, const IDBKeyRange* range, IDBCursor::Direction direction)
 {
-    IDB_TRACE("IDBLevelDBBackingStore::openObjectStoreKeyCursor");
-    LevelDBTransaction* levelDBTransaction = Transaction::levelDBTransactionFrom(transaction);
-    CursorOptions cursorOptions;
+    IDB_TRACE("IDBBackingStore::openObjectStoreKeyCursor");
+    LevelDBTransaction* levelDBTransaction = IDBBackingStore::Transaction::levelDBTransactionFrom(transaction);
+    IDBBackingStore::Cursor::CursorOptions cursorOptions;
     if (!objectStoreCursorOptions(levelDBTransaction, databaseId, objectStoreId, range, direction, cursorOptions))
         return 0;
     RefPtr<ObjectStoreKeyCursorImpl> cursor = ObjectStoreKeyCursorImpl::create(levelDBTransaction, cursorOptions);
@@ -1788,11 +1562,11 @@ PassRefPtr<IDBBackingStore::Cursor> IDBLevelDBBackingStore::openObjectStoreKeyCu
     return cursor.release();
 }
 
-PassRefPtr<IDBBackingStore::Cursor> IDBLevelDBBackingStore::openIndexKeyCursor(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKeyRange* range, IDBCursor::Direction direction)
+PassRefPtr<IDBBackingStore::Cursor> IDBBackingStore::openIndexKeyCursor(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKeyRange* range, IDBCursor::Direction direction)
 {
-    IDB_TRACE("IDBLevelDBBackingStore::openIndexKeyCursor");
-    LevelDBTransaction* levelDBTransaction = Transaction::levelDBTransactionFrom(transaction);
-    CursorOptions cursorOptions;
+    IDB_TRACE("IDBBackingStore::openIndexKeyCursor");
+    LevelDBTransaction* levelDBTransaction = IDBBackingStore::Transaction::levelDBTransactionFrom(transaction);
+    IDBBackingStore::Cursor::CursorOptions cursorOptions;
     if (!indexCursorOptions(levelDBTransaction, databaseId, objectStoreId, indexId, range, direction, cursorOptions))
         return 0;
     RefPtr<IndexKeyCursorImpl> cursor = IndexKeyCursorImpl::create(levelDBTransaction, cursorOptions);
@@ -1802,11 +1576,11 @@ PassRefPtr<IDBBackingStore::Cursor> IDBLevelDBBackingStore::openIndexKeyCursor(I
     return cursor.release();
 }
 
-PassRefPtr<IDBBackingStore::Cursor> IDBLevelDBBackingStore::openIndexCursor(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKeyRange* range, IDBCursor::Direction direction)
+PassRefPtr<IDBBackingStore::Cursor> IDBBackingStore::openIndexCursor(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKeyRange* range, IDBCursor::Direction direction)
 {
-    IDB_TRACE("IDBLevelDBBackingStore::openIndexCursor");
-    LevelDBTransaction* levelDBTransaction = Transaction::levelDBTransactionFrom(transaction);
-    CursorOptions cursorOptions;
+    IDB_TRACE("IDBBackingStore::openIndexCursor");
+    LevelDBTransaction* levelDBTransaction = IDBBackingStore::Transaction::levelDBTransactionFrom(transaction);
+    IDBBackingStore::Cursor::CursorOptions cursorOptions;
     if (!indexCursorOptions(levelDBTransaction, databaseId, objectStoreId, indexId, range, direction, cursorOptions))
         return 0;
     RefPtr<IndexCursorImpl> cursor = IndexCursorImpl::create(levelDBTransaction, cursorOptions);
@@ -1816,60 +1590,35 @@ PassRefPtr<IDBBackingStore::Cursor> IDBLevelDBBackingStore::openIndexCursor(IDBB
     return cursor.release();
 }
 
-PassRefPtr<IDBBackingStore::Transaction> IDBLevelDBBackingStore::createTransaction()
-{
-    return Transaction::create(this);
-}
-
-PassRefPtr<IDBLevelDBBackingStore::Transaction> IDBLevelDBBackingStore::Transaction::create(IDBLevelDBBackingStore* backingStore)
-{
-    return adoptRef(new Transaction(backingStore));
-}
-
-IDBLevelDBBackingStore::Transaction::Transaction(IDBLevelDBBackingStore* backingStore)
+IDBBackingStore::Transaction::Transaction(IDBBackingStore* backingStore)
     : m_backingStore(backingStore)
 {
 }
 
-void IDBLevelDBBackingStore::Transaction::begin()
+void IDBBackingStore::Transaction::begin()
 {
-    IDB_TRACE("IDBLevelDBBackingStore::Transaction::begin");
+    IDB_TRACE("IDBBackingStore::Transaction::begin");
     ASSERT(!m_transaction);
     m_transaction = LevelDBTransaction::create(m_backingStore->m_db.get());
 }
 
-bool IDBLevelDBBackingStore::Transaction::commit()
+bool IDBBackingStore::Transaction::commit()
 {
-    IDB_TRACE("IDBLevelDBBackingStore::Transaction::commit");
+    IDB_TRACE("IDBBackingStore::Transaction::commit");
     ASSERT(m_transaction);
     bool result = m_transaction->commit();
     m_transaction.clear();
     return result;
 }
 
-void IDBLevelDBBackingStore::Transaction::rollback()
+void IDBBackingStore::Transaction::rollback()
 {
-    IDB_TRACE("IDBLevelDBBackingStore::Transaction::rollback");
+    IDB_TRACE("IDBBackingStore::Transaction::rollback");
     ASSERT(m_transaction);
     m_transaction->rollback();
     m_transaction.clear();
 }
 
-bool IDBLevelDBBackingStore::backingStoreExists(SecurityOrigin* securityOrigin, const String&, const String& pathBaseArg)
-{
-    String pathBase = pathBaseArg;
-
-    if (pathBase.isEmpty())
-        return false;
-
-    // FIXME: We should eventually use the same LevelDB database for all origins.
-    String path = pathByAppendingComponent(pathBase, securityOrigin->databaseIdentifier() + ".indexeddb.leveldb");
-
-    // FIXME: this is checking for presence of the domain, not the database itself
-    return fileExists(path+"/CURRENT");
-}
-
 } // namespace WebCore
 
-#endif // USE(LEVELDB)
 #endif // ENABLE(INDEXED_DATABASE)