2011-05-20 Michael Nordman <michaeln@google.com>
authormichaeln@google.com <michaeln@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 May 2011 23:48:46 +0000 (23:48 +0000)
committermichaeln@google.com <michaeln@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 May 2011 23:48:46 +0000 (23:48 +0000)
        Reviewed by Darin Fisher.

        [Chromium] Support the new webkit apis so the WebDatabase system participates
        in the unified quota management system.
        https://bugs.webkit.org/show_bug.cgi?id=60985

        No change in functionality, no new tests.

        * platform/chromium/PlatformBridge.h:
        * storage/chromium/QuotaTracker.cpp:
        (WebCore::QuotaTracker::getDatabaseSizeAndSpaceAvailableToOrigin):
        (WebCore::QuotaTracker::updateDatabaseSize):
        (WebCore::QuotaTracker::updateSpaceAvailableToOrigin):
        (WebCore::QuotaTracker::resetSpaceAvailableToOrigin):
        * storage/chromium/QuotaTracker.h:
2011-05-20  Michael Nordman  <michaeln@google.com>

        Reviewed by Darin Fisher.

        Changes to allow the WebDatabase system to participate in Chrome's unified quota
        management system. Now that changes outside of the database system affect the space
        available to the database system, we need new ways of getting the limit to renderers.

        Split WebDatabase::updateDatabaseSizeAndSpaceAvailable() into three methods.
        - WebDatabase::updateDatababaseSize()
        - WebDatabase::updateSpaceAvailable()
        - WebDatabase::resetSpaceAvailable()
        The WebDatabase methods are used to 'push' size and space available info into renderers.
        The space available can change independently of a database having changed size.

        Also provide a means for the renderer to 'pull' the space available from the main
        process if that value has not been pushed into it.
        - WebCore::PlatformBridge::databaseGetSpaceAvailableForOrigin()
        - WebKit::WebKitClient::databaseGetSpaceAvailableForOrigin()

        https://bugs.webkit.org/show_bug.cgi?id=60985

        * public/WebDatabase.h:
        * public/WebKitClient.h:
        (WebKit::WebKitClient::databaseGetSpaceAvailableForOrigin):
        * src/PlatformBridge.cpp:
        (WebCore::PlatformBridge::databaseGetSpaceAvailableForOrigin):
        * src/WebDatabase.cpp:
        (WebKit::WebDatabase::updateDatabaseSize):
        (WebKit::WebDatabase::updateSpaceAvailable):
        (WebKit::WebDatabase::resetSpaceAvailable):

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

Source/WebCore/ChangeLog
Source/WebCore/platform/chromium/PlatformBridge.h
Source/WebCore/storage/chromium/QuotaTracker.cpp
Source/WebCore/storage/chromium/QuotaTracker.h
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/public/WebDatabase.h
Source/WebKit/chromium/public/WebKitClient.h
Source/WebKit/chromium/src/PlatformBridge.cpp
Source/WebKit/chromium/src/WebDatabase.cpp

index 1ebeaa1..bf0ec41 100644 (file)
@@ -1,3 +1,21 @@
+2011-05-20  Michael Nordman  <michaeln@google.com>
+
+        Reviewed by Darin Fisher.
+
+        [Chromium] Support the new webkit apis so the WebDatabase system participates
+        in the unified quota management system.
+        https://bugs.webkit.org/show_bug.cgi?id=60985
+
+        No change in functionality, no new tests.
+
+        * platform/chromium/PlatformBridge.h:
+        * storage/chromium/QuotaTracker.cpp:
+        (WebCore::QuotaTracker::getDatabaseSizeAndSpaceAvailableToOrigin):
+        (WebCore::QuotaTracker::updateDatabaseSize):
+        (WebCore::QuotaTracker::updateSpaceAvailableToOrigin):
+        (WebCore::QuotaTracker::resetSpaceAvailableToOrigin):
+        * storage/chromium/QuotaTracker.h:
+
 2011-05-20  Andy Estes  <aestes@apple.com>
 
         Reviewed by Darin Adler.
index 87ae1b3..96bcfd9 100644 (file)
@@ -168,6 +168,8 @@ public:
     static long databaseGetFileAttributes(const String& vfsFileName);
     // Returns the size of the DB file
     static long long databaseGetFileSize(const String& vfsFileName);
+    // Returns the space available for the origin
+    static long long databaseGetSpaceAvailableForOrigin(const String& originIdentifier);
 
     // IndexedDB ----------------------------------------------------------
     static PassRefPtr<IDBFactoryBackendInterface> idbFactory();
index 3f48682..95087fc 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "config.h"
 #include "QuotaTracker.h"
+#include "PlatformBridge.h"
 
 #if ENABLE(DATABASE)
 
@@ -47,26 +48,45 @@ void QuotaTracker::getDatabaseSizeAndSpaceAvailableToOrigin(
     const String& originIdentifier, const String& databaseName,
     unsigned long long* databaseSize, unsigned long long* spaceAvailable)
 {
-    MutexLocker lockData(m_dataGuard);
-    ASSERT(m_databaseSizes.contains(originIdentifier));
-    HashMap<String, SizeMap>::const_iterator it = m_databaseSizes.find(originIdentifier);
-    ASSERT(it->second.contains(databaseName));
-    *databaseSize = it->second.get(databaseName);
+    // Extra scope to unlock prior to potentially calling PlatformBridge.
+    {
+        MutexLocker lockData(m_dataGuard);
+        ASSERT(m_databaseSizes.contains(originIdentifier));
+        HashMap<String, SizeMap>::const_iterator it = m_databaseSizes.find(originIdentifier);
+        ASSERT(it->second.contains(databaseName));
+        *databaseSize = it->second.get(databaseName);
+
+        if (m_spaceAvailableToOrigins.contains(originIdentifier)) {
+            *spaceAvailable = m_spaceAvailableToOrigins.get(originIdentifier);
+            return;
+        }
+    }
 
-    ASSERT(m_spaceAvailableToOrigins.contains(originIdentifier));
-    *spaceAvailable = m_spaceAvailableToOrigins.get(originIdentifier);
+    // The embedder hasn't pushed this value to us, so we pull it as needed.
+    *spaceAvailable = PlatformBridge::databaseGetSpaceAvailableForOrigin(originIdentifier);
 }
 
-void QuotaTracker::updateDatabaseSizeAndSpaceAvailableToOrigin(
+void QuotaTracker::updateDatabaseSize(
     const String& originIdentifier, const String& databaseName,
-    unsigned long long databaseSize, unsigned long long spaceAvailable)
+    unsigned long long databaseSize)
 {
     MutexLocker lockData(m_dataGuard);
-    m_spaceAvailableToOrigins.set(originIdentifier, spaceAvailable);
     HashMap<String, SizeMap>::iterator it = m_databaseSizes.add(originIdentifier, SizeMap()).first;
     it->second.set(databaseName, databaseSize);
 }
 
+void QuotaTracker::updateSpaceAvailableToOrigin(const String& originIdentifier, unsigned long long spaceAvailable)
+{
+    MutexLocker lockData(m_dataGuard);
+    m_spaceAvailableToOrigins.set(originIdentifier, spaceAvailable);
 }
 
+void QuotaTracker::resetSpaceAvailableToOrigin(const String& originIdentifier)
+{
+    MutexLocker lockData(m_dataGuard);
+    m_spaceAvailableToOrigins.remove(originIdentifier);
+}
+
+} // namespace WebCore
+
 #endif // ENABLE(DATABASE)
index 774475e..fcf49e5 100644 (file)
@@ -47,9 +47,11 @@ public:
     void getDatabaseSizeAndSpaceAvailableToOrigin(
         const String& originIdentifier, const String& databaseName,
         unsigned long long* databaseSize, unsigned long long* spaceAvailable);
-    void updateDatabaseSizeAndSpaceAvailableToOrigin(
+    void updateDatabaseSize(
         const String& originIdentifier, const String& databaseName,
-        unsigned long long databaseSize, unsigned long long spaceAvailable);
+        unsigned long long databaseSize);
+    void updateSpaceAvailableToOrigin(const String& originIdentifier, unsigned long long spaceAvailable);
+    void resetSpaceAvailableToOrigin(const String& originIdentifier);
 
 private:
     QuotaTracker() { }
index 3b93ffe..1327c91 100644 (file)
@@ -1,3 +1,35 @@
+2011-05-20  Michael Nordman  <michaeln@google.com>
+
+        Reviewed by Darin Fisher.
+
+        Changes to allow the WebDatabase system to participate in Chrome's unified quota
+        management system. Now that changes outside of the database system affect the space
+        available to the database system, we need new ways of getting the limit to renderers.
+
+        Split WebDatabase::updateDatabaseSizeAndSpaceAvailable() into three methods.
+        - WebDatabase::updateDatababaseSize()
+        - WebDatabase::updateSpaceAvailable()
+        - WebDatabase::resetSpaceAvailable()
+        The WebDatabase methods are used to 'push' size and space available info into renderers.
+        The space available can change independently of a database having changed size.
+
+        Also provide a means for the renderer to 'pull' the space available from the main
+        process if that value has not been pushed into it.
+        - WebCore::PlatformBridge::databaseGetSpaceAvailableForOrigin()
+        - WebKit::WebKitClient::databaseGetSpaceAvailableForOrigin()
+
+        https://bugs.webkit.org/show_bug.cgi?id=60985
+
+        * public/WebDatabase.h:
+        * public/WebKitClient.h:
+        (WebKit::WebKitClient::databaseGetSpaceAvailableForOrigin):
+        * src/PlatformBridge.cpp:
+        (WebCore::PlatformBridge::databaseGetSpaceAvailableForOrigin):
+        * src/WebDatabase.cpp:
+        (WebKit::WebDatabase::updateDatabaseSize):
+        (WebKit::WebDatabase::updateSpaceAvailable):
+        (WebKit::WebDatabase::resetSpaceAvailable):
+
 2011-05-20  Simon Fraser  <simon.fraser@apple.com>
 
         Reviewed by Sam Weinig.
index 0a5d4f8..767f198 100644 (file)
@@ -52,11 +52,20 @@ public:
     WEBKIT_API static WebDatabaseObserver* observer();
 
     WEBKIT_API static void updateDatabaseSize(
-        const WebString& originIdentifier, const WebString& databaseName,
-        unsigned long long databaseSize, unsigned long long spaceAvailable);
+        const WebString& originIdentifier, const WebString& name, long long size);
+    WEBKIT_API static void updateSpaceAvailable(
+        const WebString& originIdentifier, long long spaceAvailable);
+    WEBKIT_API static void resetSpaceAvailable(
+        const WebString& originIdentifier);
+
     WEBKIT_API static void closeDatabaseImmediately(
         const WebString& originIdentifier, const WebString& databaseName);
 
+    // DEPRECATED - to be removed soon
+    WEBKIT_API static void updateDatabaseSize(
+        const WebString& originIdentifier, const WebString& databaseName,
+        long long databaseSize, long long spaceAvailable);
+
 #if WEBKIT_IMPLEMENTATION
     WebDatabase(const WebCore::AbstractDatabase*);
 #endif
index 838e685..1a74648 100644 (file)
@@ -139,6 +139,8 @@ public:
     // Returns the size of the given database file
     virtual long long databaseGetFileSize(const WebString& vfsFileName) { return 0; }
 
+    // Returns the space available for the given origin
+    virtual long long databaseGetSpaceAvailableForOrigin(const WebKit::WebString& originIdentifier) { return 0; }
 
     // Indexed Database ----------------------------------------------------
 
index 23de57d..e5920a9 100644 (file)
@@ -500,6 +500,11 @@ long long PlatformBridge::databaseGetFileSize(const String& vfsFileName)
     return webKitClient()->databaseGetFileSize(WebString(vfsFileName));
 }
 
+long long PlatformBridge::databaseGetSpaceAvailableForOrigin(const String& originIdentifier)
+{
+    return webKitClient()->databaseGetSpaceAvailableForOrigin(originIdentifier);
+}
+
 // Indexed Database -----------------------------------------------------------
 
 PassRefPtr<IDBFactoryBackendInterface> PlatformBridge::idbFactory()
index 561d7c4..3053daa 100644 (file)
@@ -92,13 +92,35 @@ WebDatabaseObserver* WebDatabase::observer()
     return databaseObserver;
 }
 
+void WebDatabase::updateDatabaseSize(const WebString& originIdentifier, const WebString& name, long long size)
+{
+#if ENABLE(DATABASE)
+    QuotaTracker::instance().updateDatabaseSize(originIdentifier, name, size);
+#endif // ENABLE(DATABASE)
+}
+
+void WebDatabase::updateSpaceAvailable(const WebString& originIdentifier, long long spaceAvailable)
+{
+#if ENABLE(DATABASE)
+    QuotaTracker::instance().updateSpaceAvailableToOrigin(originIdentifier, spaceAvailable);
+#endif // ENABLE(DATABASE)
+}
+
+void WebDatabase::resetSpaceAvailable(const WebString& originIdentifier)
+{
+#if ENABLE(DATABASE)
+    QuotaTracker::instance().resetSpaceAvailableToOrigin(originIdentifier);
+#endif // ENABLE(DATABASE)
+}
+
+// FIXME: This is deprecated, delete after rolling DEPs and chrome is using the new methods.
 void WebDatabase::updateDatabaseSize(
     const WebString& originIdentifier, const WebString& databaseName,
-    unsigned long long databaseSize, unsigned long long spaceAvailable)
+    long long databaseSize, long long spaceAvailable)
 {
 #if ENABLE(DATABASE)
-    WebCore::QuotaTracker::instance().updateDatabaseSizeAndSpaceAvailableToOrigin(
-        originIdentifier, databaseName, databaseSize, spaceAvailable);
+    updateDatabaseSize(originIdentifier, databaseName, databaseSize);
+    updateSpaceAvailable(originIdentifier, spaceAvailable);
 #endif // ENABLE(DATABASE)
 }