IndexedDB: propagate transaction_ids through open/upgradeneeded
authoralecflett@chromium.org <alecflett@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 7 Dec 2012 23:20:04 +0000 (23:20 +0000)
committeralecflett@chromium.org <alecflett@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 7 Dec 2012 23:20:04 +0000 (23:20 +0000)
https://bugs.webkit.org/show_bug.cgi?id=103922

Reviewed by Tony Chang.

Source/WebCore:

Make sure front-end is always generating the transaction id,
so that it can be relied upon as an alternative to the
to-be-deprecated IDBTransactionBackendInterface pointer.

No new tests, this is one stage in a larger refactor.

* Modules/indexeddb/IDBDatabaseBackendImpl.cpp:
(WebCore::IDBDatabaseBackendImpl::VersionChangeOperation::create):
(WebCore::IDBDatabaseBackendImpl::VersionChangeOperation::VersionChangeOperation):
(IDBDatabaseBackendImpl::VersionChangeOperation):
(WebCore::IDBDatabaseBackendImpl::PendingOpenCall::create):
(WebCore::IDBDatabaseBackendImpl::PendingOpenCall::transactionId):
(WebCore::IDBDatabaseBackendImpl::PendingOpenCall::PendingOpenCall):
(IDBDatabaseBackendImpl::PendingOpenCall):
(WebCore::IDBDatabaseBackendImpl::PendingOpenWithVersionCall::create):
(WebCore::IDBDatabaseBackendImpl::PendingOpenWithVersionCall::transactionId):
(WebCore::IDBDatabaseBackendImpl::PendingOpenWithVersionCall::PendingOpenWithVersionCall):
(IDBDatabaseBackendImpl::PendingOpenWithVersionCall):
(WebCore::IDBDatabaseBackendImpl::VersionChangeOperation::perform):
(WebCore::IDBDatabaseBackendImpl::processPendingCalls):
(WebCore::IDBDatabaseBackendImpl::createTransaction):
(WebCore::IDBDatabaseBackendImpl::openConnection):
(WebCore::IDBDatabaseBackendImpl::runIntVersionChangeTransaction):
(WebCore::IDBDatabaseBackendImpl::openConnectionWithVersion):
* Modules/indexeddb/IDBDatabaseBackendImpl.h:
(IDBDatabaseBackendImpl):
* Modules/indexeddb/IDBFactory.cpp:
(WebCore::IDBFactory::openInternal):
* Modules/indexeddb/IDBFactoryBackendImpl.cpp:
(WebCore::IDBFactoryBackendImpl::open):

Source/WebKit/chromium:

Update test to account for pre-generated transaction ids.

* tests/IDBDatabaseBackendTest.cpp:

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

Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/IDBDatabase.cpp
Source/WebCore/Modules/indexeddb/IDBDatabase.h
Source/WebCore/Modules/indexeddb/IDBDatabaseBackendImpl.cpp
Source/WebCore/Modules/indexeddb/IDBDatabaseBackendImpl.h
Source/WebCore/Modules/indexeddb/IDBFactory.cpp
Source/WebCore/Modules/indexeddb/IDBFactoryBackendImpl.cpp
Source/WebCore/Modules/indexeddb/IDBTransactionBackendImpl.h
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/tests/IDBDatabaseBackendTest.cpp

index 82c3499..89b5270 100644 (file)
@@ -1,3 +1,41 @@
+2012-12-07  Alec Flett  <alecflett@chromium.org>
+
+        IndexedDB: propagate transaction_ids through open/upgradeneeded
+        https://bugs.webkit.org/show_bug.cgi?id=103922
+
+        Reviewed by Tony Chang.
+
+        Make sure front-end is always generating the transaction id,
+        so that it can be relied upon as an alternative to the
+        to-be-deprecated IDBTransactionBackendInterface pointer.
+
+        No new tests, this is one stage in a larger refactor.
+
+        * Modules/indexeddb/IDBDatabaseBackendImpl.cpp:
+        (WebCore::IDBDatabaseBackendImpl::VersionChangeOperation::create):
+        (WebCore::IDBDatabaseBackendImpl::VersionChangeOperation::VersionChangeOperation):
+        (IDBDatabaseBackendImpl::VersionChangeOperation):
+        (WebCore::IDBDatabaseBackendImpl::PendingOpenCall::create):
+        (WebCore::IDBDatabaseBackendImpl::PendingOpenCall::transactionId):
+        (WebCore::IDBDatabaseBackendImpl::PendingOpenCall::PendingOpenCall):
+        (IDBDatabaseBackendImpl::PendingOpenCall):
+        (WebCore::IDBDatabaseBackendImpl::PendingOpenWithVersionCall::create):
+        (WebCore::IDBDatabaseBackendImpl::PendingOpenWithVersionCall::transactionId):
+        (WebCore::IDBDatabaseBackendImpl::PendingOpenWithVersionCall::PendingOpenWithVersionCall):
+        (IDBDatabaseBackendImpl::PendingOpenWithVersionCall):
+        (WebCore::IDBDatabaseBackendImpl::VersionChangeOperation::perform):
+        (WebCore::IDBDatabaseBackendImpl::processPendingCalls):
+        (WebCore::IDBDatabaseBackendImpl::createTransaction):
+        (WebCore::IDBDatabaseBackendImpl::openConnection):
+        (WebCore::IDBDatabaseBackendImpl::runIntVersionChangeTransaction):
+        (WebCore::IDBDatabaseBackendImpl::openConnectionWithVersion):
+        * Modules/indexeddb/IDBDatabaseBackendImpl.h:
+        (IDBDatabaseBackendImpl):
+        * Modules/indexeddb/IDBFactory.cpp:
+        (WebCore::IDBFactory::openInternal):
+        * Modules/indexeddb/IDBFactoryBackendImpl.cpp:
+        (WebCore::IDBFactoryBackendImpl::open):
+
 2012-12-07  Dima Gorbik  <dgorbik@apple.com>
 
         Implement general ::cue pseudo element for the <video>
index e41e8fc..1bd5b88 100644 (file)
@@ -85,8 +85,8 @@ int64_t IDBDatabase::nextTransactionId()
 void IDBDatabase::transactionCreated(IDBTransaction* transaction)
 {
     ASSERT(transaction);
-    ASSERT(!m_transactions.contains(transaction));
-    m_transactions.add(transaction);
+    ASSERT(!m_transactions.contains(transaction->id()));
+    m_transactions.add(transaction->id(), transaction);
 
     if (transaction->isVersionChange()) {
         ASSERT(!m_versionChangeTransaction);
@@ -97,8 +97,9 @@ void IDBDatabase::transactionCreated(IDBTransaction* transaction)
 void IDBDatabase::transactionFinished(IDBTransaction* transaction)
 {
     ASSERT(transaction);
-    ASSERT(m_transactions.contains(transaction));
-    m_transactions.remove(transaction);
+    ASSERT(m_transactions.contains(transaction->id()));
+    ASSERT(m_transactions.get(transaction->id()) == transaction);
+    m_transactions.remove(transaction->id());
 
     if (transaction->isVersionChange()) {
         ASSERT(m_versionChangeTransaction == transaction);
@@ -111,12 +112,14 @@ void IDBDatabase::transactionFinished(IDBTransaction* transaction)
 
 void IDBDatabase::onAbort(int64_t transactionId, PassRefPtr<IDBDatabaseError> error)
 {
-    ASSERT_NOT_REACHED();
+    ASSERT(m_transactions.contains(transactionId));
+    m_transactions.get(transactionId)->onAbort(error);
 }
 
 void IDBDatabase::onComplete(int64_t transactionId)
 {
-    ASSERT_NOT_REACHED();
+    ASSERT(m_transactions.contains(transactionId));
+    m_transactions.get(transactionId)->onComplete();
 }
 
 PassRefPtr<DOMStringList> IDBDatabase::objectStoreNames() const
@@ -268,7 +271,7 @@ PassRefPtr<IDBTransaction> IDBDatabase::transaction(ScriptExecutionContext* cont
 void IDBDatabase::forceClose()
 {
     ExceptionCode ec = 0;
-    for (HashSet<IDBTransaction*>::iterator it = m_transactions.begin(); it != m_transactions.end(); ++it)
+    for (TransactionMap::const_iterator::Values it = m_transactions.begin().values(), end = m_transactions.end().values(); it != end; ++it)
         (*it)->abort(ec);
     this->close();
 }
index 20bcaaa..1c97796 100644 (file)
@@ -120,7 +120,8 @@ private:
     IDBDatabaseMetadata m_metadata;
     RefPtr<IDBDatabaseBackendInterface> m_backend;
     RefPtr<IDBTransaction> m_versionChangeTransaction;
-    HashSet<IDBTransaction*> m_transactions;
+    typedef HashMap<int64_t, IDBTransaction*> TransactionMap;
+    TransactionMap m_transactions;
 
     bool m_closePending;
     bool m_contextStopped;
index ecb61ee..3bc754a 100644 (file)
@@ -76,14 +76,15 @@ private:
 
 class IDBDatabaseBackendImpl::VersionChangeOperation : public IDBTransactionBackendImpl::Operation {
 public:
-    static PassOwnPtr<IDBTransactionBackendImpl::Operation> create(PassRefPtr<IDBDatabaseBackendImpl> database, int64_t version, PassRefPtr<IDBCallbacks> callbacks, PassRefPtr<IDBDatabaseCallbacks> databaseCallbacks)
+    static PassOwnPtr<IDBTransactionBackendImpl::Operation> create(PassRefPtr<IDBDatabaseBackendImpl> database, int64_t transactionId, int64_t version, PassRefPtr<IDBCallbacks> callbacks, PassRefPtr<IDBDatabaseCallbacks> databaseCallbacks)
     {
-        return adoptPtr(new VersionChangeOperation(database, version, callbacks, databaseCallbacks));
+        return adoptPtr(new VersionChangeOperation(database, transactionId, version, callbacks, databaseCallbacks));
     }
     virtual void perform(IDBTransactionBackendImpl*);
 private:
-    VersionChangeOperation(PassRefPtr<IDBDatabaseBackendImpl> database, int64_t version, PassRefPtr<IDBCallbacks> callbacks, PassRefPtr<IDBDatabaseCallbacks> databaseCallbacks)
+    VersionChangeOperation(PassRefPtr<IDBDatabaseBackendImpl> database, int64_t transactionId, int64_t version, PassRefPtr<IDBCallbacks> callbacks, PassRefPtr<IDBDatabaseCallbacks> databaseCallbacks)
         : m_database(database)
+        , m_transactionId(transactionId)
         , m_version(version)
         , m_callbacks(callbacks)
         , m_databaseCallbacks(databaseCallbacks)
@@ -91,6 +92,7 @@ private:
     }
 
     RefPtr<IDBDatabaseBackendImpl> m_database;
+    int64_t m_transactionId;
     int64_t m_version;
     RefPtr<IDBCallbacks> m_callbacks;
     RefPtr<IDBDatabaseCallbacks> m_databaseCallbacks;
@@ -155,44 +157,50 @@ private:
 
 class IDBDatabaseBackendImpl::PendingOpenCall {
 public:
-    static PassOwnPtr<PendingOpenCall> create(PassRefPtr<IDBCallbacks> callbacks, PassRefPtr<IDBDatabaseCallbacks> databaseCallbacks)
+    static PassOwnPtr<PendingOpenCall> create(PassRefPtr<IDBCallbacks> callbacks, PassRefPtr<IDBDatabaseCallbacks> databaseCallbacks, int64_t transactionId)
     {
-        return adoptPtr(new PendingOpenCall(callbacks, databaseCallbacks));
+        return adoptPtr(new PendingOpenCall(callbacks, databaseCallbacks, transactionId));
     }
     PassRefPtr<IDBCallbacks> callbacks() { return m_callbacks; }
     PassRefPtr<IDBDatabaseCallbacks> databaseCallbacks() { return m_databaseCallbacks; }
+    int64_t transactionId() const { return m_transactionId; }
 
 private:
-    PendingOpenCall(PassRefPtr<IDBCallbacks> callbacks, PassRefPtr<IDBDatabaseCallbacks> databaseCallbacks)
+    PendingOpenCall(PassRefPtr<IDBCallbacks> callbacks, PassRefPtr<IDBDatabaseCallbacks> databaseCallbacks, int64_t transactionId)
         : m_callbacks(callbacks)
         , m_databaseCallbacks(databaseCallbacks)
+        , m_transactionId(transactionId)
     {
     }
 
     RefPtr<IDBCallbacks> m_callbacks;
     RefPtr<IDBDatabaseCallbacks> m_databaseCallbacks;
+    const int64_t m_transactionId;
 };
 
 class IDBDatabaseBackendImpl::PendingOpenWithVersionCall {
 public:
-    static PassOwnPtr<PendingOpenWithVersionCall> create(PassRefPtr<IDBCallbacks> callbacks, PassRefPtr<IDBDatabaseCallbacks> databaseCallbacks, int64_t version)
+    static PassOwnPtr<PendingOpenWithVersionCall> create(PassRefPtr<IDBCallbacks> callbacks, PassRefPtr<IDBDatabaseCallbacks> databaseCallbacks, int64_t transactionId, int64_t version)
     {
-        return adoptPtr(new PendingOpenWithVersionCall(callbacks, databaseCallbacks, version));
+        return adoptPtr(new PendingOpenWithVersionCall(callbacks, databaseCallbacks, transactionId, version));
     }
     PassRefPtr<IDBCallbacks> callbacks() { return m_callbacks; }
     PassRefPtr<IDBDatabaseCallbacks> databaseCallbacks() { return m_databaseCallbacks; }
     int64_t version() { return m_version; }
+    int64_t transactionId() const { return m_transactionId; }
 
 private:
-    PendingOpenWithVersionCall(PassRefPtr<IDBCallbacks> callbacks, PassRefPtr<IDBDatabaseCallbacks> databaseCallbacks, int64_t version)
+    PendingOpenWithVersionCall(PassRefPtr<IDBCallbacks> callbacks, PassRefPtr<IDBDatabaseCallbacks> databaseCallbacks, int64_t transactionId, int64_t version)
         : m_callbacks(callbacks)
         , m_databaseCallbacks(databaseCallbacks)
         , m_version(version)
+        , m_transactionId(transactionId)
     {
     }
     RefPtr<IDBCallbacks> m_callbacks;
     RefPtr<IDBDatabaseCallbacks> m_databaseCallbacks;
     int64_t m_version;
+    const int64_t m_transactionId;
 };
 
 class IDBDatabaseBackendImpl::PendingDeleteCall {
@@ -318,6 +326,19 @@ void IDBDatabaseBackendImpl::deleteObjectStore(int64_t id, IDBTransactionBackend
     m_objectStores.remove(id);
 }
 
+void IDBDatabaseBackendImpl::commit(int64_t transactionId)
+{
+    ASSERT(m_transactions.contains(transactionId));
+    m_transactions.get(transactionId)->commit();
+}
+
+void IDBDatabaseBackendImpl::abort(int64_t transactionId)
+{
+    ASSERT(m_transactions.contains(transactionId));
+    m_transactions.get(transactionId)->abort();
+}
+
+
 void IDBDatabaseBackendImpl::DeleteObjectStoreOperation::perform(IDBTransactionBackendImpl* transaction)
 {
     IDB_TRACE("DeleteObjectStoreOperation");
@@ -342,7 +363,7 @@ void IDBDatabaseBackendImpl::VersionChangeOperation::perform(IDBTransactionBacke
         return;
     }
     ASSERT(!m_database->m_pendingSecondHalfOpenWithVersion);
-    m_database->m_pendingSecondHalfOpenWithVersion = PendingOpenWithVersionCall::create(m_callbacks, m_databaseCallbacks, m_version);
+    m_database->m_pendingSecondHalfOpenWithVersion = PendingOpenWithVersionCall::create(m_callbacks, m_databaseCallbacks, m_transactionId, m_version);
     m_callbacks->onUpgradeNeeded(oldVersion, transaction, m_database);
 }
 
@@ -358,8 +379,9 @@ void IDBDatabaseBackendImpl::transactionStarted(PassRefPtr<IDBTransactionBackend
 void IDBDatabaseBackendImpl::transactionFinished(PassRefPtr<IDBTransactionBackendImpl> prpTransaction)
 {
     RefPtr<IDBTransactionBackendImpl> transaction = prpTransaction;
-    ASSERT(m_transactions.contains(transaction.get()));
-    m_transactions.remove(transaction.get());
+    ASSERT(m_transactions.contains(transaction->id()));
+    ASSERT(m_transactions.get(transaction->id()) == transaction.get());
+    m_transactions.remove(transaction->id());
     if (transaction->mode() == IDBTransaction::VERSION_CHANGE) {
         ASSERT(transaction.get() == m_runningVersionChangeTransaction.get());
         m_runningVersionChangeTransaction.clear();
@@ -426,7 +448,7 @@ void IDBDatabaseBackendImpl::processPendingCalls()
     m_pendingOpenWithVersionCalls.swap(pendingOpenWithVersionCalls);
     while (!pendingOpenWithVersionCalls.isEmpty()) {
         OwnPtr<PendingOpenWithVersionCall> pendingOpenWithVersionCall = pendingOpenWithVersionCalls.takeFirst();
-        openConnectionWithVersion(pendingOpenWithVersionCall->callbacks(), pendingOpenWithVersionCall->databaseCallbacks(), pendingOpenWithVersionCall->version());
+        openConnectionWithVersion(pendingOpenWithVersionCall->callbacks(), pendingOpenWithVersionCall->databaseCallbacks(), pendingOpenWithVersionCall->transactionId(), pendingOpenWithVersionCall->version());
     }
 
     // Open calls can be requeued if an openWithVersion call started a version
@@ -435,7 +457,7 @@ void IDBDatabaseBackendImpl::processPendingCalls()
     m_pendingOpenCalls.swap(pendingOpenCalls);
     while (!pendingOpenCalls.isEmpty()) {
         OwnPtr<PendingOpenCall> pendingOpenCall = pendingOpenCalls.takeFirst();
-        openConnection(pendingOpenCall->callbacks(), pendingOpenCall->databaseCallbacks());
+        openConnection(pendingOpenCall->callbacks(), pendingOpenCall->databaseCallbacks(), pendingOpenCall->transactionId());
     }
 }
 
@@ -443,7 +465,8 @@ void IDBDatabaseBackendImpl::processPendingCalls()
 PassRefPtr<IDBTransactionBackendInterface> IDBDatabaseBackendImpl::createTransaction(int64_t transactionId, const Vector<int64_t>& objectStoreIds, IDBTransaction::Mode mode)
 {
     RefPtr<IDBTransactionBackendImpl> transaction = IDBTransactionBackendImpl::create(transactionId, objectStoreIds, mode, this);
-    m_transactions.add(transaction.get());
+    ASSERT(!m_transactions.contains(transactionId));
+    m_transactions.add(transactionId, transaction.get());
     return transaction.release();
 }
 
@@ -452,11 +475,11 @@ void IDBDatabaseBackendImpl::createTransaction(int64_t transactionId, PassRefPtr
     ASSERT_NOT_REACHED();
 }
 
-void IDBDatabaseBackendImpl::openConnection(PassRefPtr<IDBCallbacks> callbacks, PassRefPtr<IDBDatabaseCallbacks> databaseCallbacks)
+void IDBDatabaseBackendImpl::openConnection(PassRefPtr<IDBCallbacks> callbacks, PassRefPtr<IDBDatabaseCallbacks> databaseCallbacks, int64_t transactionId)
 {
     ASSERT(m_backingStore.get());
     if (!m_pendingDeleteCalls.isEmpty() || m_runningVersionChangeTransaction) {
-        m_pendingOpenCalls.append(PendingOpenCall::create(callbacks, databaseCallbacks));
+        m_pendingOpenCalls.append(PendingOpenCall::create(callbacks, databaseCallbacks, transactionId));
         return;
     }
     if (m_metadata.id == InvalidId && !openInternal()) {
@@ -467,14 +490,14 @@ void IDBDatabaseBackendImpl::openConnection(PassRefPtr<IDBCallbacks> callbacks,
         // Spec says: If no version is specified and no database exists, set
         // database version to 1. We infer that the database didn't exist from
         // its lack of either type of version.
-        openConnectionWithVersion(callbacks, databaseCallbacks, 1);
+        openConnectionWithVersion(callbacks, databaseCallbacks, transactionId, 1);
         return;
     }
     m_databaseCallbacksSet.add(RefPtr<IDBDatabaseCallbacks>(databaseCallbacks));
     callbacks->onSuccess(this);
 }
 
-void IDBDatabaseBackendImpl::runIntVersionChangeTransaction(int64_t requestedVersion, PassRefPtr<IDBCallbacks> prpCallbacks, PassRefPtr<IDBDatabaseCallbacks> prpDatabaseCallbacks)
+void IDBDatabaseBackendImpl::runIntVersionChangeTransaction(PassRefPtr<IDBCallbacks> prpCallbacks, PassRefPtr<IDBDatabaseCallbacks> prpDatabaseCallbacks, int64_t transactionId, int64_t requestedVersion)
 {
     RefPtr<IDBCallbacks> callbacks = prpCallbacks;
     RefPtr<IDBDatabaseCallbacks> databaseCallbacks = prpDatabaseCallbacks;
@@ -495,28 +518,27 @@ void IDBDatabaseBackendImpl::runIntVersionChangeTransaction(int64_t requestedVer
         callbacks->onBlocked(m_metadata.intVersion);
     // FIXME: Add test for m_runningVersionChangeTransaction.
     if (m_runningVersionChangeTransaction || connectionCount()) {
-        m_pendingOpenWithVersionCalls.append(PendingOpenWithVersionCall::create(callbacks, databaseCallbacks, requestedVersion));
+        m_pendingOpenWithVersionCalls.append(PendingOpenWithVersionCall::create(callbacks, databaseCallbacks, transactionId, requestedVersion));
         return;
     }
 
     Vector<int64_t> objectStoreIds;
-    // FIXME: The transactionId needs to be piped in through IDBDatabaseBackendInterface::open().
-    RefPtr<IDBTransactionBackendInterface> transactionInterface = createTransaction(0, objectStoreIds, IDBTransaction::VERSION_CHANGE);
+    RefPtr<IDBTransactionBackendInterface> transactionInterface = createTransaction(transactionId, objectStoreIds, IDBTransaction::VERSION_CHANGE);
     RefPtr<IDBTransactionBackendImpl> transaction = IDBTransactionBackendImpl::from(transactionInterface.get());
 
-    if (!transaction->scheduleTask(VersionChangeOperation::create(this, requestedVersion, callbacks, databaseCallbacks), VersionChangeAbortOperation::create(this, m_metadata.version, m_metadata.intVersion))) {
+    if (!transaction->scheduleTask(VersionChangeOperation::create(this, transactionId, requestedVersion, callbacks, databaseCallbacks), VersionChangeAbortOperation::create(this, m_metadata.version, m_metadata.intVersion))) {
         ASSERT_NOT_REACHED();
     }
     ASSERT(!m_pendingSecondHalfOpenWithVersion);
     m_databaseCallbacksSet.add(databaseCallbacks);
 }
 
-void IDBDatabaseBackendImpl::openConnectionWithVersion(PassRefPtr<IDBCallbacks> prpCallbacks, PassRefPtr<IDBDatabaseCallbacks> prpDatabaseCallbacks, int64_t version)
+void IDBDatabaseBackendImpl::openConnectionWithVersion(PassRefPtr<IDBCallbacks> prpCallbacks, PassRefPtr<IDBDatabaseCallbacks> prpDatabaseCallbacks, int64_t transactionId, int64_t version)
 {
     RefPtr<IDBCallbacks> callbacks = prpCallbacks;
     RefPtr<IDBDatabaseCallbacks> databaseCallbacks = prpDatabaseCallbacks;
     if (!m_pendingDeleteCalls.isEmpty() || m_runningVersionChangeTransaction) {
-        m_pendingOpenWithVersionCalls.append(PendingOpenWithVersionCall::create(callbacks, databaseCallbacks, version));
+        m_pendingOpenWithVersionCalls.append(PendingOpenWithVersionCall::create(callbacks, databaseCallbacks, transactionId, version));
         return;
     }
     if (m_metadata.id == InvalidId) {
@@ -528,7 +550,7 @@ void IDBDatabaseBackendImpl::openConnectionWithVersion(PassRefPtr<IDBCallbacks>
         }
     }
     if (version > m_metadata.intVersion) {
-        runIntVersionChangeTransaction(version, callbacks, databaseCallbacks);
+        runIntVersionChangeTransaction(callbacks, databaseCallbacks, transactionId, version);
         return;
     }
     if (version < m_metadata.intVersion) {
@@ -597,8 +619,8 @@ void IDBDatabaseBackendImpl::close(PassRefPtr<IDBDatabaseCallbacks> prpCallbacks
 
     // FIXME: Add a test for the m_pendingOpenCalls and m_pendingOpenWithVersionCalls cases below.
     if (!connectionCount() && !m_pendingOpenCalls.size() && !m_pendingOpenWithVersionCalls.size() && !m_pendingDeleteCalls.size()) {
-        TransactionSet transactions(m_transactions);
-        for (TransactionSet::const_iterator it = transactions.begin(); it != transactions.end(); ++it)
+        TransactionMap transactions(m_transactions);
+        for (TransactionMap::const_iterator::Values it = transactions.values().begin(), end = transactions.values().end(); it != end; ++it)
             (*it)->abort();
 
         ASSERT(m_transactions.isEmpty());
index 632aa6a..014ebf2 100644 (file)
@@ -55,8 +55,8 @@ public:
     static const int64_t InvalidId = 0;
     int64_t id() const { return m_metadata.id; }
 
-    void openConnection(PassRefPtr<IDBCallbacks>, PassRefPtr<IDBDatabaseCallbacks>);
-    void openConnectionWithVersion(PassRefPtr<IDBCallbacks>, PassRefPtr<IDBDatabaseCallbacks>, int64_t version);
+    void openConnection(PassRefPtr<IDBCallbacks>, PassRefPtr<IDBDatabaseCallbacks>, int64_t transactionId);
+    void openConnectionWithVersion(PassRefPtr<IDBCallbacks>, PassRefPtr<IDBDatabaseCallbacks>, int64_t transactionId, int64_t version);
     void deleteDatabase(PassRefPtr<IDBCallbacks>);
 
     // IDBDatabaseBackendInterface
@@ -68,8 +68,8 @@ public:
     virtual void createTransaction(int64_t transactionId, PassRefPtr<IDBDatabaseCallbacks>, const Vector<int64_t>& objectStoreIds, unsigned short mode);
     virtual void close(PassRefPtr<IDBDatabaseCallbacks>);
 
-    virtual void commit(int64_t transactionId) { ASSERT_NOT_REACHED(); }
-    virtual void abort(int64_t transactionId) { ASSERT_NOT_REACHED(); }
+    virtual void commit(int64_t transactionId);
+    virtual void abort(int64_t transactionId);
 
     PassRefPtr<IDBObjectStoreBackendImpl> objectStore(int64_t id);
     IDBTransactionCoordinator* transactionCoordinator() const { return m_transactionCoordinator.get(); }
@@ -82,7 +82,7 @@ private:
     IDBDatabaseBackendImpl(const String& name, IDBBackingStore* database, IDBFactoryBackendImpl*, const String& uniqueIdentifier);
 
     bool openInternal();
-    void runIntVersionChangeTransaction(int64_t requestedVersion, PassRefPtr<IDBCallbacks>, PassRefPtr<IDBDatabaseCallbacks>);
+    void runIntVersionChangeTransaction(PassRefPtr<IDBCallbacks>, PassRefPtr<IDBDatabaseCallbacks>, int64_t transactionId, int64_t requestedVersion);
     void loadObjectStores();
     size_t connectionCount();
     void processPendingCalls();
@@ -109,8 +109,8 @@ private:
     OwnPtr<IDBTransactionCoordinator> m_transactionCoordinator;
     RefPtr<IDBTransactionBackendImpl> m_runningVersionChangeTransaction;
 
-    typedef HashSet<IDBTransactionBackendImpl*> TransactionSet;
-    TransactionSet m_transactions;
+    typedef HashMap<int64_t, IDBTransactionBackendImpl*> TransactionMap;
+    TransactionMap m_transactions;
 
     class PendingOpenCall;
     Deque<OwnPtr<PendingOpenCall> > m_pendingOpenCalls;
index 3bcbc44..840ca98 100644 (file)
@@ -129,8 +129,7 @@ PassRefPtr<IDBOpenDBRequest> IDBFactory::openInternal(ScriptExecutionContext* co
     RefPtr<IDBDatabaseCallbacksImpl> databaseCallbacks = IDBDatabaseCallbacksImpl::create();
     int64_t transactionId = IDBDatabase::nextTransactionId();
     RefPtr<IDBOpenDBRequest> request = IDBOpenDBRequest::create(context, IDBAny::createNull(), databaseCallbacks, transactionId, version);
-    // FIXME: pass the transactionId in here in https://bugs.webkit.org/show_bug.cgi?id=103922
-    m_backend->open(name, version, request, databaseCallbacks, context->securityOrigin(), context, getIndexedDBDatabasePath(context));
+    m_backend->open(name, version, transactionId, request, databaseCallbacks, context->securityOrigin(), context, getIndexedDBDatabasePath(context));
     return request;
 }
 
index be04739..51ae8ce 100644 (file)
@@ -166,9 +166,9 @@ void IDBFactoryBackendImpl::open(const String& name, int64_t version, int64_t tr
         databaseBackend = it->value;
 
     if (version == IDBDatabaseMetadata::NoIntVersion)
-        databaseBackend->openConnection(callbacks, databaseCallbacks);
+        databaseBackend->openConnection(callbacks, databaseCallbacks, transactionId);
     else
-        databaseBackend->openConnectionWithVersion(callbacks, databaseCallbacks, version);
+        databaseBackend->openConnectionWithVersion(callbacks, databaseCallbacks, transactionId, version);
 }
 
 } // namespace WebCore
index 439c75b..1e22b71 100644 (file)
@@ -54,6 +54,7 @@ public:
     // IDBTransactionBackendInterface
     virtual PassRefPtr<IDBObjectStoreBackendInterface> objectStore(int64_t, ExceptionCode&);
     virtual void abort();
+    void commit();
     virtual void setCallbacks(IDBTransactionCallbacks* callbacks) { m_callbacks = callbacks; }
 
     class Operation {
@@ -87,7 +88,6 @@ private:
     };
 
     void start();
-    void commit();
 
     bool isTaskQueueEmpty() const;
     bool hasPendingTasks() const;
index 39cbb17..adc237f 100644 (file)
@@ -1,3 +1,14 @@
+2012-12-07  Alec Flett  <alecflett@chromium.org>
+
+        IndexedDB: propagate transaction_ids through open/upgradeneeded
+        https://bugs.webkit.org/show_bug.cgi?id=103922
+
+        Reviewed by Tony Chang.
+
+        Update test to account for pre-generated transaction ids.
+
+        * tests/IDBDatabaseBackendTest.cpp:
+
 2012-12-07  Scott Violet  <sky@chromium.org>
 
         [chromium] Remove linux theme related files and switch to default
index c2efc19..0849034 100644 (file)
@@ -125,11 +125,11 @@ TEST(IDBDatabaseBackendTest, ConnectionLifecycle)
 
     RefPtr<MockIDBCallbacks> request1 = MockIDBCallbacks::create();
     RefPtr<FakeIDBDatabaseCallbacks> connection1 = FakeIDBDatabaseCallbacks::create();
-    db->openConnectionWithVersion(request1, connection1, IDBDatabaseMetadata::NoIntVersion);
+    db->openConnectionWithVersion(request1, connection1, 1, IDBDatabaseMetadata::NoIntVersion);
 
     RefPtr<MockIDBCallbacks> request2 = MockIDBCallbacks::create();
     RefPtr<FakeIDBDatabaseCallbacks> connection2 = FakeIDBDatabaseCallbacks::create();
-    db->openConnectionWithVersion(request2, connection2, IDBDatabaseMetadata::NoIntVersion);
+    db->openConnectionWithVersion(request2, connection2, 2, IDBDatabaseMetadata::NoIntVersion);
 
     db->close(connection1);
     EXPECT_GT(backingStore->refCount(), 1);
@@ -192,7 +192,7 @@ TEST(IDBDatabaseBackendTest, ForcedClose)
 
     RefPtr<MockIDBDatabaseBackendProxy> proxy = MockIDBDatabaseBackendProxy::create(webDatabase);
     RefPtr<MockIDBCallbacks> request = MockIDBCallbacks::create();
-    backend->openConnectionWithVersion(request, connectionProxy, IDBDatabaseMetadata::NoIntVersion);
+    backend->openConnectionWithVersion(request, connectionProxy, 3, IDBDatabaseMetadata::NoIntVersion);
 
     ScriptExecutionContext* context = 0;
     RefPtr<IDBDatabase> idbDatabase = IDBDatabase::create(context, proxy, connection);