A new database should be registered with the Document,
[WebKit-https.git] / WebCore / storage / Database.cpp
index 62d4039af2a61021fc994dd1ef94ef151dda760d..aca66b057a285ea1e2b30bd1a351ebfcda23dd75 100644 (file)
@@ -132,11 +132,12 @@ PassRefPtr<Database> Database::openDatabase(Document* document, const String& na
 
     if (!database->openAndVerifyVersion(e)) {
        LOG(StorageAPI, "Failed to open and verify version (expected %s) of database %s", expectedVersion.ascii().data(), database->databaseDebugName().ascii().data());
-       document->removeOpenDatabase(database.get());
-       DatabaseTracker::tracker().removeOpenDatabase(database.get());
        return 0;
     }
 
+    DatabaseTracker::tracker().addOpenDatabase(database.get());
+    document->addOpenDatabase(database.get());
+
     DatabaseTracker::tracker().setDatabaseDetails(document->securityOrigin(), name, displayName, estimatedSize);
 
     document->setHasOpenDatabases();
@@ -188,9 +189,6 @@ Database::Database(Document* document, const String& name, const String& expecte
     ASSERT(m_document->databaseThread());
 
     m_filename = DatabaseTracker::tracker().fullPathForDatabase(m_mainThreadSecurityOrigin.get(), m_name);
-
-    DatabaseTracker::tracker().addOpenDatabase(this);
-    m_document->addOpenDatabase(this);
 }
 
 static void derefDocument(void* document)
@@ -462,10 +460,6 @@ bool Database::performOpenAndVerify(ExceptionCode& e)
         return false;
     }
 
-    m_opened = true;
-    if (m_document->databaseThread())
-        m_document->databaseThread()->recordDatabaseOpen(this);
-
     ASSERT(m_databaseAuthorizer);
     m_sqliteDatabase.setAuthorizer(m_databaseAuthorizer);
     m_sqliteDatabase.setBusyTimeout(maxSqliteBusyWaitTime);
@@ -525,6 +519,10 @@ bool Database::performOpenAndVerify(ExceptionCode& e)
         return false;
     }
 
+    m_opened = true;
+    if (m_document->databaseThread())
+        m_document->databaseThread()->recordDatabaseOpen(this);
+
     return true;
 }