IndexedDB: promote objectstore/index backend ids to the frontend
authoralecflett@chromium.org <alecflett@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 4 Oct 2012 22:38:18 +0000 (22:38 +0000)
committeralecflett@chromium.org <alecflett@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 4 Oct 2012 22:38:18 +0000 (22:38 +0000)
https://bugs.webkit.org/show_bug.cgi?id=97834

Reviewed by Tony Chang.

Source/WebCore:

Expose int64-based database/objectStore/index ids to the renderer,
step 1 of 2. Support both styles of createObjectStore and
createIndex: those that take an explicit id, and those that take
-1, meaning to autogenerate an id on the backend. In part 2, after
the chromium side lands, support for the autogenerated ids will be
removed. (See https://bugs.webkit.org/show_bug.cgi?id=98085)

This is a part of larger refactoring work to ultimately make the interface
between the frontend and the backend simpler.

No new tests, extensive ASSERTs and existing tests cover correctness.

* Modules/indexeddb/IDBBackingStore.h:
(IDBBackingStore):
* Modules/indexeddb/IDBDatabase.cpp:
(WebCore::IDBDatabase::createObjectStore):
* Modules/indexeddb/IDBDatabaseBackendImpl.cpp:
(WebCore::IDBDatabaseBackendImpl::IDBDatabaseBackendImpl):
(WebCore::IDBDatabaseBackendImpl::openInternal):
(WebCore::IDBDatabaseBackendImpl::metadata):
(WebCore::IDBDatabaseBackendImpl::createObjectStore):
(WebCore):
(WebCore::IDBDatabaseBackendImpl::createObjectStoreInternal):
(WebCore::IDBDatabaseBackendImpl::loadObjectStores):
* Modules/indexeddb/IDBDatabaseBackendImpl.h:
(IDBDatabaseBackendImpl):
* Modules/indexeddb/IDBDatabaseBackendInterface.h:
(IDBDatabaseBackendInterface):
* Modules/indexeddb/IDBIndexBackendImpl.cpp:
(WebCore::IDBIndexBackendImpl::metadata):
* Modules/indexeddb/IDBIndexBackendImpl.h:
(WebCore::IDBIndexBackendImpl::create):
(IDBIndexBackendImpl):
* Modules/indexeddb/IDBLevelDBBackingStore.cpp:
(WebCore):
(WebCore::getMaxObjectStoreId):
(WebCore::IDBLevelDBBackingStore::getIDBDatabaseMetaData):
(WebCore::IDBLevelDBBackingStore::deleteDatabase):
(WebCore::IDBLevelDBBackingStore::getObjectStores):
(WebCore::setMaxObjectStoreId):
(WebCore::IDBLevelDBBackingStore::createObjectStore):
(WebCore::getMaxIndexId):
(WebCore::setMaxIndexId):
(WebCore::IDBLevelDBBackingStore::createIndex):
* Modules/indexeddb/IDBLevelDBBackingStore.h:
(IDBLevelDBBackingStore):
* Modules/indexeddb/IDBMetadata.h:
(WebCore::IDBDatabaseMetadata::IDBDatabaseMetadata):
(IDBDatabaseMetadata):
(WebCore::IDBObjectStoreMetadata::IDBObjectStoreMetadata):
(IDBObjectStoreMetadata):
(WebCore::IDBIndexMetadata::IDBIndexMetadata):
(IDBIndexMetadata):
* Modules/indexeddb/IDBObjectStore.cpp:
(WebCore::IDBObjectStore::createIndex):
* Modules/indexeddb/IDBObjectStoreBackendImpl.cpp:
(WebCore::IDBObjectStoreBackendImpl::IDBObjectStoreBackendImpl):
(WebCore::IDBObjectStoreBackendImpl::metadata):
(WebCore::IDBObjectStoreBackendImpl::createIndex):
(WebCore):
(WebCore::IDBObjectStoreBackendImpl::createIndexInternal):
* Modules/indexeddb/IDBObjectStoreBackendImpl.h:
(WebCore::IDBObjectStoreBackendImpl::create):
(IDBObjectStoreBackendImpl):
* Modules/indexeddb/IDBObjectStoreBackendInterface.h:

Source/WebKit/chromium:

Support for marshalling additional IDBMetadata and new calls to
createObjectStore/createIndex.

* public/WebIDBDatabase.h:
(WebKit::WebIDBDatabase::createObjectStore):
* public/WebIDBMetadata.h:
(ObjectStore):
(Index):
* public/WebIDBObjectStore.h:
(WebKit::WebIDBObjectStore::createIndex):
* src/IDBDatabaseBackendProxy.cpp:
(WebKit::IDBDatabaseBackendProxy::createObjectStore):
(WebKit):
* src/IDBDatabaseBackendProxy.h:
(IDBDatabaseBackendProxy):
* src/IDBObjectStoreBackendProxy.cpp:
(WebKit::IDBObjectStoreBackendProxy::createIndex):
(WebKit):
* src/IDBObjectStoreBackendProxy.h:
(IDBObjectStoreBackendProxy):
* src/WebIDBDatabaseImpl.cpp:
(WebKit::WebIDBDatabaseImpl::createObjectStore):
(WebKit):
* src/WebIDBDatabaseImpl.h:
(WebIDBDatabaseImpl):
* src/WebIDBMetadata.cpp:
(WebKit::WebIDBMetadata::WebIDBMetadata):
(WebKit::WebIDBMetadata::operator IDBDatabaseMetadata):
* src/WebIDBObjectStoreImpl.cpp:
(WebKit::WebIDBObjectStoreImpl::createIndex):
(WebKit):
* src/WebIDBObjectStoreImpl.h:
(WebIDBObjectStoreImpl):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@130428 268f45cc-cd09-0410-ab3c-d52691b4dbfc

30 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/IDBBackingStore.h
Source/WebCore/Modules/indexeddb/IDBDatabase.cpp
Source/WebCore/Modules/indexeddb/IDBDatabaseBackendImpl.cpp
Source/WebCore/Modules/indexeddb/IDBDatabaseBackendImpl.h
Source/WebCore/Modules/indexeddb/IDBDatabaseBackendInterface.h
Source/WebCore/Modules/indexeddb/IDBIndexBackendImpl.cpp
Source/WebCore/Modules/indexeddb/IDBIndexBackendImpl.h
Source/WebCore/Modules/indexeddb/IDBLevelDBBackingStore.cpp
Source/WebCore/Modules/indexeddb/IDBLevelDBBackingStore.h
Source/WebCore/Modules/indexeddb/IDBMetadata.h
Source/WebCore/Modules/indexeddb/IDBObjectStore.cpp
Source/WebCore/Modules/indexeddb/IDBObjectStoreBackendImpl.cpp
Source/WebCore/Modules/indexeddb/IDBObjectStoreBackendImpl.h
Source/WebCore/Modules/indexeddb/IDBObjectStoreBackendInterface.h
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/public/WebIDBDatabase.h
Source/WebKit/chromium/public/WebIDBMetadata.h
Source/WebKit/chromium/public/WebIDBObjectStore.h
Source/WebKit/chromium/src/IDBDatabaseBackendProxy.cpp
Source/WebKit/chromium/src/IDBDatabaseBackendProxy.h
Source/WebKit/chromium/src/IDBObjectStoreBackendProxy.cpp
Source/WebKit/chromium/src/IDBObjectStoreBackendProxy.h
Source/WebKit/chromium/src/WebIDBDatabaseImpl.cpp
Source/WebKit/chromium/src/WebIDBDatabaseImpl.h
Source/WebKit/chromium/src/WebIDBMetadata.cpp
Source/WebKit/chromium/src/WebIDBObjectStoreImpl.cpp
Source/WebKit/chromium/src/WebIDBObjectStoreImpl.h
Source/WebKit/chromium/tests/IDBDatabaseBackendTest.cpp
Source/WebKit/chromium/tests/IDBFakeBackingStore.h

index a66664697a2184d8be810a45211bc2d1e8274976..cdd4b8c67ab0960362cc2403030b50bdc145383b 100644 (file)
@@ -1,3 +1,75 @@
+2012-10-04  Alec Flett  <alecflett@chromium.org>
+
+        IndexedDB: promote objectstore/index backend ids to the frontend
+        https://bugs.webkit.org/show_bug.cgi?id=97834
+
+        Reviewed by Tony Chang.
+
+        Expose int64-based database/objectStore/index ids to the renderer,
+        step 1 of 2. Support both styles of createObjectStore and
+        createIndex: those that take an explicit id, and those that take
+        -1, meaning to autogenerate an id on the backend. In part 2, after
+        the chromium side lands, support for the autogenerated ids will be
+        removed. (See https://bugs.webkit.org/show_bug.cgi?id=98085)
+
+        This is a part of larger refactoring work to ultimately make the interface
+        between the frontend and the backend simpler.
+
+        No new tests, extensive ASSERTs and existing tests cover correctness.
+
+        * Modules/indexeddb/IDBBackingStore.h:
+        (IDBBackingStore):
+        * Modules/indexeddb/IDBDatabase.cpp:
+        (WebCore::IDBDatabase::createObjectStore):
+        * Modules/indexeddb/IDBDatabaseBackendImpl.cpp:
+        (WebCore::IDBDatabaseBackendImpl::IDBDatabaseBackendImpl):
+        (WebCore::IDBDatabaseBackendImpl::openInternal):
+        (WebCore::IDBDatabaseBackendImpl::metadata):
+        (WebCore::IDBDatabaseBackendImpl::createObjectStore):
+        (WebCore):
+        (WebCore::IDBDatabaseBackendImpl::createObjectStoreInternal):
+        (WebCore::IDBDatabaseBackendImpl::loadObjectStores):
+        * Modules/indexeddb/IDBDatabaseBackendImpl.h:
+        (IDBDatabaseBackendImpl):
+        * Modules/indexeddb/IDBDatabaseBackendInterface.h:
+        (IDBDatabaseBackendInterface):
+        * Modules/indexeddb/IDBIndexBackendImpl.cpp:
+        (WebCore::IDBIndexBackendImpl::metadata):
+        * Modules/indexeddb/IDBIndexBackendImpl.h:
+        (WebCore::IDBIndexBackendImpl::create):
+        (IDBIndexBackendImpl):
+        * Modules/indexeddb/IDBLevelDBBackingStore.cpp:
+        (WebCore):
+        (WebCore::getMaxObjectStoreId):
+        (WebCore::IDBLevelDBBackingStore::getIDBDatabaseMetaData):
+        (WebCore::IDBLevelDBBackingStore::deleteDatabase):
+        (WebCore::IDBLevelDBBackingStore::getObjectStores):
+        (WebCore::setMaxObjectStoreId):
+        (WebCore::IDBLevelDBBackingStore::createObjectStore):
+        (WebCore::getMaxIndexId):
+        (WebCore::setMaxIndexId):
+        (WebCore::IDBLevelDBBackingStore::createIndex):
+        * Modules/indexeddb/IDBLevelDBBackingStore.h:
+        (IDBLevelDBBackingStore):
+        * Modules/indexeddb/IDBMetadata.h:
+        (WebCore::IDBDatabaseMetadata::IDBDatabaseMetadata):
+        (IDBDatabaseMetadata):
+        (WebCore::IDBObjectStoreMetadata::IDBObjectStoreMetadata):
+        (IDBObjectStoreMetadata):
+        (WebCore::IDBIndexMetadata::IDBIndexMetadata):
+        (IDBIndexMetadata):
+        * Modules/indexeddb/IDBObjectStore.cpp:
+        (WebCore::IDBObjectStore::createIndex):
+        * Modules/indexeddb/IDBObjectStoreBackendImpl.cpp:
+        (WebCore::IDBObjectStoreBackendImpl::IDBObjectStoreBackendImpl):
+        (WebCore::IDBObjectStoreBackendImpl::metadata):
+        (WebCore::IDBObjectStoreBackendImpl::createIndex):
+        (WebCore):
+        (WebCore::IDBObjectStoreBackendImpl::createIndexInternal):
+        * Modules/indexeddb/IDBObjectStoreBackendImpl.h:
+        (WebCore::IDBObjectStoreBackendImpl::create):
+        (IDBObjectStoreBackendImpl):
+        * Modules/indexeddb/IDBObjectStoreBackendInterface.h:
 2012-10-04  Pravin D  <pravind.2k4@gmail.com>
 
         Layout broken after cloning and re-inserting a table with a misplaced <form>
index 11b511fc390fe60583f1e9ab94f08e41e7b55716..0a74e74902765767e4db4314ef0787ae28760fb8 100644 (file)
@@ -46,17 +46,21 @@ class IDBBackingStore : public RefCounted<IDBBackingStore> {
 public:
     class Transaction;
 
+    // FIXME: Remove these when switch to front-end ID management is complete: https://bugs.webkit.org/show_bug.cgi?id=98085
+    static const int64_t AutogenerateIndexId = -1;
+    static const int64_t AutogenerateObjectStoreId = -1;
+
     virtual ~IDBBackingStore() {};
 
     virtual void getDatabaseNames(Vector<String>& foundNames) = 0;
-    virtual bool getIDBDatabaseMetaData(const String& name, String& foundStringVersion, int64_t& foundIntVersion, int64_t& foundId) = 0;
+    virtual bool getIDBDatabaseMetaData(const String& name, String& foundStringVersion, int64_t& foundIntVersion, int64_t& foundId, int64_t& maxObjectStoreId) = 0;
     virtual bool createIDBDatabaseMetaData(const String& name, const String& stringVersion, int64_t intVersion, int64_t& rowId) = 0;
     virtual bool updateIDBDatabaseIntVersion(Transaction*, int64_t rowId, int64_t intVersion) = 0;
     virtual bool updateIDBDatabaseMetaData(Transaction*, int64_t rowId, const String& version) = 0;
     virtual bool deleteDatabase(const String& name) = 0;
 
-    virtual void getObjectStores(int64_t databaseId, Vector<int64_t>& foundIds, Vector<String>& foundNames, Vector<IDBKeyPath>& foundKeyPaths, Vector<bool>& foundAutoIncrementFlags) = 0;
-    virtual bool createObjectStore(Transaction*, int64_t databaseId, const String& name, const IDBKeyPath&, bool autoIncrement, int64_t& assignedObjectStoreId) = 0;
+    virtual void getObjectStores(int64_t databaseId, Vector<int64_t>& foundIds, Vector<String>& foundNames, Vector<IDBKeyPath>& foundKeyPaths, Vector<bool>& foundAutoIncrementFlags, Vector<int64_t>& foundMaxIndexIds) = 0;
+    virtual bool createObjectStore(Transaction*, int64_t databaseId, int64_t objectStoreId, const String& name, const IDBKeyPath&, bool autoIncrement, int64_t& assignedObjectStoreId) = 0;
     virtual void deleteObjectStore(Transaction*, int64_t databaseId, int64_t objectStoreId) = 0;
 
     class ObjectStoreRecordIdentifier : public RefCounted<ObjectStoreRecordIdentifier> {
@@ -82,7 +86,7 @@ public:
     virtual bool forEachObjectStoreRecord(Transaction*, int64_t databaseId, int64_t objectStoreId, ObjectStoreRecordCallback&) = 0;
 
     virtual void getIndexes(int64_t databaseId, int64_t objectStoreId, Vector<int64_t>& foundIds, Vector<String>& foundNames, Vector<IDBKeyPath>& foundKeyPaths, Vector<bool>& foundUniqueFlags, Vector<bool>& foundMultiEntryFlags) = 0;
-    virtual bool createIndex(Transaction*, int64_t databaseId, int64_t objectStoreId, const String& name, const IDBKeyPath&, bool isUnique, bool isMultiEntry, int64_t& indexId) = 0;
+    virtual bool createIndex(Transaction*, int64_t databaseId, int64_t objectStoreId, int64_t indexId, const String& name, const IDBKeyPath&, bool isUnique, bool isMultiEntry, int64_t& assignedIndexId) = 0;
     virtual void deleteIndex(Transaction*, int64_t databaseId, int64_t objectStoreId, int64_t indexId) = 0;
     virtual bool putIndexDataForRecord(Transaction*, int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKey&, const ObjectStoreRecordIdentifier*) = 0;
     virtual bool deleteIndexDataForRecord(Transaction*, int64_t databaseId, int64_t objectStoreId, int64_t indexId, const ObjectStoreRecordIdentifier*) = 0;
index 43e0bdeeee83c807de96e24b67284de877a5b211..d972c2dbd2565c359aa0601d16ff3249f43473b2 100644 (file)
@@ -167,9 +167,11 @@ PassRefPtr<IDBObjectStore> IDBDatabase::createObjectStore(const String& name, co
         return 0;
     }
 
-    IDBObjectStoreMetadata metadata(name, keyPath, autoIncrement);
+    int64_t objectStoreId = IDBDatabaseBackendInterface::AutogenerateObjectStoreId;
+    IDBObjectStoreMetadata metadata(name, objectStoreId, keyPath, autoIncrement, IDBObjectStoreBackendInterface::MinimumIndexId);
     RefPtr<IDBObjectStore> objectStore = IDBObjectStore::create(metadata, objectStoreBackend.release(), m_versionChangeTransaction.get());
     m_metadata.objectStores.set(name, metadata);
+    ++m_metadata.maxObjectStoreId;
 
     m_versionChangeTransaction->objectStoreCreated(name, objectStore);
     return objectStore.release();
index 4466c5cd66406ae95c85eec94362a476fa0179d8..6c41ed608e84d07d3a88c2dbbb16217d6f8a39b4 100644 (file)
@@ -137,6 +137,7 @@ IDBDatabaseBackendImpl::IDBDatabaseBackendImpl(const String& name, IDBBackingSto
     , m_name(name)
     , m_version(NoStringVersion)
     , m_intVersion(IDBDatabaseMetadata::NoIntVersion)
+    , m_maxObjectStoreId(InvalidId)
     , m_identifier(uniqueIdentifier)
     , m_factory(factory)
     , m_transactionCoordinator(IDBTransactionCoordinator::create())
@@ -147,7 +148,7 @@ IDBDatabaseBackendImpl::IDBDatabaseBackendImpl(const String& name, IDBBackingSto
 
 bool IDBDatabaseBackendImpl::openInternal()
 {
-    bool success = m_backingStore->getIDBDatabaseMetaData(m_name, m_version, m_intVersion, m_id);
+    bool success = m_backingStore->getIDBDatabaseMetaData(m_name, m_version, m_intVersion, m_id, m_maxObjectStoreId);
     ASSERT_WITH_MESSAGE(success == (m_id != InvalidId), "success = %s, m_id = %lld", success ? "true" : "false", static_cast<long long>(m_id));
     if (success) {
         loadObjectStores();
@@ -167,22 +168,32 @@ PassRefPtr<IDBBackingStore> IDBDatabaseBackendImpl::backingStore() const
 
 IDBDatabaseMetadata IDBDatabaseBackendImpl::metadata() const
 {
-    IDBDatabaseMetadata metadata(m_name, m_version, m_intVersion);
+    IDBDatabaseMetadata metadata(m_name, m_id, m_version, m_intVersion, m_maxObjectStoreId);
     for (ObjectStoreMap::const_iterator it = m_objectStores.begin(); it != m_objectStores.end(); ++it)
         metadata.objectStores.set(it->first, it->second->metadata());
     return metadata;
 }
 
 PassRefPtr<IDBObjectStoreBackendInterface> IDBDatabaseBackendImpl::createObjectStore(const String& name, const IDBKeyPath& keyPath, bool autoIncrement, IDBTransactionBackendInterface* transactionPtr, ExceptionCode& ec)
+{
+    return createObjectStore(AutogenerateObjectStoreId, name, keyPath, autoIncrement, transactionPtr, ec);
+}
+
+PassRefPtr<IDBObjectStoreBackendInterface> IDBDatabaseBackendImpl::createObjectStore(int64_t id, const String& name, const IDBKeyPath& keyPath, bool autoIncrement, IDBTransactionBackendInterface* transactionPtr, ExceptionCode& ec)
 {
     ASSERT(!m_objectStores.contains(name));
 
-    RefPtr<IDBObjectStoreBackendImpl> objectStore = IDBObjectStoreBackendImpl::create(this, name, keyPath, autoIncrement);
+    COMPILE_ASSERT(AutogenerateObjectStoreId == IDBBackingStore::AutogenerateObjectStoreId, AutogenerateObjectStoreIdMatches);
+    RefPtr<IDBObjectStoreBackendImpl> objectStore = IDBObjectStoreBackendImpl::create(this, id, name, keyPath, autoIncrement, IDBObjectStoreBackendInterface::MinimumIndexId);
     ASSERT(objectStore->name() == name);
 
     RefPtr<IDBTransactionBackendImpl> transaction = IDBTransactionBackendImpl::from(transactionPtr);
     ASSERT(transaction->mode() == IDBTransaction::VERSION_CHANGE);
 
+    // FIXME: Fix edge cases around transaction aborts that prevent this from just being ASSERT(id == m_maxObjectStoreId + 1)
+    ASSERT(id == AutogenerateObjectStoreId || id > m_maxObjectStoreId);
+    m_maxObjectStoreId = id;
+
     RefPtr<IDBDatabaseBackendImpl> database = this;
     if (!transaction->scheduleTask(
             createCallbackTask(&IDBDatabaseBackendImpl::createObjectStoreInternal, database, objectStore, transaction),
@@ -199,11 +210,13 @@ void IDBDatabaseBackendImpl::createObjectStoreInternal(ScriptExecutionContext*,
 {
     int64_t objectStoreId;
 
-    if (!database->m_backingStore->createObjectStore(transaction->backingStoreTransaction(), database->id(), objectStore->name(), objectStore->keyPath(), objectStore->autoIncrement(), objectStoreId)) {
+    if (!database->m_backingStore->createObjectStore(transaction->backingStoreTransaction(), database->id(), objectStore->id(), objectStore->name(), objectStore->keyPath(), objectStore->autoIncrement(), objectStoreId)) {
         transaction->abort();
         return;
     }
 
+    // FIXME: Remove this when switch to front-end ID management is complete: https://bugs.webkit.org/show_bug.cgi?id=98085
+    ASSERT(objectStore->id() == AutogenerateObjectStoreId || objectStore->id() == objectStoreId);
     objectStore->setId(objectStoreId);
     transaction->didCompleteTaskEvents();
 }
@@ -606,14 +619,16 @@ void IDBDatabaseBackendImpl::loadObjectStores()
     Vector<String> names;
     Vector<IDBKeyPath> keyPaths;
     Vector<bool> autoIncrementFlags;
-    m_backingStore->getObjectStores(m_id, ids, names, keyPaths, autoIncrementFlags);
+    Vector<int64_t> maxIndexIds;
+    m_backingStore->getObjectStores(m_id, ids, names, keyPaths, autoIncrementFlags, maxIndexIds);
 
     ASSERT(names.size() == ids.size());
     ASSERT(keyPaths.size() == ids.size());
     ASSERT(autoIncrementFlags.size() == ids.size());
+    ASSERT(maxIndexIds.size() == ids.size());
 
     for (size_t i = 0; i < ids.size(); i++)
-        m_objectStores.set(names[i], IDBObjectStoreBackendImpl::create(this, ids[i], names[i], keyPaths[i], autoIncrementFlags[i]));
+        m_objectStores.set(names[i], IDBObjectStoreBackendImpl::create(this, ids[i], names[i], keyPaths[i], autoIncrementFlags[i], maxIndexIds[i]));
 }
 
 void IDBDatabaseBackendImpl::removeObjectStoreFromMap(ScriptExecutionContext*, PassRefPtr<IDBDatabaseBackendImpl> database, PassRefPtr<IDBObjectStoreBackendImpl> prpObjectStore)
index 7342e7054b525df99251b5dfd83fd25a38a31aa7..1994b5f9b54188977317ffb49015e6f422b31a82 100644 (file)
@@ -62,6 +62,7 @@ public:
     // IDBDatabaseBackendInterface
     virtual IDBDatabaseMetadata metadata() const;
     virtual PassRefPtr<IDBObjectStoreBackendInterface> createObjectStore(const String& name, const IDBKeyPath&, bool autoIncrement, IDBTransactionBackendInterface*, ExceptionCode&);
+    virtual PassRefPtr<IDBObjectStoreBackendInterface> createObjectStore(int64_t id, const String& name, const IDBKeyPath&, bool autoIncrement, IDBTransactionBackendInterface*, ExceptionCode&);
     virtual void deleteObjectStore(const String& name, IDBTransactionBackendInterface*, ExceptionCode&);
     virtual void setVersion(const String& version, PassRefPtr<IDBCallbacks>, PassRefPtr<IDBDatabaseCallbacks>, ExceptionCode&);
     virtual PassRefPtr<IDBTransactionBackendInterface> transaction(DOMStringList* objectStoreNames, unsigned short mode, ExceptionCode&);
@@ -98,6 +99,7 @@ private:
     String m_name;
     String m_version;
     int64_t m_intVersion;
+    int64_t m_maxObjectStoreId;
 
     String m_identifier;
     // This might not need to be a RefPtr since the factory's lifetime is that of the page group, but it's better to be conservitive than sorry.
index cbcb9a59c556ac05ca76b4cb7880bb39fec01268..a32a96bca058b0e82f9075c5341d5dc39870261a 100644 (file)
@@ -54,6 +54,11 @@ public:
 
     virtual IDBDatabaseMetadata metadata() const = 0;
 
+    // FIXME: Remove this when switch to front-end ID management is complete: https://bugs.webkit.org/show_bug.cgi?id=98085
+    static const int64_t AutogenerateObjectStoreId = -1;
+
+    virtual PassRefPtr<IDBObjectStoreBackendInterface> createObjectStore(int64_t, const String& name, const IDBKeyPath&, bool autoIncrement, IDBTransactionBackendInterface*, ExceptionCode&) = 0;
+    // FIXME: Remove this when switch to front-end ID management is complete: https://bugs.webkit.org/show_bug.cgi?id=98085
     virtual PassRefPtr<IDBObjectStoreBackendInterface> createObjectStore(const String& name, const IDBKeyPath&, bool autoIncrement, IDBTransactionBackendInterface*, ExceptionCode&) = 0;
     virtual void deleteObjectStore(const String& name, IDBTransactionBackendInterface*, ExceptionCode&) = 0;
     virtual void setVersion(const String& version, PassRefPtr<IDBCallbacks>, PassRefPtr<IDBDatabaseCallbacks>, ExceptionCode&) = 0;
index e3d3e043d24907ab32408e53854cf756fae302da..7f32b9cd2ffe153e7edb02e26cda4a6ac5b44bb0 100644 (file)
@@ -54,24 +54,13 @@ IDBIndexBackendImpl::IDBIndexBackendImpl(const IDBDatabaseBackendImpl* database,
 {
 }
 
-IDBIndexBackendImpl::IDBIndexBackendImpl(const IDBDatabaseBackendImpl* database, IDBObjectStoreBackendImpl* objectStoreBackend, const String& name, const IDBKeyPath& keyPath, bool unique, bool multiEntry)
-    : m_database(database)
-    , m_objectStoreBackend(objectStoreBackend)
-    , m_id(InvalidId)
-    , m_name(name)
-    , m_keyPath(keyPath)
-    , m_unique(unique)
-    , m_multiEntry(multiEntry)
-{
-}
-
 IDBIndexBackendImpl::~IDBIndexBackendImpl()
 {
 }
 
 IDBIndexMetadata IDBIndexBackendImpl::metadata() const
 {
-    return IDBIndexMetadata(m_name, m_keyPath, m_unique, m_multiEntry);
+    return IDBIndexMetadata(m_name, m_id, m_keyPath, m_unique, m_multiEntry);
 }
 
 void IDBIndexBackendImpl::openCursorInternal(ScriptExecutionContext*, PassRefPtr<IDBIndexBackendImpl> index, PassRefPtr<IDBKeyRange> range, unsigned short untypedDirection, IDBCursorBackendInterface::CursorType cursorType, PassRefPtr<IDBCallbacks> callbacks, PassRefPtr<IDBTransactionBackendImpl> transaction)
index 173c32d08ff1433b9990e5052250cc89ca6da8b9..9fbec1697e271c73a02d5615676c63ce4d910b0c 100644 (file)
@@ -47,10 +47,6 @@ public:
     {
         return adoptRef(new IDBIndexBackendImpl(database, objectStoreBackend, id, name, keyPath, unique, multiEntry));
     }
-    static PassRefPtr<IDBIndexBackendImpl> create(const IDBDatabaseBackendImpl* database, IDBObjectStoreBackendImpl* objectStoreBackend, const String& name, const IDBKeyPath& keyPath, bool unique, bool multiEntry)
-    {
-        return adoptRef(new IDBIndexBackendImpl(database, objectStoreBackend, name, keyPath, unique, multiEntry));
-    }
     virtual ~IDBIndexBackendImpl();
 
     int64_t id() const
@@ -76,7 +72,6 @@ public:
 
 private:
     IDBIndexBackendImpl(const IDBDatabaseBackendImpl*, IDBObjectStoreBackendImpl*, int64_t id, const String& name, const IDBKeyPath&, bool unique, bool multiEntry);
-    IDBIndexBackendImpl(const IDBDatabaseBackendImpl*, IDBObjectStoreBackendImpl*, const String& name, const IDBKeyPath&, bool unique, bool multiEntry);
 
     static void openCursorInternal(ScriptExecutionContext*, PassRefPtr<IDBIndexBackendImpl>, PassRefPtr<IDBKeyRange>, unsigned short direction, IDBCursorBackendInterface::CursorType, PassRefPtr<IDBCallbacks>, PassRefPtr<IDBTransactionBackendImpl>);
     static void countInternal(ScriptExecutionContext*, PassRefPtr<IDBIndexBackendImpl>, PassRefPtr<IDBKeyRange>, PassRefPtr<IDBCallbacks>, PassRefPtr<IDBTransactionBackendImpl>);
index 50edfd46cc0c2c9934dc5d5c89d2ec5ad7edbdba..8c305bca3778ad8977d1b76eec7bdb1eb419b7da 100644 (file)
@@ -194,6 +194,24 @@ static bool setUpMetadata(LevelDBDatabase* db, const String& origin)
     return true;
 }
 
+template <typename DBOrTransaction>
+static int64_t getMaxObjectStoreId(DBOrTransaction* db, int64_t databaseId)
+{
+    const Vector<char> maxObjectStoreIdKey = DatabaseMetaDataKey::encode(databaseId, DatabaseMetaDataKey::MaxObjectStoreId);
+    return getMaxObjectStoreId(db, maxObjectStoreIdKey);
+}
+
+template <typename DBOrTransaction>
+static int64_t getMaxObjectStoreId(DBOrTransaction* db, const Vector<char>& maxObjectStoreIdKey)
+{
+    int64_t maxObjectStoreId = -1;
+    if (!getInt(db, maxObjectStoreIdKey, maxObjectStoreId))
+        maxObjectStoreId = 0;
+
+    ASSERT(maxObjectStoreId >= 0);
+    return maxObjectStoreId;
+}
+
 IDBLevelDBBackingStore::IDBLevelDBBackingStore(const String& identifier, IDBFactoryBackendImpl* factory, PassOwnPtr<LevelDBDatabase> db)
     : m_identifier(identifier)
     , m_factory(factory)
@@ -282,7 +300,7 @@ void IDBLevelDBBackingStore::getDatabaseNames(Vector<String>& foundNames)
     }
 }
 
-bool IDBLevelDBBackingStore::getIDBDatabaseMetaData(const String& name, String& foundStringVersion, int64_t& foundIntVersion, int64_t& foundId)
+bool IDBLevelDBBackingStore::getIDBDatabaseMetaData(const String& name, String& foundStringVersion, int64_t& foundIntVersion, int64_t& foundId, int64_t& maxObjectStoreId)
 {
     const Vector<char> key = DatabaseNameKey::encode(m_identifier, name);
 
@@ -300,6 +318,8 @@ bool IDBLevelDBBackingStore::getIDBDatabaseMetaData(const String& name, String&
     if (foundIntVersion == IDBDatabaseMetadata::DefaultIntVersion)
         foundIntVersion = IDBDatabaseMetadata::NoIntVersion;
 
+    maxObjectStoreId = getMaxObjectStoreId(m_db.get(), foundId);
+
     return true;
 }
 
@@ -375,7 +395,8 @@ bool IDBLevelDBBackingStore::deleteDatabase(const String& name)
     int64_t databaseId;
     String version;
     int64_t intVersion;
-    if (!getIDBDatabaseMetaData(name, version, intVersion, databaseId))
+    int64_t maxObjectStoreId;
+    if (!getIDBDatabaseMetaData(name, version, intVersion, databaseId, maxObjectStoreId))
         return true;
 
     const Vector<char> startKey = DatabaseMetaDataKey::encode(databaseId, DatabaseMetaDataKey::OriginName);
@@ -405,7 +426,7 @@ static bool checkObjectStoreAndMetaDataType(const LevelDBIterator* it, const Vec
     return true;
 }
 
-void IDBLevelDBBackingStore::getObjectStores(int64_t databaseId, Vector<int64_t>& foundIds, Vector<String>& foundNames, Vector<IDBKeyPath>& foundKeyPaths, Vector<bool>& foundAutoIncrementFlags)
+void IDBLevelDBBackingStore::getObjectStores(int64_t databaseId, Vector<int64_t>& foundIds, Vector<String>& foundNames, Vector<IDBKeyPath>& foundKeyPaths, Vector<bool>& foundAutoIncrementFlags, Vector<int64_t>& foundMaxIndexIds)
 {
     IDB_TRACE("IDBLevelDBBackingStore::getObjectStores");
     const Vector<char> startKey = ObjectStoreMetaDataKey::encode(databaseId, 1, 0);
@@ -415,6 +436,7 @@ void IDBLevelDBBackingStore::getObjectStores(int64_t databaseId, Vector<int64_t>
     ASSERT(foundNames.isEmpty());
     ASSERT(foundKeyPaths.isEmpty());
     ASSERT(foundAutoIncrementFlags.isEmpty());
+    ASSERT(foundMaxIndexIds.isEmpty());
 
     OwnPtr<LevelDBIterator> it = m_db->createIterator();
     it->seek(startKey);
@@ -468,6 +490,7 @@ void IDBLevelDBBackingStore::getObjectStores(int64_t databaseId, Vector<int64_t>
             LOG_ERROR("Internal Indexed DB error.");
             return;
         }
+        int64_t maxIndexId = decodeInt(it->value().begin(), it->value().end());
 
         it->next(); // [optional] has key path (is not null)
         if (checkObjectStoreAndMetaDataType(it.get(), stopKey, objectStoreId, ObjectStoreMetaDataKey::HasKeyPath)) {
@@ -498,31 +521,31 @@ void IDBLevelDBBackingStore::getObjectStores(int64_t databaseId, Vector<int64_t>
         foundNames.append(objectStoreName);
         foundKeyPaths.append(keyPath);
         foundAutoIncrementFlags.append(autoIncrement);
+        foundMaxIndexIds.append(maxIndexId);
     }
 }
 
-static int64_t getNewObjectStoreId(LevelDBTransaction* transaction, int64_t databaseId)
+static bool setMaxObjectStoreId(LevelDBTransaction* transaction, int64_t databaseId, int64_t objectStoreId)
 {
-    int64_t maxObjectStoreId = -1;
     const Vector<char> maxObjectStoreIdKey = DatabaseMetaDataKey::encode(databaseId, DatabaseMetaDataKey::MaxObjectStoreId);
-    if (!getInt(transaction, maxObjectStoreIdKey, maxObjectStoreId))
-        maxObjectStoreId = 0;
-
-    ASSERT(maxObjectStoreId >= 0);
+    int64_t maxObjectStoreId = getMaxObjectStoreId(transaction, maxObjectStoreIdKey);
 
-    int64_t objectStoreId = maxObjectStoreId + 1;
-    if (!putInt(transaction, maxObjectStoreIdKey, objectStoreId))
-        return -1;
-
-    return objectStoreId;
+    if (objectStoreId <= maxObjectStoreId) {
+        LOG_ERROR("Possible corruption: new object store id is too small.");
+        return false;
+    }
+    return putInt(transaction, maxObjectStoreIdKey, objectStoreId);
 }
 
-bool IDBLevelDBBackingStore::createObjectStore(IDBBackingStore::Transaction* transaction, int64_t databaseId, const String& name, const IDBKeyPath& keyPath, bool autoIncrement, int64_t& assignedObjectStoreId)
+bool IDBLevelDBBackingStore::createObjectStore(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, const String& name, const IDBKeyPath& keyPath, bool autoIncrement, int64_t& assignedObjectStoreId)
 {
     IDB_TRACE("IDBLevelDBBackingStore::createObjectStore");
     LevelDBTransaction* levelDBTransaction = Transaction::levelDBTransactionFrom(transaction);
-    int64_t objectStoreId = getNewObjectStoreId(levelDBTransaction, databaseId);
-    if (objectStoreId < 0)
+    // FIXME: Remove this when switch to front-end ID management is complete: https://bugs.webkit.org/show_bug.cgi?id=98085
+    if (objectStoreId == AutogenerateObjectStoreId)
+        objectStoreId = getMaxObjectStoreId(levelDBTransaction, databaseId) + 1;
+
+    if (!setMaxObjectStoreId(levelDBTransaction, databaseId, objectStoreId))
         return false;
 
     const Vector<char> nameKey = ObjectStoreMetaDataKey::encode(databaseId, objectStoreId, ObjectStoreMetaDataKey::Name);
@@ -589,6 +612,7 @@ bool IDBLevelDBBackingStore::createObjectStore(IDBBackingStore::Transaction* tra
         return false;
     }
 
+    // FIXME: Remove this when switch to front-end ID management is complete: https://bugs.webkit.org/show_bug.cgi?id=98085
     assignedObjectStoreId = objectStoreId;
 
     return true;
@@ -918,7 +942,7 @@ void IDBLevelDBBackingStore::getIndexes(int64_t databaseId, int64_t objectStoreI
     }
 }
 
-static int64_t getNewIndexId(LevelDBTransaction* transaction, int64_t databaseId, int64_t objectStoreId)
+static int64_t getMaxIndexId(LevelDBTransaction* transaction, int64_t databaseId, int64_t objectStoreId)
 {
     int64_t maxIndexId = -1;
     const Vector<char> maxIndexIdKey = ObjectStoreMetaDataKey::encode(databaseId, objectStoreId, ObjectStoreMetaDataKey::MaxIndexId);
@@ -926,20 +950,37 @@ static int64_t getNewIndexId(LevelDBTransaction* transaction, int64_t databaseId
         maxIndexId = MinimumIndexId;
 
     ASSERT(maxIndexId >= 0);
+    return maxIndexId;
+}
 
-    int64_t indexId = maxIndexId + 1;
-    if (!putInt(transaction, maxIndexIdKey, indexId))
-        return -1;
+static bool setMaxIndexId(LevelDBTransaction* transaction, int64_t databaseId, int64_t objectStoreId, int64_t indexId)
+{
+    int64_t maxIndexId = -1;
+    const Vector<char> maxIndexIdKey = ObjectStoreMetaDataKey::encode(databaseId, objectStoreId, ObjectStoreMetaDataKey::MaxIndexId);
+    if (!getInt(transaction, maxIndexIdKey, maxIndexId))
+        maxIndexId = MinimumIndexId;
 
-    return indexId;
+    // FIXME: Remove this when switch to front-end ID management is complete: https://bugs.webkit.org/show_bug.cgi?id=98085
+    if (indexId == IDBBackingStore::AutogenerateIndexId)
+        indexId = maxIndexId + 1;
+
+    if (indexId <= maxIndexId) {
+        LOG_ERROR("Possible corruption: new index id is too small.");
+        return false;
+    }
+
+    return putInt(transaction, maxIndexIdKey, indexId);
 }
 
-bool IDBLevelDBBackingStore::createIndex(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, const String& name, const IDBKeyPath& keyPath, bool isUnique, bool isMultiEntry, int64_t& indexId)
+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, int64_t& assignedIndexId)
 {
     IDB_TRACE("IDBLevelDBBackingStore::createIndex");
     LevelDBTransaction* levelDBTransaction = Transaction::levelDBTransactionFrom(transaction);
-    indexId = getNewIndexId(levelDBTransaction, databaseId, objectStoreId);
-    if (indexId < 0)
+    // FIXME: Remove this when switch to front-end ID management is complete: https://bugs.webkit.org/show_bug.cgi?id=98085
+    if (indexId == AutogenerateIndexId)
+        indexId = getMaxIndexId(levelDBTransaction, databaseId, objectStoreId) + 1;
+
+    if (!setMaxIndexId(levelDBTransaction, databaseId, objectStoreId, indexId))
         return false;
 
     const Vector<char> nameKey = IndexMetaDataKey::encode(databaseId, objectStoreId, indexId, IndexMetaDataKey::Name);
@@ -971,6 +1012,9 @@ bool IDBLevelDBBackingStore::createIndex(IDBBackingStore::Transaction* transacti
         return false;
     }
 
+    // FIXME: Remove this when switch to front-end ID management is complete: https://bugs.webkit.org/show_bug.cgi?id=98085
+    assignedIndexId = indexId;
+
     return true;
 }
 
index 77cb06e785af8098097b9e92c86fe1f2a7edf669..eea23d294f0e9406751877233a02efd3764f112a 100644 (file)
@@ -45,14 +45,14 @@ public:
     virtual ~IDBLevelDBBackingStore();
 
     virtual void getDatabaseNames(Vector<String>& foundNames);
-    virtual bool getIDBDatabaseMetaData(const String& name, String& foundVersion, int64_t& foundIntVersion, int64_t& foundId);
+    virtual bool getIDBDatabaseMetaData(const String& name, String& foundVersion, int64_t& foundIntVersion, int64_t& foundId, int64_t& maxObjectStoreId);
     virtual bool createIDBDatabaseMetaData(const String& name, const String& version, int64_t intVersion, int64_t& rowId);
     virtual bool updateIDBDatabaseMetaData(IDBBackingStore::Transaction*, int64_t rowId, const String& version);
     virtual bool updateIDBDatabaseIntVersion(IDBBackingStore::Transaction*, int64_t rowId, int64_t intVersion);
     virtual bool deleteDatabase(const String& name);
 
-    virtual void getObjectStores(int64_t databaseId, Vector<int64_t>& foundIds, Vector<String>& foundNames, Vector<IDBKeyPath>& foundKeyPaths, Vector<bool>& foundAutoIncrementFlags);
-    virtual bool createObjectStore(IDBBackingStore::Transaction*, int64_t databaseId, const String& name, const IDBKeyPath&, bool autoIncrement, int64_t& assignedObjectStoreId);
+    virtual void getObjectStores(int64_t databaseId, Vector<int64_t>& foundIds, Vector<String>& foundNames, Vector<IDBKeyPath>& foundKeyPaths, Vector<bool>& foundAutoIncrementFlags, Vector<int64_t>& foundMaxIndexIds);
+    virtual bool createObjectStore(IDBBackingStore::Transaction*, int64_t databaseId, int64_t objectStoreId, const String& name, const IDBKeyPath&, bool autoIncrement, int64_t& assignedObjectStoreId);
     virtual void deleteObjectStore(IDBBackingStore::Transaction*, int64_t databaseId, int64_t objectStoreId);
     virtual PassRefPtr<ObjectStoreRecordIdentifier> createInvalidRecordIdentifier();
     virtual String getObjectStoreRecord(IDBBackingStore::Transaction*, int64_t databaseId, int64_t objectStoreId, const IDBKey&);
@@ -66,7 +66,7 @@ public:
     virtual bool forEachObjectStoreRecord(IDBBackingStore::Transaction*, int64_t databaseId, int64_t objectStoreId, ObjectStoreRecordCallback&);
 
     virtual void getIndexes(int64_t databaseId, int64_t objectStoreId, Vector<int64_t>& foundIds, Vector<String>& foundNames, Vector<IDBKeyPath>& foundKeyPaths, Vector<bool>& foundUniqueFlags, Vector<bool>& foundMultiEntryFlags);
-    virtual bool createIndex(IDBBackingStore::Transaction*, int64_t databaseId, int64_t objectStoreId, const String& name, const IDBKeyPath&, bool isUnique, bool isMultiEntry, int64_t& indexId);
+    virtual bool createIndex(IDBBackingStore::Transaction*, int64_t databaseId, int64_t objectStoreId, int64_t indexId, const String& name, const IDBKeyPath&, bool isUnique, bool isMultiEntry, int64_t& assignedIndexId);
     virtual void deleteIndex(IDBBackingStore::Transaction*, int64_t databaseId, int64_t objectStoreId, int64_t indexId);
     virtual bool putIndexDataForRecord(IDBBackingStore::Transaction*, int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKey&, const ObjectStoreRecordIdentifier*);
     virtual bool deleteIndexDataForRecord(IDBBackingStore::Transaction*, int64_t databaseId, int64_t objectStoreId, int64_t indexId, const ObjectStoreRecordIdentifier*);
index b3cbca1b2649062a4ccf0781b3cf1c8034f9f607..096f89afa93d11f9b8bb8fecbe97f91dc215430d 100644 (file)
@@ -52,16 +52,20 @@ struct IDBDatabaseMetadata {
         : intVersion(NoIntVersion)
     {
     }
-    IDBDatabaseMetadata(const String& name, const String& version, int64_t intVersion)
+    IDBDatabaseMetadata(const String& name, int64_t id, const String& version, int64_t intVersion, int64_t maxObjectStoreId)
         : name(name)
+        , id(id)
         , version(version)
         , intVersion(intVersion)
+        , maxObjectStoreId(maxObjectStoreId)
     {
     }
 
     String name;
+    int64_t id;
     String version;
     int64_t intVersion;
+    int64_t maxObjectStoreId;
 
     typedef HashMap<String, IDBObjectStoreMetadata> ObjectStoreMap;
     ObjectStoreMap objectStores;
@@ -69,13 +73,18 @@ struct IDBDatabaseMetadata {
 
 struct IDBObjectStoreMetadata {
     IDBObjectStoreMetadata() { }
-    IDBObjectStoreMetadata(const String& name, const IDBKeyPath& keyPath, bool autoIncrement)
+    IDBObjectStoreMetadata(const String& name, int64_t id, const IDBKeyPath& keyPath, bool autoIncrement, int64_t maxIndexId)
         : name(name)
         , keyPath(keyPath)
-        , autoIncrement(autoIncrement) { }
+        , autoIncrement(autoIncrement)
+        , maxIndexId(maxIndexId)
+    {
+    }
     String name;
+    int64_t id;
     IDBKeyPath keyPath;
     bool autoIncrement;
+    int64_t maxIndexId;
 
     typedef HashMap<String, IDBIndexMetadata> IndexMap;
     IndexMap indexes;
@@ -83,12 +92,14 @@ struct IDBObjectStoreMetadata {
 
 struct IDBIndexMetadata {
     IDBIndexMetadata() { }
-    IDBIndexMetadata(const String& name, const IDBKeyPath& keyPath, bool unique, bool multiEntry)
+    IDBIndexMetadata(const String& name, int64_t id, const IDBKeyPath& keyPath, bool unique, bool multiEntry)
         : name(name)
+        , id(id)
         , keyPath(keyPath)
         , unique(unique)
         , multiEntry(multiEntry) { }
     String name;
+    int64_t id;
     IDBKeyPath keyPath;
     bool unique;
     bool multiEntry;
index 4cbe63d115e0aa044b60f94e54bfeeadc94e7bdc..2177f7ea0d7d4bb6dc4d0cad27ef3abe28ece64d 100644 (file)
@@ -401,12 +401,15 @@ PassRefPtr<IDBIndex> IDBObjectStore::createIndex(ScriptExecutionContext* context
         return 0;
     }
 
+    int64_t indexId = IDBObjectStoreBackendInterface::AutogenerateIndexId;
     RefPtr<IDBIndexBackendInterface> indexBackend = m_backend->createIndex(name, keyPath, unique, multiEntry, m_transaction->backend(), ec);
     ASSERT(!indexBackend != !ec); // If we didn't get an index, we should have gotten an exception code. And vice versa.
     if (ec)
         return 0;
 
-    IDBIndexMetadata metadata(name, keyPath, unique, multiEntry);
+    ++m_metadata.maxIndexId;
+
+    IDBIndexMetadata metadata(name, indexId, keyPath, unique, multiEntry);
     RefPtr<IDBIndex> index = IDBIndex::create(metadata, indexBackend.release(), this, m_transaction.get());
     m_indexMap.set(name, index);
     m_metadata.indexes.set(name, metadata);
index 789992ab6e5c34df45cb29a655d6c9a6755521a5..1c94c8a961fc2dc5a84cec39f830916819f51c4b 100644 (file)
@@ -51,28 +51,21 @@ IDBObjectStoreBackendImpl::~IDBObjectStoreBackendImpl()
 {
 }
 
-IDBObjectStoreBackendImpl::IDBObjectStoreBackendImpl(const IDBDatabaseBackendImpl* database, int64_t id, const String& name, const IDBKeyPath& keyPath, bool autoIncrement)
+IDBObjectStoreBackendImpl::IDBObjectStoreBackendImpl(const IDBDatabaseBackendImpl* database, int64_t id, const String& name, const IDBKeyPath& keyPath, bool autoIncrement, int64_t maxIndexId)
     : m_database(database)
     , m_id(id)
     , m_name(name)
     , m_keyPath(keyPath)
     , m_autoIncrement(autoIncrement)
+    , m_maxIndexId(maxIndexId)
 {
-    loadIndexes();
-}
-
-IDBObjectStoreBackendImpl::IDBObjectStoreBackendImpl(const IDBDatabaseBackendImpl* database, const String& name, const IDBKeyPath& keyPath, bool autoIncrement)
-    : m_database(database)
-    , m_id(InvalidId)
-    , m_name(name)
-    , m_keyPath(keyPath)
-    , m_autoIncrement(autoIncrement)
-{
+    if (m_id != AutogenerateIndexId)
+        loadIndexes();
 }
 
 IDBObjectStoreMetadata IDBObjectStoreBackendImpl::metadata() const
 {
-    IDBObjectStoreMetadata metadata(m_name, m_keyPath, m_autoIncrement);
+    IDBObjectStoreMetadata metadata(m_name, m_id, m_keyPath, m_autoIncrement, m_maxIndexId);
     for (IndexMap::const_iterator it = m_indexes.begin(); it != m_indexes.end(); ++it)
         metadata.indexes.set(it->first, it->second->metadata());
     return metadata;
@@ -436,13 +429,21 @@ void IDBObjectStoreBackendImpl::clearInternal(ScriptExecutionContext*, PassRefPt
 
 PassRefPtr<IDBIndexBackendInterface> IDBObjectStoreBackendImpl::createIndex(const String& name, const IDBKeyPath& keyPath, bool unique, bool multiEntry, IDBTransactionBackendInterface* transactionPtr, ExceptionCode& ec)
 {
-    ASSERT(!m_indexes.contains(name));
+    return createIndex(AutogenerateIndexId, name, keyPath, unique, multiEntry, transactionPtr, ec);
+}
+
+PassRefPtr<IDBIndexBackendInterface> IDBObjectStoreBackendImpl::createIndex(int64_t id, const String& name, const IDBKeyPath& keyPath, bool unique, bool multiEntry, IDBTransactionBackendInterface* transactionPtr, ExceptionCode& ec)
+{
+    ASSERT_WITH_MESSAGE(!m_indexes.contains(name), "Indexes already contain %s", name.utf8().data());
 
-    RefPtr<IDBIndexBackendImpl> index = IDBIndexBackendImpl::create(m_database, this, name, keyPath, unique, multiEntry);
+    COMPILE_ASSERT(AutogenerateIndexId == IDBBackingStore::AutogenerateIndexId, AutogenerateIndexIdMatches);
+    RefPtr<IDBIndexBackendImpl> index = IDBIndexBackendImpl::create(m_database, this, id, name, keyPath, unique, multiEntry);
     ASSERT(index->name() == name);
 
     RefPtr<IDBTransactionBackendImpl> transaction = IDBTransactionBackendImpl::from(transactionPtr);
     ASSERT(transaction->mode() == IDBTransaction::VERSION_CHANGE);
+    ASSERT(id == AutogenerateIndexId || id > m_maxIndexId);
+    m_maxIndexId = id;
 
     RefPtr<IDBObjectStoreBackendImpl> objectStore = this;
     if (!transaction->scheduleTask(
@@ -459,11 +460,13 @@ PassRefPtr<IDBIndexBackendInterface> IDBObjectStoreBackendImpl::createIndex(cons
 void IDBObjectStoreBackendImpl::createIndexInternal(ScriptExecutionContext*, PassRefPtr<IDBObjectStoreBackendImpl> objectStore, PassRefPtr<IDBIndexBackendImpl> index, PassRefPtr<IDBTransactionBackendImpl> transaction)
 {
     int64_t id;
-    if (!objectStore->backingStore()->createIndex(transaction->backingStoreTransaction(), objectStore->databaseId(), objectStore->id(), index->name(), index->keyPath(), index->unique(), index->multiEntry(), id)) {
+    if (!objectStore->backingStore()->createIndex(transaction->backingStoreTransaction(), objectStore->databaseId(), objectStore->id(), index->id(), index->name(), index->keyPath(), index->unique(), index->multiEntry(), id)) {
         transaction->abort();
         return;
     }
 
+    // FIXME: Remove this when switch to front-end ID management is complete: https://bugs.webkit.org/show_bug.cgi?id=98085
+    ASSERT(index->id() == AutogenerateIndexId || index->id() == id);
     index->setId(id);
 
     transaction->didCompleteTaskEvents();
index bd95bbebe2f7e2a2bd293120bff8127e0cbb2fe7..b5dacab9fc4696c39f8a6cbde0a4e25c054c77c5 100644 (file)
@@ -47,13 +47,9 @@ struct IDBObjectStoreMetadata;
 
 class IDBObjectStoreBackendImpl : public IDBObjectStoreBackendInterface {
 public:
-    static PassRefPtr<IDBObjectStoreBackendImpl> create(const IDBDatabaseBackendImpl* database, int64_t id, const String& name, const IDBKeyPath& keyPath, bool autoIncrement)
+    static PassRefPtr<IDBObjectStoreBackendImpl> create(const IDBDatabaseBackendImpl* database, int64_t id, const String& name, const IDBKeyPath& keyPath, bool autoIncrement, int64_t maxIndexId)
     {
-        return adoptRef(new IDBObjectStoreBackendImpl(database, id, name, keyPath, autoIncrement));
-    }
-    static PassRefPtr<IDBObjectStoreBackendImpl> create(const IDBDatabaseBackendImpl* database, const String& name, const IDBKeyPath& keyPath, bool autoIncrement)
-    {
-        return adoptRef(new IDBObjectStoreBackendImpl(database, name, keyPath, autoIncrement));
+        return adoptRef(new IDBObjectStoreBackendImpl(database, id, name, keyPath, autoIncrement, maxIndexId));
     }
     virtual ~IDBObjectStoreBackendImpl();
 
@@ -73,7 +69,9 @@ public:
     virtual void deleteFunction(PassRefPtr<IDBKeyRange>, PassRefPtr<IDBCallbacks>, IDBTransactionBackendInterface*, ExceptionCode&);
     virtual void clear(PassRefPtr<IDBCallbacks>, IDBTransactionBackendInterface*, ExceptionCode&);
 
+    // FIXME: Remove this when switch to front-end ID management is complete: https://bugs.webkit.org/show_bug.cgi?id=98085
     virtual PassRefPtr<IDBIndexBackendInterface> createIndex(const String& name, const IDBKeyPath&, bool unique, bool multiEntry, IDBTransactionBackendInterface*, ExceptionCode&);
+    virtual PassRefPtr<IDBIndexBackendInterface> createIndex(int64_t, const String& name, const IDBKeyPath&, bool unique, bool multiEntry, IDBTransactionBackendInterface*, ExceptionCode&);
     virtual void setIndexKeys(PassRefPtr<IDBKey> prpPrimaryKey, const Vector<String>&, const Vector<IndexKeys>& , IDBTransactionBackendInterface*);
     virtual void setIndexesReady(const Vector<String>&, IDBTransactionBackendInterface*);
     virtual PassRefPtr<IDBIndexBackendInterface> index(const String& name, ExceptionCode&);
@@ -96,8 +94,7 @@ public:
     int64_t databaseId() const { return m_database->id(); }
     
 private:
-    IDBObjectStoreBackendImpl(const IDBDatabaseBackendImpl*, int64_t databaseId, const String& name, const IDBKeyPath&, bool autoIncrement);
-    IDBObjectStoreBackendImpl(const IDBDatabaseBackendImpl*, const String& name, const IDBKeyPath&, bool autoIncrement);
+    IDBObjectStoreBackendImpl(const IDBDatabaseBackendImpl*, int64_t id, const String& name, const IDBKeyPath&, bool autoIncrement, int64_t maxIndexId);
 
     void loadIndexes();
     PassRefPtr<IDBKey> generateKey(PassRefPtr<IDBTransactionBackendImpl>);
@@ -122,6 +119,7 @@ private:
     String m_name;
     IDBKeyPath m_keyPath;
     bool m_autoIncrement;
+    int64_t m_maxIndexId;
 
     IndexMap m_indexes;
 };
index 0179b6a88af626adb2ecc4ab20410ad0ca3faf2f..2eb5a86085d74806498fbf5598fc9dabaf84f4c2 100644 (file)
@@ -56,6 +56,11 @@ public:
         AddOnly,
         CursorUpdate
     };
+
+    static const int64_t MinimumIndexId = 30;
+    // FIXME: Remove this when switch to front-end ID management is complete: https://bugs.webkit.org/show_bug.cgi?id=98085
+    static const int64_t AutogenerateIndexId = -1;
+
     typedef Vector<RefPtr<IDBKey> > IndexKeys;
 
     virtual void putWithIndexKeys(PassRefPtr<SerializedScriptValue>, PassRefPtr<IDBKey>, PutMode, PassRefPtr<IDBCallbacks>, IDBTransactionBackendInterface*, const Vector<String>&, const Vector<IndexKeys>&, ExceptionCode&) = 0;
@@ -63,6 +68,8 @@ public:
 
     virtual void clear(PassRefPtr<IDBCallbacks>, IDBTransactionBackendInterface*, ExceptionCode&) = 0;
 
+    virtual PassRefPtr<IDBIndexBackendInterface> createIndex(int64_t, const String& name, const IDBKeyPath&, bool unique, bool multiEntry, IDBTransactionBackendInterface*, ExceptionCode&) = 0;
+    // FIXME: Remove this when switch to front-end ID management is complete: https://bugs.webkit.org/show_bug.cgi?id=98085
     virtual PassRefPtr<IDBIndexBackendInterface> createIndex(const String& name, const IDBKeyPath&, bool unique, bool multiEntry, IDBTransactionBackendInterface*, ExceptionCode&) = 0;
     virtual void setIndexKeys(PassRefPtr<IDBKey> prpPrimaryKey, const Vector<String>&, const Vector<IndexKeys>&, IDBTransactionBackendInterface*) = 0;
     virtual void setIndexesReady(const Vector<String>&, IDBTransactionBackendInterface*) = 0;
index ea9d4bc5aa69e89d28010237bb64be5743215e28..2e9c19a0e00e2c6ddf703e47706ec80d4f66043f 100644 (file)
@@ -1,3 +1,43 @@
+2012-10-04  Alec Flett  <alecflett@chromium.org>
+
+        IndexedDB: promote objectstore/index backend ids to the frontend
+        https://bugs.webkit.org/show_bug.cgi?id=97834
+
+        Reviewed by Tony Chang.
+
+        Support for marshalling additional IDBMetadata and new calls to
+        createObjectStore/createIndex.
+
+        * public/WebIDBDatabase.h:
+        (WebKit::WebIDBDatabase::createObjectStore):
+        * public/WebIDBMetadata.h:
+        (ObjectStore):
+        (Index):
+        * public/WebIDBObjectStore.h:
+        (WebKit::WebIDBObjectStore::createIndex):
+        * src/IDBDatabaseBackendProxy.cpp:
+        (WebKit::IDBDatabaseBackendProxy::createObjectStore):
+        (WebKit):
+        * src/IDBDatabaseBackendProxy.h:
+        (IDBDatabaseBackendProxy):
+        * src/IDBObjectStoreBackendProxy.cpp:
+        (WebKit::IDBObjectStoreBackendProxy::createIndex):
+        (WebKit):
+        * src/IDBObjectStoreBackendProxy.h:
+        (IDBObjectStoreBackendProxy):
+        * src/WebIDBDatabaseImpl.cpp:
+        (WebKit::WebIDBDatabaseImpl::createObjectStore):
+        (WebKit):
+        * src/WebIDBDatabaseImpl.h:
+        (WebIDBDatabaseImpl):
+        * src/WebIDBMetadata.cpp:
+        (WebKit::WebIDBMetadata::WebIDBMetadata):
+        (WebKit::WebIDBMetadata::operator IDBDatabaseMetadata):
+        * src/WebIDBObjectStoreImpl.cpp:
+        (WebKit::WebIDBObjectStoreImpl::createIndex):
+        (WebKit):
+        * src/WebIDBObjectStoreImpl.h:
+        (WebIDBObjectStoreImpl):
 2012-10-04  Simon Fraser  <simon.fraser@apple.com>
 
         Standardize on "flush" terminology for compositing layer flushing/syncing
index 83b9a425f847fa9d881737c309ea8a282ab4ef29..16cfbd85db4613b4df3ffd8cfaaaf14690fce4b5 100644 (file)
@@ -55,6 +55,11 @@ public:
         WEBKIT_ASSERT_NOT_REACHED();
         return 0;
     }
+    virtual WebIDBObjectStore* createObjectStore(long long, const WebString&, const WebIDBKeyPath&, bool, const WebIDBTransaction&, WebExceptionCode&)
+    {
+        WEBKIT_ASSERT_NOT_REACHED();
+        return 0;
+    }
     virtual void deleteObjectStore(const WebString& name, const WebIDBTransaction& transaction, WebExceptionCode& ec) { WEBKIT_ASSERT_NOT_REACHED(); }
     virtual void setVersion(const WebString& version, WebIDBCallbacks* callbacks, WebExceptionCode&) { WEBKIT_ASSERT_NOT_REACHED(); }
     // Transfers ownership of the WebIDBTransaction to the caller.
index 1f2e9ead45f223a69a660cc7cc67841002f1ff6e..957e082bb0fb26297e45d5d8ff78fa874f0fd28e 100644 (file)
@@ -50,6 +50,8 @@ struct WebIDBMetadata {
     // setVersion, WebString version can be removed.
     WebString version;
     long long intVersion;
+    long long id;
+    long long maxObjectStoreId;
     WebVector<ObjectStore> objectStores;
     WebIDBMetadata()
         : intVersion(NoIntVersion) { }
@@ -58,6 +60,8 @@ struct WebIDBMetadata {
         WebString name;
         WebIDBKeyPath keyPath;
         bool autoIncrement;
+        long long id;
+        long long maxIndexId;
         WebVector<Index> indexes;
         ObjectStore()
             : keyPath(WebIDBKeyPath::createNull())
@@ -69,6 +73,7 @@ struct WebIDBMetadata {
         WebIDBKeyPath keyPath;
         bool unique;
         bool multiEntry;
+        long long id;
         Index()
             : keyPath(WebIDBKeyPath::createNull())
             , unique(false)
index a2b87da8161e883f04429b7e23025e1ab208c7c1..ca0103cda6fc3f372cadcaab7cd6ce305a227d2e 100644 (file)
@@ -63,6 +63,11 @@ public:
         WEBKIT_ASSERT_NOT_REACHED();
         return 0;
     }
+    virtual WebIDBIndex* createIndex(long long, const WebString&, const WebIDBKeyPath&, bool, bool, const WebIDBTransaction&, WebExceptionCode&)
+    {
+        WEBKIT_ASSERT_NOT_REACHED();
+        return 0;
+    }
     virtual void setIndexKeys(const WebIDBKey&, const WebVector<WebString>&, const WebVector<WebIndexKeys>&, const WebIDBTransaction&) { WEBKIT_ASSERT_NOT_REACHED(); }
     virtual void setIndexesReady(const WebVector<WebString>&, const WebIDBTransaction&) { WEBKIT_ASSERT_NOT_REACHED(); };
     // Transfers ownership of the WebIDBIndex to the caller.
index 501ce61fb5956266b0c3bf1b4c02aef6cda00806..8b1fbc405caa19090ec0300482857464c0f4c420 100644 (file)
@@ -66,6 +66,17 @@ IDBDatabaseMetadata IDBDatabaseBackendProxy::metadata() const
     return m_webIDBDatabase->metadata();
 }
 
+PassRefPtr<IDBObjectStoreBackendInterface> IDBDatabaseBackendProxy::createObjectStore(int64_t id, const String& name, const IDBKeyPath& keyPath, bool autoIncrement, IDBTransactionBackendInterface* transaction, ExceptionCode& ec)
+{
+    // The transaction pointer is guaranteed to be a pointer to a proxy object as, in the renderer,
+    // all implementations of IDB interfaces are proxy objects.
+    IDBTransactionBackendProxy* transactionProxy = static_cast<IDBTransactionBackendProxy*>(transaction);
+    OwnPtr<WebIDBObjectStore> objectStore = adoptPtr(m_webIDBDatabase->createObjectStore(id, name, keyPath, autoIncrement, *transactionProxy->getWebIDBTransaction(), ec));
+    if (!objectStore)
+        return 0;
+    return IDBObjectStoreBackendProxy::create(objectStore.release());
+}
+
 PassRefPtr<IDBObjectStoreBackendInterface> IDBDatabaseBackendProxy::createObjectStore(const String& name, const IDBKeyPath& keyPath, bool autoIncrement, IDBTransactionBackendInterface* transaction, ExceptionCode& ec)
 {
     // The transaction pointer is guaranteed to be a pointer to a proxy object as, in the renderer,
index 795610aa6572dca46cc264db5b08bd178c1c5650..ea693ada17e3a51ecb19a09da346b7dc1fca1056 100644 (file)
@@ -45,6 +45,7 @@ public:
     virtual WebCore::IDBDatabaseMetadata metadata() const;
 
     virtual PassRefPtr<WebCore::IDBObjectStoreBackendInterface> createObjectStore(const String& name, const WebCore::IDBKeyPath&, bool autoIncrement, WebCore::IDBTransactionBackendInterface*, WebCore::ExceptionCode&);
+    virtual PassRefPtr<WebCore::IDBObjectStoreBackendInterface> createObjectStore(int64_t, const String& name, const WebCore::IDBKeyPath&, bool autoIncrement, WebCore::IDBTransactionBackendInterface*, WebCore::ExceptionCode&);
     virtual void deleteObjectStore(const String& name, WebCore::IDBTransactionBackendInterface*, WebCore::ExceptionCode&);
     virtual void setVersion(const String& version, PassRefPtr<WebCore::IDBCallbacks>, PassRefPtr<WebCore::IDBDatabaseCallbacks>, WebCore::ExceptionCode&);
     virtual PassRefPtr<WebCore::IDBTransactionBackendInterface> transaction(WebCore::DOMStringList* storeNames, unsigned short mode, WebCore::ExceptionCode&);
index b53eb2c3a4686e6d3ae426da314b2675a22f20f0..2b9b44a7a1ffcdd802075ea0d38e6b7c071748a5 100755 (executable)
@@ -103,6 +103,17 @@ void IDBObjectStoreBackendProxy::clear(PassRefPtr<IDBCallbacks> callbacks, IDBTr
     m_webIDBObjectStore->clear(new WebIDBCallbacksImpl(callbacks), *transactionProxy->getWebIDBTransaction(), ec);
 }
 
+PassRefPtr<IDBIndexBackendInterface> IDBObjectStoreBackendProxy::createIndex(int64_t id, const String& name, const IDBKeyPath& keyPath, bool unique, bool multiEntry, IDBTransactionBackendInterface* transaction, ExceptionCode& ec)
+{
+    // The transaction pointer is guaranteed to be a pointer to a proxy object as, in the renderer,
+    // all implementations of IDB interfaces are proxy objects.
+    IDBTransactionBackendProxy* transactionProxy = static_cast<IDBTransactionBackendProxy*>(transaction);
+    OwnPtr<WebIDBIndex> index = adoptPtr(m_webIDBObjectStore->createIndex(id, name, keyPath, unique, multiEntry, *transactionProxy->getWebIDBTransaction(), ec));
+    if (!index)
+        return 0;
+    return IDBIndexBackendProxy::create(index.release());
+}
+
 PassRefPtr<IDBIndexBackendInterface> IDBObjectStoreBackendProxy::createIndex(const String& name, const IDBKeyPath& keyPath, bool unique, bool multiEntry, IDBTransactionBackendInterface* transaction, ExceptionCode& ec)
 {
     // The transaction pointer is guaranteed to be a pointer to a proxy object as, in the renderer,
index 74cb0bd5703b61525da5fd5c482e5e6ea448cdb1..8470c1ad905bc156fd9f3b8fc14eff1e411e8beb 100644 (file)
@@ -48,6 +48,7 @@ public:
     virtual void deleteFunction(PassRefPtr<WebCore::IDBKeyRange>, PassRefPtr<WebCore::IDBCallbacks>, WebCore::IDBTransactionBackendInterface*, WebCore::ExceptionCode&);
     virtual void clear(PassRefPtr<WebCore::IDBCallbacks>, WebCore::IDBTransactionBackendInterface*, WebCore::ExceptionCode&);
 
+    PassRefPtr<WebCore::IDBIndexBackendInterface> createIndex(int64_t id, const String& name, const WebCore::IDBKeyPath&, bool unique, bool multiEntry, WebCore::IDBTransactionBackendInterface*, WebCore::ExceptionCode&);
     PassRefPtr<WebCore::IDBIndexBackendInterface> createIndex(const String& name, const WebCore::IDBKeyPath&, bool unique, bool multiEntry, WebCore::IDBTransactionBackendInterface*, WebCore::ExceptionCode&);
     virtual void setIndexKeys(PassRefPtr<WebCore::IDBKey> prpPrimaryKey, const WTF::Vector<WTF::String>&, const WTF::Vector<IndexKeys>&, WebCore::IDBTransactionBackendInterface*);
     virtual void setIndexesReady(const Vector<String>&, WebCore::IDBTransactionBackendInterface*);
index b58cd5111776884f95601e9ee79e0d82893c62d0..aefeb0faf6c1b3d4c612f75626be91d2295bff52 100644 (file)
@@ -60,6 +60,16 @@ WebIDBMetadata WebIDBDatabaseImpl::metadata() const
     return m_databaseBackend->metadata();
 }
 
+WebIDBObjectStore* WebIDBDatabaseImpl::createObjectStore(long long id, const WebString& name, const WebIDBKeyPath& keyPath, bool autoIncrement, const WebIDBTransaction& transaction, WebExceptionCode& ec)
+{
+    RefPtr<IDBObjectStoreBackendInterface> objectStore = m_databaseBackend->createObjectStore(id, name, keyPath, autoIncrement, transaction.getIDBTransactionBackendInterface(), ec);
+    if (!objectStore) {
+        ASSERT(ec);
+        return 0;
+    }
+    return new WebIDBObjectStoreImpl(objectStore);
+}
+
 WebIDBObjectStore* WebIDBDatabaseImpl::createObjectStore(const WebString& name, const WebIDBKeyPath& keyPath, bool autoIncrement, const WebIDBTransaction& transaction, WebExceptionCode& ec)
 {
     RefPtr<IDBObjectStoreBackendInterface> objectStore = m_databaseBackend->createObjectStore(name, keyPath, autoIncrement, transaction.getIDBTransactionBackendInterface(), ec);
index 518ffcdb9798005e4c88c0788e04eae53f76c8c7..849969cb4ba28f058a5152f9388923faaf1caa74 100644 (file)
@@ -53,6 +53,7 @@ public:
     virtual WebIDBMetadata metadata() const;
 
     virtual WebIDBObjectStore* createObjectStore(const WebString& name, const WebIDBKeyPath&, bool autoIncrement, const WebIDBTransaction&, WebExceptionCode&);
+    virtual WebIDBObjectStore* createObjectStore(long long, const WebString& name, const WebIDBKeyPath&, bool autoIncrement, const WebIDBTransaction&, WebExceptionCode&);
     virtual void deleteObjectStore(const WebString& name, const WebIDBTransaction&, WebExceptionCode&);
     virtual void setVersion(const WebString& version, WebIDBCallbacks*, WebExceptionCode&);
     virtual WebIDBTransaction* transaction(const WebDOMStringList& names, unsigned short mode, WebExceptionCode&);
index b44a9e9f8b973fdae28701c3ee71c681b73146ae..b8e3db3a4017fa7530f926d0ffcd8d2e1e82d734 100644 (file)
@@ -43,6 +43,7 @@ WebIDBMetadata::WebIDBMetadata(const WebCore::IDBDatabaseMetadata& metadata)
     version = metadata.version;
     intVersion = metadata.intVersion;
     objectStores = WebVector<ObjectStore>(static_cast<size_t>(metadata.objectStores.size()));
+    maxObjectStoreId = metadata.maxObjectStoreId;
 
     size_t i = 0;
     for (IDBDatabaseMetadata::ObjectStoreMap::const_iterator storeIterator = metadata.objectStores.begin(); storeIterator != metadata.objectStores.end(); ++storeIterator) {
@@ -52,6 +53,7 @@ WebIDBMetadata::WebIDBMetadata(const WebCore::IDBDatabaseMetadata& metadata)
         webObjectStore.keyPath = objectStore.keyPath;
         webObjectStore.autoIncrement = objectStore.autoIncrement;
         webObjectStore.indexes = WebVector<Index>(static_cast<size_t>(objectStore.indexes.size()));
+        webObjectStore.maxIndexId = objectStore.maxIndexId;
 
         size_t j = 0;
         for (IDBObjectStoreMetadata::IndexMap::const_iterator indexIterator = objectStore.indexes.begin(); indexIterator != objectStore.indexes.end(); ++indexIterator) {
@@ -69,14 +71,14 @@ WebIDBMetadata::WebIDBMetadata(const WebCore::IDBDatabaseMetadata& metadata)
 
 WebIDBMetadata::operator IDBDatabaseMetadata() const
 {
-    IDBDatabaseMetadata db(name, version, intVersion);
+    IDBDatabaseMetadata db(name, id, version, intVersion, maxObjectStoreId);
     for (size_t i = 0; i < objectStores.size(); ++i) {
         const ObjectStore webObjectStore = objectStores[i];
-        IDBObjectStoreMetadata objectStore(webObjectStore.name, webObjectStore.keyPath, webObjectStore.autoIncrement);
+        IDBObjectStoreMetadata objectStore(webObjectStore.name, webObjectStore.id, webObjectStore.keyPath, webObjectStore.autoIncrement, webObjectStore.maxIndexId);
 
         for (size_t j = 0; j < webObjectStore.indexes.size(); ++j) {
             const Index webIndex = webObjectStore.indexes[j];
-            IDBIndexMetadata index(webIndex.name, webIndex.keyPath, webIndex.unique, webIndex.multiEntry);
+            IDBIndexMetadata index(webIndex.name, webIndex.id, webIndex.keyPath, webIndex.unique, webIndex.multiEntry);
             objectStore.indexes.set(index.name, index);
         }
         db.objectStores.set(objectStore.name, objectStore);
index f5dd913c9485278b4668bd2734612f8aed21759a..198a287886a268de8244bb47936f87af0e10b66e 100755 (executable)
@@ -117,6 +117,14 @@ WebIDBIndex* WebIDBObjectStoreImpl::createIndex(const WebString& name, const Web
     return new WebIDBIndexImpl(index);
 }
 
+WebIDBIndex* WebIDBObjectStoreImpl::createIndex(long long id, const WebString& name, const WebIDBKeyPath& keyPath, bool unique, bool multiEntry, const WebIDBTransaction& transaction, WebExceptionCode& ec)
+{
+    RefPtr<IDBIndexBackendInterface> index = m_objectStore->createIndex(id, name, keyPath, unique, multiEntry, transaction.getIDBTransactionBackendInterface(), ec);
+    if (!index)
+        return 0;
+    return new WebIDBIndexImpl(index);
+}
+
 WebIDBIndex* WebIDBObjectStoreImpl::index(const WebString& name, WebExceptionCode& ec)
 {
     RefPtr<IDBIndexBackendInterface> index = m_objectStore->index(name, ec);
index 04020e558f44d41dbf69942e36ee60b58744e823..902641a0194f7873914164b026f40db9a4560848 100644 (file)
@@ -53,6 +53,7 @@ public:
     void clear(WebIDBCallbacks*, const WebIDBTransaction&, WebExceptionCode&);
 
     WebIDBIndex* createIndex(const WebString& name, const WebIDBKeyPath&, bool unique, bool multiEntry, const WebIDBTransaction&, WebExceptionCode&);
+    WebIDBIndex* createIndex(long long, const WebString& name, const WebIDBKeyPath&, bool unique, bool multiEntry, const WebIDBTransaction&, WebExceptionCode&);
     WebIDBIndex* index(const WebString& name, WebExceptionCode&);
     void deleteIndex(const WebString& name, const WebIDBTransaction&, WebExceptionCode&);
 
index b6b36671d74ff34e6afb7641de8b81878dcd996f..216c893846775cf5bd2f45c8a3ec0e6685e0e79b 100644 (file)
@@ -57,12 +57,12 @@ TEST(IDBDatabaseBackendTest, BackingStoreRetention)
     EXPECT_GT(backingStore->refCount(), 1);
 
     const bool autoIncrement = false;
-    RefPtr<IDBObjectStoreBackendImpl> store = IDBObjectStoreBackendImpl::create(db.get(), "store", IDBKeyPath("keyPath"), autoIncrement);
+    RefPtr<IDBObjectStoreBackendImpl> store = IDBObjectStoreBackendImpl::create(db.get(), IDBDatabaseBackendInterface::AutogenerateObjectStoreId, "store", IDBKeyPath("keyPath"), autoIncrement, 0);
     EXPECT_GT(backingStore->refCount(), 1);
 
     const bool unique = false;
     const bool multiEntry = false;
-    RefPtr<IDBIndexBackendImpl> index = IDBIndexBackendImpl::create(db.get(), store.get(), "index", IDBKeyPath("keyPath"), unique, multiEntry);
+    RefPtr<IDBIndexBackendImpl> index = IDBIndexBackendImpl::create(db.get(), store.get(), -1, "index", IDBKeyPath("keyPath"), unique, multiEntry);
     EXPECT_GT(backingStore->refCount(), 1);
 
     db.clear();
@@ -149,6 +149,7 @@ public:
 
     virtual IDBDatabaseMetadata metadata() const { return IDBDatabaseMetadata(); }
     virtual PassRefPtr<IDBObjectStoreBackendInterface> createObjectStore(const String& name, const IDBKeyPath&, bool autoIncrement, IDBTransactionBackendInterface*, ExceptionCode&) { return 0; }
+    virtual PassRefPtr<IDBObjectStoreBackendInterface> createObjectStore(int64_t, const String& name, const IDBKeyPath&, bool autoIncrement, IDBTransactionBackendInterface*, ExceptionCode&) { return 0; }
     virtual void deleteObjectStore(const String& name, IDBTransactionBackendInterface*, ExceptionCode&) { }
     virtual void setVersion(const String& version, PassRefPtr<IDBCallbacks>, PassRefPtr<IDBDatabaseCallbacks>, ExceptionCode&) { }
     virtual PassRefPtr<IDBTransactionBackendInterface> transaction(DOMStringList* storeNames, unsigned short mode, ExceptionCode&) { return 0; }
index 457ae3745f42c6e84d29e72271f19568f32c017b..75e06585ed93f729c835d4a5bfce69d0e5c106f1 100644 (file)
@@ -33,14 +33,14 @@ namespace WebCore {
 class IDBFakeBackingStore : public IDBBackingStore {
 public:
     virtual void getDatabaseNames(Vector<String>& foundNames) OVERRIDE { }
-    virtual bool getIDBDatabaseMetaData(const String& name, String& foundVersion, int64_t& foundIntVersion, int64_t& foundId) OVERRIDE { return false; }
+    virtual bool getIDBDatabaseMetaData(const String& name, String& foundStringVersion, int64_t& foundIntVersion, int64_t& foundId, int64_t& maxObjectStoreId) OVERRIDE { return false; }
     virtual bool createIDBDatabaseMetaData(const String& name, const String& version, int64_t intVersion, int64_t& rowId) OVERRIDE { return true; }
     virtual bool updateIDBDatabaseMetaData(Transaction*, int64_t rowId, const String& version) OVERRIDE { return false; }
     virtual bool updateIDBDatabaseIntVersion(Transaction*, int64_t rowId, int64_t version) OVERRIDE { return false; }
     virtual bool deleteDatabase(const String& name) OVERRIDE { return false; }
 
-    virtual void getObjectStores(int64_t databaseId, Vector<int64_t>& foundIds, Vector<String>& foundNames, Vector<IDBKeyPath>& foundKeyPaths, Vector<bool>& foundAutoIncrementFlags) OVERRIDE { }
-    virtual bool createObjectStore(Transaction*, int64_t databaseId, const String& name, const IDBKeyPath& keyPath, bool autoIncrement, int64_t& assignedObjectStoreId) OVERRIDE { return false; }
+    virtual void getObjectStores(int64_t databaseId, Vector<int64_t>& foundIds, Vector<String>& foundNames, Vector<IDBKeyPath>& foundKeyPaths, Vector<bool>& foundAutoIncrementFlags, Vector<int64_t>& foundMaxIndexIds) OVERRIDE { }
+    virtual bool createObjectStore(Transaction*, int64_t databaseId, int64_t objectStoreId, const String& name, const IDBKeyPath&, bool autoIncrement, int64_t& assignedObjectStoreId) OVERRIDE { return false; }
     virtual void deleteObjectStore(Transaction*, int64_t databaseId, int64_t objectStoreId) OVERRIDE { }
 
     virtual PassRefPtr<ObjectStoreRecordIdentifier> createInvalidRecordIdentifier() OVERRIDE { return PassRefPtr<ObjectStoreRecordIdentifier>(); }
@@ -56,7 +56,7 @@ public:
     virtual bool forEachObjectStoreRecord(Transaction*, int64_t databaseId, int64_t objectStoreId, ObjectStoreRecordCallback&) OVERRIDE { return false; }
 
     virtual void getIndexes(int64_t databaseId, int64_t objectStoreId, Vector<int64_t>& foundIds, Vector<String>& foundNames, Vector<IDBKeyPath>& foundKeyPaths, Vector<bool>& foundUniqueFlags, Vector<bool>& foundMultiEntryFlags) OVERRIDE { }
-    virtual bool createIndex(Transaction*, int64_t databaseId, int64_t objectStoreId, const String& name, const IDBKeyPath& keyPath, bool isUnique, bool isMultiEntry, int64_t& indexId) OVERRIDE { return false; }
+    virtual bool createIndex(Transaction*, int64_t databaseId, int64_t objectStoreId, int64_t indexId, const String& name, const IDBKeyPath&, bool isUnique, bool isMultiEntry, int64_t& assignedIndexId) OVERRIDE { return false; };
     virtual void deleteIndex(Transaction*, int64_t databaseId, int64_t objectStoreId, int64_t indexId) OVERRIDE { }
     virtual bool putIndexDataForRecord(Transaction*, int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKey&, const ObjectStoreRecordIdentifier*) OVERRIDE { return false; }
     virtual bool deleteIndexDataForRecord(Transaction*, int64_t databaseId, int64_t objectStoreId, int64_t indexId, const ObjectStoreRecordIdentifier*) OVERRIDE { return false; }