[SCM] WebKit Debian packaging branch, webkit-1.2, updated. upstream/1.1.90-6072-g9a69373

dumi at chromium.org dumi at chromium.org
Wed Apr 7 23:09:30 UTC 2010


The following commit has been merged in the webkit-1.2 branch:
commit a3b8874cba95d49e1f4cf969e0b37aa8e9c742ab
Author: dumi at chromium.org <dumi at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Oct 27 20:14:29 2009 +0000

    Refactoring the Database class to not depend on
    OriginQuotaManager. Also, adding a SecurityOrigin copy to each
    Database instance, that is safe to use on the file
    thread. Finally, adding new simple fields and getters to the
    Database object for storing/getting the display name and estimated
    size specified by the user in the openDatabase() call.
    
    Patch by Dumitru Daniliuc <dumi at chromium.org> on 2009-10-27
    Reviewed by Adam Barth.
    
    https://bugs.webkit.org/show_bug.cgi?id=30548
    
    * page/SecurityOrigin.h:
    * storage/Database.cpp:
    (WebCore::Database::openDatabase): Storing the display name and
    the estimated size in the Database object.
    (WebCore::Database::Database): Storing the display name and the
    estimated size in the Database object, as well as a SecurityOrigin
    instance that is safe to use on the DB thread.
    (WebCore::Database::maximumSize): Delegate the call to
    DatabaseTracker::getMaxSizeForDatabase().
    (WebCore::Database::databaseThreadSecurityOrigin): Return the
    SecurityOrigin instance that's safe to use on the DB thread.
    (WebCore::Database::threadSafeSecurityOrigin): Return the
    SecurityOrigin instance that's safe to use on the current thread.
    (WebCore::Database::displayName): Return the display name
    specified by the user in the openDatabase() call.
    (WebCore::Database::estimatedSize): Return the estimated size
    specified by the user in the openDatabase() call.
    (WebCore::Database::fileName): Return the name of the file where
    the current Database is tored.
    * storage/Database.h:
    * storage/DatabaseTracker.cpp:
    (WebCore::DatabaseTracker::getMaxSizeForDatabase): Returns the
    maximum size for a DB file based on the current size of that file
    and the space available for that origin.
    * storage/DatabaseTracker.h:
    * storage/SQLTransaction.cpp:
    * storage/SQLTransactionClient.cpp:
    (WebCore::SQLTransactionClient::didCommitTransaction): Use the
    correct SecurityOrigin instance.
    
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@50169 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 9be5fa2..9a0149e 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,46 @@
+2009-10-27  Dumitru Daniliuc  <dumi at chromium.org>
+
+        Reviewed by Adam Barth.
+
+        Refactoring the Database class to not depend on
+        OriginQuotaManager. Also, adding a SecurityOrigin copy to each
+        Database instance, that is safe to use on the file
+        thread. Finally, adding new simple fields and getters to the
+        Database object for storing/getting the display name and estimated
+        size specified by the user in the openDatabase() call.
+
+        https://bugs.webkit.org/show_bug.cgi?id=30548
+
+        * page/SecurityOrigin.h:
+        * storage/Database.cpp:
+        (WebCore::Database::openDatabase): Storing the display name and
+        the estimated size in the Database object.
+        (WebCore::Database::Database): Storing the display name and the
+        estimated size in the Database object, as well as a SecurityOrigin
+        instance that is safe to use on the DB thread.
+        (WebCore::Database::maximumSize): Delegate the call to
+        DatabaseTracker::getMaxSizeForDatabase().
+        (WebCore::Database::databaseThreadSecurityOrigin): Return the
+        SecurityOrigin instance that's safe to use on the DB thread.
+        (WebCore::Database::threadSafeSecurityOrigin): Return the
+        SecurityOrigin instance that's safe to use on the current thread.
+        (WebCore::Database::displayName): Return the display name
+        specified by the user in the openDatabase() call.
+        (WebCore::Database::estimatedSize): Return the estimated size
+        specified by the user in the openDatabase() call.
+        (WebCore::Database::fileName): Return the name of the file where
+        the current Database is tored.
+        * storage/Database.h:
+        * storage/DatabaseTracker.cpp:
+        (WebCore::DatabaseTracker::getMaxSizeForDatabase): Returns the
+        maximum size for a DB file based on the current size of that file
+        and the space available for that origin.
+        * storage/DatabaseTracker.h:
+        * storage/SQLTransaction.cpp:
+        * storage/SQLTransactionClient.cpp:
+        (WebCore::SQLTransactionClient::didCommitTransaction): Use the
+        correct SecurityOrigin instance.
+
 2009-10-27  Joseph Pecoraro  <joepeck at webkit.org>
 
         Reviewed by Timothy Hatcher.
diff --git a/WebCore/page/SecurityOrigin.h b/WebCore/page/SecurityOrigin.h
index 46e6fad..6d4ce1f 100644
--- a/WebCore/page/SecurityOrigin.h
+++ b/WebCore/page/SecurityOrigin.h
@@ -127,9 +127,8 @@ namespace WebCore {
         // SecurityOrigin is represented with the string "null".
         String toString() const;
 
-        // Serialize the security origin for storage in the database. This format is
-        // deprecated and should be used only for compatibility with old databases;
-        // use toString() and createFromString() instead.
+        // Serialize the security origin to a string that could be used as part of
+        // file names. This format should be used in storage APIs only.
         String databaseIdentifier() const;
 
         // This method checks for equality between SecurityOrigins, not whether
diff --git a/WebCore/storage/Database.cpp b/WebCore/storage/Database.cpp
index 08ea289..dabb416 100644
--- a/WebCore/storage/Database.cpp
+++ b/WebCore/storage/Database.cpp
@@ -128,7 +128,7 @@ PassRefPtr<Database> Database::openDatabase(Document* document, const String& na
         return 0;
     }
 
-    RefPtr<Database> database = adoptRef(new Database(document, name, expectedVersion));
+    RefPtr<Database> database = adoptRef(new Database(document, name, expectedVersion, displayName, estimatedSize));
 
     if (!database->openAndVerifyVersion(e)) {
        LOG(StorageAPI, "Failed to open and verify version (expected %s) of database %s", expectedVersion.ascii().data(), database->databaseDebugName().ascii().data());
@@ -147,18 +147,21 @@ PassRefPtr<Database> Database::openDatabase(Document* document, const String& na
     return database;
 }
 
-Database::Database(Document* document, const String& name, const String& expectedVersion)
+Database::Database(Document* document, const String& name, const String& expectedVersion, const String& displayName, unsigned long estimatedSize)
     : m_transactionInProgress(false)
     , m_document(document)
     , m_name(name.crossThreadString())
     , m_guid(0)
     , m_expectedVersion(expectedVersion)
+    , m_displayName(displayName)
+    , m_estimatedSize(estimatedSize)
     , m_deleted(false)
     , m_stopped(false)
     , m_opened(false)
 {
     ASSERT(document);
-    m_securityOrigin = document->securityOrigin();
+    m_mainThreadSecurityOrigin = document->securityOrigin();
+    m_databaseThreadSecurityOrigin = m_mainThreadSecurityOrigin->threadsafeCopy();
 
     if (m_name.isNull())
         m_name = "";
@@ -167,7 +170,7 @@ Database::Database(Document* document, const String& name, const String& expecte
     JSC::initializeThreading();
 #endif
 
-    m_guid = guidForOriginAndName(m_securityOrigin->toString(), name);
+    m_guid = guidForOriginAndName(m_mainThreadSecurityOrigin->toString(), name);
 
     {
         MutexLocker locker(guidMutex());
@@ -183,7 +186,7 @@ Database::Database(Document* document, const String& name, const String& expecte
 
     ASSERT(m_document->databaseThread());
 
-    m_filename = DatabaseTracker::tracker().fullPathForDatabase(m_securityOrigin.get(), m_name);
+    m_filename = DatabaseTracker::tracker().fullPathForDatabase(m_mainThreadSecurityOrigin.get(), m_name);
 
     DatabaseTracker::tracker().addOpenDatabase(this);
     m_document->addOpenDatabase(this);
@@ -366,20 +369,9 @@ void Database::stop()
     }
 }
 
-unsigned long long Database::databaseSize() const
-{
-    return SQLiteFileSystem::getDatabaseFileSize(m_filename);
-}
-
 unsigned long long Database::maximumSize() const
 {
-    // The maximum size for this database is the full quota for this origin, minus the current usage within this origin,
-    // except for the current usage of this database
-
-    OriginQuotaManager& manager(DatabaseTracker::tracker().originQuotaManager());
-    Locker<OriginQuotaManager> locker(manager);
-
-    return DatabaseTracker::tracker().quotaForOrigin(m_securityOrigin.get()) - manager.diskUsage(m_securityOrigin.get()) + databaseSize();
+    return DatabaseTracker::tracker().getMaxSizeForDatabase(this);
 }
 
 void Database::disableAuthorizer()
@@ -647,9 +639,13 @@ void Database::setExpectedVersion(const String& version)
     updateGuidVersionMap(m_guid, version);
 }
 
-PassRefPtr<SecurityOrigin> Database::securityOriginCopy() const
+SecurityOrigin* Database::securityOrigin() const
 {
-    return m_securityOrigin->threadsafeCopy();
+    if (isMainThread())
+        return m_mainThreadSecurityOrigin.get();
+    if (currentThread() == document()->databaseThread()->getThreadID())
+        return m_databaseThreadSecurityOrigin.get();
+    return 0;
 }
 
 String Database::stringIdentifier() const
@@ -658,6 +654,23 @@ String Database::stringIdentifier() const
     return m_name.threadsafeCopy();
 }
 
+String Database::displayName() const
+{
+    // Return a deep copy for ref counting thread safety
+    return m_displayName.threadsafeCopy();
+}
+
+unsigned long Database::estimatedSize() const
+{
+    return m_estimatedSize;
+}
+
+String Database::fileName() const
+{
+    // Return a deep copy for ref counting thread safety
+    return m_filename.threadsafeCopy();
+}
+
 #endif
 
 }
diff --git a/WebCore/storage/Database.h b/WebCore/storage/Database.h
index b850686..098845c 100644
--- a/WebCore/storage/Database.h
+++ b/WebCore/storage/Database.h
@@ -89,8 +89,11 @@ public:
     Vector<String> tableNames();
 
     Document* document() const { return m_document.get(); }
-    PassRefPtr<SecurityOrigin> securityOriginCopy() const;
+    SecurityOrigin* securityOrigin() const;
     String stringIdentifier() const;
+    String displayName() const;
+    unsigned long estimatedSize() const;
+    String fileName() const;
 
     bool getVersionFromDatabase(String&);
     bool setVersionInDatabase(const String&);
@@ -121,7 +124,8 @@ public:
     SQLTransactionCoordinator* transactionCoordinator() const;
 
 private:
-    Database(Document* document, const String& name, const String& expectedVersion);
+    Database(Document* document, const String& name, const String& expectedVersion,
+             const String& displayName, unsigned long estimatedSize);
 
     bool openAndVerifyVersion(ExceptionCode&);
 
@@ -136,10 +140,13 @@ private:
     static void deliverPendingCallback(void*);
 
     RefPtr<Document> m_document;
-    RefPtr<SecurityOrigin> m_securityOrigin;
+    RefPtr<SecurityOrigin> m_mainThreadSecurityOrigin;
+    RefPtr<SecurityOrigin> m_databaseThreadSecurityOrigin;
     String m_name;
     int m_guid;
     String m_expectedVersion;
+    String m_displayName;
+    unsigned long long m_estimatedSize;
     String m_filename;
 
     bool m_deleted;
@@ -152,7 +159,7 @@ private:
     RefPtr<DatabaseAuthorizer> m_databaseAuthorizer;
 
 #ifndef NDEBUG
-    String databaseDebugName() const { return m_securityOrigin->toString() + "::" + m_name; }
+    String databaseDebugName() const { return m_mainThreadSecurityOrigin->toString() + "::" + m_name; }
 #endif
 };
 
diff --git a/WebCore/storage/DatabaseTracker.cpp b/WebCore/storage/DatabaseTracker.cpp
index 265cd0d..c0c4242 100644
--- a/WebCore/storage/DatabaseTracker.cpp
+++ b/WebCore/storage/DatabaseTracker.cpp
@@ -33,6 +33,7 @@
 
 #include "ChromeClient.h"
 #include "Database.h"
+#include "DatabaseThread.h"
 #include "DatabaseTrackerClient.h"
 #include "Document.h"
 #include "Logging.h"
@@ -182,6 +183,16 @@ bool DatabaseTracker::hasEntryForDatabase(SecurityOrigin* origin, const String&
     return statement.step() == SQLResultRow;
 }
 
+unsigned long long DatabaseTracker::getMaxSizeForDatabase(const Database* database)
+{
+    ASSERT(currentThread() == database->document()->databaseThread()->getThreadID());
+    // The maximum size for a database is the full quota for its origin, minus the current usage within the origin,
+    // plus the current usage of the given database
+    Locker<OriginQuotaManager> locker(originQuotaManager());
+    SecurityOrigin* origin = database->securityOrigin();
+    return quotaForOrigin(origin) - originQuotaManager().diskUsage(origin) + SQLiteFileSystem::getDatabaseFileSize(database->fileName());
+}
+
 String DatabaseTracker::originPath(SecurityOrigin* origin) const
 {
     ASSERT(currentThread() == m_thread);
@@ -409,13 +420,11 @@ void DatabaseTracker::addOpenDatabase(Database* database)
     if (!m_openDatabaseMap)
         m_openDatabaseMap.set(new DatabaseOriginMap);
 
-    RefPtr<SecurityOrigin> origin(database->securityOriginCopy());
     String name(database->stringIdentifier());
-
-    DatabaseNameMap* nameMap = m_openDatabaseMap->get(origin);
+    DatabaseNameMap* nameMap = m_openDatabaseMap->get(database->securityOrigin());
     if (!nameMap) {
         nameMap = new DatabaseNameMap;
-        m_openDatabaseMap->set(origin, nameMap);
+        m_openDatabaseMap->set(database->securityOrigin(), nameMap);
     }
 
     DatabaseSet* databaseSet = nameMap->get(name);
@@ -441,10 +450,8 @@ void DatabaseTracker::removeOpenDatabase(Database* database)
         return;
     }
 
-    RefPtr<SecurityOrigin> origin(database->securityOriginCopy());
     String name(database->stringIdentifier());
-
-    DatabaseNameMap* nameMap = m_openDatabaseMap->get(origin);
+    DatabaseNameMap* nameMap = m_openDatabaseMap->get(database->securityOrigin());
     if (!nameMap) {
         ASSERT_NOT_REACHED();
         return;
@@ -469,7 +476,7 @@ void DatabaseTracker::removeOpenDatabase(Database* database)
     if (!nameMap->isEmpty())
         return;
 
-    m_openDatabaseMap->remove(origin);
+    m_openDatabaseMap->remove(database->securityOrigin());
     delete nameMap;
 }
 
diff --git a/WebCore/storage/DatabaseTracker.h b/WebCore/storage/DatabaseTracker.h
index 2f6e06d..85e4858 100644
--- a/WebCore/storage/DatabaseTracker.h
+++ b/WebCore/storage/DatabaseTracker.h
@@ -86,6 +86,8 @@ public:
 
     bool hasEntryForOrigin(SecurityOrigin*);
 
+    unsigned long long getMaxSizeForDatabase(const Database*);
+
 private:
     DatabaseTracker();
 
diff --git a/WebCore/storage/OriginQuotaManager.cpp b/WebCore/storage/OriginQuotaManager.cpp
index 20bb34d..30b3271 100644
--- a/WebCore/storage/OriginQuotaManager.cpp
+++ b/WebCore/storage/OriginQuotaManager.cpp
@@ -104,8 +104,7 @@ void OriginQuotaManager::markDatabase(Database* database)
 {
     ASSERT(database);
     ASSERT(m_usageRecordGuardLocked);
-    RefPtr<SecurityOrigin> origin = database->securityOriginCopy();
-    OriginUsageRecord* usageRecord = m_usageMap.get(origin);
+    OriginUsageRecord* usageRecord = m_usageMap.get(database->securityOrigin());
     ASSERT(usageRecord);
 
     usageRecord->markDatabase(database->stringIdentifier());
diff --git a/WebCore/storage/SQLTransaction.cpp b/WebCore/storage/SQLTransaction.cpp
index 149b384..165685b 100644
--- a/WebCore/storage/SQLTransaction.cpp
+++ b/WebCore/storage/SQLTransaction.cpp
@@ -40,7 +40,6 @@
 #include "Logging.h"
 #include "Page.h"
 #include "PlatformString.h"
-#include "SecurityOrigin.h"
 #include "Settings.h"
 #include "SQLError.h"
 #include "SQLiteTransaction.h"
diff --git a/WebCore/storage/SQLTransactionClient.cpp b/WebCore/storage/SQLTransactionClient.cpp
index e72f5ed..5918bd8 100644
--- a/WebCore/storage/SQLTransactionClient.cpp
+++ b/WebCore/storage/SQLTransactionClient.cpp
@@ -47,7 +47,7 @@ void SQLTransactionClient::didCommitTransaction(SQLTransaction* transaction)
     ASSERT(currentThread() == transaction->database()->document()->databaseThread()->getThreadID());
     Database* database = transaction->database();
     DatabaseTracker::tracker().scheduleNotifyDatabaseChanged(
-        database->document()->securityOrigin(), database->stringIdentifier());
+        database->securityOrigin(), database->stringIdentifier());
 }
 
 void SQLTransactionClient::didExecuteStatement(SQLTransaction* transaction)
@@ -65,11 +65,9 @@ bool SQLTransactionClient::didExceedQuota(SQLTransaction* transaction)
     Page* page = database->document()->page();
     ASSERT(page);
 
-    RefPtr<SecurityOrigin> origin = database->securityOriginCopy();
-
-    unsigned long long currentQuota = DatabaseTracker::tracker().quotaForOrigin(origin.get());
+    unsigned long long currentQuota = DatabaseTracker::tracker().quotaForOrigin(database->securityOrigin());
     page->chrome()->client()->exceededDatabaseQuota(database->document()->frame(), database->stringIdentifier());
-    unsigned long long newQuota = DatabaseTracker::tracker().quotaForOrigin(origin.get());
+    unsigned long long newQuota = DatabaseTracker::tracker().quotaForOrigin(database->securityOrigin());
     return (newQuota > currentQuota);
 }
 

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list