Initial refactoring of database functionality into the manager and server.
authormark.lam@apple.com <mark.lam@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 19 Dec 2012 00:27:34 +0000 (00:27 +0000)
committermark.lam@apple.com <mark.lam@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 19 Dec 2012 00:27:34 +0000 (00:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=104748.

Reviewed by Brady Eidson.

This is not a complete refactor, but a stepping stone on the way to isolating
script side database activity from the SQL backend.

No new tests.

* CMakeLists.txt:
* GNUmakefile.list.am:
* Modules/webdatabase/AbstractDatabase.cpp:
(WebCore):
(WebCore::updateGuidVersionMap):
(WebCore::guidForOriginAndName):
(WebCore::AbstractDatabase::AbstractDatabase):
(WebCore::AbstractDatabase::maximumSize):
* Modules/webdatabase/AbstractDatabase.h:
(AbstractDatabase):
- Moved isAvailable() and setIsAvailable() to the DatabaseManager.
* Modules/webdatabase/AbstractDatabaseServer.h:
(AbstractDatabaseServer):
* Modules/webdatabase/DBBackendServer.cpp: Added.
(WebCore::DBBackend::Server::initialize):
(WebCore::DBBackend::Server::setClient):
(WebCore::DBBackend::Server::databaseDirectoryPath):
(WebCore::DBBackend::Server::setDatabaseDirectoryPath):
(WebCore::DBBackend::Server::fullPathForDatabase):
(WebCore::DBBackend::Server::hasEntryForOrigin):
(WebCore::DBBackend::Server::origins):
(WebCore::DBBackend::Server::databaseNamesForOrigin):
(WebCore::DBBackend::Server::detailsForNameAndOrigin):
(WebCore::DBBackend::Server::usageForOrigin):
(WebCore::DBBackend::Server::quotaForOrigin):
(WebCore::DBBackend::Server::setQuota):
(WebCore::DBBackend::Server::deleteAllDatabases):
(WebCore::DBBackend::Server::deleteOrigin):
(WebCore::DBBackend::Server::deleteDatabase):
(WebCore::DBBackend::Server::scheduleNotifyDatabaseChanged):
(WebCore::DBBackend::Server::databaseChanged):
(WebCore::DBBackend::Server::closeDatabasesImmediately):
(WebCore::DBBackend::Server::interruptAllDatabasesForContext):
(WebCore::DBBackend::Server::canEstablishDatabase):
(WebCore::DBBackend::Server::addOpenDatabase):
(WebCore::DBBackend::Server::removeOpenDatabase):
(WebCore::DBBackend::Server::setDatabaseDetails):
(WebCore::DBBackend::Server::getMaxSizeForDatabase):
- Refactored all calls to the DatabaseTracker to go thru the DBBackend::Server.
* Modules/webdatabase/DBBackendServer.h:
* Modules/webdatabase/DOMWindowWebDatabase.cpp:
(WebCore::DOMWindowWebDatabase::openDatabase):
* Modules/webdatabase/Database.cpp:
(WebCore::Database::close):
(WebCore::Database::maximumSize):
* Modules/webdatabase/Database.h:
(Database):
- Moved the openDatabase() factory method to the DatabaseManager.
- Removed the unused deliverPendingCallback() prototype.
* Modules/webdatabase/DatabaseBasicTypes.h: Added.
- A place to define some common basic types used by the database module.
* Modules/webdatabase/DatabaseContext.cpp:
(WebCore::DatabaseContext::databaseExceededQuota):
* Modules/webdatabase/DatabaseManager.cpp:
(WebCore::DatabaseManager::DatabaseManager):
(WebCore::DatabaseManager::initialize):
(WebCore::DatabaseManager::setClient):
(WebCore::DatabaseManager::databaseDirectoryPath):
(WebCore::DatabaseManager::setDatabaseDirectoryPath):
(WebCore::DatabaseManager::isAvailable):
(WebCore::DatabaseManager::setIsAvailable):
(DatabaseCreationCallbackTask):
(WebCore::DatabaseCreationCallbackTask::create):
(WebCore::DatabaseCreationCallbackTask::performTask):
(WebCore::DatabaseCreationCallbackTask::DatabaseCreationCallbackTask):
(WebCore::DatabaseManager::openDatabase):
(WebCore::DatabaseManager::openDatabaseSync):
(WebCore::DatabaseManager::setHasOpenDatabases):
(WebCore::DatabaseManager::fullPathForDatabase):
(WebCore::DatabaseManager::hasEntryForOrigin):
(WebCore::DatabaseManager::origins):
(WebCore::DatabaseManager::databaseNamesForOrigin):
(WebCore::DatabaseManager::detailsForNameAndOrigin):
(WebCore::DatabaseManager::usageForOrigin):
(WebCore::DatabaseManager::quotaForOrigin):
(WebCore::DatabaseManager::setQuota):
(WebCore::DatabaseManager::deleteAllDatabases):
(WebCore::DatabaseManager::deleteOrigin):
(WebCore::DatabaseManager::deleteDatabase):
(WebCore::DatabaseManager::scheduleNotifyDatabaseChanged):
(WebCore::DatabaseManager::databaseChanged):
(WebCore::DatabaseManager::closeDatabasesImmediately):
(WebCore::DatabaseManager::interruptAllDatabasesForContext):
(WebCore::DatabaseManager::canEstablishDatabase):
(WebCore::DatabaseManager::addOpenDatabase):
(WebCore::DatabaseManager::removeOpenDatabase):
(WebCore::DatabaseManager::setDatabaseDetails):
(WebCore::DatabaseManager::getMaxSizeForDatabase):
* Modules/webdatabase/DatabaseManager.h:
(DatabaseManager):
* Modules/webdatabase/DatabaseSync.cpp:
(WebCore::DatabaseSync::~DatabaseSync):
(WebCore::DatabaseSync::closeImmediately):
* Modules/webdatabase/DatabaseSync.h:
(DatabaseSync):
- Moved the openDatabaseSync() factory method to the DatabaseManager.
* Modules/webdatabase/DatabaseTask.h:
* Modules/webdatabase/SQLResultSet.h:
* Modules/webdatabase/SQLStatementSync.h:
* Modules/webdatabase/SQLTransaction.h:
* Modules/webdatabase/SQLTransactionClient.cpp:
(WebCore::SQLTransactionClient::didCommitWriteTransaction):
(WebCore::SQLTransactionClient::didExecuteStatement):
(WebCore::SQLTransactionClient::didExceedQuota):
* Modules/webdatabase/SQLTransactionSync.h:
* Modules/webdatabase/WorkerContextWebDatabase.cpp:
(WebCore::WorkerContextWebDatabase::openDatabase):
(WebCore::WorkerContextWebDatabase::openDatabaseSync):
* Target.pri:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:

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

28 files changed:
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/Modules/webdatabase/AbstractDatabase.cpp
Source/WebCore/Modules/webdatabase/AbstractDatabase.h
Source/WebCore/Modules/webdatabase/AbstractDatabaseServer.h
Source/WebCore/Modules/webdatabase/DBBackendServer.cpp [new file with mode: 0644]
Source/WebCore/Modules/webdatabase/DBBackendServer.h
Source/WebCore/Modules/webdatabase/DOMWindowWebDatabase.cpp
Source/WebCore/Modules/webdatabase/Database.cpp
Source/WebCore/Modules/webdatabase/Database.h
Source/WebCore/Modules/webdatabase/DatabaseBasicTypes.h [new file with mode: 0644]
Source/WebCore/Modules/webdatabase/DatabaseContext.cpp
Source/WebCore/Modules/webdatabase/DatabaseManager.cpp
Source/WebCore/Modules/webdatabase/DatabaseManager.h
Source/WebCore/Modules/webdatabase/DatabaseSync.cpp
Source/WebCore/Modules/webdatabase/DatabaseSync.h
Source/WebCore/Modules/webdatabase/DatabaseTask.h
Source/WebCore/Modules/webdatabase/SQLResultSet.h
Source/WebCore/Modules/webdatabase/SQLStatementSync.h
Source/WebCore/Modules/webdatabase/SQLTransaction.h
Source/WebCore/Modules/webdatabase/SQLTransactionClient.cpp
Source/WebCore/Modules/webdatabase/SQLTransactionSync.h
Source/WebCore/Modules/webdatabase/WorkerContextWebDatabase.cpp
Source/WebCore/Target.pri
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.vcproj/WebCore.vcproj
Source/WebCore/WebCore.xcodeproj/project.pbxproj

index 2192d56..1745933 100644 (file)
@@ -952,6 +952,7 @@ set(WebCore_SOURCES
     Modules/webdatabase/DatabaseTask.cpp
     Modules/webdatabase/DatabaseThread.cpp
     Modules/webdatabase/DatabaseTracker.cpp
+    Modules/webdatabase/DBBackendServer.cpp
     Modules/webdatabase/OriginQuotaManager.cpp
     Modules/webdatabase/OriginUsageRecord.cpp
     Modules/webdatabase/SQLException.cpp
index e42ab11..2ce4017 100644 (file)
@@ -1,3 +1,128 @@
+2012-12-18  Mark Lam  <mark.lam@apple.com>
+
+        Initial refactoring of database functionality into the manager and server.
+        https://bugs.webkit.org/show_bug.cgi?id=104748.
+
+        Reviewed by Brady Eidson.
+
+        This is not a complete refactor, but a stepping stone on the way to isolating
+        script side database activity from the SQL backend.
+
+        No new tests.
+
+        * CMakeLists.txt:
+        * GNUmakefile.list.am:
+        * Modules/webdatabase/AbstractDatabase.cpp:
+        (WebCore):
+        (WebCore::updateGuidVersionMap):
+        (WebCore::guidForOriginAndName):
+        (WebCore::AbstractDatabase::AbstractDatabase):
+        (WebCore::AbstractDatabase::maximumSize):
+        * Modules/webdatabase/AbstractDatabase.h:
+        (AbstractDatabase):
+        - Moved isAvailable() and setIsAvailable() to the DatabaseManager.
+        * Modules/webdatabase/AbstractDatabaseServer.h:
+        (AbstractDatabaseServer):
+        * Modules/webdatabase/DBBackendServer.cpp: Added.
+        (WebCore::DBBackend::Server::initialize):
+        (WebCore::DBBackend::Server::setClient):
+        (WebCore::DBBackend::Server::databaseDirectoryPath):
+        (WebCore::DBBackend::Server::setDatabaseDirectoryPath):
+        (WebCore::DBBackend::Server::fullPathForDatabase):
+        (WebCore::DBBackend::Server::hasEntryForOrigin):
+        (WebCore::DBBackend::Server::origins):
+        (WebCore::DBBackend::Server::databaseNamesForOrigin):
+        (WebCore::DBBackend::Server::detailsForNameAndOrigin):
+        (WebCore::DBBackend::Server::usageForOrigin):
+        (WebCore::DBBackend::Server::quotaForOrigin):
+        (WebCore::DBBackend::Server::setQuota):
+        (WebCore::DBBackend::Server::deleteAllDatabases):
+        (WebCore::DBBackend::Server::deleteOrigin):
+        (WebCore::DBBackend::Server::deleteDatabase):
+        (WebCore::DBBackend::Server::scheduleNotifyDatabaseChanged):
+        (WebCore::DBBackend::Server::databaseChanged):
+        (WebCore::DBBackend::Server::closeDatabasesImmediately):
+        (WebCore::DBBackend::Server::interruptAllDatabasesForContext):
+        (WebCore::DBBackend::Server::canEstablishDatabase):
+        (WebCore::DBBackend::Server::addOpenDatabase):
+        (WebCore::DBBackend::Server::removeOpenDatabase):
+        (WebCore::DBBackend::Server::setDatabaseDetails):
+        (WebCore::DBBackend::Server::getMaxSizeForDatabase):
+        - Refactored all calls to the DatabaseTracker to go thru the DBBackend::Server.
+        * Modules/webdatabase/DBBackendServer.h:
+        * Modules/webdatabase/DOMWindowWebDatabase.cpp:
+        (WebCore::DOMWindowWebDatabase::openDatabase):
+        * Modules/webdatabase/Database.cpp:
+        (WebCore::Database::close):
+        (WebCore::Database::maximumSize):
+        * Modules/webdatabase/Database.h:
+        (Database):
+        - Moved the openDatabase() factory method to the DatabaseManager.
+        - Removed the unused deliverPendingCallback() prototype.
+        * Modules/webdatabase/DatabaseBasicTypes.h: Added.
+        - A place to define some common basic types used by the database module.
+        * Modules/webdatabase/DatabaseContext.cpp:
+        (WebCore::DatabaseContext::databaseExceededQuota):
+        * Modules/webdatabase/DatabaseManager.cpp:
+        (WebCore::DatabaseManager::DatabaseManager):
+        (WebCore::DatabaseManager::initialize):
+        (WebCore::DatabaseManager::setClient):
+        (WebCore::DatabaseManager::databaseDirectoryPath):
+        (WebCore::DatabaseManager::setDatabaseDirectoryPath):
+        (WebCore::DatabaseManager::isAvailable):
+        (WebCore::DatabaseManager::setIsAvailable):
+        (DatabaseCreationCallbackTask):
+        (WebCore::DatabaseCreationCallbackTask::create):
+        (WebCore::DatabaseCreationCallbackTask::performTask):
+        (WebCore::DatabaseCreationCallbackTask::DatabaseCreationCallbackTask):
+        (WebCore::DatabaseManager::openDatabase):
+        (WebCore::DatabaseManager::openDatabaseSync):
+        (WebCore::DatabaseManager::setHasOpenDatabases):
+        (WebCore::DatabaseManager::fullPathForDatabase):
+        (WebCore::DatabaseManager::hasEntryForOrigin):
+        (WebCore::DatabaseManager::origins):
+        (WebCore::DatabaseManager::databaseNamesForOrigin):
+        (WebCore::DatabaseManager::detailsForNameAndOrigin):
+        (WebCore::DatabaseManager::usageForOrigin):
+        (WebCore::DatabaseManager::quotaForOrigin):
+        (WebCore::DatabaseManager::setQuota):
+        (WebCore::DatabaseManager::deleteAllDatabases):
+        (WebCore::DatabaseManager::deleteOrigin):
+        (WebCore::DatabaseManager::deleteDatabase):
+        (WebCore::DatabaseManager::scheduleNotifyDatabaseChanged):
+        (WebCore::DatabaseManager::databaseChanged):
+        (WebCore::DatabaseManager::closeDatabasesImmediately):
+        (WebCore::DatabaseManager::interruptAllDatabasesForContext):
+        (WebCore::DatabaseManager::canEstablishDatabase):
+        (WebCore::DatabaseManager::addOpenDatabase):
+        (WebCore::DatabaseManager::removeOpenDatabase):
+        (WebCore::DatabaseManager::setDatabaseDetails):
+        (WebCore::DatabaseManager::getMaxSizeForDatabase):
+        * Modules/webdatabase/DatabaseManager.h:
+        (DatabaseManager):
+        * Modules/webdatabase/DatabaseSync.cpp:
+        (WebCore::DatabaseSync::~DatabaseSync):
+        (WebCore::DatabaseSync::closeImmediately):
+        * Modules/webdatabase/DatabaseSync.h:
+        (DatabaseSync):
+        - Moved the openDatabaseSync() factory method to the DatabaseManager.
+        * Modules/webdatabase/DatabaseTask.h:
+        * Modules/webdatabase/SQLResultSet.h:
+        * Modules/webdatabase/SQLStatementSync.h:
+        * Modules/webdatabase/SQLTransaction.h:
+        * Modules/webdatabase/SQLTransactionClient.cpp:
+        (WebCore::SQLTransactionClient::didCommitWriteTransaction):
+        (WebCore::SQLTransactionClient::didExecuteStatement):
+        (WebCore::SQLTransactionClient::didExceedQuota):
+        * Modules/webdatabase/SQLTransactionSync.h:
+        * Modules/webdatabase/WorkerContextWebDatabase.cpp:
+        (WebCore::WorkerContextWebDatabase::openDatabase):
+        (WebCore::WorkerContextWebDatabase::openDatabaseSync):
+        * Target.pri:
+        * WebCore.gypi:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+
 2012-12-18  Per-Erik Brodin  <per-erik.brodin@ericsson.com>
 
         EventSource should support CORS
index b783ca3..9092533 100644 (file)
@@ -2110,6 +2110,7 @@ webcore_modules_sources += \
        Source/WebCore/Modules/webdatabase/DatabaseThread.h \
        Source/WebCore/Modules/webdatabase/DatabaseTracker.cpp \
        Source/WebCore/Modules/webdatabase/DatabaseTracker.h \
+       Source/WebCore/Modules/webdatabase/DBBackendServer.cpp \
        Source/WebCore/Modules/webdatabase/DBBackendServer.h \
        Source/WebCore/Modules/webdatabase/OriginQuotaManager.cpp \
        Source/WebCore/Modules/webdatabase/OriginQuotaManager.h \
index 6cfe51b..794c3f7 100644 (file)
@@ -33,7 +33,7 @@
 
 #include "DatabaseAuthorizer.h"
 #include "DatabaseContext.h"
-#include "DatabaseTracker.h"
+#include "DatabaseManager.h"
 #include "ExceptionCode.h"
 #include "Logging.h"
 #include "SQLiteStatement.h"
@@ -115,7 +115,7 @@ static Mutex& guidMutex()
     return mutex;
 }
 
-typedef HashMap<int, String> GuidVersionMap;
+typedef HashMap<DatabaseGuid, String> GuidVersionMap;
 static GuidVersionMap& guidToVersionMap()
 {
     // Ensure the the mutex is locked.
@@ -125,7 +125,7 @@ static GuidVersionMap& guidToVersionMap()
 }
 
 // NOTE: Caller must lock guidMutex().
-static inline void updateGuidVersionMap(int guid, String newVersion)
+static inline void updateGuidVersionMap(DatabaseGuid guid, String newVersion)
 {
     // Ensure the the mutex is locked.
     ASSERT(!guidMutex().tryLock());
@@ -140,7 +140,7 @@ static inline void updateGuidVersionMap(int guid, String newVersion)
     guidToVersionMap().set(guid, newVersion.isEmpty() ? String() : newVersion.isolatedCopy());
 }
 
-typedef HashMap<int, HashSet<AbstractDatabase*>*> GuidDatabaseMap;
+typedef HashMap<DatabaseGuid, HashSet<AbstractDatabase*>*> GuidDatabaseMap;
 static GuidDatabaseMap& guidToDatabaseMap()
 {
     // Ensure the the mutex is locked.
@@ -149,7 +149,7 @@ static GuidDatabaseMap& guidToDatabaseMap()
     return map;
 }
 
-static int guidForOriginAndName(const String& origin, const String& name)
+static DatabaseGuid guidForOriginAndName(const String& origin, const String& name)
 {
     // Ensure the the mutex is locked.
     ASSERT(!guidMutex().tryLock());
@@ -158,7 +158,7 @@ static int guidForOriginAndName(const String& origin, const String& name)
 
     typedef HashMap<String, int> IDGuidMap;
     DEFINE_STATIC_LOCAL(IDGuidMap, stringIdentifierToGUIDMap, ());
-    int guid = stringIdentifierToGUIDMap.get(stringID);
+    DatabaseGuid guid = stringIdentifierToGUIDMap.get(stringID);
     if (!guid) {
         static int currentNewGUID = 1;
         guid = currentNewGUID++;
@@ -168,18 +168,6 @@ static int guidForOriginAndName(const String& origin, const String& name)
     return guid;
 }
 
-static bool isDatabaseAvailable = true;
-
-bool AbstractDatabase::isAvailable()
-{
-    return isDatabaseAvailable;
-}
-
-void AbstractDatabase::setIsAvailable(bool available)
-{
-    isDatabaseAvailable = available;
-}
-
 // static
 const char* AbstractDatabase::databaseInfoTableName()
 {
@@ -219,8 +207,8 @@ AbstractDatabase::AbstractDatabase(ScriptExecutionContext* context, const String
         hashSet->add(this);
     }
 
-    m_filename = DatabaseTracker::tracker().fullPathForDatabase(securityOrigin(), m_name);
-    DatabaseTracker::tracker().addOpenDatabase(this);
+    m_filename = DatabaseManager::manager().fullPathForDatabase(securityOrigin(), m_name);
+    DatabaseManager::manager().addOpenDatabase(this);
 }
 
 AbstractDatabase::~AbstractDatabase()
@@ -539,7 +527,7 @@ void AbstractDatabase::resetAuthorizer()
 
 unsigned long long AbstractDatabase::maximumSize() const
 {
-    return DatabaseTracker::tracker().getMaxSizeForDatabase(this);
+    return DatabaseManager::manager().getMaxSizeForDatabase(this);
 }
 
 void AbstractDatabase::incrementalVacuumIfNeeded()
index d3700e8..6b3eb73 100644 (file)
@@ -31,6 +31,7 @@
 
 #if ENABLE(SQL_DATABASE)
 
+#include "DatabaseBasicTypes.h"
 #include "SQLiteDatabase.h"
 #include <wtf/Forward.h>
 #include <wtf/ThreadSafeRefCounted.h>
@@ -47,13 +48,8 @@ class DatabaseContext;
 class ScriptExecutionContext;
 class SecurityOrigin;
 
-typedef int ExceptionCode;
-
 class AbstractDatabase : public ThreadSafeRefCounted<AbstractDatabase> {
 public:
-    static bool isAvailable();
-    static void setIsAvailable(bool available);
-
     virtual ~AbstractDatabase();
 
     virtual String version() const;
@@ -143,7 +139,7 @@ protected:
 #endif
 
 private:
-    int m_guid;
+    DatabaseGuid m_guid;
     bool m_opened;
     bool m_new;
     const bool m_isSyncDatabase;
index df156bd..6049793 100644 (file)
 
 #if ENABLE(SQL_DATABASE)
 
+#include "DatabaseDetails.h"
+#include <wtf/RefPtr.h>
+#include <wtf/Vector.h>
+#include <wtf/text/WTFString.h>
+
 namespace WebCore {
 
+class AbstractDatabase;
+class DatabaseManagerClient;
+class ScriptExecutionContext;
+class SecurityOrigin;
+
 class AbstractDatabaseServer {
+public:
+    virtual void initialize(const String& databasePath) = 0;
+
+    virtual void setClient(DatabaseManagerClient*) = 0;
+    virtual String databaseDirectoryPath() const = 0;
+    virtual void setDatabaseDirectoryPath(const String&) = 0;
+
+    virtual String fullPathForDatabase(SecurityOrigin*, const String& name, bool createIfDoesNotExist = true) = 0;
+
+#if !PLATFORM(CHROMIUM)
+    virtual bool hasEntryForOrigin(SecurityOrigin*) = 0;
+    virtual void origins(Vector<RefPtr<SecurityOrigin> >& result) = 0;
+    virtual bool databaseNamesForOrigin(SecurityOrigin*, Vector<String>& result) = 0;
+    virtual DatabaseDetails detailsForNameAndOrigin(const String&, SecurityOrigin*) = 0;
+
+    virtual unsigned long long usageForOrigin(SecurityOrigin*) = 0;
+    virtual unsigned long long quotaForOrigin(SecurityOrigin*) = 0;
+
+    virtual void setQuota(SecurityOrigin*, unsigned long long) = 0;
+
+    virtual void deleteAllDatabases() = 0;
+    virtual bool deleteOrigin(SecurityOrigin*) = 0;
+    virtual bool deleteDatabase(SecurityOrigin*, const String& name) = 0;
+
+    // From a secondary thread, must be thread safe with its data
+    virtual void scheduleNotifyDatabaseChanged(SecurityOrigin*, const String& name) = 0;
+    virtual void databaseChanged(AbstractDatabase*) = 0;
+
+#else // PLATFORM(CHROMIUM)
+    virtual void closeDatabasesImmediately(const String& originIdentifier, const String& name) = 0;
+#endif // PLATFORM(CHROMIUM)
+
+    virtual void interruptAllDatabasesForContext(const ScriptExecutionContext*) = 0;
+
+    virtual bool canEstablishDatabase(ScriptExecutionContext*, const String& name, const String& displayName, unsigned long estimatedSize) = 0;
+    virtual void addOpenDatabase(AbstractDatabase*) = 0;
+    virtual void removeOpenDatabase(AbstractDatabase*) = 0;
+
+    virtual void setDatabaseDetails(SecurityOrigin*, const String& name, const String& displayName, unsigned long estimatedSize) = 0;
+    virtual unsigned long long getMaxSizeForDatabase(const AbstractDatabase*) = 0;
+
 protected:
     AbstractDatabaseServer() { }
     virtual ~AbstractDatabaseServer() { }
diff --git a/Source/WebCore/Modules/webdatabase/DBBackendServer.cpp b/Source/WebCore/Modules/webdatabase/DBBackendServer.cpp
new file mode 100644 (file)
index 0000000..444f339
--- /dev/null
@@ -0,0 +1,356 @@
+/*
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "config.h"
+#include "DBBackendServer.h"
+
+#if ENABLE(SQL_DATABASE)
+
+#include "DatabaseTracker.h"
+#include <wtf/UnusedParam.h>
+
+namespace WebCore {
+namespace DBBackend {
+
+void Server::initialize(const String& databasePath)
+{
+#if !PLATFORM(CHROMIUM)
+    DatabaseTracker::initializeTracker(databasePath);
+#else
+    UNUSED_PARAM(databasePath);
+#endif
+}
+
+void Server::setClient(DatabaseManagerClient* client)
+{
+#if !PLATFORM(CHROMIUM)
+    DatabaseTracker::tracker().setClient(client);
+#else
+    UNUSED_PARAM(client);
+#endif
+}
+
+String Server::databaseDirectoryPath() const
+{
+#if !PLATFORM(CHROMIUM)
+    return DatabaseTracker::tracker().databaseDirectoryPath();
+#else
+    return "";
+#endif
+}
+
+void Server::setDatabaseDirectoryPath(const String& path)
+{
+#if !PLATFORM(CHROMIUM)
+    DatabaseTracker::tracker().setDatabaseDirectoryPath(path);
+#endif
+}
+
+String Server::fullPathForDatabase(SecurityOrigin* origin, const String& name, bool createIfDoesNotExist)
+{
+    return DatabaseTracker::tracker().fullPathForDatabase(origin, name, createIfDoesNotExist);
+}
+
+#if !PLATFORM(CHROMIUM)
+bool Server::hasEntryForOrigin(SecurityOrigin* origin)
+{
+    return DatabaseTracker::tracker().hasEntryForOrigin(origin);
+}
+
+void Server::origins(Vector<RefPtr<SecurityOrigin> >& result)
+{
+    DatabaseTracker::tracker().origins(result);
+}
+
+bool Server::databaseNamesForOrigin(SecurityOrigin* origin, Vector<String>& result)
+{
+    return DatabaseTracker::tracker().databaseNamesForOrigin(origin, result);
+}
+
+DatabaseDetails Server::detailsForNameAndOrigin(const String& name, SecurityOrigin* origin)
+{
+    return DatabaseTracker::tracker().detailsForNameAndOrigin(name, origin);
+}
+
+unsigned long long Server::usageForOrigin(SecurityOrigin* origin)
+{
+    return DatabaseTracker::tracker().usageForOrigin(origin);
+}
+
+unsigned long long Server::quotaForOrigin(SecurityOrigin* origin)
+{
+    return DatabaseTracker::tracker().quotaForOrigin(origin);
+}
+
+void Server::setQuota(SecurityOrigin* origin, unsigned long long quotaSize)
+{
+    DatabaseTracker::tracker().setQuota(origin, quotaSize);
+}
+
+void Server::deleteAllDatabases()
+{
+    DatabaseTracker::tracker().deleteAllDatabases();
+}
+
+bool Server::deleteOrigin(SecurityOrigin* origin)
+{
+    return DatabaseTracker::tracker().deleteOrigin(origin);
+}
+
+bool Server::deleteDatabase(SecurityOrigin* origin, const String& name)
+{
+    return DatabaseTracker::tracker().deleteDatabase(origin, name);
+}
+
+// From a secondary thread, must be thread safe with its data
+void Server::scheduleNotifyDatabaseChanged(SecurityOrigin* origin, const String& name)
+{
+    DatabaseTracker::tracker().scheduleNotifyDatabaseChanged(origin, name);
+}
+
+void Server::databaseChanged(AbstractDatabase* database)
+{
+    DatabaseTracker::tracker().databaseChanged(database);
+}
+
+#else // PLATFORM(CHROMIUM)
+void Server::closeDatabasesImmediately(const String& originIdentifier, const String& name)
+{
+    DatabaseTracker::tracker().closeDatabasesImmediately(originIdentifier, name);
+}
+#endif // PLATFORM(CHROMIUM)
+
+void Server::interruptAllDatabasesForContext(const ScriptExecutionContext* context)
+{
+    DatabaseTracker::tracker().interruptAllDatabasesForContext(context);
+}
+
+bool Server::canEstablishDatabase(ScriptExecutionContext* context, const String& name, const String& displayName, unsigned long estimatedSize)
+{
+    return DatabaseTracker::tracker().canEstablishDatabase(context, name, displayName, estimatedSize);
+}
+
+void Server::addOpenDatabase(AbstractDatabase* database)
+{
+    DatabaseTracker::tracker().addOpenDatabase(database);
+}
+
+void Server::removeOpenDatabase(AbstractDatabase* database)
+{
+    DatabaseTracker::tracker().removeOpenDatabase(database);
+}
+
+void Server::setDatabaseDetails(SecurityOrigin* origin, const String& name, const String& displayName, unsigned long estimatedSize)
+{
+    DatabaseTracker::tracker().setDatabaseDetails(origin, name, displayName, estimatedSize);
+}
+
+unsigned long long Server::getMaxSizeForDatabase(const AbstractDatabase* database)
+{
+    return DatabaseTracker::tracker().getMaxSizeForDatabase(database);
+}
+
+} // namespace DBBackend
+} // namespace WebCore
+
+#endif // ENABLE(SQL_DATABASE)
+/*
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "config.h"
+#include "DBBackendServer.h"
+
+#if ENABLE(SQL_DATABASE)
+
+#include "DatabaseTracker.h"
+#include <wtf/UnusedParam.h>
+
+namespace WebCore {
+namespace DBBackend {
+
+void Server::initialize(const String& databasePath)
+{
+#if !PLATFORM(CHROMIUM)
+    DatabaseTracker::tracker().initializeTracker(databasePath);
+#else
+    UNUSED_PARAM(databasePath);
+#endif
+}
+
+void Server::setClient(DatabaseManagerClient* client)
+{
+#if !PLATFORM(CHROMIUM)
+    DatabaseTracker::tracker().setClient(client);
+#else
+    UNUSED_PARAM(client);
+#endif
+}
+
+String Server::databaseDirectoryPath() const
+{
+#if !PLATFORM(CHROMIUM)
+    return DatabaseTracker::tracker().databaseDirectoryPath();
+#else
+    return "";
+#endif
+}
+
+void Server::setDatabaseDirectoryPath(const String& path)
+{
+#if !PLATFORM(CHROMIUM)
+    DatabaseTracker::tracker().setDatabaseDirectoryPath(path);
+#endif
+}
+
+String Server::fullPathForDatabase(SecurityOrigin* origin, const String& name, bool createIfDoesNotExist)
+{
+    return DatabaseTracker::tracker().fullPathForDatabase(origin, name, createIfDoesNotExist);
+}
+
+#if !PLATFORM(CHROMIUM)
+bool Server::hasEntryForOrigin(SecurityOrigin* origin)
+{
+    return DatabaseTracker::tracker().hasEntryForOrigin(origin);
+}
+
+void Server::origins(Vector<RefPtr<SecurityOrigin> >& result)
+{
+    DatabaseTracker::tracker().origins(result);
+}
+
+bool Server::databaseNamesForOrigin(SecurityOrigin* origin, Vector<String>& result)
+{
+    return DatabaseTracker::tracker().databaseNamesForOrigin(origin, result);
+}
+
+DatabaseDetails Server::detailsForNameAndOrigin(const String& name, SecurityOrigin* origin)
+{
+    return DatabaseTracker::tracker().detailsForNameAndOrigin(name, origin);
+}
+
+unsigned long long Server::usageForOrigin(SecurityOrigin* origin)
+{
+    return DatabaseTracker::tracker().usageForOrigin(origin);
+}
+
+unsigned long long Server::quotaForOrigin(SecurityOrigin* origin)
+{
+    return DatabaseTracker::tracker().quotaForOrigin(origin);
+}
+
+void Server::setQuota(SecurityOrigin* origin, unsigned long long quotaSize)
+{
+    DatabaseTracker::tracker().setQuota(origin, quotaSize);
+}
+
+void Server::deleteAllDatabases()
+{
+    DatabaseTracker::tracker().deleteAllDatabases();
+}
+
+bool Server::deleteOrigin(SecurityOrigin* origin)
+{
+    return DatabaseTracker::tracker().deleteOrigin(origin);
+}
+
+bool Server::deleteDatabase(SecurityOrigin* origin, const String& name)
+{
+    return DatabaseTracker::tracker().deleteDatabase(origin, name);
+}
+
+// From a secondary thread, must be thread safe with its data
+void Server::scheduleNotifyDatabaseChanged(SecurityOrigin* origin, const String& name)
+{
+    DatabaseTracker::tracker().scheduleNotifyDatabaseChanged(origin, name);
+}
+
+void Server::databaseChanged(AbstractDatabase* database)
+{
+    DatabaseTracker::tracker().databaseChanged(database);
+}
+
+#else // PLATFORM(CHROMIUM)
+void Server::closeDatabasesImmediately(const String& originIdentifier, const String& name)
+{
+    DatabaseTracker::tracker().closeDatabasesImmediately(originIdentifier, name);
+}
+#endif // PLATFORM(CHROMIUM)
+
+void Server::interruptAllDatabasesForContext(const ScriptExecutionContext* context)
+{
+    DatabaseTracker::tracker().interruptAllDatabasesForContext(context);
+}
+
+bool Server::canEstablishDatabase(ScriptExecutionContext* context, const String& name, const String& displayName, unsigned long estimatedSize)
+{
+    return DatabaseTracker::tracker().canEstablishDatabase(context, name, displayName, estimatedSize);
+}
+
+void Server::addOpenDatabase(AbstractDatabase* database)
+{
+    DatabaseTracker::tracker().addOpenDatabase(database);
+}
+
+void Server::removeOpenDatabase(AbstractDatabase* database)
+{
+    DatabaseTracker::tracker().removeOpenDatabase(database);
+}
+
+void Server::setDatabaseDetails(SecurityOrigin* origin, const String& name, const String& displayName, unsigned long estimatedSize)
+{
+    DatabaseTracker::tracker().setDatabaseDetails(origin, name, displayName, estimatedSize);
+}
+
+unsigned long long Server::getMaxSizeForDatabase(const AbstractDatabase* database)
+{
+    return DatabaseTracker::tracker().getMaxSizeForDatabase(database);
+}
+
+} // namespace DBBackend
+} // namespace WebCore
+
+#endif // ENABLE(SQL_DATABASE)
index 56a1f5b..36f674b 100644 (file)
@@ -37,6 +37,46 @@ class Server: public AbstractDatabaseServer {
 public:
     Server() { };
     virtual ~Server() { }
+
+    virtual void initialize(const String& databasePath);
+
+    virtual void setClient(DatabaseManagerClient*);
+    virtual String databaseDirectoryPath() const;
+    virtual void setDatabaseDirectoryPath(const String&);
+
+    virtual String fullPathForDatabase(SecurityOrigin*, const String& name, bool createIfDoesNotExist);
+
+#if !PLATFORM(CHROMIUM)
+    virtual bool hasEntryForOrigin(SecurityOrigin*);
+    virtual void origins(Vector<RefPtr<SecurityOrigin> >& result);
+    virtual bool databaseNamesForOrigin(SecurityOrigin*, Vector<String>& result);
+    virtual DatabaseDetails detailsForNameAndOrigin(const String&, SecurityOrigin*);
+
+    virtual unsigned long long usageForOrigin(SecurityOrigin*);
+    virtual unsigned long long quotaForOrigin(SecurityOrigin*);
+
+    virtual void setQuota(SecurityOrigin*, unsigned long long);
+
+    virtual void deleteAllDatabases();
+    virtual bool deleteOrigin(SecurityOrigin*);
+    virtual bool deleteDatabase(SecurityOrigin*, const String& name);
+
+    // From a secondary thread, must be thread safe with its data
+    virtual void scheduleNotifyDatabaseChanged(SecurityOrigin*, const String& name);
+    virtual void databaseChanged(AbstractDatabase*);
+
+#else // PLATFORM(CHROMIUM)
+    virtual void closeDatabasesImmediately(const String& originIdentifier, const String& name);
+#endif // PLATFORM(CHROMIUM)
+
+    virtual void interruptAllDatabasesForContext(const ScriptExecutionContext*);
+
+    virtual bool canEstablishDatabase(ScriptExecutionContext*, const String& name, const String& displayName, unsigned long estimatedSize);
+    virtual void addOpenDatabase(AbstractDatabase*);
+    virtual void removeOpenDatabase(AbstractDatabase*);
+
+    virtual void setDatabaseDetails(SecurityOrigin*, const String& name, const String& displayName, unsigned long estimatedSize);
+    virtual unsigned long long getMaxSizeForDatabase(const AbstractDatabase*);
 };
 
 } // namespace DBBackend
index 7848759..2b53188 100644 (file)
 
 #include "DOMWindowWebDatabase.h"
 
-#include "AbstractDatabase.h"
 #include "DOMWindow.h"
 #include "Database.h"
 #include "DatabaseCallback.h"
+#include "DatabaseManager.h"
 #include "Document.h"
 #include "Frame.h"
 #include "SecurityOrigin.h"
@@ -46,8 +46,9 @@ PassRefPtr<Database> DOMWindowWebDatabase::openDatabase(DOMWindow* window, const
         return 0;
 
     RefPtr<Database> database = 0;
-    if (AbstractDatabase::isAvailable() && window->document()->securityOrigin()->canAccessDatabase(window->document()->topDocument()->securityOrigin()))
-        database = Database::openDatabase(window->document(), name, version, displayName, estimatedSize, creationCallback, ec);
+    DatabaseManager& dbManager = DatabaseManager::manager();
+    if (dbManager.isAvailable() && window->document()->securityOrigin()->canAccessDatabase(window->document()->topDocument()->securityOrigin()))
+        database = dbManager.openDatabase(window->document(), name, version, displayName, estimatedSize, creationCallback, ec);
 
     if (!database && !ec)
         ec = SECURITY_ERR;
index d0c3a7a..256f027 100644 (file)
 #include "CrossThreadTask.h"
 #include "DatabaseCallback.h"
 #include "DatabaseContext.h"
+#include "DatabaseManager.h"
 #include "DatabaseTask.h"
 #include "DatabaseThread.h"
-#include "DatabaseTracker.h"
 #include "Document.h"
-#include "InspectorDatabaseInstrumentation.h"
 #include "Logging.h"
 #include "NotImplemented.h"
 #include "Page.h"
 
 namespace WebCore {
 
-class DatabaseCreationCallbackTask : public ScriptExecutionContext::Task {
-public:
-    static PassOwnPtr<DatabaseCreationCallbackTask> create(PassRefPtr<Database> database, PassRefPtr<DatabaseCallback> creationCallback)
-    {
-        return adoptPtr(new DatabaseCreationCallbackTask(database, creationCallback));
-    }
-
-    virtual void performTask(ScriptExecutionContext*)
-    {
-        m_creationCallback->handleEvent(m_database.get());
-    }
-
-private:
-    DatabaseCreationCallbackTask(PassRefPtr<Database> database, PassRefPtr<DatabaseCallback> callback)
-        : m_database(database)
-        , m_creationCallback(callback)
-    {
-    }
-
-    RefPtr<Database> m_database;
-    RefPtr<DatabaseCallback> m_creationCallback;
-};
-
-PassRefPtr<Database> Database::openDatabase(ScriptExecutionContext* context, const String& name,
-                                            const String& expectedVersion, const String& displayName,
-                                            unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback,
-                                            ExceptionCode& e)
-{
-    if (!DatabaseTracker::tracker().canEstablishDatabase(context, name, displayName, estimatedSize)) {
-        LOG(StorageAPI, "Database %s for origin %s not allowed to be established", name.ascii().data(), context->securityOrigin()->toString().ascii().data());
-        return 0;
-    }
-
-    RefPtr<Database> database = adoptRef(new Database(context, name, expectedVersion, displayName, estimatedSize));
-
-    String errorMessage;
-    if (!database->openAndVerifyVersion(!creationCallback, e, errorMessage)) {
-        database->logErrorMessage(errorMessage);
-        DatabaseTracker::tracker().removeOpenDatabase(database.get());
-        return 0;
-    }
-
-    DatabaseTracker::tracker().setDatabaseDetails(context->securityOrigin(), name, displayName, estimatedSize);
-
-    DatabaseContext::from(context)->setHasOpenDatabases();
-
-    InspectorInstrumentation::didOpenDatabase(context, database, context->securityOrigin()->host(), name, expectedVersion);
-
-    if (database->isNew() && creationCallback.get()) {
-        LOG(StorageAPI, "Scheduling DatabaseCreationCallbackTask for database %p\n", database.get());
-        database->m_scriptExecutionContext->postTask(DatabaseCreationCallbackTask::create(database, creationCallback));
-    }
-
-    return database;
-}
-
 Database::Database(ScriptExecutionContext* context, const String& name, const String& expectedVersion, const String& displayName, unsigned long estimatedSize)
     : AbstractDatabase(context, name, expectedVersion, displayName, estimatedSize, AsyncDatabase)
     , m_transactionInProgress(false)
@@ -228,7 +171,7 @@ void Database::close()
     RefPtr<Database> protect = this;
     databaseContext()->databaseThread()->recordDatabaseClosed(this);
     databaseContext()->databaseThread()->unscheduleDatabaseTasks(this);
-    DatabaseTracker::tracker().removeOpenDatabase(this);
+    DatabaseManager::manager().removeOpenDatabase(this);
 }
 
 void Database::closeImmediately()
@@ -243,7 +186,7 @@ void Database::closeImmediately()
 
 unsigned long long Database::maximumSize() const
 {
-    return DatabaseTracker::tracker().getMaxSizeForDatabase(this);
+    return DatabaseManager::manager().getMaxSizeForDatabase(this);
 }
 
 bool Database::performOpenAndVerify(bool setVersionInNewDatabase, ExceptionCode& e, String& errorMessage)
index 0e54022..6da0ba2 100644 (file)
@@ -32,6 +32,7 @@
 #if ENABLE(SQL_DATABASE)
 
 #include "AbstractDatabase.h"
+#include "DatabaseBasicTypes.h"
 #include <wtf/Deque.h>
 #include <wtf/Forward.h>
 #include <wtf/text/WTFString.h>
@@ -49,15 +50,11 @@ class SQLTransactionErrorCallback;
 class SQLTransactionWrapper;
 class VoidCallback;
 
-typedef int ExceptionCode;
-
 class Database : public AbstractDatabase {
 public:
     virtual ~Database();
 
     // Direct support for the DOM API
-    static PassRefPtr<Database> openDatabase(ScriptExecutionContext*, const String& name, const String& expectedVersion, const String& displayName,
-                                             unsigned long estimatedSize, PassRefPtr<DatabaseCallback>, ExceptionCode&);
     virtual String version() const;
     void changeVersion(const String& oldVersion, const String& newVersion, PassRefPtr<SQLTransactionCallback>,
                        PassRefPtr<SQLTransactionErrorCallback>, PassRefPtr<VoidCallback> successCallback);
@@ -103,8 +100,6 @@ private:
 
     Vector<String> performGetTableNames();
 
-    static void deliverPendingCallback(void*);
-
     Deque<RefPtr<SQLTransaction> > m_transactionQueue;
     Mutex m_transactionInProgressMutex;
     bool m_transactionInProgress;
@@ -113,6 +108,8 @@ private:
     RefPtr<SecurityOrigin> m_databaseThreadSecurityOrigin;
 
     bool m_deleted;
+
+    friend class DatabaseManager;
 };
 
 } // namespace WebCore
diff --git a/Source/WebCore/Modules/webdatabase/DatabaseBasicTypes.h b/Source/WebCore/Modules/webdatabase/DatabaseBasicTypes.h
new file mode 100644 (file)
index 0000000..b5454b1
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef DatabaseBasicTypes_h
+#define DatabaseBasicTypes_h
+
+#if ENABLE(SQL_DATABASE)
+
+namespace WebCore {
+
+typedef int DatabaseGuid;
+typedef int ExceptionCode;
+
+} // namespace WebCore
+
+#endif // ENABLE(SQL_DATABASE)
+
+#endif // DatabaseBasicTypes_h
index 0b662a8..1a99e77 100644 (file)
@@ -33,9 +33,9 @@
 #include "Chrome.h"
 #include "ChromeClient.h"
 #include "Database.h"
+#include "DatabaseManager.h"
 #include "DatabaseTask.h"
 #include "DatabaseThread.h"
-#include "DatabaseTracker.h"
 #include "Document.h"
 #include "Page.h"
 #include "SchemeRegistry.h"
@@ -134,7 +134,7 @@ void DatabaseContext::databaseExceededQuota(const String& name)
 #if !PLATFORM(CHROMIUM)
     // FIXME: This needs a real implementation; this is a temporary solution for testing.
     const unsigned long long defaultQuota = 5 * 1024 * 1024;
-    DatabaseTracker::tracker().setQuota(m_scriptExecutionContext->securityOrigin(), defaultQuota);
+    DatabaseManager::manager().setQuota(m_scriptExecutionContext->securityOrigin(), defaultQuota);
 #endif
 }
 
index 193ebc3..fa42ad8 100644 (file)
 #if ENABLE(SQL_DATABASE)
 
 #include "AbstractDatabase.h"
+#include "Database.h"
+#include "DatabaseCallback.h"
 #include "DatabaseContext.h"
-#include "DatabaseTracker.h"
-#include <wtf/UnusedParam.h>
+#include "DatabaseSync.h"
+#include "InspectorDatabaseInstrumentation.h"
+#include "Logging.h"
+#include "ScriptExecutionContext.h"
+#include "SecurityOrigin.h"
 
 #if USE(PLATFORM_STRATEGIES)
 #include "DatabaseStrategy.h"
@@ -52,6 +57,8 @@ DatabaseManager& DatabaseManager::manager()
 }
 
 DatabaseManager::DatabaseManager()
+    : m_client(0)
+    , m_databaseIsAvailable(true)
 {
 #if USE(PLATFORM_STRATEGIES)
     m_server = platformStrategies()->databaseStrategy()->getDatabaseServer();
@@ -63,38 +70,117 @@ DatabaseManager::DatabaseManager()
 
 void DatabaseManager::initialize(const String& databasePath)
 {
-#if !PLATFORM(CHROMIUM)
-    DatabaseTracker::initializeTracker(databasePath);
-#else
-    UNUSED_PARAM(databasePath);
-#endif
+    m_server->initialize(databasePath);
 }
 
-#if !PLATFORM(CHROMIUM)
 void DatabaseManager::setClient(DatabaseManagerClient* client)
 {
-    DatabaseTracker::tracker().setClient(client);
+    m_client = client;
+    m_server->setClient(client);
 }
 
 String DatabaseManager::databaseDirectoryPath() const
 {
-    return DatabaseTracker::tracker().databaseDirectoryPath();
+    return m_server->databaseDirectoryPath();
 }
 
 void DatabaseManager::setDatabaseDirectoryPath(const String& path)
 {
-    DatabaseTracker::tracker().setDatabaseDirectoryPath(path);
+    m_server->setDatabaseDirectoryPath(path);
 }
-#endif
 
 bool DatabaseManager::isAvailable()
 {
-    return AbstractDatabase::isAvailable();
+    return m_databaseIsAvailable;
 }
 
 void DatabaseManager::setIsAvailable(bool available)
 {
-    AbstractDatabase::setIsAvailable(available);
+    m_databaseIsAvailable = available;
+}
+
+class DatabaseCreationCallbackTask : public ScriptExecutionContext::Task {
+public:
+    static PassOwnPtr<DatabaseCreationCallbackTask> create(PassRefPtr<Database> database, PassRefPtr<DatabaseCallback> creationCallback)
+    {
+        return adoptPtr(new DatabaseCreationCallbackTask(database, creationCallback));
+    }
+
+    virtual void performTask(ScriptExecutionContext*)
+    {
+        m_creationCallback->handleEvent(m_database.get());
+    }
+
+private:
+    DatabaseCreationCallbackTask(PassRefPtr<Database> database, PassRefPtr<DatabaseCallback> callback)
+        : m_database(database)
+        , m_creationCallback(callback)
+    {
+    }
+
+    RefPtr<Database> m_database;
+    RefPtr<DatabaseCallback> m_creationCallback;
+};
+
+PassRefPtr<Database> DatabaseManager::openDatabase(ScriptExecutionContext* context,
+    const String& name, const String& expectedVersion, const String& displayName,
+    unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback, ExceptionCode& e)
+{
+    if (!canEstablishDatabase(context, name, displayName, estimatedSize)) {
+        LOG(StorageAPI, "Database %s for origin %s not allowed to be established", name.ascii().data(), context->securityOrigin()->toString().ascii().data());
+        return 0;
+    }
+
+    RefPtr<Database> database = adoptRef(new Database(context, name, expectedVersion, displayName, estimatedSize));
+
+    String errorMessage;
+    if (!database->openAndVerifyVersion(!creationCallback, e, errorMessage)) {
+        database->logErrorMessage(errorMessage);
+        DatabaseManager::manager().removeOpenDatabase(database.get());
+        return 0;
+    }
+
+    DatabaseManager::manager().setDatabaseDetails(context->securityOrigin(), name, displayName, estimatedSize);
+    DatabaseManager::manager().setHasOpenDatabases(context);
+
+    InspectorInstrumentation::didOpenDatabase(context, database, context->securityOrigin()->host(), name, expectedVersion);
+
+    if (database->isNew() && creationCallback.get()) {
+        LOG(StorageAPI, "Scheduling DatabaseCreationCallbackTask for database %p\n", database.get());
+        database->m_scriptExecutionContext->postTask(DatabaseCreationCallbackTask::create(database, creationCallback));
+    }
+
+    return database;
+}
+
+PassRefPtr<DatabaseSync> DatabaseManager::openDatabaseSync(ScriptExecutionContext* context,
+    const String& name, const String& expectedVersion, const String& displayName,
+    unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback, ExceptionCode& ec)
+{
+    ASSERT(context->isContextThread());
+
+    if (!canEstablishDatabase(context, name, displayName, estimatedSize)) {
+        LOG(StorageAPI, "Database %s for origin %s not allowed to be established", name.ascii().data(), context->securityOrigin()->toString().ascii().data());
+        return 0;
+    }
+
+    RefPtr<DatabaseSync> database = adoptRef(new DatabaseSync(context, name, expectedVersion, displayName, estimatedSize));
+
+    String errorMessage;
+    if (!database->performOpenAndVerify(!creationCallback, ec, errorMessage)) {
+        database->logErrorMessage(errorMessage);
+        DatabaseManager::manager().removeOpenDatabase(database.get());
+        return 0;
+    }
+
+    DatabaseManager::manager().setDatabaseDetails(context->securityOrigin(), name, displayName, estimatedSize);
+
+    if (database->isNew() && creationCallback.get()) {
+        LOG(StorageAPI, "Invoking the creation callback for database %p\n", database.get());
+        creationCallback->handleEvent(database.get());
+    }
+
+    return database;
 }
 
 bool DatabaseManager::hasOpenDatabases(ScriptExecutionContext* context)
@@ -102,6 +188,11 @@ bool DatabaseManager::hasOpenDatabases(ScriptExecutionContext* context)
     return DatabaseContext::hasOpenDatabases(context);
 }
 
+void DatabaseManager::setHasOpenDatabases(ScriptExecutionContext* context)
+{
+    DatabaseContext::from(context)->setHasOpenDatabases();
+}
+
 void DatabaseManager::stopDatabases(ScriptExecutionContext* context, DatabaseTaskSynchronizer* synchronizer)
 {
     DatabaseContext::stopDatabases(context, synchronizer);
@@ -109,70 +200,106 @@ void DatabaseManager::stopDatabases(ScriptExecutionContext* context, DatabaseTas
 
 String DatabaseManager::fullPathForDatabase(SecurityOrigin* origin, const String& name, bool createIfDoesNotExist)
 {
-    return DatabaseTracker::tracker().fullPathForDatabase(origin, name, createIfDoesNotExist);
+    return m_server->fullPathForDatabase(origin, name, createIfDoesNotExist);
 }
 
 #if !PLATFORM(CHROMIUM)
 bool DatabaseManager::hasEntryForOrigin(SecurityOrigin* origin)
 {
-    return DatabaseTracker::tracker().hasEntryForOrigin(origin);
+    return m_server->hasEntryForOrigin(origin);
 }
 
 void DatabaseManager::origins(Vector<RefPtr<SecurityOrigin> >& result)
 {
-    DatabaseTracker::tracker().origins(result);
+    m_server->origins(result);
 }
 
 bool DatabaseManager::databaseNamesForOrigin(SecurityOrigin* origin, Vector<String>& result)
 {
-    return DatabaseTracker::tracker().databaseNamesForOrigin(origin, result);
+    return m_server->databaseNamesForOrigin(origin, result);
 }
 
 DatabaseDetails DatabaseManager::detailsForNameAndOrigin(const String& name, SecurityOrigin* origin)
 {
-    return DatabaseTracker::tracker().detailsForNameAndOrigin(name, origin);
+    return m_server->detailsForNameAndOrigin(name, origin);
 }
 
 unsigned long long DatabaseManager::usageForOrigin(SecurityOrigin* origin)
 {
-    return DatabaseTracker::tracker().usageForOrigin(origin);
+    return m_server->usageForOrigin(origin);
 }
 
 unsigned long long DatabaseManager::quotaForOrigin(SecurityOrigin* origin)
 {
-    return DatabaseTracker::tracker().quotaForOrigin(origin);
+    return m_server->quotaForOrigin(origin);
 }
 
 void DatabaseManager::setQuota(SecurityOrigin* origin, unsigned long long quotaSize)
 {
-    DatabaseTracker::tracker().setQuota(origin, quotaSize);
+    m_server->setQuota(origin, quotaSize);
 }
 
 void DatabaseManager::deleteAllDatabases()
 {
-    DatabaseTracker::tracker().deleteAllDatabases();
+    m_server->deleteAllDatabases();
 }
 
 bool DatabaseManager::deleteOrigin(SecurityOrigin* origin)
 {
-    return DatabaseTracker::tracker().deleteOrigin(origin);
+    return m_server->deleteOrigin(origin);
 }
 
 bool DatabaseManager::deleteDatabase(SecurityOrigin* origin, const String& name)
 {
-    return DatabaseTracker::tracker().deleteDatabase(origin, name);
+    return m_server->deleteDatabase(origin, name);
+}
+
+// From a secondary thread, must be thread safe with its data
+void DatabaseManager::scheduleNotifyDatabaseChanged(SecurityOrigin* origin, const String& name)
+{
+    m_server->scheduleNotifyDatabaseChanged(origin, name);
+}
+
+void DatabaseManager::databaseChanged(AbstractDatabase* database)
+{
+    m_server->databaseChanged(database);
 }
 
 #else // PLATFORM(CHROMIUM)
 void DatabaseManager::closeDatabasesImmediately(const String& originIdentifier, const String& name)
 {
-    DatabaseTracker::tracker().closeDatabasesImmediately(originIdentifier, name);
+    m_server->closeDatabasesImmediately(originIdentifier, name);
 }
 #endif // PLATFORM(CHROMIUM)
 
 void DatabaseManager::interruptAllDatabasesForContext(const ScriptExecutionContext* context)
 {
-    DatabaseTracker::tracker().interruptAllDatabasesForContext(context);
+    m_server->interruptAllDatabasesForContext(context);
+}
+
+bool DatabaseManager::canEstablishDatabase(ScriptExecutionContext* context, const String& name, const String& displayName, unsigned long estimatedSize)
+{
+    return m_server->canEstablishDatabase(context, name, displayName, estimatedSize);
+}
+
+void DatabaseManager::addOpenDatabase(AbstractDatabase* database)
+{
+    m_server->addOpenDatabase(database);
+}
+
+void DatabaseManager::removeOpenDatabase(AbstractDatabase* database)
+{
+    m_server->removeOpenDatabase(database);
+}
+
+void DatabaseManager::setDatabaseDetails(SecurityOrigin* origin, const String& name, const String& displayName, unsigned long estimatedSize)
+{
+    m_server->setDatabaseDetails(origin, name, displayName, estimatedSize);
+}
+
+unsigned long long DatabaseManager::getMaxSizeForDatabase(const AbstractDatabase* database)
+{
+    return m_server->getMaxSizeForDatabase(database);
 }
 
 } // namespace WebCore
index b7d3812..a4e24ed 100644 (file)
 
 #if ENABLE(SQL_DATABASE)
 
-#include "DatabaseDetails.h"
-#include <wtf/RefPtr.h>
-#include <wtf/Vector.h>
-#include <wtf/text/WTFString.h>
+#include "AbstractDatabaseServer.h"
+#include "DatabaseBasicTypes.h"
+#include <wtf/PassRefPtr.h>
 
 namespace WebCore {
 
 class AbstractDatabaseServer;
+class Database;
+class DatabaseCallback;
 class DatabaseManagerClient;
+class DatabaseSync;
 class DatabaseTaskSynchronizer;
 class SecurityOrigin;
 class ScriptExecutionContext;
@@ -47,17 +49,18 @@ public:
     static DatabaseManager& manager();
 
     void initialize(const String& databasePath);
-#if !PLATFORM(CHROMIUM)
     void setClient(DatabaseManagerClient*);
     String databaseDirectoryPath() const;
     void setDatabaseDirectoryPath(const String&);
-#endif
 
     bool isAvailable();
     void setIsAvailable(bool);
 
+    PassRefPtr<Database> openDatabase(ScriptExecutionContext*, const String& name, const String& expectedVersion, const String& displayName, unsigned long estimatedSize, PassRefPtr<DatabaseCallback>, ExceptionCode&);
+    PassRefPtr<DatabaseSync> openDatabaseSync(ScriptExecutionContext*, const String& name, const String& expectedVersion, const String& displayName, unsigned long estimatedSize, PassRefPtr<DatabaseCallback>, ExceptionCode&);
+
     bool hasOpenDatabases(ScriptExecutionContext*);
-    // When the database cleanup is done, cleanupSync will be signalled.
+    void setHasOpenDatabases(ScriptExecutionContext*);
     void stopDatabases(ScriptExecutionContext*, DatabaseTaskSynchronizer*);
 
     String fullPathForDatabase(SecurityOrigin*, const String& name, bool createIfDoesNotExist = true);
@@ -77,17 +80,31 @@ public:
     bool deleteOrigin(SecurityOrigin*);
     bool deleteDatabase(SecurityOrigin*, const String& name);
 
+    // From a secondary thread, must be thread safe with its data
+    void scheduleNotifyDatabaseChanged(SecurityOrigin*, const String& name);
+
+    void databaseChanged(AbstractDatabase*);
+
 #else // PLATFORM(CHROMIUM)
     void closeDatabasesImmediately(const String& originIdentifier, const String& name);
 #endif // PLATFORM(CHROMIUM)
 
     void interruptAllDatabasesForContext(const ScriptExecutionContext*);
 
+    bool canEstablishDatabase(ScriptExecutionContext*, const String& name, const String& displayName, unsigned long estimatedSize);
+    void addOpenDatabase(AbstractDatabase*);
+    void removeOpenDatabase(AbstractDatabase*);
+
+    void setDatabaseDetails(SecurityOrigin*, const String& name, const String& displayName, unsigned long estimatedSize);
+    unsigned long long getMaxSizeForDatabase(const AbstractDatabase*);
+
 private:
     DatabaseManager();
     ~DatabaseManager() { }
 
     AbstractDatabaseServer* m_server;
+    DatabaseManagerClient* m_client;
+    bool m_databaseIsAvailable;
 };
 
 } // namespace WebCore
index 8b744b8..1f79271 100644 (file)
@@ -34,7 +34,7 @@
 #if ENABLE(SQL_DATABASE)
 
 #include "DatabaseCallback.h"
-#include "DatabaseTracker.h"
+#include "DatabaseManager.h"
 #include "Logging.h"
 #include "SQLException.h"
 #include "SQLTransactionSync.h"
 
 namespace WebCore {
 
-PassRefPtr<DatabaseSync> DatabaseSync::openDatabaseSync(ScriptExecutionContext* context, const String& name, const String& expectedVersion, const String& displayName,
-                                                        unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback, ExceptionCode& ec)
-{
-    ASSERT(context->isContextThread());
-
-    if (!DatabaseTracker::tracker().canEstablishDatabase(context, name, displayName, estimatedSize)) {
-        LOG(StorageAPI, "Database %s for origin %s not allowed to be established", name.ascii().data(), context->securityOrigin()->toString().ascii().data());
-        return 0;
-    }
-
-    RefPtr<DatabaseSync> database = adoptRef(new DatabaseSync(context, name, expectedVersion, displayName, estimatedSize));
-
-    String errorMessage;
-    if (!database->performOpenAndVerify(!creationCallback, ec, errorMessage)) {
-        database->logErrorMessage(errorMessage);
-        DatabaseTracker::tracker().removeOpenDatabase(database.get());
-        return 0;
-    }
-
-    DatabaseTracker::tracker().setDatabaseDetails(context->securityOrigin(), name, displayName, estimatedSize);
-
-    if (database->isNew() && creationCallback.get()) {
-        LOG(StorageAPI, "Invoking the creation callback for database %p\n", database.get());
-        creationCallback->handleEvent(database.get());
-    }
-
-    return database;
-}
-
 DatabaseSync::DatabaseSync(ScriptExecutionContext* context, const String& name, const String& expectedVersion,
                            const String& displayName, unsigned long estimatedSize)
     : AbstractDatabase(context, name, expectedVersion, displayName, estimatedSize, SyncDatabase)
@@ -87,7 +58,7 @@ DatabaseSync::~DatabaseSync()
     ASSERT(m_scriptExecutionContext->isContextThread());
 
     if (opened()) {
-        DatabaseTracker::tracker().removeOpenDatabase(this);
+        DatabaseManager::manager().removeOpenDatabase(this);
         closeDatabase();
     }
 }
@@ -211,7 +182,7 @@ void DatabaseSync::closeImmediately()
         return;
 
     logErrorMessage("forcibly closing database");
-    DatabaseTracker::tracker().removeOpenDatabase(this);
+    DatabaseManager::manager().removeOpenDatabase(this);
     closeDatabase();
 }
 
index 7f18c90..ed6fb33 100644 (file)
@@ -34,6 +34,7 @@
 #if ENABLE(SQL_DATABASE)
 
 #include "AbstractDatabase.h"
+#include "DatabaseBasicTypes.h"
 #include <wtf/Forward.h>
 #include <wtf/text/WTFString.h>
 
@@ -49,15 +50,11 @@ class SQLTransactionSyncCallback;
 class ScriptExecutionContext;
 class SecurityOrigin;
 
-typedef int ExceptionCode;
-
 // Instances of this class should be created and used only on the worker's context thread.
 class DatabaseSync : public AbstractDatabase {
 public:
     virtual ~DatabaseSync();
 
-    static PassRefPtr<DatabaseSync> openDatabaseSync(ScriptExecutionContext*, const String& name, const String& expectedVersion,
-                                                     const String& displayName, unsigned long estimatedSize, PassRefPtr<DatabaseCallback>, ExceptionCode&);
     void changeVersion(const String& oldVersion, const String& newVersion, PassRefPtr<SQLTransactionSyncCallback>, ExceptionCode&);
     void transaction(PassRefPtr<SQLTransactionSyncCallback>, ExceptionCode&);
     void readTransaction(PassRefPtr<SQLTransactionSyncCallback>, ExceptionCode&);
@@ -82,6 +79,8 @@ private:
     void runTransaction(PassRefPtr<SQLTransactionSyncCallback>, bool readOnly, ExceptionCode&);
 
     String m_lastErrorMessage;
+
+    friend class DatabaseManager;
 };
 
 } // namespace WebCore
index 4fa290f..b5c6165 100644 (file)
@@ -31,6 +31,7 @@
 #if ENABLE(SQL_DATABASE)
 
 #include "Database.h"
+#include "DatabaseBasicTypes.h"
 #include "SQLTransaction.h"
 #include <wtf/OwnPtr.h>
 #include <wtf/PassOwnPtr.h>
@@ -41,8 +42,6 @@
 
 namespace WebCore {
 
-typedef int ExceptionCode;
-
 // Can be used to wait until DatabaseTask is completed.
 // Has to be passed into DatabaseTask::create to be associated with the task.
 class DatabaseTaskSynchronizer {
index e30be59..28ea431 100644 (file)
 
 #if ENABLE(SQL_DATABASE)
 
+#include "DatabaseBasicTypes.h"
 #include "SQLResultSetRowList.h"
 #include <wtf/ThreadSafeRefCounted.h>
 
 namespace WebCore {
 
-typedef int ExceptionCode;
-
 class SQLResultSet : public ThreadSafeRefCounted<SQLResultSet> {
 public:
     static PassRefPtr<SQLResultSet> create() { return adoptRef(new SQLResultSet); }
index afdee2a..3278b95 100644 (file)
@@ -33,6 +33,7 @@
 
 #if ENABLE(SQL_DATABASE)
 
+#include "DatabaseBasicTypes.h"
 #include "SQLValue.h"
 #include <wtf/Forward.h>
 #include <wtf/Vector.h>
@@ -43,8 +44,6 @@ namespace WebCore {
 class DatabaseSync;
 class SQLResultSet;
 
-typedef int ExceptionCode;
-
 class SQLStatementSync {
 public:
     SQLStatementSync(const String& statement, const Vector<SQLValue>& arguments, int permissions);
index 11438e2..4df4db0 100644 (file)
@@ -30,6 +30,7 @@
 
 #if ENABLE(SQL_DATABASE)
 
+#include "DatabaseBasicTypes.h"
 #include "SQLStatement.h"
 #include <wtf/Deque.h>
 #include <wtf/Forward.h>
@@ -49,8 +50,6 @@ class SQLTransactionErrorCallback;
 class SQLValue;
 class VoidCallback;
 
-typedef int ExceptionCode;
-
 class SQLTransactionWrapper : public ThreadSafeRefCounted<SQLTransactionWrapper> {
 public:
     virtual ~SQLTransactionWrapper() { }
index 07c83d2..d3422a0 100644 (file)
@@ -35,7 +35,7 @@
 
 #include "AbstractDatabase.h"
 #include "DatabaseContext.h"
-#include "DatabaseTracker.h"
+#include "DatabaseManager.h"
 #include "ScriptExecutionContext.h"
 #include "SecurityOrigin.h"
 
@@ -43,21 +43,21 @@ namespace WebCore {
 
 void SQLTransactionClient::didCommitWriteTransaction(AbstractDatabase* database)
 {
-    DatabaseTracker::tracker().scheduleNotifyDatabaseChanged(
+    DatabaseManager::manager().scheduleNotifyDatabaseChanged(
         database->securityOrigin(), database->stringIdentifier());
 }
 
 void SQLTransactionClient::didExecuteStatement(AbstractDatabase* database)
 {
-    DatabaseTracker::tracker().databaseChanged(database);
+    DatabaseManager::manager().databaseChanged(database);
 }
 
 bool SQLTransactionClient::didExceedQuota(AbstractDatabase* database)
 {
     ASSERT(database->scriptExecutionContext()->isContextThread());
-    unsigned long long currentQuota = DatabaseTracker::tracker().quotaForOrigin(database->securityOrigin());
+    unsigned long long currentQuota = DatabaseManager::manager().quotaForOrigin(database->securityOrigin());
     database->databaseContext()->databaseExceededQuota(database->stringIdentifier());
-    unsigned long long newQuota = DatabaseTracker::tracker().quotaForOrigin(database->securityOrigin());
+    unsigned long long newQuota = DatabaseManager::manager().quotaForOrigin(database->securityOrigin());
     return (newQuota > currentQuota);
 }
 
index 918b970..8809e4a 100644 (file)
@@ -33,6 +33,7 @@
 
 #if ENABLE(SQL_DATABASE)
 
+#include "DatabaseBasicTypes.h"
 #include <wtf/Forward.h>
 #include <wtf/RefCounted.h>
 #include <wtf/Vector.h>
@@ -47,8 +48,6 @@ class SQLTransactionSyncCallback;
 class SQLValue;
 class SQLiteTransaction;
 
-typedef int ExceptionCode;
-
 // Instances of this class should be created and used only on the worker's context thread.
 class SQLTransactionSync : public RefCounted<SQLTransactionSync> {
 public:
index 899b705..15301da 100644 (file)
 
 #include "WorkerContextWebDatabase.h"
 
-#include "AbstractDatabase.h"
 #include "Database.h"
 #include "DatabaseCallback.h"
+#include "DatabaseManager.h"
 #include "DatabaseSync.h"
-#include "DatabaseTracker.h"
 #include "SecurityOrigin.h"
 #include "WorkerContext.h"
 
@@ -43,22 +42,24 @@ namespace WebCore {
 
 PassRefPtr<Database> WorkerContextWebDatabase::openDatabase(WorkerContext* context, const String& name, const String& version, const String& displayName, unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback, ExceptionCode& ec)
 {
-    if (!context->securityOrigin()->canAccessDatabase(context->topOrigin()) || !AbstractDatabase::isAvailable()) {
+    DatabaseManager& dbManager = DatabaseManager::manager();
+    if (!context->securityOrigin()->canAccessDatabase(context->topOrigin()) || !dbManager.isAvailable()) {
         ec = SECURITY_ERR;
         return 0;
     }
 
-    return Database::openDatabase(context, name, version, displayName, estimatedSize, creationCallback, ec);
+    return dbManager.openDatabase(context, name, version, displayName, estimatedSize, creationCallback, ec);
 }
 
 PassRefPtr<DatabaseSync> WorkerContextWebDatabase::openDatabaseSync(WorkerContext* context, const String& name, const String& version, const String& displayName, unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback, ExceptionCode& ec)
 {
-    if (!context->securityOrigin()->canAccessDatabase(context->topOrigin()) || !AbstractDatabase::isAvailable()) {
+    DatabaseManager& dbManager = DatabaseManager::manager();
+    if (!context->securityOrigin()->canAccessDatabase(context->topOrigin()) || !dbManager.isAvailable()) {
         ec = SECURITY_ERR;
         return 0;
     }
 
-    return DatabaseSync::openDatabaseSync(context, name, version, displayName, estimatedSize, creationCallback, ec);
+    return dbManager.openDatabaseSync(context, name, version, displayName, estimatedSize, creationCallback, ec);
 }
 
 } // namespace WebCore
index a68ad84..d1045c5 100644 (file)
@@ -25,6 +25,7 @@ SOURCES += \
     Modules/webdatabase/DatabaseAuthorizer.cpp \
     Modules/webdatabase/DatabaseContext.cpp \
     Modules/webdatabase/DatabaseSync.cpp \
+    Modules/webdatabase/DBBackendServer.cpp \
     Modules/webdatabase/WorkerContextWebDatabase.cpp \
     \
     accessibility/AccessibilityImageMapLink.cpp \
index a0fdbd6..bd4a386 100644 (file)
             'Modules/webdatabase/DatabaseThread.cpp',
             'Modules/webdatabase/DatabaseThread.h',
             'Modules/webdatabase/DatabaseTracker.cpp',
+            'Modules/webdatabase/DBBackendServer.cpp',
             'Modules/webdatabase/DBBackendServer.h',
             'Modules/webdatabase/DOMWindowWebDatabase.cpp',
             'Modules/webdatabase/DOMWindowWebDatabase.h',
index 78f7824..2f67f48 100755 (executable)
                                        >
                                </File>
                                <File
+                                       RelativePath="..\Modules\webdatabase\DBBackendServer.cpp"
+                                       >
+                               </File>
+                               <File
                                        RelativePath="..\Modules\webdatabase\DBBackendServer.h"
                                        >
                                </File>
index ccd5fae..72515b6 100644 (file)
                FDF7E9C313AC21DB00A51EAC /* JSAudioBufferCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FDF7E9C113AC21DB00A51EAC /* JSAudioBufferCallback.cpp */; };
                FDF7E9C413AC21DB00A51EAC /* JSAudioBufferCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = FDF7E9C213AC21DB00A51EAC /* JSAudioBufferCallback.h */; };
                FE115FAB167988CD00249134 /* AbstractDatabaseServer.h in Headers */ = {isa = PBXBuildFile; fileRef = FE115FA9167988CD00249134 /* AbstractDatabaseServer.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               FE3371A2167C11D400EDB752 /* DatabaseBasicTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = FE3371A0167C11D400EDB752 /* DatabaseBasicTypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
                FE456F181677D74E005EDDF9 /* DatabaseManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE456F161677D74E005EDDF9 /* DatabaseManager.cpp */; };
                FE456F191677D74E005EDDF9 /* DatabaseManager.h in Headers */ = {isa = PBXBuildFile; fileRef = FE456F171677D74E005EDDF9 /* DatabaseManager.h */; settings = {ATTRIBUTES = (Private, ); }; };
                FE6FD4880F676E5700092873 /* Coordinates.h in Headers */ = {isa = PBXBuildFile; fileRef = FE6FD4850F676E5700092873 /* Coordinates.h */; settings = {ATTRIBUTES = (Private, ); }; };
                FE80DA710E9C472F000D6F75 /* JSPositionError.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE80DA6D0E9C472F000D6F75 /* JSPositionError.cpp */; };
                FE80DA720E9C472F000D6F75 /* JSPositionError.h in Headers */ = {isa = PBXBuildFile; fileRef = FE80DA6E0E9C472F000D6F75 /* JSPositionError.h */; };
                FEAF6654167970320062D0C5 /* DBBackendServer.h in Headers */ = {isa = PBXBuildFile; fileRef = FEAF6653167970070062D0C5 /* DBBackendServer.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               FEB26D28167A8F2A00FDD26B /* DBBackendServer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FEB26D27167A8F2A00FDD26B /* DBBackendServer.cpp */; };
                FEDEF84116797108000E444A /* DatabaseStrategy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FEDEF83F16797108000E444A /* DatabaseStrategy.cpp */; };
                FEDEF84216797108000E444A /* DatabaseStrategy.h in Headers */ = {isa = PBXBuildFile; fileRef = FEDEF84016797108000E444A /* DatabaseStrategy.h */; settings = {ATTRIBUTES = (Private, ); }; };
                FF945ECB161F7F3600971BC8 /* PseudoElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FF945EC9161F7F3600971BC8 /* PseudoElement.cpp */; };
                FDF7E9C113AC21DB00A51EAC /* JSAudioBufferCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSAudioBufferCallback.cpp; sourceTree = "<group>"; };
                FDF7E9C213AC21DB00A51EAC /* JSAudioBufferCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSAudioBufferCallback.h; sourceTree = "<group>"; };
                FE115FA9167988CD00249134 /* AbstractDatabaseServer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AbstractDatabaseServer.h; path = Modules/webdatabase/AbstractDatabaseServer.h; sourceTree = "<group>"; };
+               FE3371A0167C11D400EDB752 /* DatabaseBasicTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DatabaseBasicTypes.h; path = Modules/webdatabase/DatabaseBasicTypes.h; sourceTree = "<group>"; };
                FE456F161677D74E005EDDF9 /* DatabaseManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DatabaseManager.cpp; path = Modules/webdatabase/DatabaseManager.cpp; sourceTree = "<group>"; };
                FE456F171677D74E005EDDF9 /* DatabaseManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DatabaseManager.h; path = Modules/webdatabase/DatabaseManager.h; sourceTree = "<group>"; };
                FE6FD4850F676E5700092873 /* Coordinates.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Coordinates.h; sourceTree = "<group>"; };
                FE80DA6D0E9C472F000D6F75 /* JSPositionError.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSPositionError.cpp; sourceTree = "<group>"; };
                FE80DA6E0E9C472F000D6F75 /* JSPositionError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSPositionError.h; sourceTree = "<group>"; };
                FEAF6653167970070062D0C5 /* DBBackendServer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DBBackendServer.h; path = Modules/webdatabase/DBBackendServer.h; sourceTree = "<group>"; };
+               FEB26D27167A8F2A00FDD26B /* DBBackendServer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DBBackendServer.cpp; path = Modules/webdatabase/DBBackendServer.cpp; sourceTree = "<group>"; };
                FEDEF83F16797108000E444A /* DatabaseStrategy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DatabaseStrategy.cpp; sourceTree = "<group>"; };
                FEDEF84016797108000E444A /* DatabaseStrategy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DatabaseStrategy.h; sourceTree = "<group>"; };
                FF945EC9161F7F3600971BC8 /* PseudoElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PseudoElement.cpp; sourceTree = "<group>"; };
                                97BC69E01505F081001B74AC /* Database.idl */,
                                97BC69E11505F081001B74AC /* DatabaseAuthorizer.cpp */,
                                97BC69E21505F081001B74AC /* DatabaseAuthorizer.h */,
+                               FE3371A0167C11D400EDB752 /* DatabaseBasicTypes.h */,
                                97BC69E31505F081001B74AC /* DatabaseCallback.h */,
                                97BC69E41505F081001B74AC /* DatabaseCallback.idl */,
                                97BC69E51505F081001B74AC /* DatabaseContext.cpp */,
                                97BC69EE1505F081001B74AC /* DatabaseThread.h */,
                                97BC69EF1505F081001B74AC /* DatabaseTracker.cpp */,
                                97BC69F01505F081001B74AC /* DatabaseTracker.h */,
+                               FEB26D27167A8F2A00FDD26B /* DBBackendServer.cpp */,
                                FEAF6653167970070062D0C5 /* DBBackendServer.h */,
                                A8CCBB46151F831600AB7CE9 /* DOMWindowWebDatabase.cpp */,
                                A8CCBB47151F831600AB7CE9 /* DOMWindowWebDatabase.h */,
                        files = (
                                FEDEF84216797108000E444A /* DatabaseStrategy.h in Headers */,
                                FE115FAB167988CD00249134 /* AbstractDatabaseServer.h in Headers */,
+                               FE3371A2167C11D400EDB752 /* DatabaseBasicTypes.h in Headers */,
                                FEAF6654167970320062D0C5 /* DBBackendServer.h in Headers */,
                                FE456F191677D74E005EDDF9 /* DatabaseManager.h in Headers */,
                                E43105BB16750F1600DB2FB8 /* NodeTraversal.h in Headers */,
                                FDA9326616703BA9008982DC /* JSOfflineAudioContext.cpp in Sources */,
                                FE456F181677D74E005EDDF9 /* DatabaseManager.cpp in Sources */,
                                FEDEF84116797108000E444A /* DatabaseStrategy.cpp in Sources */,
+                               FEB26D28167A8F2A00FDD26B /* DBBackendServer.cpp in Sources */,
                                F37A56221679CF7B00C57046 /* HeapGraphSerializer.cpp in Sources */,
                                CD1E7347167BC78E009A885D /* TextTrackRepresentation.cpp in Sources */,
                                9A9CEF8D163B3EA100DE7EFE /* ExclusionShapeOutsideInfo.cpp in Sources */,